Fortran Coder

查看: 8048|回复: 2
打印 上一主题 下一主题

[并行] CUDA Fortran 结构体问题

[复制链接]

809

帖子

2

主题

0

精华

大宗师

F 币
3829 元
贡献
2286 点
楼主
发表于 2021-10-20 12:18:11 | 显示全部楼层
本帖最后由 li913 于 2021-10-20 12:43 编辑

1、去掉 第六行的 allocatable;
2、MODULE Global_variables 放在最开始;      
3、主程序 use Compute。


[Fortran] 纯文本查看 复制代码
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




11.jpg (41.7 KB, 下载次数: 281)

11.jpg
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-29 14:56

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表