Bug Report: Error in ProcessorCount() under linux

There is a small mistake in the implementation of ProcessorCount() under linux.

By default the linux implementation calls the command-line program “nproc” to determine the number of cores available. However “nproc’s” behaviour depends on the value of environment variable OMP_NUM_THREADS. So for example

$ nproc
12
$ OMP_NUM_THREADS=1 nproc
1

For determining the run-time number of cores, depending on the build configuration-time value of this variable is certainly not appropriate. And an OpenMP variable ought not to affect the cores available for MPI or process concurrency. (Also it is inconsistent with the other mechanisms such as schedtool. )

I suggest that the invocation be modified to add the “–all” flag.

$ OMP_NUM_THREADS=1 nproc --all
12

K.R.

That does look like a potential bug. Could you please open an issue in our issue tracker for this? Someone more familiar with that part of CMake’s logic will need to take a look at it.

https://gitlab.kitware.com/cmake/cmake/-/issues/new