[CMake] Determining number of cores on a system

Eric Noulard eric.noulard at gmail.com
Fri Nov 27 15:41:27 EST 2009


2009/11/27 James C. Sutherland <James.Sutherland at utah.edu>:
> Is there a way in CMake to determine the number of shared-memory cores on a system?

I don't know but I discover recently a tiny tool call hwloc
which may help for that:

http://www.open-mpi.org/projects/hwloc/

It is [unfortunately] using autotools :-) but claims [I did only test
it on Linux]
to be quite portable:

>>>>>>>>>>>>>>>>>
hwloc supports the following operating systems:

  * Linux (including old kernels not having sysfs topology information, with
 knowledge of cpusets, offline cpus, and Kerrighed support)
  * Solaris
  * AIX
  * Darwin
  * OSF/1 (aka. Tru64)
  * HP-UX
  * Windows
  * For other OSes, only the number of processors is available for now.
>>>>>>>>>>>>>>>>>

It may be used with CMake because:

1) there is a library/API
    http://www.open-mpi.org/projects/hwloc/doc/v0.9.2/#interface

2) The license is BSD-like
    http://www.open-mpi.org/projects/hwloc/license.php

However I don't if it worth a new feature in CMake?
execute_process(.. hwloc-ls...) + string(...)  may do the job.


-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list