[Omp] Noob question about processors

Jakub Jelinek jakub at redhat.com
Thu Apr 27 02:58:28 PDT 2006


On Thu, Apr 27, 2006 at 10:33:54AM +0200, Terboven, Christian wrote:
> Scheduling depends on the OpenMP runtime library and the operating
> system.
> AFAIK the combination gcc/linux does not provide reliable mechanisms to
> bind threads to processors. You can expect that if your program is the
> only one running on that node only one thread at a time will run on
> given processor, but you will probably experience your threads changing
> the processors very often. This situation is different on Solaris (for
> example) where you can do explicit thread binding.

Not true, Linux provides
pthread_attr_setaffinity_np
pthread_attr_getaffinity_np
pthread_setaffinity_np
pthread_getaffinity_np
sched_setaffinity
sched_getaffinity
functions with which you can bind processes and/or threads explicitly
to chosen CPUs (and there is a taskset(1) program as well).
But, gomp doesn't use these interfaces ATM.
Seems SunPRO uses SUNW_MP_PROCBIND env variable for this, guess we could
do something similar (GOMP_MP_PROCBIND ?).

> > Finally I am wondering about the following, I would like
> > to compile my code on a couple of machines separately,
> > and the amount of threads I have depend on the amount
> > of real/virtual processors.  Is there a preprocessor
> > directive which obtains the amount of cpus?  In that way
> > I could do something like
> No, compilation is independent of the number of threads during runtime.
> There is _OPENMP defined during compilation if you enable OpenMP support
> in your compiler.

You could use something like
-DNUM_CPUS=`getconf _NPROCESSORS_ONLN`
on the command line.  But, generally depending on compiling sources on
the same machine where you intend to run them sounds like a bad idea.

	Jakub


More information about the Omp mailing list