mpirun (and mpiexec) do not seem to be passing command line arguments to my c code.
Running my exeutable "gecko" directly from the command line gives expected:
$ ./gecko -np 2
main:There are 3 arguments:
arg=./gecko
arg=-np
arg=2
But running the same through mpirun is different:
$ mpirun -np 2 ./gecko
main:There are 1 arguments:
arg=./gecko
which means MPI_init(argc,argv) doesn't have any arguments to work with. I'm on Ubuntu 12.04 with MPICH 2.
Can anyone see a reason why this is not happening?
Thanks.
--------------------------- EDIT ---------------------------------
There are many examples on the net that say the way to initialize MPI is via the command line arguments, eg.:
#include <stdio.h>
#include “mpi.h”
int main(int argc, char* argv[])
{
int size, rank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf(“Greetings from process %i\n”, rank);
MPI_Finalize();
return 0;
}
and that the way to execute the mpi code is to use:
mpirun -np 2 ./code_name
So, if mpirun does not pass the arguments np and 2 to the c code, how does the c code ever get to know how many processors it should be run on?
mpirun -np 2 ./gecko -np 2if you'd like to pass-np 2togecko. - Hristo Ilievargcandargvshould be passed toMPI_Init. MPI-2 removed that requirement. Most examples useMPI_Init(&argc, &argv)purely of historical reasons. - Hristo Iliev