Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

ATOMIC_CAS in OpenMP

jimdempseyatthecove
Honored Contributor III
651 Views

The ATOMIC_CAS is documented as having the atom as a scalar coarray or coindexed object and of type integer with kind ATOMIC_INT_KIND or type logical with kind ATOMIC_LOGICAL_KIND.

 

However, this would preclude the use of this in an OpenMP multi-threaded environment (variables located in same process, but accessed by multiple threads).

 

So the questions are:

1) Can the ATOMIC_CAS be used without MPI (iow within a single image)?

2) When doing so, is the code smart enough to recognize this and avoid MPI overhead?

3) Or should I impliment my own CAS in C using <stdatomic.h>?

 

Jim Dempsey

0 Kudos
1 Solution
Ron_Green
Moderator
444 Views

Confirmed.  We always use MPI, and no special logic to skip the MPI calls. 

View solution in original post

0 Kudos
3 Replies
Ron_Green
Moderator
452 Views

I am checking with 2 of the developers.  99% sure I know the answer but waiting for confirmation.  I think the answer is you will have to create your own CAS in C.  but let's let the actual code owner for our CAF implementation answer. 

0 Kudos
Ron_Green
Moderator
445 Views

Confirmed.  We always use MPI, and no special logic to skip the MPI calls. 

0 Kudos
jimdempseyatthecove
Honored Contributor III
229 Views

Thanks for looking into this.

I will call C functions.

FWIW

In my use requirements, the OpenMP reduction clause is not appropriate. I have a large array where a few cells may be updated by different threads. Thus, a reduction on the whole array is not optimal. A CAS would be better.

Old = Array(i)   ! any type
New = Old + Change
! CAS is an interface of various types
! that uses the address and widths of the variables
do while(.not.CAS(Array(i), Old, New))
  Old = Array(i)
  New = Old + Change
end do

Jim Dempsey

0 Kudos
Reply