CUDA Fortran 结构体问题
最近在学习CUDA Fortran,但相关资料里的示例全部都是对一二维数组进行并行加速的,但在我的实际应用过程中,派生类(TYPE定义的结构数组)是程序的主要数据结构,所以今天试了一下可否在CUDA Fortran中实现结构体的并行
但出错了,错误截图如下,请问是否是CUDA 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
本帖最后由 li913 于 2021-10-20 12:43 编辑
1、去掉 第六行的 allocatable;
2、MODULE Global_variables 放在最开始;
3、主程序 use Compute。
MODULE Global_variables
IMPLICIT NONE
type Person
integer(kind=4) :: age ! 年龄
integer(kind=4) :: height ! 身高
integer(kind=4) :: weight ! 体重
end type
END module
MODULE Compute
USE Global_variables
IMPLICIT NONE
CONTAINS
attributes ( global ) SUBROUTINE Age_add(People_d)
INTEGER :: I,N1
type(Person) :: 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
program Test
use cudafor
use Global_variables
use Compute
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
li913 发表于 2021-10-20 12:18
1、去掉 第六行的 allocatable;
2、MODULE Global_variables 放在最开始;
3、主程序 use Compute。
感谢!!解决了我的问题
页:
[1]