PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

How to use atomicadd.

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
alfvenwave



Joined: 08 Apr 2010
Posts: 79

PostPosted: Thu Sep 23, 2010 8:56 am    Post subject: How to use atomicadd. Reply with quote

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.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6218
Location: The Portland Group Inc.

PostPosted: Fri Sep 24, 2010 4:16 pm    Post subject: Reply with quote

Hi Rob,

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

Code:
% 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
Back to top
View user's profile
alfvenwave



Joined: 08 Apr 2010
Posts: 79

PostPosted: Sun Oct 03, 2010 3:15 am    Post subject: Reply with quote

Brilliant - just what I wanted. Thanks Mat.

Rob.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group