24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 586  |  回复: 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
[考研] 0856材料化工调剂 总分330 +17 zhubinhao 2026-03-27 17/850 2026-03-31 18:56 by 小张做实验
[考研] 308求调剂 +11 墨墨漠 2026-03-25 11/550 2026-03-31 17:54 by 无际的草原
[考研] 317求调剂 +12 蛋黄咸肉粽 2026-03-26 13/650 2026-03-31 16:44 by asdfzly
[考研] 362求调剂 +9 西南交材料专硕3 2026-03-31 9/450 2026-03-31 16:25 by w虫虫123
[考研] 353求调剂 +3 江上枫_26 2026-03-28 3/150 2026-03-31 15:53 by jp9609
[考研] 08工科,295,接受跨专业调剂 +4 lmnlzy 2026-03-31 4/200 2026-03-31 15:25 by 西京学院招办
[考研] 085601 329分调剂 +6 yzsa12 2026-03-31 6/300 2026-03-31 15:23 by yanflower7133
[考研] 277跪求调剂 +8 1915668 2026-03-27 13/650 2026-03-31 14:58 by 王亮_大连医科大
[考研] 274求调剂 +6 xiao爱同学 2026-03-30 6/300 2026-03-31 10:04 by cal0306
[考研] 食品工程专硕一志愿中海洋309求调剂 +5 小张zxy张 2026-03-26 10/500 2026-03-31 00:29 by jp9609
[考研] 298求调剂 +3 什么是胖头鱼 2026-03-30 5/250 2026-03-30 14:41 by 青海小西牛
[考研] 0703本科郑州大学求调剂 +7 nhj_ 2026-03-25 7/350 2026-03-30 12:44 by fangnagu
[考研] 337求调剂 +6 《树》 2026-03-29 6/300 2026-03-30 10:15 by herarysara
[考研] 340求调剂 +6 Amber00 2026-03-26 6/300 2026-03-29 12:06 by 无际的草原
[考研] 298求调剂 +3 种圣赐 2026-03-29 3/150 2026-03-29 12:06 by longlotian
[考研] 一志愿华理,数一英一285求A区调剂 +8 AZMK 2026-03-25 12/600 2026-03-28 18:15 by AZMK
[考研] 0703化学求调剂,各位老师看看我!!! +5 祁祺祺 2026-03-25 5/250 2026-03-27 21:44 by 东方猪猪
[考研] 070300化学求调剂 +4 起个名咋这么难 2026-03-27 4/200 2026-03-27 21:39 by 83503孙老师
[考研] 一志愿 西北大学 总分282 英语一62 求调剂 +7 18419759900 2026-03-25 8/400 2026-03-27 16:38 by 18419759900
信息提示
请填处理意见