iqapple
iqapple

Reputation: 75

Is it possible for openmp to run different threads on a same cpu(core)

Assume I have two cores. Let us denote them as core1 and core2. If I use openmp to parallelize my program, two threads will be generated. Is it possible for openmp implementation to allocate both of the two threads on core1 to excute instead of on core1 and core2? In the first case we will lose parallelism.

I am using Intel openmp included with icc. By default, is it possible to run different threads on a same cpu(core)

Thanks.

Upvotes: 1

Views: 588

Answers (1)

Hristo Iliev
Hristo Iliev

Reputation: 74485

It is possible to instruct the OpenMP runtime to do specific binding (or pinning in Intel's terminology) of the threads to the available CPU cores. OpenMP 4.0 comes with provisions to specify this in an abstract and portable way, while current OpenMP implementations provide their own specific mechanisms to do it:

  • KMP_AFFINITY for Intel compilers - see here;
  • GOMP_CPU_AFFINITY for GCC (and Intel in compatibility mode) - see here.

Unless these are set, both runtimes default to no binding and the OS is free to dispatch the threads as it deems fit, e.g. it might dispatch both threads on a single core. The latter is rather unlikely unless there are other running processes that require lots of CPU time. Still most OS schedulers tend to constantly migrate threads and processes around, therefore it is advisable that you employ the binding mechanisms for maximum performance.

Upvotes: 3

Related Questions