2016-05-13 47 views
0

我們是否有關於郵件大小的限制MPI_SendMPI_Recv - 或通過計算機限制?當我嘗試發送大量數據時,無法完成。 這是我的代碼:MPI_Send或MPI_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流程)

回答

1

你的代碼是不正確停止。只有在各自的發送完成後才能發送接收者。 MPI_Send只有在發佈相應的MPI_Recv後才能保證完成,因此您會遇到經典的死鎖。

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

另外,您可以:

  • 後立即發送或接收(MPI_IsendMPI_Irecv)來解決僵局。
  • 使用MPI_Sendrecv
  • 使用MPI_Allgather

我推薦後者。

+0

但是對於性能,哪種方法可以是最好的解決方案???(MPI_Send,ISend,Sendrecv) – voxter

+0

'MPI_Allgather'。 – Zulan