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 .. :)
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With