charmplusplus / charm

The Charm++ parallel programming system. Visit https://charmplusplus.org/ for more information.
Apache License 2.0
202 stars 49 forks source link

AMPI Fortran command line arg's not parsed consistently w/ Fortran standard #669

Closed epmikida closed 9 years ago

epmikida commented 9 years ago

Original issue: https://charm.cs.illinois.edu/redmine/issues/669


To recreate using the attached program:

./build AMPI net-linux-x86_64 gfortran gcc ampif90 cmd_line.f90 -o cmd_line ./charmrun ./cmd_line x y z

This should cause the following output: Arg count = 3 Arg 1: x Arg 2: y Arg 3: z

But instead nothing gets printed out.

If you comment out lines 4 and 25 and uncomment lines 3 and 26, you can recompile and run it as a regular MPI program:

mpif90 cmd_line.f90 -o cmd_line mpirun -n 1 ./cmd_line x y z

And it gives the expected output.

cmd_line.f90

stwhite91 commented 5 years ago

Original date: 2015-02-12 21:20:55


This problem does not occur with C/C++ AMPI programs, only Fortran.

The example program uses the Fortran2003 standard's command line parsing functions. Before the 2003 standard, Fortran did not have a standard way of accessing the command line, though gfortran provided its own intrinsic functions iargc() and getarg() which other compilers copied before the 2003 standard.

MPI implementations seem to differ on their support of Fortran command line arguments. MPICH1 required compiler intrinsics for it and MPICH2 and MPICH3 abandoned that requirement and guaranteed nothing.

stwhite91 commented 5 years ago

Original date: 2015-02-18 22:33:48


I found two functions in ampif.C for handling command line arguments in Fortran AMPI programs: mpi_get_argc() and mpi_get_argv(). These have to be called in place of the usual Fortran command line parsing functions in order to handle command line arguments in Fortran AMPI programs.

These functions use the C/C++ idiom of command line parsing though: they include the program's name in argc and argv. Fortran does not include the program's name or anything before it in the argument list. I will add functions to AMPI that follow the Fortran conventions so that you can drop the replacements into a Fortran MPI program when running with AMPI.

Also, this should probably be added to the AMPI documentation somewhere, since no other MPI implementation does this. And more generally we might also want to add a Fortran AMPI example program to examples/ampi/.