How to use atomicadd.

Hi,

I’ve been trying to find an example of how to use atomicadd in a cuda fortran program - and have failed. Can anyone point me to some example code to show how this function can be used?

Thanks,

Rob.

Hi Rob,

Here’s a simple example from one of our correctness tests where each thread add it’s thread id to a scalar.

% cat atomics.cuf
module atomictests
  contains
    attributes(global) subroutine testatomicadd( a )
    integer, device :: a
    i = threadIdx%x
    istat = atomicadd(a, i)
    return
    end subroutine testatomicadd

end module atomictests

program t
use atomictests
integer, allocatable, device :: n
integer m
allocate(n)
n = 0
call testatomicadd<<<1,5>>> (n)
m = n
print *, m
end
% pgf90 atomics.cuf -V10.9; a.out
           15
  • Mat

Brilliant - just what I wanted. Thanks Mat.

Rob.