Processor Cores

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
jsgroby
Posts: 83
Joined: Mon Mar 24, 2014 12:26 am
Location: Glen Carbon, IL USA

Processor Cores

Post by jsgroby »

I am using the following code to detect the number of processor cores:

int numofcpus = sysconf(_SC_NPROCESSORS_ONLN)

This is supposed to reveal the number of logical cpus. So, in my dev machine I have a 3.0Ghz Intel Core i7 and this code states I have 4 cpus. My OS tells me I have two cores, but I think I read somewhere that each core is treated as two logical cpus, thus the 4 should be correct even though the OS says 2. Does that sound right?

I am going to compile on my Windows 8.1 machine and see what that says as well.

Dev machines operating system is OS X Mavericks 10.9.4

Thanks
Jeff
syzygy
Posts: 5563
Joined: Tue Feb 28, 2012 11:56 pm

Re: Processor Cores

Post by syzygy »

A logical core is not a physical processor core.

If your OS is not broken, then you have two physical cores. With an i7 this seems only possible if it is a relatively old (2010) mobile "Arrandale" cpu. However these do not go faster than 2.66 Ghz (maybe turboboost can make them reach 3.0 Ghz, I am not sure).

With HT enabled in the BIOS, that means you have four logical cores.

You first need to understand the difference and then ask yourself what you want to know:
- number of physical cores, or
- number of logical cores.

The difference is pretty significant. Which number you want to know will depend on the application. For a chess engine you will typically want to know the number of physical cores.

sysconf() is a Unix thing, so won't compile on Windows.
User avatar
jsgroby
Posts: 83
Joined: Mon Mar 24, 2014 12:26 am
Location: Glen Carbon, IL USA

Re: Processor Cores

Post by jsgroby »

syzygy wrote:A logical core is not a physical processor core.

If your OS is not broken, then you have two physical cores. With an i7 this seems only possible if it is a relatively old (2010) mobile "Arrandale" cpu. However these do not go faster than 2.66 Ghz (maybe turboboost can make them reach 3.0 Ghz, I am not sure).

With HT enabled in the BIOS, that means you have four logical cores.

You first need to understand the difference and then ask yourself what you want to know:
- number of physical cores, or
- number of logical cores.

The difference is pretty significant. Which number you want to know will depend on the application. For a chess engine you will typically want to know the number of physical cores.

sysconf() is a Unix thing, so won't compile on Windows.
Now I am confused as to why sysconf is reporting 4 cores, here is what the Operating System is reporting:

Model Name: MacBook Pro
Model Identifier: MacBookPro10,2
Processor Name: Intel Core i7
Processor Speed: 3 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache (per Core): 256 KB
L3 Cache: 4 MB
Memory: 8 GB
Boot ROM Version: MBP102.0106.B03
SMC Version (system): 2.6f59
Serial Number (system): C2QKV00FFGN5
Hardware UUID: 439E419D-5CB7-5707-9F48-992D46CC1046
Sudden Motion Sensor:
State: Enabled

Here is what MacTracker says about my machine:

OVERVIEW

Introduced February 2013
Discontinued October 2013
Model Identifier MacBookPro10,2
Model Number A1425
EMC 2672
Order Number ME662LL/A (2.6 GHz with 256 GB storage)
Initial Price $1,699 (2.6 GHz with 256 GB storage)
Support Status Supported
Case Precision aluminum unibody
Weight and Dimensions 3.57 lbs., 0.75" H x 12.35" W x 8.62" D
PROCESSOR

Processor Intel Core i5 or Core i7 (3230M, 3540M) ("Ivy Bridge")
Processor Speed 2.6 GHz (Core i5) or 3.0 GHz (Core i7)
Architecture 64-bit
Number of Cores 2
Cache 3 MB (2.6 GHz) 4 MB (3.0 GHz) L3
System Bus Intel Direct Media Interface (DMI) at 5 GT/s
STORAGE AND MEDIA

Storage 256, 512, or 768 GB flash storage
Media None
KEYBOARD AND TRACKPAD

Trackpad Multi-Touch trackpad
Keyboard Built-in full-size backlit with 78 (U.S.) or 79 (ISO) keys, incl. 12 function and 4 arrow

Is there a better, more acceptable way to determine number of cores for both windows and unix or will I have to do one thing if win32 is defined and another for unix?

Thanks


Jeff
User avatar
jsgroby
Posts: 83
Joined: Mon Mar 24, 2014 12:26 am
Location: Glen Carbon, IL USA

Re: Processor Cores

Post by jsgroby »

I have also followed this and the results are still 4 cores.

So why does the machine report 2 cores in the OS and in MacTracker? Do I have a freak machine?

http://stackoverflow.com/questions/1715 ... n-mac-os-x
zullil
Posts: 6442
Joined: Tue Jan 09, 2007 12:31 am
Location: PA USA
Full name: Louis Zulli

Re: Processor Cores

Post by zullil »

jsgroby wrote:I have also followed this and the results are still 4 cores.

So why does the machine report 2 cores in the OS and in MacTracker? Do I have a freak machine?

http://stackoverflow.com/questions/1715 ... n-mac-os-x
You have one Intel Core i7 cpu. That CPU has two physical cores. Unless you managed to disable hyperthreading, each physical core amounts to two logical cores.

1 CPU, 2 physical cores, 4 logical cores (unless HT is disabled, which used to be hard to manage on a Mac).
User avatar
jsgroby
Posts: 83
Joined: Mon Mar 24, 2014 12:26 am
Location: Glen Carbon, IL USA

Re: Processor Cores

Post by jsgroby »

zullil wrote:
jsgroby wrote:I have also followed this and the results are still 4 cores.

So why does the machine report 2 cores in the OS and in MacTracker? Do I have a freak machine?

http://stackoverflow.com/questions/1715 ... n-mac-os-x
You have one Intel Core i7 cpu. That CPU has two physical cores. Unless you managed to disable hyperthreading, each physical core amounts to two logical cores.

1 CPU, 2 physical cores, 4 logical cores (unless HT is disabled, which used to be hard to manage on a Mac).
Thank you, and from what I understand, the two PHYSICAL cores are the ones that matter from a multiprocessor point of view, right?
zullil
Posts: 6442
Joined: Tue Jan 09, 2007 12:31 am
Location: PA USA
Full name: Louis Zulli

Re: Processor Cores

Post by zullil »

jsgroby wrote:
zullil wrote:
jsgroby wrote:I have also followed this and the results are still 4 cores.

So why does the machine report 2 cores in the OS and in MacTracker? Do I have a freak machine?

http://stackoverflow.com/questions/1715 ... n-mac-os-x
You have one Intel Core i7 cpu. That CPU has two physical cores. Unless you managed to disable hyperthreading, each physical core amounts to two logical cores.

1 CPU, 2 physical cores, 4 logical cores (unless HT is disabled, which used to be hard to manage on a Mac).
Thank you, and from what I understand, the two PHYSICAL cores are the ones that matter from a multiprocessor point of view, right?
Yes, as far as chess programs are concerned. One typically wants the number of threads used for searching to equal the number of physical cores.
User avatar
jsgroby
Posts: 83
Joined: Mon Mar 24, 2014 12:26 am
Location: Glen Carbon, IL USA

Re: Processor Cores

Post by jsgroby »

zullil wrote:
jsgroby wrote:
zullil wrote:
jsgroby wrote:I have also followed this and the results are still 4 cores.

So why does the machine report 2 cores in the OS and in MacTracker? Do I have a freak machine?

http://stackoverflow.com/questions/1715 ... n-mac-os-x
You have one Intel Core i7 cpu. That CPU has two physical cores. Unless you managed to disable hyperthreading, each physical core amounts to two logical cores.

1 CPU, 2 physical cores, 4 logical cores (unless HT is disabled, which used to be hard to manage on a Mac).
Thank you, and from what I understand, the two PHYSICAL cores are the ones that matter from a multiprocessor point of view, right?
Yes, as far as chess programs are concerned. One typically wants the number of threads used for searching to equal the number of physical cores.
Thank you very much. One of these days when I get the engine to a point where I feel comfortable releasing it, I hope to share it with everyone here.

As it stands now, I am not super happy with the ELO rating I came up with after running the LCTII suite against it. So, more work to do to tweak it.

Jeff
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: Processor Cores

Post by xmas79 »

zullil wrote:...Yes, as far as chess programs are concerned. One typically wants the number of threads used for searching to equal the number of physical cores.
I would say:

Yes, as far as chess programs with good SMP code are concerned.

And I would not equate search threads to the equal number of physical cores... I would only equate running threads count to that number, I would create more (2x? 4x?) and let the OS do the technical switch... This could allow better control IHMO.

Please note I still didn't go for an SMP search in my engine. But one day I will....
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Processor Cores

Post by bob »

jsgroby wrote:
syzygy wrote:A logical core is not a physical processor core.

If your OS is not broken, then you have two physical cores. With an i7 this seems only possible if it is a relatively old (2010) mobile "Arrandale" cpu. However these do not go faster than 2.66 Ghz (maybe turboboost can make them reach 3.0 Ghz, I am not sure).

With HT enabled in the BIOS, that means you have four logical cores.

You first need to understand the difference and then ask yourself what you want to know:
- number of physical cores, or
- number of logical cores.

The difference is pretty significant. Which number you want to know will depend on the application. For a chess engine you will typically want to know the number of physical cores.

sysconf() is a Unix thing, so won't compile on Windows.
Now I am confused as to why sysconf is reporting 4 cores, here is what the Operating System is reporting:

Model Name: MacBook Pro
Model Identifier: MacBookPro10,2
Processor Name: Intel Core i7
Processor Speed: 3 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache (per Core): 256 KB
L3 Cache: 4 MB
Memory: 8 GB
Boot ROM Version: MBP102.0106.B03
SMC Version (system): 2.6f59
Serial Number (system): C2QKV00FFGN5
Hardware UUID: 439E419D-5CB7-5707-9F48-992D46CC1046
Sudden Motion Sensor:
State: Enabled

Here is what MacTracker says about my machine:

OVERVIEW

Introduced February 2013
Discontinued October 2013
Model Identifier MacBookPro10,2
Model Number A1425
EMC 2672
Order Number ME662LL/A (2.6 GHz with 256 GB storage)
Initial Price $1,699 (2.6 GHz with 256 GB storage)
Support Status Supported
Case Precision aluminum unibody
Weight and Dimensions 3.57 lbs., 0.75" H x 12.35" W x 8.62" D
PROCESSOR

Processor Intel Core i5 or Core i7 (3230M, 3540M) ("Ivy Bridge")
Processor Speed 2.6 GHz (Core i5) or 3.0 GHz (Core i7)
Architecture 64-bit
Number of Cores 2
Cache 3 MB (2.6 GHz) 4 MB (3.0 GHz) L3
System Bus Intel Direct Media Interface (DMI) at 5 GT/s
STORAGE AND MEDIA

Storage 256, 512, or 768 GB flash storage
Media None
KEYBOARD AND TRACKPAD

Trackpad Multi-Touch trackpad
Keyboard Built-in full-size backlit with 78 (U.S.) or 79 (ISO) keys, incl. 12 function and 4 arrow

Is there a better, more acceptable way to determine number of cores for both windows and unix or will I have to do one thing if win32 is defined and another for unix?

Thanks


Jeff
Looks perfectly rational. 1 cpu chip (Package). 2 physical cores. And with hyper-threading you get 4 logical processors.

My Macbook (mid-2012) gives this:

Model Name: MacBook Air
Model Identifier: MacBookAir5,2
Processor Name: Intel Core i7
Processor Speed: 2 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache (per Core): 256 KB
L3 Cache: 4 MB
Memory: 8 GB

And it definitely says I have 4 processors, but since it is not possible to disable HT permanently, I don't worry about it but do try to use 2 threads only when running Crafty.