在C中运行以下程序时,我得到了上述错误。该程序使用三维超立方体拓扑来查找一个8元素数组的所有元素的和。它使用MPI库。
#include<stdio.h>
#include<mpi.h>
int main(int argc, char **argv)
{
int rank, n, src, dest;
MPI_Init(&argc, &argv);
MPI_Status status;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &n);
int tag = 100;
int receive;
int array[8] = {10, 20, 30, 40, 50, 60, 70, 80};
if (rank&1 == 1)
MPI_Send(&array[rank], 1, MPI_INT, rank-1, tag, MPI_COMM_WORLD);
else
{
MPI_Recv(&receive, 1, MPI_INT, rank+1, tag, MPI_COMM_WORLD, &status);
array[rank] += receive;
if (rank&2 == 1)
MPI_Send(&array[rank], 1, MPI_INT, rank-2, tag, MPI_COMM_WORLD);
else
{
MPI_Recv(&receive, 1, MPI_INT, rank+2, tag, MPI_COMM_WORLD, &status);
array[rank] += receive;
if (rank&4 == 1)
MPI_Send(&array[rank], 1, MPI_INT, rank-4, tag, MPI_COMM_WORLD);
else
{
MPI_Recv(&receive, 1, MPI_INT, rank+4, tag, MPI_COMM_WORLD, &status);
array[rank] += receive;
printf("\n%d \n", array[0]);
}
}
}
MPI_Finalize();
return 0;
}通过调用使用8个进程
mpirun -n 8 ./a.out运行时错误消息:
process 3153068033,6在通信器MPI_Recv MPI_ERR_RANK上报告的错误:无效的秩MPI_ERRORS_ARE_FATAL (此通信器中的进程现在将中止,并且可能是您的MPI作业)
发布于 2017-09-07 14:14:26
它看起来像一个错误的方式使用按位和。
例如,它应该是
if (rank & 2)而不是
if (rank&2 == 1)rank&2是按位的,这意味着它的值要么是0,要么是2 (而且它永远不是1)。
https://stackoverflow.com/questions/46090999
复制相似问题