Skip to content

Commit

Permalink
KMP_HW_SUBSET vs KMP_PLACE_THREADS rival envirables fix
Browse files Browse the repository at this point in the history
If both KMP_HW_SUBSET and KMP_PLACE_THREADS are set and KMP_PLACE_THREADS gets
parsed first, then the current environment variable parser rejects both and
neither get used. This patch uses the rivals mechanism that is used for other
environment variable groups (e.g., KMP_STACKSIZE, GOMP_STACKSIZE, OMP_STACKSIZE).
If both are set, then it tells the user that it is ignoring KMP_PLACE_THREADS in
favor of KMP_HW_SUBSET. The message about deprecating KMP_PLACE_THREADS when it
is set is still printed regardless.

Differential Revision: https://reviews.llvm.org/D38292

llvm-svn: 315091
  • Loading branch information
jpeyton52 committed Oct 6, 2017
1 parent 30df03b commit 3f850bf
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions openmp/runtime/src/kmp_settings.cpp
Expand Up @@ -4114,14 +4114,13 @@ static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
void *data) {
// Value example: 1s,5c@3,2T
// Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
static int parsed = 0;
kmp_setting_t **rivals = (kmp_setting_t **)data;
if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
if (parsed == 1) {
return; // already parsed KMP_HW_SUBSET
}
}
parsed = 1;
if (__kmp_stg_check_rivals(name, value, rivals)) {
return;
}

char *components[MAX_T_LEVEL];
char const *digits = "0123456789";
Expand Down Expand Up @@ -4731,6 +4730,24 @@ static void __kmp_stg_init(void) {
kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
}

{ // Initialize KMP_HW_SUBSET and KMP_PLACE_THREADS
// 1st priority
kmp_setting_t *kmp_hw_subset = __kmp_stg_find("KMP_HW_SUBSET");
// 2nd priority
kmp_setting_t *kmp_place_threads = __kmp_stg_find("KMP_PLACE_THREADS");

// !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
static kmp_setting_t *volatile rivals[3];
int i = 0;

rivals[i++] = kmp_hw_subset;
rivals[i++] = kmp_place_threads;
rivals[i++] = NULL;

kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
}

#if KMP_AFFINITY_SUPPORTED
{ // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
kmp_setting_t *kmp_affinity =
Expand Down

0 comments on commit 3f850bf

Please sign in to comment.