0

I have #pragma omp parallel for in multiple independent threads, but I am not sure that those parallel regions can run concurrently at the same time.

It would be inconvenient to change those regular threads to omp task regions.

So is it possible to execute two OpenMP parallel regions in two separate threads concurrently or may only one region run at a time?

Example:

void f1()// executed in thread 1  
{  
#pragma omp parallel for  
for(...)  
    {/*do something*/}  
}  
void f2()//executed in thread 2  
{  
#pragma omp parallel for  
for(...)  
    {/*do something else*/}  
}    

So my question is: will the parallel loops in f1() and f2() run concurrently at the same time having twice as many threads in total as OpenMP uses for one parallel region, or, it will run only one parallel block at a time and another will be waiting on a semaphore?

Community
  • 1
  • 1
  • Can you please show some code? – Z boson Sep 24 '14 at 10:50
  • I'm sorry, I couldn't make the formatting rules work. I hope you understand what I wanted to say. – user2751291 Sep 24 '14 at 13:18
  • Edit your question. After you paste your code select it and hit ctrl-k. That will auto-format your code. Fix any problems by hand. Nobody is going to take your question serious unless you spend the time time to do this. – Z boson Sep 24 '14 at 14:10
  • It turns out that the formatting works only in the original question text, but it doesn't work in the comments. – user2751291 Sep 24 '14 at 16:25
  • How do you plan to run each function in seperate threads? – Z boson Sep 24 '14 at 16:31
  • Each function f1() and f2() runs in an infinite loop each in it's own thread. I am running it now and everything seems OK, but I'm not sure that those two teams really run concurrently - how can I check it in a profiler? Thanks! – user2751291 Sep 24 '14 at 16:37
  • I'm sorry, one thing I didn't tell is that those two threads are not logically independent: they are doing producer-consumer pattern. So I can't just turn off second one and see how fast the first one alone. Probably, I have to program a separate test with two really independent threads each doing OpenMP parallel for. I'll let you know how it worked. Thanks! – user2751291 Sep 25 '14 at 13:55
  • How do you create the two threads? Pthreads? – Z boson Sep 25 '14 at 15:11
  • No, it's a windows project, I have to use winapi _beginthreadex(...) functions. – user2751291 Sep 26 '14 at 15:57
  • Doing so goes outside of what the OpenMP standard specifies. Your question is basically a duplicate of [Can I safely use OpenMP with C++11?](http://stackoverflow.com/questions/13837696/can-i-safely-use-openmp-with-c11) – Hristo Iliev Oct 09 '14 at 10:00

0 Answers0