【问题标题】:Limits with MPI_Send or MPI_Recv?MPI_Send 或 MPI_Recv 的限制?
【发布时间】:2016-09-09 11:42:53
【问题描述】:

MPI_SendMPI_Recv 上的邮件大小是否有任何限制 - 或计算机限制?当我尝试发送大数据时,它无法完成。 这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include <math.h>
#include <string.h>

void AllGather_ring(void* data, int count, MPI_Datatype datatype,MPI_Comm communicator)
{
  int me;
  MPI_Comm_rank(communicator, &me);
  int world_size;
  MPI_Comm_size(communicator, &world_size);
  int next=me+1;
  if(next>=world_size)
      next=0;
  int prev=me-1;
  if(prev<0)
      prev=world_size-1;
  int i,curi=me;
  for(i=0;i<world_size-1;i++)
  {
     MPI_Send(data+curi*sizeof(int)*count, count, datatype, next, 0, communicator);
     curi=curi-1;
     if(curi<0)
         curi=world_size-1;
     MPI_Recv(data+curi*sizeof(int)*count, count, datatype, prev, 0, communicator, MPI_STATUS_IGNORE);
  }
}


void test(void* buff,int world_size,int count)
{
    MPI_Barrier(MPI_COMM_WORLD);
    AllGather_ring(buff,count,MPI_INT,MPI_COMM_WORLD);
    MPI_Barrier(MPI_COMM_WORLD);
    }
}
void main(int argc, char* argv[]) {
    int count = 20000;
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    MPI_Init(&argc,&argv);
    int world_rank,world_size,namelen;
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
    int* buff=(int*) malloc(world_size*sizeof(int)*count);
      int i;
      for (i = 0; i < world_size; i++) {
          buff[i]=world_rank;
      }
    test(buff,world_size,count);
    MPI_Finalize();
}

当我尝试使用大约 80000 字节(40000 个整数)的缓冲区运行时,它停止了 (按计数 = 20000 + 4 个进程)

【问题讨论】:

    标签: c mpi openmpi hpc


    【解决方案1】:

    您的代码不正确。您仅在各自的发送完成后才发布接收。 MPI_Send 只有在相应的MPI_Recv 发布后才能保证完成,因此您会遇到典型的死锁。

    它恰好适用于小消息,因为它们的处理方式不同(使用意外消息缓冲区作为性能优化)。在这种情况下,MPI_Send 可以在 MPI_Recv 发布之前完成。

    您也可以:

    • 发布立即发送或接收(MPI_IsendMPI_Irecv)以解决死锁。
    • 使用MPI_Sendrecv
    • 使用MPI_Allgather

    我推荐后者。

    【讨论】:

    • 但是对于性能,哪种方法可以是最好的解决方案???( MPI_Send , ISend , Sendrecv )
    猜你喜欢
    • 2011-11-11
    • 2016-04-22
    • 2014-04-25
    • 2014-04-17
    • 2011-01-24
    • 1970-01-01
    • 2017-10-25
    • 2018-03-05
    • 2018-05-29
    相关资源
    最近更新 更多