Hi,
I’m trying to use a user defined datatype inside a kernel, but the program fails.
When I compile with the deepcopy flag it works but I would like to know how to manually create a deep copy.
How do I make a correct copy of the comm_data datatype?
I tried to create small example program, it creates a library and then links it to a testprogram.
Thank you for your help.
type.f90
module krylov
type nrk
integer ndata
integer,allocatable :: offset(:)
end type nrk
type comm
integer ndata
type(nrk),allocatable :: nrk_array(:)
end type comm
type KSP
type(comm) :: comm_data
real*8,allocatable :: r(:)
real*8,allocatable :: x(:)
real*8,allocatable :: b(:)
end type KSP
contains
subroutine set_KSP_solver(method,size_n)
implicit none
type(KSP) :: method
integer size_n
write(*,*)"Set_ksp_solver"
end subroutine set_KSP_solver
end module krylov
libmain.f90
subroutine solver(vec_size)
use krylov
implicit none
type(KSP) method
integer n,j,i,vec_size
real*8,bnorm
n=vec_size
bnorm=0.0d0
write(*,*)"Start testprogram"
call init_KSP_CRS(method,10)
!$acc data copyin(method, method%comm_data,&
!$acc method%comm_data%nrk_array)
!$acc parallel loop
do j=1,n
bnorm = bnorm+method%b(i)
write(*,*)method%comm_data%nrk_array(j)%ndata
write(*,*)method%comm_data%nrk_array(j)%offset(j)
enddo
!$acc end data
write(*,*)"End testprogram"
end subroutine solver
subroutine init_KSP_CRS(method,n)
use krylov
implicit none
type(KSP) method
integer n,i
allocate(method%comm_data%nrk_array(n))
do i=1,n
method%comm_data%nrk_array(i)%ndata = i
allocate(method%comm_data%nrk_array(i)%offset(i))
enddo
end subroutine init_KSP_CRS
main.f90
PROGRAM test
implicit none
write(*,*)"Start testprogram"
call solver(10)
write(*,*)"End testprogram"
end PROGRAM test
makefile
CC=pgf90
OBJS=type.o libmain.o
OPTS=-ta=tesla:cc70 -acc -Minfo=accel -Minfo
%.o: %.f90
${CC} ${OPTS} -c $<
all: myProgram
myProgram: main.o libtest.a
${CC} ${OPTS} -o myProgram main.o -L. -ltest
myProg:main.o
${CC} ${OPTS} -c $<
libtest.a:${OBJS}
ar rc libtest.a ${OBJS}
clean:
rm -f libtest.a *.o