- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following code snippet is located inside a !$OMP PARALLEL region. THIS_THREAD and LOCAL_FAILED_THREAD are private variables, FAILED_THREAD is a shared variable.
I am wondering if it is truly necessary to use the !$OMP ATOMIC directives inside the !$OMP CRITICAL region. The intent here is to guarantee memory consistency between what each local thread thinks FAILED_THREAD is; but maybe the mere fact that the access (read or write) to FAILED_THREAD is inside the !$OMP CRITICAL region is sufficient in itself to guarantee this?
THIS_THREAD = OMP_GET_THREAD_NUM() !$OMP CRITICAL !$OMP ATOMIC READ LOCAL_FAILED_THREAD = FAILED_THREAD !$OMP END ATOMIC IF (LOCAL_FAILED_THREAD==-1) THEN LOCAL_FAILED_THREAD = THIS_THREAD !$OMP ATOMIC WRITE FAILED_THREAD = LOCAL_FAILED_THREAD !$OMP END ATOMIC END IF !$OMP END CRITICAL IF (THIS_THREAD==LOCAL_FAILED_THREAD) THEN ! Do some work here. END IF
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
On Intel processors IA32 and Intel64 (but not necessarily IA64 and not necessarily some other processors) the above atomics may be unnecessary. A cleaner solution would be to use FLUSH
THIS_THREAD = OMP_GET_THREAD_NUM() !$OMP CRITICAL !$OMP FLUSH(FAILED_THREAD) LOCAL_FAILED_THREAD = FAILED_THREAD IF (LOCAL_FAILED_THREAD==-1) THEN LOCAL_FAILED_THREAD = THIS_THREAD FAILED_THREAD = LOCAL_FAILED_THREAD !$OMP FLUSH(FAILED_THREAD) END IF !$OMP END CRITICAL IF (THIS_THREAD==LOCAL_FAILED_THREAD) THEN ! Do some work here. END IF
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Note, the code provided is indicative that FAILED_THREAD is read elsewhere. Where it is read may require !$OMP FLUSH(FAILED_THREAD) as well.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Flush is implied at a number of locations, including the entry and exit of a critical region (OpenMP 4.5 p168).
If all reads and writes of FAILED_THREAD
are within that critical construct then ATOMIC
is not required.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks to all for the clarification!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>Flush is implied at a number of locations, including the entry and exit of a critical region (OpenMP 4.5 p168).
Depending on the rest of the code, it may or may not require more immediate notification than that at the end of the parallel region. This is a design consideration.
Jim Dempsey
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page