【发布时间】:2018-06-18 20:18:44
【问题描述】:
我正在使用 MPI 解决负载平衡问题:主进程将任务发送给从属进程,并在它们计算并发回工作时收集结果。 由于我想尽可能提高性能,我使用非阻塞通信:Master 发送多个任务,然后等到一个进程发回其响应,以便 Master 可以向它发送额外的工作等等。
我使用 MPI_Waitany(),因为我事先不知道哪个从进程首先响应,然后我从状态中获取发送者,然后我可以将新作业发送给它。
我的问题是有时我收到的发件人是错误的(不在 MPI_COMM_WORLD 中的排名)并且程序崩溃;其他时候效果很好。
这是代码。谢谢!
//master
if (rank == 0) {
int N_chunks = 10;
MPI_Request request[N_chunks];
MPI_Status status[N_chunks];
int N_computed = 0;
int dest,index_completed;
//initialize array of my data structure
vec send[N_chunks];
vec recv[N_chunks];
//send one job to each process in communicator
for(int i=1;i<size;i++){
MPI_Send( &send[N_computed], 1, mpi_vec_type, i, tag, MPI_COMM_WORLD);
MPI_Irecv(&recv[N_computed], 1, mpi_vec_type, i, tag, MPI_COMM_WORLD,
&request[N_computed]);
N_computed++;
}
// loop
while (N_computed < N_chunks){
//get processed messages
MPI_Waitany(N_computed,request,&index_completed,status);
//get sender ID dest
dest = status[index_completed].MPI_SOURCE;
//send a new job to that process
MPI_Send( &send[N_computed], 1, mpi_vec_type, dest, tag, MPI_COMM_WORLD);
MPI_Irecv(&recv[N_computed], 1, mpi_vec_type, dest, tag, MPI_COMM_WORLD,
&request[N_computed]);
N_computed++;
}
MPI_Waitall(N_computed,request,status);
//close all process
printf("End master\n");
}
【问题讨论】:
标签: c parallel-processing mpi