我和我的代码并行,其中一部分有一个我无法弄清楚的奇怪行为。这段代码如下:
int SizeEdgeForNewNodes_int;
{
MPI_Request send_request[mpi_size - 1], recv_request;
MPI_Status send_status[mpi_size - 1], recv_status;
MPI_Barrier(MPI_COMM_WORLD);
if (myrank == 0) {
for (int m = 1; m < mpi_size; ++m){
int sendTag = m;
MPI_Isend(&SizeEdgeForNewNodes[m], 1, MPI_INT64_T, m, sendTag, MPI_COMM_WORLD, &send_request[m - 1]);
cout << myrank << " - SizeEdgeForNewNodes[m] = " << SizeEdgeForNewNodes[m] << endl;
}
}
MPI_Barrier(MPI_COMM_WORLD);
if (myrank > 0) {
int recvTag = myrank;
cout << "within b4 - myrank = " << myrank << endl;
MPI_Irecv(&SizeEdgeForNewNodes_int, 1, MPI_INT64_T, 0, recvTag, MPI_COMM_WORLD, &recv_request); // 1st non blocking receive
cout << "within after - myrank = " << myrank << endl;
}
MPI_Barrier(MPI_COMM_WORLD);
if (myrank != 0){
MPI_Wait(&recv_request, &recv_status);
}
MPI_Barrier(MPI_COMM_WORLD);
if (myrank == 0){
MPI_Waitall(mpi_size - 1, send_request, send_status);
}
MPI_Barrier(MPI_COMM_WORLD);
}
在Debug版本中运行代码时一切正常,获得的输出为:
0 - SizeEdgeForNewNodes[m] = 0
within b4 - myrank = 1
within after - myrank = 1
在Release中运行时,我获得以下输出:
0 - SizeEdgeForNewNodes[m] = 0
within b4 - myrank = 1
within after - myrank = 0
我使用的是intel-15.0编译器,MPI实现是mvapich2 / 2.1。 谢谢你的帮助,
JB
答案 0 :(得分:3)
你收到一个64位的int,但你的缓冲区被分配了32位!因此,接收到的值将覆盖您的本地变量(myrank)。 要解决此问题,请更改接收缓冲区的dataType(SizeEdgeForNewNodes_int)