Software Archive
Read-only legacy content
17061 Discussions

number of threads running on cores

TK
Beginner
409 Views

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.

0 Kudos
3 Replies
TimP
Honored Contributor III
409 Views

If you wish to spread OpenMP threads evenly across cores, use KMP_AFFINITY=scatter or KMP_PLACE_THREADS=57C,1t

0 Kudos
Florian_R_
Beginner
409 Views

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]

0 Kudos
James_C_Intel2
Employee
409 Views

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.

0 Kudos
Reply