Fortran Coder

查看: 601|回复: 1
打印 上一主题 下一主题

[并行] MPI缓存发送消息如何修改正确

[复制链接]

5

帖子

3

主题

0

精华

入门

F 币
34 元
贡献
13 点
跳转到指定楼层
楼主
发表于 2024-3-23 20:05:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
[Fortran] 纯文本查看 复制代码
program main
    use mpi
    implicit none

    integer::ierr,myid,nprocs
    integer::msize=6, bsize
    real(8)::buffer(6),b(6)
    real(8),allocatable::tmbuff(:)
    integer, parameter :: MAX_BUFFER_SIZE = 1024

    call MPI_init(ierr)
    call MPI_comm_size(MPI_comm_world,nprocs,ierr)
    call MPI_comm_rank(MPI_comm_world,myid,ierr)

    if(myid==0)then

        buffer(1:6)=(/1.0,2.0,3.0,4.0,5.0,6.0/)

        allocate(tmbuff(MAX_BUFFER_SIZE))
        call MPI_Buffer_attach(tmbuff, size(tmbuff)*8, ierr)

        call MPI_bsend(buffer,msize-1,MPI_double_precision,1,2000,MPI_comm_world,ierr)
        call MPI_bsend(buffer,1,      MPI_double_precision,1,2001,MPI_comm_world,ierr)
        
        call MPI_buffer_detach(tmbuff, size(tmbuff)*8, ierr)
        
    else if (myid==1) then
        call MPI_recv(b,msize-1,MPI_double_precision,0,2000,MPI_comm_world,ierr)
        print *,'b1 = ',b
        call MPI_recv(b,1,      MPI_double_precision,0,2001,MPI_comm_world,ierr)
        print *,'b2 = ',b
    end if


    call MPI_finalize(ierr)
end program

请问这段代码的这一部分如何修改正确?
[Fortran] 纯文本查看 复制代码
allocate(tmbuff(MAX_BUFFER_SIZE))
call MPI_Buffer_attach(tmbuff, size(tmbuff)*8, ierr)

call MPI_bsend(buffer,msize-1,MPI_double_precision,1,2000,MPI_comm_world,ierr)
call MPI_bsend(buffer,1, MPI_double_precision,1,2001,MPI_comm_world,ierr)

运行时候有错误
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

5

帖子

3

主题

0

精华

入门

F 币
34 元
贡献
13 点
沙发
 楼主| 发表于 2024-3-23 23:10:14 | 只看该作者
解决了
这是正确的代码
[Fortran] 纯文本查看 复制代码
program main
    use mpi
    implicit none

    integer::ierr,myid,nprocs
    integer::msize=6, bsize
    real(8)::buffer(6),b(6)
    real(8),allocatable::tmbuff(:)
    integer, parameter :: MAX_BUFFER_SIZE = 1024
    integer::status(MPI_status_size)

    call MPI_init(ierr)
    call MPI_comm_size(MPI_comm_world,nprocs,ierr)
    call MPI_comm_rank(MPI_comm_world,myid,ierr)

    if(myid==0)then

        buffer(1:6)=(/1.0,2.0,3.0,4.0,5.0,6.0/)
        !call MPI_pack_size(msize,MPI_double_precision,MPI_comm_world,bsize,ierr)
        print *,'MPI_bsend_overhead = ', MPI_bsend_overhead
        allocate(tmbuff(size(buffer)+2*MPI_bsend_overhead))
        call MPI_Buffer_attach(tmbuff, size(tmbuff), ierr)

        call MPI_bsend(buffer,msize-1,MPI_double_precision,1,2000,MPI_comm_world,status,ierr)
        call MPI_bsend(buffer,1,      MPI_double_precision,1,2001,MPI_comm_world,status,ierr)
        
        call MPI_buffer_detach(tmbuff, size(tmbuff), ierr)
        
    else if (myid==1) then
        call MPI_recv(b,msize-1,MPI_double_precision,0,2000,MPI_comm_world,status,ierr)
        print *,'b1 = ',b
        call MPI_recv(buffer,1,      MPI_double_precision,0,2001,MPI_comm_world,status,ierr)
        print *,'b2 = ',buffer
    end if


    call MPI_finalize(ierr)
end program


少了status数组
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-12-22 13:05

Powered by Tencent X3.4

© 2013-2024 Tencent

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