/physical-cpu-count

Single C++ function cpu_count() gives physical CPU count across OS and hardware.

Primary LanguageC++BSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Physical CPU count

This code was adapted from Kitware KWSYS. More sophisticated approaches to Physical CPU count are available in projects including:

For projects that use MPI on a wide variety of computers running MacOS, Linux, and Windows we have found this single-file approach adequate to determine physical CPU count. For MacOS with Apple Silicon, we extract the count of the "fast" CPU cores.

Examples are given in app/ for C, C++ and Fortran calling the only public-facing function:

unsigned int cpu_count()

Build the examples and test:

cmake --workflow --preset default

Works with every compiler we tried including: GCC, Clang, Intel oneAPI, Visual Studio.