nested critical/atomic

Discuss the OpenMP 3.0 API Specifications with the OpenMP Arch. Review Board. (Read Only)

nested critical/atomic

Postby vweber » Fri Apr 22, 2011 8:52 am

Dear All

I am wondering if the following nested constructs is conform to the OpenMP 3.0 Spec?

!$omp critical
!$omp atomic
i = i + 1
!$omp end critical

Thanks

V
vweber
 
Posts: 4
Joined: Fri Apr 22, 2011 8:43 am

Re: nested critical/atomic

Postby ejd » Sun Apr 24, 2011 2:46 pm

There is no restriction in the OpenMP V3.0 specification that prohibits this. That said, an atomic can be implemented with a critical construct and a critical construct cannot be nested within a critical region with the same name. That would mean that an implementation would have to make sure that if it used a critical construct to implement atomic, that it used a unique name.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: nested critical/atomic

Postby vweber » Mon Apr 25, 2011 9:06 am

But the specs 3.0 says that (page 104 line 30) nesting critical regions with different names is not sufficient to prevent deadlock.
If it is possible to substitute an atomic by a critical construct I would have expected that nesting an atomic inside a critical
not to be allowed like a critical/critical construct. So I am a bit confused.

V
vweber
 
Posts: 4
Joined: Fri Apr 22, 2011 8:43 am

Re: nested critical/atomic

Postby ejd » Mon Apr 25, 2011 12:43 pm

You have it a little mixed up. A critical construct may be nested within a critical region as long as the names of the critical constructs are different. An atomic may be nested within a critical, because if you look at Section 2.8.5 atomic Construct, you will see that "atomic regions do not enforce exclusive access with respect to any critical or ordered regions that access the same storage location x". So you have to use an atomic if you are using an atomic elsewhere to update a storage location that both atomics are accessing.

The statement about data races is true, if an atomic happened to contain a critical region (or atomic) within the expression. Then it is possible that you could create a deadlock condition. However, all the spec is saying, is not allowing this to happen is not sufficient to prevent deadlocks. In the V3.1 specification atomic and critical are no longer allowed to be closely nested inside an atomic region.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am


Return to OpenMP 3.0 API Specifications

Who is online

Users browsing this forum: No registered users and 3 guests