Using #pragma omp critical "outside of OpenMP"

General OpenMP discussion

Using #pragma omp critical "outside of OpenMP"

Postby loopless » Thu Dec 08, 2011 11:19 am

For various reasons I have to use boost::threads in some parts of my code, and OpenMP threads in others. Boost threads and OpenMP may call the same underlying routine which may require a critical lock What I am finding is that a construct
#pragma omp critical
{
}

has no locking effect when called from , say, a boost::thread, only when inside a OMP parallel region.
I suppose that makes sense, but is a bit of a pain, as I will have to re-imlement all these critical regions using boost mutex ( which of course will work with any threading model).
loopless
 
Posts: 12
Joined: Mon Apr 11, 2011 11:57 am

Re: Using #pragma omp critical "outside of OpenMP"

Postby anv » Wed Dec 14, 2011 10:59 am

If you compiled your code with boos::threads without compiler option that enables OpenMP, then OpenMP critical directives in that code should be ignored.

If you compiled this code with OpenMP option, then probably the compiler you are using has a bug. Because according to OpenMP specification critical region should restrict execution to one thread at a time among all threads in the program (given that critical directives are recognized by the compiler, as I mentioned).

Regards,
Andrey
anv
 
Posts: 31
Joined: Wed Dec 12, 2007 9:36 am

Re: Using #pragma omp critical "outside of OpenMP"

Postby MarkB » Fri Feb 17, 2012 10:12 am

anv wrote:If you compiled this code with OpenMP option, then probably the compiler you are using has a bug.


I'm afraid I disagree: an OpenMP critical is not obliged to synchronize threads which were not created with an OpenMP parallel region!
MarkB
 
Posts: 428
Joined: Thu Jan 08, 2009 10:12 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 6 guests