Detecting Core

Detecting Core

Is it possible for a pice of code to detect in which core it is running? I am starting to do some multicore programming and would try a small looping program to just display something like, "Hello from Core 1" etc. etc.


3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.


have a look at this article : Intel 64 Architecture Processor Topology Enumeration
It allows to enumerate the CPU topology including counting packages/dies/cores/Hyper-threading.
With this, you can identify your thread using core APICID.
Unless you bound your thread to a core, it's likely that the OS will let it jump between coresand thus, when launching n thread with a hello wolrd sample, you'll end up with n "Hello from Core 1".

If you don't wan't to go through the article and don't need all topology, you can add at the beginning of your application a loop that goes through each core (using thread affinity) and get the APICID of these cores in a LUT for later use in the program.


Thank you, I will look into this.

Leave a Comment

Please sign in to add a comment. Not a member? Join today