argv is an array of strings containing arguments that are passed to the program. The first element of argv is the first argument passed to command, not, as is conventional in some contexts, the command itself. The argument list is terminated by NULL in C and C++ and an empty string in Fortran. In Fortran, leading and trailing spaces are always stripped, so that a string consisting of all spaces is considered an empty string. The constant MPI_ARGV_NULL may be used in C, C++ and Fortran to indicate an empty argument list. In C and C++, this constant is the same as NULL.
To run the program ``ocean'' with arguments ``-gridfile'' and ``ocean1.grd'' in C:
char command[] = "ocean"; char *argv[] = {"-gridfile", "ocean1.grd", NULL}; MPI_Comm_spawn(command, argv, ...);or, if not everything is known at compile time:
char *command; char **argv; command = "ocean"; argv=(char **)malloc(3 * sizeof(char *)); argv[0] = "-gridfile"; argv[1] = "ocean1.grd"; argv[2] = NULL; MPI_Comm_spawn(command, argv, ...);In Fortran:
CHARACTER*25 command, argv(3) command = ' ocean ' argv(1) = ' -gridfile ' argv(2) = ' ocean1.grd' argv(3) = ' ' call MPI_COMM_SPAWN(command, argv, ...)
Arguments are supplied to the program if this is allowed by the operating system. In C, the MPI_COMM_SPAWN argument argv differs from the argv argument of main in two respects. First, it is shifted by one element. Specifically, argv[0] of main is provided by the implementation and conventionally contains the name of the program (given by command). argv[1] of main corresponds to argv[0] in MPI_COMM_SPAWN, argv[2] of main to argv[1] of MPI_COMM_SPAWN, etc. Second, argv of MPI_COMM_SPAWN must be null-terminated, so that its length can be determined. Passing an argv of MPI_ARGV_NULL to MPI_COMM_SPAWN results in main receiving argc of 1 and an argv whose element 0 is (conventionally) the name of the program.
If a Fortran implementation supplies routines that allow a program to obtain its arguments, the arguments may be available through that mechanism. In C, if the operating system does not support arguments appearing in argv of main(), the MPI-/ implementation may add the arguments to the argv that is passed to MPI_INIT.
MPI-Standard for MARMOT