最近在学习CUDA Fortran,但相关资料里的示例全部都是对一二维数组进行并行加速的,
但在我的实际应用过程中,派生类(TYPE定义的结构数组)是程序的主要数据结构,所以今天试了一下可否在CUDA Fortran中实现结构体的并行
但出错了,错误截图如下,请问是否是CUDA Fortran原生的不支持结构体?
[Fortran] 纯文本查看 复制代码 MODULE Compute
USE Global_variables
IMPLICIT NONE
CONTAINS
attributes ( global ) SUBROUTINE Age_add(People_d)
INTEGER :: I,N1
type(Person), allocatable :: People_d(:)
I=(BLOCKIDX%X-1)*BLOCKDIM%X+THREADIDX%X
N1=SIZE(People_d,1)
IF (I>N1) RETURN
People_d(I)%age = People_d(I)%age + 1
END SUBROUTINE
END
MODULE Global_variables
IMPLICIT NONE
type Person
integer(kind=4) :: age ! 年龄
integer(kind=4) :: height ! 身高
integer(kind=4) :: weight ! 体重
end type
END
program Test
use cudafor
use Global_variables
implicit none
integer , parameter :: PersonNum = 10000
type(Person), allocatable :: People(:)
type(Person),device,allocatable :: People_d(:)
integer :: i
allocate(People(PersonNum))
allocate(People_d(PersonNum))
DO i = 1, PersonNum
People(i)%age = i
People(i)%height = i
People(i)%weight = i
ENDDO
People_d = People
CALL Age_add<<<CEILING(REAL(PersonNum)/256),256>>>(People_d)
People = People_d
write(*,*) People(500)%age
write(*,*) SIZE(People, 1)
end program Test
|