Discussion:
Getting MPI_Send error in my first program
(too old to reply)
Gaurav Gupta
2008-12-30 17:24:41 UTC
Permalink
I tried to run code :


#include <mpi.h>
void main(int argc, char **argv)
{
int nprocs, myrank, tag, rc;
float sendbuf, recvbuf;
MPI_Request req;
MPI_Status status;
rc = MPI_Init(&argc, &argv);
rc = MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
rc = MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
tag = 1;
if (myrank == 0)
{
sendbuf = 9.0;
rc = MPI_Send(&sendbuf, 1, MPI_FLOAT, 1, tag, MPI_COMM_WORLD);
}
else if (myrank == 1)
{
rc = MPI_Irecv(&recvbuf, 1, MPI_FLOAT, 0, tag, MPI_COMM_WORLD,
&req);
rc = MPI_Wait(&req, &status);
printf("recvbuf = %f\n", recvbuf);
}
rc = MPI_Finalize();
}


and got error message ::

[administrator-desktop:23637] *** An error occurred in MPI_Send
[administrator-desktop:23637] *** on communicator MPI_COMM_WORLD
[administrator-desktop:23637] *** MPI_ERR_RANK: invalid rank
[administrator-desktop:23637] *** MPI_ERRORS_ARE_FATAL (goodbye)

I am new to MPI programming and not able to figure out what is the
actual problem please help me out so i can start.

Thanks in advance.
Dave Seaman
2008-12-30 18:13:25 UTC
Permalink
Post by Gaurav Gupta
#include <mpi.h>
void main(int argc, char **argv)
{
int nprocs, myrank, tag, rc;
float sendbuf, recvbuf;
MPI_Request req;
MPI_Status status;
rc = MPI_Init(&argc, &argv);
rc = MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
rc = MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
tag = 1;
if (myrank == 0)
{
sendbuf = 9.0;
rc = MPI_Send(&sendbuf, 1, MPI_FLOAT, 1, tag, MPI_COMM_WORLD);
}
else if (myrank == 1)
{
rc = MPI_Irecv(&recvbuf, 1, MPI_FLOAT, 0, tag, MPI_COMM_WORLD,
&req);
rc = MPI_Wait(&req, &status);
printf("recvbuf = %f\n", recvbuf);
}
rc = MPI_Finalize();
}
[administrator-desktop:23637] *** An error occurred in MPI_Send
[administrator-desktop:23637] *** on communicator MPI_COMM_WORLD
[administrator-desktop:23637] *** MPI_ERR_RANK: invalid rank
[administrator-desktop:23637] *** MPI_ERRORS_ARE_FATAL (goodbye)
I am new to MPI programming and not able to figure out what is the
actual problem please help me out so i can start.
Thanks in advance.
The error messages indicate that you evidently ran the program with just
a single MPI process, which therefore would have rank 0. You attempted
to send a message to a process with rank 1, but no such process exists.

You need to make sure that at least two MPI processes are started.
Depending on your MPI implementation, you may be able to use a command
such as

mpiexec -n 2 ./a.out
--
Dave Seaman
Third Circuit ignores precedent in Mumia Abu-Jamal ruling.
<http://www.indybay.org/newsitems/2008/03/29/18489281.php>
Gaurav Gupta
2008-12-30 18:24:56 UTC
Permalink
Thank You very much sir.
Post by Dave Seaman
Post by Gaurav Gupta
#include <mpi.h>
void main(int argc, char **argv)
{
int nprocs, myrank, tag, rc;
float sendbuf, recvbuf;
MPI_Request req;
MPI_Status status;
rc = MPI_Init(&argc, &argv);
rc = MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
rc = MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
tag = 1;
if (myrank == 0)
{
sendbuf = 9.0;
rc = MPI_Send(&sendbuf, 1, MPI_FLOAT, 1, tag, MPI_COMM_WORLD);
}
else if (myrank == 1)
{
rc = MPI_Irecv(&recvbuf, 1, MPI_FLOAT, 0, tag, MPI_COMM_WORLD,
&req);
rc = MPI_Wait(&req, &status);
printf("recvbuf = %f\n", recvbuf);
}
rc = MPI_Finalize();
}
[administrator-desktop:23637] *** An error occurred in MPI_Send
[administrator-desktop:23637] *** on communicator MPI_COMM_WORLD
[administrator-desktop:23637] *** MPI_ERR_RANK: invalid rank
[administrator-desktop:23637] *** MPI_ERRORS_ARE_FATAL (goodbye)
I am new to MPI programming and not able to figure out what is the
actual problem please help me out so i can start.
Thanks in advance.
The error messages indicate that you evidently ran the program with just
a single MPI process, which therefore would have rank 0. You attempted
to send a message to a process with rank 1, but no such process exists.
You need to make sure that at least two MPI processes are started.
Depending on your MPI implementation, you may be able to use a command
such as
mpiexec -n 2 ./a.out
--
Dave Seaman
Third Circuit ignores precedent in Mumia Abu-Jamal ruling.
<http://www.indybay.org/newsitems/2008/03/29/18489281.php>
Loading...