MPI接收不返回

时间:2019-05-02 01:28:16

标签: c++ linux mpi

我正在尝试在Linux上使用MPI发送和接收数据。我已经检查了以前的解决方案,并据此进行了更改,但是我的接收代码仍处于阻塞状态。如果我只是运行MPI_Send(...),就没有问题。但是,如果我先运行MPI_Send(...),再运行MPI_Recv(...),则程序进入睡眠状态。

#include <iostream>
#include <fstream>
#include <cmath>
#include <mpi.h>
#include <ctime>
#include <vector>

//using namespace std;





int rank, size;
int tag = 99;
int main(int argc, char * argv[])
{
double sTime, eTime, rTime;
std::ifstream inFile;
int num_rows = 3200;
int num_cols = 3200;
int cur_control = 0;
double * send_buffer = NULL;
double * recv_buffer = NULL;
double ** data = NULL;
double determinant;
MPI_Status stat;
std::vector<double> file_buffer;


// Just get the initialization of the program going.
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);



send_buffer = new double[num_rows];
// Broadcasts p2p the number of rows to each processor.
//MPI_Bcast (&num_rows, 1, MPI_INT, 0, MPI_COMM_WORLD);

if(! rank) { 
for(int i=1; i<size; ++i) {

 MPI_Send(&num_rows, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
}
}
for(int i=1; i<size; ++i) {

 MPI_Recv(&num_rows, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &stat);
}
num_cols = num_rows / size;

delete [] send_buffer;
MPI_Finalize();
return 0;
}

0 个答案:

没有答案
相关问题