Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

openmp

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++){

....

}

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 .. :)

like image 247
Omar Osama Avatar asked Jul 14 '11 04:07

Omar Osama


People also ask

Does OpenMP use threads or processes?

When run, an OpenMP program will use one thread (in the sequential sections), and several threads (in the parallel sections). There is one thread that runs from the beginning to the end, and it's called the master thread.

Does OpenMP use a thread pool?

The OpenMP runtime library maintains a pool of threads that can be used as slave threads in parallel regions. Setting the SUNW_MP_MAX_POOL_THREADS environment variable controls the number of threads in the pool. The default value is 1023.


1 Answers

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.

like image 80
evnu Avatar answered Sep 18 '22 02:09

evnu