Re: getting processor numbers

Andrew Morton
2007-04-03T20:16:36Z

On Tue, 03 Apr 2007 09:54:46 -0700
Ulrich Drepper <drepper@redhat.com> wrote:

> More and more code depends on knowing the number of processors in the
> system to efficiently scale the code. E.g., in OpenMP it is used by
> default to determine how many threads to create. Creating more threads
> than there are processors/cores doesn't make sense.

but... It would be a mistake for an application to assume that it is
allowed to _use_ all the present CPUs. People can and do run applications
within cpusets, and under sched_setaffinity().

So I'd have thought that in general an application should be querying its
present affinity mask - something like sched_getaffinity()? That fixes the
CPU hotplug issues too, of course.

But we discussed this all a couple years back and it was decided that
sched_getaffinity() was unsuitable. I remember at the time not really
understanding why?