开发者

in OpenMP, how can I make every single core runs a single thread?

I start to use OpenMP 3 days ago. I want to know how to use #pragma to make every single core runs a single thread. In more details:-

int ncores = omp_get_num_procs();

for(i = 0; i < ncores;i开发者_C百科++){

....

}

I want this for loop to be distributed in the cores I have so, what #pragma I should use?

another thing, what are those #pragmas mean?

#pragma omp parallel

#pragma omp for

#pragma omp parallel for

I got little confused with those #pragmas

thank you alot .. :)


Thread Pinning

I want to know how to use #pragma to make every single core runs a single thread.

Which openmp implementation do you use? The answer depends on that.

Pinning is not defined with pragmas. You will have to use environment variables. When using gcc, one can use an environment variable to pin threads to cores:

GOMP_CPU_AFFINITY="0-3" ./main

binds the first thread to the first core, the second thread to the second, and so on. See the gomp documentation for more information (section 3, Environment Variables). I forgot how to do the same thing with PGI and other compilers, but you should be able to find the answer for those compilers using a popular search engine.

OpenMP Pragmas

There's no way to avoid reading documentation. See this link to an IBM website for example. I found the tutorial by Blaise Barney quite useful.


To add to the previous answer, the equivalent environment variable in the Intel OpenMP library is KMP_AFFINITY. A similar usage to

GOMP_CPU_AFFINITY="0-3"

would be

KMP_AFFINITY="proclist=[0-3]"

Full details for the KMP_AFFINITY syntax and options are here: http://software.intel.com/sites/products/documentation/studio/composer/en-us/2009/compiler_c/optaps/common/optaps_openmp_thread_affinity.htm


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

export OMP_PROC_BIND=true

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜