diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index c3c487fbcd1..cfcc48aa3a7 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,22 @@ +2013-10-12 Jakub Jelinek + + PR libgomp/58691 + * config/linux/proc.c (gomp_cpuset_popcount): Add unused attribute + to check variable. + (gomp_init_num_threads): Move i variable declaration into + #ifdef CPU_ALLOC_SIZE block. + * config/linux/affinity.c (gomp_affinity_init_level): Test + gomp_places_list_len == 0 rather than gomp_places_list == 0 + when checking for topology reading error. + * team.c (gomp_team_start): Don't handle bind == omp_proc_bind_false. + * env.c (parse_affinity): Add ignore argument, if true, don't populate + gomp_places_list, only parse env var and always return false. + (parse_places_var): Likewise. Don't check gomp_global_icv.bind_var. + (initialize_env): Always parse OMP_PLACES and GOMP_CPU_AFFINITY env + vars, default to OMP_PROC_BIND=true if OMP_PROC_BIND wasn't specified + and either of these variables were parsed correctly into a places + list. + 2013-10-11 Thomas Schwinge Jakub Jelinek diff --git a/libgomp/config/linux/affinity.c b/libgomp/config/linux/affinity.c index 789cdce077d..bc5c9fcb656 100644 --- a/libgomp/config/linux/affinity.c +++ b/libgomp/config/linux/affinity.c @@ -309,7 +309,7 @@ gomp_affinity_init_level (int level, unsigned long count, bool quiet) fclose (f); } } - if (gomp_places_list == 0) + if (gomp_places_list_len == 0) { if (!quiet) gomp_error ("Error reading %s topology", diff --git a/libgomp/config/linux/proc.c b/libgomp/config/linux/proc.c index d4ae116e239..76616dd37a0 100644 --- a/libgomp/config/linux/proc.c +++ b/libgomp/config/linux/proc.c @@ -59,7 +59,7 @@ gomp_cpuset_popcount (unsigned long cpusetsize, cpu_set_t *cpusetp) size_t i; unsigned long ret = 0; extern int check[sizeof (cpusetp->__bits[0]) == sizeof (unsigned long int) - ? 1 : -1]; + ? 1 : -1] __attribute__((unused)); for (i = 0; i < cpusetsize / sizeof (cpusetp->__bits[0]); i++) { @@ -94,7 +94,6 @@ gomp_init_num_threads (void) gomp_cpusetp); if (ret == 0) { - unsigned long i; /* Count only the CPUs this process can use. */ gomp_global_icv.nthreads_var = gomp_cpuset_popcount (gomp_cpuset_size, gomp_cpusetp); @@ -102,6 +101,7 @@ gomp_init_num_threads (void) break; gomp_get_cpuset_size = gomp_cpuset_size; #ifdef CPU_ALLOC_SIZE + unsigned long i; for (i = gomp_cpuset_size * 8; i; i--) if (CPU_ISSET_S (i - 1, gomp_cpuset_size, gomp_cpusetp)) break; diff --git a/libgomp/env.c b/libgomp/env.c index 57997c5765c..75483385b80 100644 --- a/libgomp/env.c +++ b/libgomp/env.c @@ -548,7 +548,7 @@ parse_one_place (char **envp, bool *negatep, unsigned long *lenp, } static bool -parse_places_var (const char *name) +parse_places_var (const char *name, bool ignore) { char *env = getenv (name), *end; bool any_negate = false; @@ -604,6 +604,10 @@ parse_places_var (const char *name) if (*env != '\0') goto invalid; } + + if (ignore) + return false; + return gomp_affinity_init_level (level, count, false); } @@ -634,7 +638,7 @@ parse_places_var (const char *name) } while (1); - if (gomp_global_icv.bind_var == omp_proc_bind_false) + if (ignore) return false; gomp_places_list_len = 0; @@ -911,7 +915,7 @@ parse_wait_policy (void) present and it was successfully parsed. */ static bool -parse_affinity (void) +parse_affinity (bool ignore) { char *env, *end, *start; int pass; @@ -928,6 +932,9 @@ parse_affinity (void) env = start; if (pass == 1) { + if (ignore) + return false; + gomp_places_list_len = 0; gomp_places_list = gomp_affinity_alloc (count, true); if (gomp_places_list == NULL) @@ -995,6 +1002,7 @@ parse_affinity (void) { free (gomp_places_list); gomp_places_list = NULL; + return false; } return true; @@ -1183,14 +1191,34 @@ initialize_env (void) &gomp_nthreads_var_list, &gomp_nthreads_var_list_len)) gomp_global_icv.nthreads_var = gomp_available_cpus; - if (!parse_bind_var ("OMP_PROC_BIND", - &gomp_global_icv.bind_var, - &gomp_bind_var_list, - &gomp_bind_var_list_len)) - gomp_global_icv.bind_var = omp_proc_bind_false; - if (parse_places_var ("OMP_PLACES") - || parse_affinity () - || gomp_global_icv.bind_var) + bool ignore = false; + if (parse_bind_var ("OMP_PROC_BIND", + &gomp_global_icv.bind_var, + &gomp_bind_var_list, + &gomp_bind_var_list_len) + && gomp_global_icv.bind_var == omp_proc_bind_false) + ignore = true; + /* Make sure OMP_PLACES and GOMP_CPU_AFFINITY env vars are always + parsed if present in the environment. If OMP_PROC_BIND was set + explictly to false, don't populate places list though. If places + list was successfully set from OMP_PLACES, only parse but don't process + GOMP_CPU_AFFINITY. If OMP_PROC_BIND was not set in the environment, + default to OMP_PROC_BIND=true if OMP_PLACES or GOMP_CPU_AFFINITY + was successfully parsed into a places list, otherwise to + OMP_PROC_BIND=false. */ + if (parse_places_var ("OMP_PLACES", ignore)) + { + if (gomp_global_icv.bind_var == omp_proc_bind_false) + gomp_global_icv.bind_var = true; + ignore = true; + } + if (parse_affinity (ignore)) + { + if (gomp_global_icv.bind_var == omp_proc_bind_false) + gomp_global_icv.bind_var = true; + ignore = true; + } + if (gomp_global_icv.bind_var != omp_proc_bind_false) gomp_init_affinity (); wait_policy = parse_wait_policy (); if (!parse_spincount ("GOMP_SPINCOUNT", &gomp_spin_count_var)) diff --git a/libgomp/team.c b/libgomp/team.c index f4c47f7cba8..20f5f91750c 100644 --- a/libgomp/team.c +++ b/libgomp/team.c @@ -339,8 +339,6 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads, if (__builtin_expect (gomp_places_list != NULL, 0)) { - if (bind == omp_proc_bind_false) - bind = omp_proc_bind_true; /* Depending on chosen proc_bind model, set subpartition for the master thread and initialize helper variables P and optionally S, K and/or REST used by later place @@ -348,9 +346,6 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads, p = thr->place - 1; switch (bind) { - case omp_proc_bind_false: - bind = omp_proc_bind_true; - /* FALLTHRU */ case omp_proc_bind_true: case omp_proc_bind_close: if (nthreads > thr->ts.place_partition_len)