【发布时间】:2016-08-11 07:55:31
【问题描述】:
MPI_Rsend man papers,为了使用 MPI_Rsend,我们需要保证接收已经发布。如果在调用就绪发送之前没有发布接收是错误的。但是如何保证接收已经发布???。我尝试找到一些关于 MPI_Rsend 的示例,但我找不到任何东西。以及如何得到这个错误?
在此链接MPI_RSend_error 中,最后有人说:“不要使用 MPI_Rsend - 它是一种古老的东西,它的行为没有明确定义,并且它已被现代 MPI 中的所有协议优化所淘汰库”。那么,哪些 MPI 库完全实现了 RSend ?事实上,在某些算法中,使用 MPI_Rsend 会比 MPI_Send 提供更好的性能。
示例代码:
void AllGather_ring_RSend(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_Rsend(data+curi*sizeof(int), count, datatype, next, 0, communicator);
curi=curi-1;
if(curi<0)
curi=world_size-1;
MPI_Recv(data+curi*sizeof(int), count, datatype, prev, 0, communicator, MPI_STATUS_IGNORE);
}
}
void main(int argc, char** argv) {
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));
int i;
for (i = 0; i < world_size; i++) {
buff[i]=world_rank;
}
if(world_rank==0)
for (i = 0; i < world_size; i++)
printf("%d\n",buff[i]);
MPI_Barrier(MPI_COMM_WORLD);
AllGather_ring_RSend(buff,1,MPI_INT,MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
}
在这段代码中,接收过程是否已经发布???
【问题讨论】: