24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 584  |  回复: 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的回帖

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的回帖
查看全部 3 个回答

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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考博] 26申博 +4 加油冲啊! 2026-03-26 4/200 2026-03-31 22:42 by greychen00
[考研] 299求调剂 +8 嗯嗯嗯嗯2 2026-03-27 8/400 2026-03-31 18:23 by lizhi8172
[考研] 考研生物与医药调剂 +6 铁憨憨123425 2026-03-31 6/300 2026-03-31 17:48 by 544594351
[考研] 286分调剂 +11 Faune 2026-03-30 13/650 2026-03-31 17:28 by michael2011
[考研] 一志愿中海洋材料357 +4 麦恩莉. 2026-03-30 4/200 2026-03-31 14:35 by 记事本2026
[考研] 347求调剂 +11 山顶见α 2026-03-25 11/550 2026-03-31 14:14 by 记事本2026
[考研] 081200-11408-276学硕求调剂 +4 崔wj 2026-03-31 4/200 2026-03-31 11:56 by jp9609
[考博] 材料专业申博 +5 杜雨婷dyt 2026-03-29 5/250 2026-03-31 11:19 by oooqiao
[考研] 一志愿大连理工大学材料求调剂 +6 Gymno 2026-03-30 6/300 2026-03-31 07:26 by 无际的草原
[考研] 材料与化工调剂一志愿大连海事085600,349 +6 吃的不少 2026-03-30 6/300 2026-03-31 04:17 by fmesaito
[考研] 085701环境工程求调剂 +11 多久上课 2026-03-27 12/600 2026-03-30 21:21 by 研究僧导导
[考研] 材料专硕 085600求调剂 +7 BBQ233 2026-03-30 7/350 2026-03-30 17:44 by oooqiao
[考研] 342求调剂 +4 加油a李zs 2026-03-26 4/200 2026-03-30 16:39 by 晶体之美
[考研] 求调剂 +7 青春裁为三截 2026-03-29 7/350 2026-03-30 13:14 by laoshidan
[考研] 340求调剂 +6 Amber00 2026-03-26 6/300 2026-03-29 12:06 by 无际的草原
[考研] 321求调剂 +7 璞玉~~ 2026-03-25 8/400 2026-03-29 06:41 by 544594351
[考研] 308求调剂 +7 墨墨漠 2026-03-27 7/350 2026-03-28 07:43 by 热情沙漠
[考研] 315分求调剂 +7 26考研上岸版26 2026-03-26 7/350 2026-03-28 04:05 by fmesaito
[考研] 265求调剂11408 +3 刘小鹿lu 2026-03-27 3/150 2026-03-27 20:53 by nihaoar
[考研] 347求调剂 +4 L when 2026-03-25 4/200 2026-03-25 13:37 by cocolv
信息提示
请填处理意见