【发布时间】:2018-09-20 10:40:25
【问题描述】:
我在使用 Isend 和 Ireceive 时遇到问题。我正在尝试向所有其他处理器发送消息,然后从其他执行相同 Isend 方法的处理器接收相同类型的消息。
void msgs(int my_rank, int num_procs){
int arrive_count = 1;
int leave_count = 0;
int i;
bool b_req = true;
MPI_Request req, req2;
//Send to all other procs
for(i=0; i<num_procs; i++){
if(i != my_rank){
MPI_Isend(&b_req,sizeof(bool),MPI_BYTE,i,1,MPI_COMM_WORLD, &req);
}
}
bool c_req;
//Receive msgs from all other procs
while(arrive_count != num_procs){
for(i=0; i<num_procs; i++){
if(i != my_rank){
MPI_Irecv(&c_req,sizeof(bool),MPI_BYTE,i,1,MPI_COMM_WORLD, &req2);
if(c_req){
c_req = false;
arrive_count ++;
}
MPI_Request_free(&req2);
}
}
}
printf("Done from rank: %d \n", my_rank);
}
【问题讨论】:
标签: c mpi distributed-computing send barrier