Hi! This patch handles OMP_PROC_BIND=true roughly as GOMP_CPU_AFFINITY=0-65535 if GOMP_CPU_AFFINITY isn't present in the environment, just slightly more efficiently during startup.
Tested on x86_64-linux, committed to gomp-3_1-branch. 2011-08-01 Jakub Jelinek <ja...@redhat.com> * env.c (initialize_env): Call parse_boolean with "OMP_PROC_BIND". If OMP_PROC_BIND=true, call gomp_init_affinity even if parse_affinity returned false. * config/linux/affinity.c (gomp_init_affinity): Handle gomp_cpu_affinity_len == 0. --- libgomp/env.c.jj 2011-07-11 17:32:52.000000000 +0200 +++ libgomp/env.c 2011-08-01 13:31:01.000000000 +0200 @@ -571,6 +571,7 @@ initialize_env (void) { unsigned long stacksize; int wait_policy; + bool bind_var = false; /* Do a compile time check that mkomp_h.pl did good job. */ omp_check_defines (); @@ -578,6 +579,7 @@ initialize_env (void) parse_schedule (); parse_boolean ("OMP_DYNAMIC", &gomp_global_icv.dyn_var); parse_boolean ("OMP_NESTED", &gomp_global_icv.nest_var); + parse_boolean ("OMP_PROC_BIND", &bind_var); parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var, true); parse_unsigned_long ("OMP_THREAD_LIMIT", &gomp_thread_limit_var, false); @@ -593,7 +595,7 @@ initialize_env (void) &gomp_nthreads_var_list, &gomp_nthreads_var_list_len)) gomp_global_icv.nthreads_var = gomp_available_cpus; - if (parse_affinity ()) + if (parse_affinity () || bind_var) gomp_init_affinity (); wait_policy = parse_wait_policy (); if (!parse_spincount ("GOMP_SPINCOUNT", &gomp_spin_count_var)) --- libgomp/config/linux/affinity.c.jj 2011-02-24 14:11:10.000000000 +0100 +++ libgomp/config/linux/affinity.c 2011-08-01 13:16:55.000000000 +0200 @@ -1,4 +1,5 @@ -/* Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +/* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 + Free Software Foundation, Inc. Contributed by Jakub Jelinek <ja...@redhat.com>. This file is part of the GNU OpenMP Library (libgomp). @@ -53,17 +54,36 @@ gomp_init_affinity (void) } CPU_ZERO (&cpusetnew); - for (widx = idx = 0; idx < gomp_cpu_affinity_len; idx++) - if (gomp_cpu_affinity[idx] < CPU_SETSIZE - && CPU_ISSET (gomp_cpu_affinity[idx], &cpuset)) - { - if (! CPU_ISSET (gomp_cpu_affinity[idx], &cpusetnew)) + if (gomp_cpu_affinity_len == 0) + { + unsigned long count = CPU_COUNT (&cpuset); + if (count >= 65536) + count = 65536; + gomp_cpu_affinity = malloc (count * sizeof (unsigned short)); + if (gomp_cpu_affinity == NULL) + { + gomp_error ("not enough memory to store CPU affinity list"); + return; + } + for (widx = idx = 0; widx < count && idx < 65536; idx++) + if (CPU_ISSET (idx, &cpuset)) { cpus++; - CPU_SET (gomp_cpu_affinity[idx], &cpusetnew); + gomp_cpu_affinity[widx++] = idx; } - gomp_cpu_affinity[widx++] = gomp_cpu_affinity[idx]; - } + } + else + for (widx = idx = 0; idx < gomp_cpu_affinity_len; idx++) + if (gomp_cpu_affinity[idx] < CPU_SETSIZE + && CPU_ISSET (gomp_cpu_affinity[idx], &cpuset)) + { + if (! CPU_ISSET (gomp_cpu_affinity[idx], &cpusetnew)) + { + cpus++; + CPU_SET (gomp_cpu_affinity[idx], &cpusetnew); + } + gomp_cpu_affinity[widx++] = gomp_cpu_affinity[idx]; + } if (widx == 0) { Jakub