Fortran Coder

CUDA Fortran 结构体问题

查看数: 8766 | 评论数: 2 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2021-10-16 15:20

正文摘要:

最近在学习CUDA Fortran,但相关资料里的示例全部都是对一二维数组进行并行加速的, 但在我的实际应用过程中,派生类(TYPE定义的结构数组)是程序的主要数据结构,所以今天试了一下可否在CUDA Fortran中实现结构体 ...

回复

hyywestwood 发表于 2021-10-20 15:20:20
li913 发表于 2021-10-20 12:18
1、去掉 第六行的 allocatable;
2、MODULE Global_variables 放在最开始;      
3、主程序 use Compute。

感谢!!解决了我的问题
li913 发表于 2021-10-20 12:18:11
本帖最后由 li913 于 2021-10-20 12:43 编辑

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


[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




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

11.jpg

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

GMT+8, 2025-4-18 01:25

Powered by Tencent X3.4

© 2013-2025 Tencent

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