Reputation: 456
I got the above mentioned error on running the following program in C. The program uses 3-d hypercube topology to find sum of all elements of an 8-element array. It uses MPI library.:
#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;
}
Used 8 processes by calling
mpirun -n 8 ./a.out
Runtime error message:
An error occurred in MPI_Recv reported by process [3153068033,6] on communicator MPI_COMM_WORLD MPI_ERR_RANK: invalid rank MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort, and potentially your MPI job)
Upvotes: 4
Views: 9266
Reputation: 8395
It looks like an error in the way you use bitwise and.
For example, it should be
if (rank & 2)
instead of
if (rank&2 == 1)
rank&2
is a bitwise and, which means its value is either 0
or 2
(and it is never 1
)
Upvotes: 2