# Bug Report: Error in ProcessorCount() under linux

**URL:** https://discourse.cmake.org/t/bug-report-error-in-processorcount-under-linux/7123
**Category:** Development
**Tags:** os:linux
**Created:** [December 23, 2022, 3:40pm UTC](https://discourse.cmake.org/t/bug-report-error-in-processorcount-under-linux/7123 "2022-12-23T15:40:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![krefson](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@krefson](https://discourse.cmake.org/u/krefson)
#### Post date: [December 23, 2022, 3:40pm UTC](https://discourse.cmake.org/t/bug-report-error-in-processorcount-under-linux/7123/1 "2022-12-23T15:40:06Z")

</div>

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

```auto
$ 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.

```auto
$ OMP_NUM_THREADS=1 nproc --all
12

```

K.R.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 27, 2022, 10:24pm UTC](https://discourse.cmake.org/t/bug-report-error-in-processorcount-under-linux/7123/2 "2022-12-27T22:24:30Z")

</div>

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](https://gitlab.kitware.com/cmake/cmake/-/issues/new)
