簡體   English   中英

限制為MPI_Send或MPI_Recv?

[英]Limits with MPI_Send or MPI_Recv?

我們對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個進程)

您的代碼不正確。 僅在完成各自的發送后才過帳接收。 只有在發布相應的MPI_Recv之后,才能保證MPI_Send完成,因此您會遇到經典的死鎖。

它恰好適用於小消息,因為它們的處理方式不同(使用意外的消息緩沖區作為性能優化)。 在這種情況下,允許在發布MPI_Recv之前完成MPI_Send

或者,您可以:

  • 立即發布發送或接收( MPI_IsendMPI_Irecv )以解決死鎖。
  • 使用MPI_Sendrecv
  • 使用MPI_Allgather

我推薦后者。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM