Hi,
I had a first stab today at determining the number of available cores on
a Mac. The methods for this are outlined here:
http://stackoverflow.com/questions/150355/programmatically-find-the-number-of-cores-on-a-machine
There are two methods for Mac, either using sysconf() or sysctl(). With
the current default settings on the trunk both methods fail. The
sysconf() method fails because _SC_NPROCESSORS_ONLN is not defined,
while the second methods drowns in compilation errors:
cirrus:source peter$ g++ -W -Wall -c cpu.cpp
In file included from /usr/include/sys/sysctl.h:83,
from cpu.cpp:36:
/usr/include/sys/ucred.h:91: error: 'u_long' does not name a type
/usr/include/sys/ucred.h:133: error: 'u_int' does not name a type
In file included from /usr/include/sys/sysctl.h:84,
from cpu.cpp:36:
/usr/include/sys/proc.h:111: error: 'u_int' does not name a type
/usr/include/sys/proc.h:116: error: 'u_int' does not name a type
/usr/include/sys/proc.h:117: error: 'u_int' does not name a type
/usr/include/sys/proc.h:131: error: 'u_char' does not name a type
/usr/include/sys/proc.h:132: error: 'u_char' does not name a type
/usr/include/sys/proc.h:137: error: 'u_short' does not name a type
/usr/include/sys/proc.h:138: error: 'u_short' does not name a type
In file included from cpu.cpp:36:
/usr/include/sys/sysctl.h:779: error: 'u_int' has not been declared
... etc...
However, if I remove the "#define _POSIX_SOURCE" in cdstd.h both methods
work perfectly fine and detect the number of cores correctly.
Either POSIX is not properly supported on Mac, or we are doing something
wrong here. How should we proceed here?
Cheers,
Peter.
--
Peter van Hoof
Royal Observatory of Belgium
Ringlaan 3
1180 Brussel
Belgium
http://homepage.oma.be/pvh