【问题标题】:MPI master unable to receiveMPI 主控无法接收
【发布时间】:2014-05-05 02:33:23
【问题描述】:

我在 fortran 中使用 MPI 来计算我的数据。我通过打印数据来验证,每个进程都在对所需范围执行计算,但是,master 无法整理数据。

这是我试图使其工作的代码: 编辑:为发送和接收创建了一个恒定的标签

  integer :: tag
  tag = 123
  if(pid.ne.0) then
  print *,'pid: ',pid,'sending'
  DO j = start_index+1, end_index      
  CALL MPI_SEND(datapacket(j),1, MPI_REAL,0, tag, MPI_COMM_WORLD)
  !print *,'sending'
  END DO
  print *,'send complete'   

  else

  DO slave_id = 1, npe-1
    rec_start_index = slave_id*population_size+1
    rec_end_index = (slave_id + 1) * population_size;

  IF (slave_id == npe-1) THEN
      rec_end_index = total-1;        
  ENDIF
  print *,'received 1',rec_start_index,rec_end_index
    CALL MPI_RECV(datapacket(j),1,MPI_REAL,slave_id,tag,MPI_COMM_WORLD,  &
 &       status)  
  !print *,'received 2',rec_start_index,rec_end_index 
  END DO

它从不打印receivedMPI_RECV 调用之后的任何内容,但是,我可以看到发送进行得很好但是,除了依赖打印语句之外,我无法验证它。 变量databpacket初始化如下:

real, dimension (:), allocatable :: datapacket

我在这里做错了什么吗?

编辑:对于测试设置,所有进程都在本地主机上运行。

【问题讨论】:

    标签: fortran mpi openmpi


    【解决方案1】:

    您为所有发送使用不同的消息标签,但是在您的接收中您只使用 j,它在根进程中永远不会改变。另请注意,您的实现看起来像 MPI_Gather,我建议您使用它而不是自己实现它。

    编辑:对不起,在你更新之后,我现在意识到,你实际上是从每个等级发送多条消息>0(start_index+1 到 end_index),如果你需要,你需要有标签来区分个别消息。但是,您还需要在您的主服务器上有多个接收。 也许最好说明你真正想要实现的目标。

    你想要这样的东西吗:

    integer :: tag
    tag = 123
    if(pid.ne.0) then
    
      print *,'pid: ',pid,'sending'
      CALL MPI_SEND(datapacket(start_index+1:end_index),end_index-start_index, MPI_REAL,0, tag, MPI_COMM_WORLD)
      !print *,'sending'
      print *,'send complete'   
    
    else
    
      DO slave_id = 1, npe-1
        rec_start_index = slave_id*population_size+1
        rec_end_index = (slave_id + 1) * population_size;
    
        IF (slave_id == npe-1) THEN
          rec_end_index = total-1;        
        ENDIF
        print *,'received 1',rec_start_index,rec_end_index
        CALL MPI_RECV(datapacket(rec_start_index:rec_end_index),rec_end_index-rec_start_index+1,MPI_REAL,slave_id,tag,MPI_COMM_WORLD,  &
          &       status)  
        !print *,'received 2',rec_start_index,rec_end_index 
      END DO
    
    end if
    

    【讨论】:

    • 谢谢,我会记下 MPI_gather 并稍后尝试。在当前上下文中,发送和接收常量标签没有帮助。我已经编辑了我当前的实现。
    • 我更新了我的答案并试图想出一些东西,我认为你正在努力实现。我仍然强烈建议您查找 MPI_Gather / MPI_Gatherv。
    猜你喜欢
    • 2011-06-30
    • 1970-01-01
    • 2015-03-08
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 2018-12-04
    • 2018-05-02
    • 2012-02-26
    相关资源
    最近更新 更多