1 dnl ###########################################################################
3 dnl lc_CPUCORES - Check how to find out the number of online CPU cores
5 dnl Check how to find out the number of available CPU cores in the system.
6 dnl sysconf(_SC_NPROCESSORS_ONLN) works on most systems, except that BSDs
9 dnl ###########################################################################
11 dnl Author: Lasse Collin
13 dnl This file has been put into the public domain.
14 dnl You can do whatever you want with this file.
16 dnl ###########################################################################
17 AC_DEFUN([lc_CPUCORES], [
18 AC_MSG_CHECKING([how to detect the number of available CPU cores])
19 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
25 i = sysconf(_SC_NPROCESSORS_ONLN);
29 AC_DEFINE([HAVE_NCPU_SYSCONF], [1],
30 [Define to 1 if the number of available CPU cores can be
31 detected with sysconf(_SC_NPROCESSORS_ONLN).])
32 AC_MSG_RESULT([sysconf])
34 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
35 #include <sys/types.h>
36 #ifdef HAVE_SYS_PARAM_H
37 # include <sys/param.h>
39 #include <sys/sysctl.h>
43 int name[2] = { CTL_HW, HW_NCPU };
45 size_t cpus_size = sizeof(cpus);
46 sysctl(name, 2, &cpus, &cpus_size, NULL, NULL);
50 AC_DEFINE([HAVE_NCPU_SYSCTL], [1],
51 [Define to 1 if the number of available CPU cores can be
52 detected with sysctl().])
53 AC_MSG_RESULT([sysctl])
55 AC_MSG_RESULT([unknown])