- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Knut
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, I will look into this.
Knut
Knut
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page