- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I just run
[cpp] #pragma omp parallel for [/cpp]
it says that it runs 236 threads. If I set the number of threads to 56, will each of threads run on a single core? Thanks.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you wish to spread OpenMP threads evenly across cores, use KMP_AFFINITY=scatter or KMP_PLACE_THREADS=57C,1t
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could also pin them directly in your code, even though it would be the best to use the environment variable with a valid value (e.g. scatter, compact, ...)
[cpp] kmp_affinity_mask_t mask; kmp_create_affinity_mask(&mask); kmp_set_affinity_mask_proc(PHYSICAL_ID_WHERE_TO_PLACE, &mask); kmp_set_affinity(&mask); [/cpp]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use the explicit setting (as Florian mentions), but it is dangerous. I have seen codes that explicitly set the worst possible affinities using this mechanism. It is much simpler to use KMP_PLACE_THREADS with KMP_AFFINITY={compact, scatter}.
If you explicitly force affinities you need to know the full mapping from hardware resources to logical CPUs, which is not at all obvious, is very unlikely to be what you think makes sense (unless you have already researched this) and is potentially subject to change at the whim of the operating system.
KMP_PLACE_THREADS hides all of that and gives you something simple to think about (How many cores to I want to use? How many thread on each core?). KMP_AFFINITY then lets you map those resources into OpenMP global thread ids in teh two ways that normally make sense.
![](/skins/images/C4F7392A5C68ACA60290C9576F107044/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page