Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determine number of cores



Ondrej Valik wrote:

>I need to detect number of cores per processor programmatically. I
>already tried:
>
>int procCount = 0;
>size_t length = sizeof(procCount);
>int error = sysctlbyname("hw.physicalcpu", &procCount, &length, NULL,
>0);
>
>with "hw.physicalcpu", "hw.logicalcpu", but I always got 4 on my
>MacPro.
>
>Also MPProcessors() returns 4.
>
>   Thanks in advance for any suggestions.
>       Valda

Running 'sysctl machdep' from the Terminal shows a couple of possible
values:

    machdep.cpu.logical_per_package: 2
    machdep.cpu.cores_per_package: 2

This is on a Mac Pro, where MPProcessorsScheduled returns 4.


If this is to cap a thread count, vs display/record this info, then the
best choice would be something like MPProcessorsScheduled.

Normally you wouldn't care how many cores vs CPUs are present, but you
probably want to use fewer threads if the user has some CPUs turned off.


-dair
___________________________________________________
mailto:email@hidden       http://www.refnum.com/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.