Intel® ISA Extensions
Use hardware-based isolation and memory encryption to provide more code protection in your solutions.

Detecting Core

knujohn4
New Contributor I
533 Views
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.

Knut
0 Kudos
2 Replies
matthieu_darbois
New Contributor III
533 Views
Hi,

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.

Regards,
Matthieu
0 Kudos
knujohn4
New Contributor I
533 Views
Thank you, I will look into this.
Knut
0 Kudos
Reply