Example for atomic capture in fortran?

Hi

In C++ there are atomic incrementors.

Atomic incrementors not only take care, that incrementing is thread safe.

They can also provide each thread with a unique number.

Let’s say counter is of type “std::atomic”. Than each thread can call “myNumber = ++counter” and each thread recieves a unique value.

My impression is, “acc atomic capture” gives a similar oppurtunity. But since Fortran lacks the incrementor-operator, I don’t know how to express is in Fortran.

Any hints?

Benedikt

Hi Benedikt,

It would be something like:

!$acc atomic capture
       counter = counter + 1
       myNumber = counter
!$acc end atomic

See my answer in this post Thread data concatenation for a fuller example.

Note that atomic capture was added in PGI 14.9.

Hope this helps,
Mat

Thank you, Mat.

Next time I’ll have a closer look through the forum first… :-)

Next time I’ll have a closer look through the forum first… :-)

No worries Benedikt. I’d rather you ask a duplicate question than not ask!