24小时热门版块排行榜    

查看: 539  |  回复: 2

tang76

铜虫 (小有名气)

[求助] 初学MPI,以下Fortran程序请教

以下程序编译后运行:
mpiexec -n 4 test.exe

出现如下结果:
myid=           2
results(           3 )=          10
myid=           1
results(           2 )=          10
myid=           3
results(           4 )=          10
myid=           0
results(           1 )=          10
results(           1 )=          10
results(           2 )=  -842150451
results(           3 )=  -842150451
results(           4 )=  -842150451

期望所有输出结果均为10,请问哪里错了?

谢谢!


附:Fortran程序:

    program test
    implicit none
    include 'mpif.h'

        integer::i
    integer rank, size, myid, ierror,commandsize
        integer,allocatable::results(
    commandsize=4
    allocate(results(commandsize))
    call MPI_INIT(ierror)
    call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierror)
    call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierror)

    write(*,*)'myid=',myid
    results(myid+1)=10
    write(*,*)'results(',myid+1,')=',results(myid+1)
    call MPI_ALLGATHER(results,commandsize,MPI_INTEGER,results,commandsize,MPI_INTEGER,MPI_COMM_WORLD,ierror)
    if(myid==0)then
      do i=1,commandsize
        write(*,*)'results(',i,')=',results(i)
      enddo
    endif
    call MPI_FINALIZE(ierror)
    deallocate(results)
    end
回复此楼

» 收录本帖的淘帖专辑推荐

资源收集

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

baghnac

金虫 (小有名气)

【答案】应助回帖

tang76(金币+1): 2011-10-26 00:08:22
引用回帖:
1楼: Originally posted by tang76 at 2011-10-24 12:46:46:
以下程序编译后运行:
mpiexec -n 4 test.exe

出现如下结果:
myid=           2
results(           3 )=          10
myid=           1
results(           2 )=          10
myid=           3 ...

⑴发送与接收缓冲区如果一样,会冲突
⑵接收缓冲区应大于各发送缓冲区的总大小
虽然书上没有找到这么说,但是我试出来的是这个结果
结果如下
myid=0
results(           1 )=          10
results(           2 )=           0
results(           3 )=           0
results(           4 )=           0
recvs(           1 )=          10
recvs(           2 )=           0
recvs(           3 )=           0
recvs(           4 )=           0
recvs(           5 )=           0
recvs(           6 )=          10
recvs(           7 )=           0
recvs(           8 )=           0
recvs(           9 )=           0
recvs(          10 )=           0
recvs(          11 )=          10
recvs(          12 )=           0
recvs(          13 )=           0
recvs(          14 )=           0
recvs(          15 )=           0
recvs(          16 )=          10
myid=1
results(           1 )=           0
results(           2 )=          10
results(           3 )=           0
results(           4 )=           0
myid=2
results(           1 )=           0
results(           2 )=           0
results(           3 )=          10
results(           4 )=           0
myid=3
results(           1 )=           0
results(           2 )=           0
results(           3 )=           0
results(           4 )=          10

附程序:
program test
    implicit none
    include 'mpif.h'

        integer::i
    integer rank, size, myid, ierror,commandsize,sendcnt,recvcnt,sendssize
        integer,allocatable::results(
        integer,allocatable::recvs(
    commandsize=4
        sendssize=16
    allocate(results(commandsize))
    allocate(recvs(sendssize))
    call MPI_INIT(ierror)
    call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierror)
    call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierror)

!    write(*,*)'myid=',myid
    results(myid+1)=10
!    write(*,*)'results(',myid+1,')=',results(myid+1)
    call MPI_ALLGATHER(results,commandsize,MPI_INTEGER,recvs,commandsize,MPI_INTEGER,MPI_COMM_WORLD,ierror)
    if(myid==0)then
      do i=1,commandsize
        write(*,*)'results(',i,')=',results(i)
      enddo
      do i=1,sendssize
        write(*,*)'recvs(',i,')=',recvs(i)
      enddo
    endif
    call MPI_FINALIZE(ierror)
    deallocate(results)
    end

运行结果

Beagreathackernotacracker!
2楼2011-10-25 14:29:53
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

tang76

铜虫 (小有名气)

非常感谢,我也找到这个问题了,应改成:
call MPI_ALLGATHER(results(myid+1),1,MPI_INTEGER,recvs,commandsize,MPI_INTEGER,MPI_COMM_WORLD,ierror)
3楼2011-10-26 00:09:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 tang76 的主题更新
信息提示
请填处理意见