[erlang-questions] logical_processors_available unknown on mac
Richard A. O'Keefe
ok@REDACTED
Thu Feb 18 23:54:42 CET 2016
On 19/02/16 12:46 am, Alin Popa wrote:
> On Wed, Feb 17, 2016 at 1:25 PM, Alin Popa <alin.popa@REDACTED
> <mailto:alin.popa@REDACTED>> wrote:
>
> I was recently trying to use
> `erlang:system_info(logical_processors_available).` on my mac,
> and getting `unknown` atom back; anyone has any idea if this
> is really by design?
>
| head
% sysctl -a | grep cpu | head
hw.ncpu = 4
hw.cpufrequency = 3200000000
to= 4
hw.ncpu: 4
hw.activecpu: 4
hw.physicalcpu: 4
hw.physicalcpu_max: 4
hw.logicalcpu: 4
hw.logicalcpu_max: 4
hw.cputype: 7
You can get at this with, e.g.,
int ans; size_t anslen = sizeof ans;
sysctlbyname("hw.activecpu", &ans, &anslen, 0, 0)
For that matter,
sysconf(_SC_NPROCESSORS_ONLN)
and
sysconf(_SC_NPROCESSORS_CONF)
are supported.
* hw.activecpu - The number of processors currently
available for executing threads.
* Use this number to determine the
number threads to create in SMP aware applications.
* This number can change when power
management modes are changed.
There are so many ways to count the number of CPUs on a Mac.
I suspect that hw.activecpu is the one to use; if it isn't, then
hw.logicalcpu may be the one.
More information about the erlang-questions
mailing list