Why does MPI_Init accept pointers to argc and argv?

Rohit Banga picture Rohit Banga · Apr 15, 2010 · Viewed 19.3k times · Source

this is how we use MPI_Init function

int main(int argc, char **argv)
{
    MPI_Init(&argc, &argv);
…
}

why does MPI_Init use pointers to argc and argv instead of values of argv?

Answer

NickTee picture NickTee · Apr 21, 2012

According to the answer stated here:

Passing arguments via command line with MPI

Most MPI implementations will remove all the mpirun-related arguments in this function so that, after calling it, you can address command line arguments as though it were a normal (non-mpirun) command execution.

i.e. after

mpirun -np 10 myapp myparam1 myparam2

argc = 7(?) because of the mpirun parameters (it also seems to add some) and the indices of myparam1 and myparam2 are unknown

but after

MPI_Init(&argc, &argv)

argc = 3 and myparam1 is at argv[1] and myparam2 is at argv[2]

Apparently this is outside the standard, but I've tested it on linux mpich and it certainly seems to be the case. Without this behaviour it would be very difficult (impossible?) to distinguish application parameters from mpirun parameters.