Skip to content

Instantly share code, notes, and snippets.

@jefflarkin
Created October 25, 2012 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jefflarkin/3952953 to your computer and use it in GitHub Desktop.
Save jefflarkin/3952953 to your computer and use it in GitHub Desktop.
Testing Derived Types with OpenACC
module dtmod
implicit none
private
integer, public, parameter :: N = 64
type, public :: mytype
sequence
real(8) :: a(N,N)
real(8) :: b(N,N)
end type mytype
end module
program test
use dtmod
type(mytype), dimension(32) :: types
integer i,j,k
!$acc data
!$acc parallel
do i=1,32
do j=1,N
do k=1,N
types(i)%a(k,j) = real(i*j*k)
enddo
enddo
enddo
!$acc end parallel
!$acc end data
do i=1,32
types(i)%b = types(i)%a
enddo
print *, sum(types(1)%a), sum(types(1)%b)
end program
$ aprun ./a.out
ACC: Initialize CUDA
ACC: Get Device 0
ACC: Create Context
ACC: Set Thread Context
ACC: Start transfer 1 items from test.F90:18
ACC: allocate, copy to acc 'types' (2097152 bytes)
ACC: End transfer (to acc 2097152 bytes, to host 0 bytes)
ACC: Execute kernel test_$ck_L18_1 blocks:1 threads:128 async(auto) from test.F90:18
ACC: Wait async(auto) from test.F90:26
ACC: Start transfer 1 items from test.F90:26
ACC: copy to host, free 'types' (2097152 bytes)
ACC: End transfer (to acc 0 bytes, to host 2097152 bytes)
2*4326400.
Application 240587 resources: utime ~0s, stime ~1s
module dtmod
implicit none
private
integer, public, parameter :: N = 64
type, public :: mytype(NNN)
integer,len :: NNN = N
sequence
real(8) :: a(N,N) ! statically sized "inline" array
real(8) :: b(NNN,NNN) ! dynamically sized "dope-vector" array
end type mytype
end module
program test
use dtmod
type(mytype), dimension(32) :: types
integer i,j,k
!$acc data
!$acc parallel
do i=1,32
do j=1,N
do k=1,N
types(i)%a(k,j) = real(i*j*k)
enddo
enddo
enddo
!$acc end parallel
!$acc end data
do i=1,32
types(i)%b = types(i)%a
enddo
print *, sum(types(1)%a), sum(types(1)%b)
end program
ACC: Initialize CUDA
ACC: Get Device 0
ACC: Create Context
ACC: Set Thread Context
ACC: Start transfer 1 items from test.F90:19
ACC: allocate, copy to acc 'types' (1051648 bytes)
ACC: End transfer (to acc 1051648 bytes, to host 0 bytes)
ACC: Execute kernel test_$ck_L19_1 blocks:1 threads:128 async(auto) from test.F90:19
ACC: Wait async(auto) from test.F90:27
ACC: Start transfer 1 items from test.F90:27
ACC: copy to host, free 'types' (1051648 bytes)
ACC: End transfer (to acc 0 bytes, to host 1051648 bytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment