When writing MPI 3.0 code, should I pass argc
and argv
to the MPI_Init
call or not, and why?
EDIT: Since Bill Barth's answer raised some questions I want to make some remarks:
- Passing
argc
/argv
is not required since MPI 1.1. - The question is specifically about why should/shouldn't one pass
argc
/argv
(why shouldn't you is then not really an answer). - Still, sometimes you cannot pass
argc
/argv
toMPI_Init
(writing a library that uses static initialization to start MPI if main is outside your control and MPI is an implementation detail).
EDIT2: The question why wouldn't you use MPI_Init(argc, argv)
has come too often now. Some reasons:
Doing it for the sake of compatibility with older/non-compliant/compliant MPI < 1.1 implementations is not possible since if you are using MPI2 or MPI3 features those won't work anyways.
MPI_Init()
initializes the MPI runtime in the same way asMPI_Init(argc, argv)
MPI_Init(argc, argv)
removes arguments passed to the MPI run-time fromargc
, andargv
and initializes MPI. AFAIK it is the only way to cleanargc
andargv
so if you need these to have no MPI arguments you need to use it.MPI_Init()
can be used in more situations thatMPI_Init(argc, argv)
. For example your library using MPI as an implementation detail can test if MPI is initialized, and if not, callMPI_Init()
and the right thing will happen. Your user doesn't know that you are using mpi, doesn't need to passargc
,argv
to your library, doesn't need to change their main (in case it is taking no arguments) to use your library....
MPI_Init()
which has to correctly get the arguments you pass tompirun
/mpiexec
somehow (it is unspecified how), and sinceMPI_Init()
can be used in more situations thanMPI_Init(argc, argv)
(and without workarounds), I don't really see the point on usingMPI_Init(argc, argv)
if you are targeting MPI 3.0. $\endgroup$argc
andargv
from MPI arguments and initialize MPI then useMPI_Init(argc, argv)
, otherwiseMPI_Init()
is fine (and sometimes it is necessary). $\endgroup$