In OpenMP, how can I get each core to start one thread?

I started using OpenMP 3 days ago. I want to know how to use #pragmaso that each core runs one thread. In details: -

int ncores = omp_get_num_procs();

for(i = 0; i < ncores;i++){

....

}

I want this for the loop to be distributed in the kernels that I have, what #pragmashould I use?

another, what do those mean #pragmas?

#pragma omp parallel

#pragma omp for

#pragma omp parallel for

I'm a little confused with those #pragmas

Many thanks.:)

+5
source share
3 answers

Thread locking

I want to know how to use #pragma so that each core runs a single thread.

What version of openmp are you using? The answer depends on that.

. . gcc :

GOMP_CPU_AFFINITY="0-3" ./main

, .. . gomp ( 3 " " ). , PGI , .

OpenMP Pragmas

. . - IBM. Blaise Barney .

+8

, Intel OpenMP - KMP_AFFINITY.

GOMP_CPU_AFFINITY="0-3"

KMP_AFFINITY="proclist=[0-3]"

KMP_AFFINITY : http://software.intel.com/sites/products/documentation/studio/composer/en-us/2009/compiler_c/optaps/common/optaps_openmp_thread_affinity.htm

+2

The new OpenMP implementation (3.0+) simplifies your life. You can simply add the following line to your .bashrc or .bash_profile.

export OMP_PROC_BIND = true

+1
source

All Articles