Quick question about command line arguments...

Pete Wyckoff pw at osc.edu
Mon Apr 12 10:30:57 EDT 2004


jjalonso at stanford.edu said on Sat, 10 Apr 2004 15:23 -0700:
> I have a quick question which is not life-or-death, but came up while 
> debugging a code today.  I had compiled an executable with mpich-p4 
> because I suspected some problem with the Myrinet libraries.  In order 
> to run it I do (from one of the nodes that PBS has assigned to the 
> job):
> 
> mpiexec -comm mpich-p4 /path/to/executable /path/to/inputfile
> 
> Our "executable" picks out the input file name "inputfile" using 
> IARGC() and GETARG() in a F95 main.  When it was not working I realized 
> that it appears that mpiexec is adding a large number of command line 
> arguments and puts the actual ones at the end.  I can obviously pick 
> out the last argument and I am happy, but this is not portable to a 
> number of different machines.
> 
> Is there something that can be done in mpiexec to solve this "ordering" 
> problem?

These extra command-line arguments are how MPICH-P4 processes figure out
the system environments for the MPI job.  Other MPI libraries use
environment variables which do not get in the way like this.  All MPI
launchers, including mpiexec and good old mpirun via rsh, must use these
command-line arguments to start up parallel tasks.

You might notice that if you had a C program it would work just fine.
In MPI_Init() there is code to strip off those argc/argv elements that
are only for the MPI library so your code sees just the arguments it
expects.  (You have to do argument processing _after_ MPI_Init(),
though.)

With FORTRAN, it looks like the MPICH authors decided it's too hard to
find the arguments directly, admittedly perhaps it is because it may be
different for each FOTRARN compiler, so they use the FORTRAN intrinsic
to pull out and copy all the args.  Thus stripping them does no good
since your FORTRAN main() still sees the original "extra" arguments.
Attached is a patch I use here that knows about the FORTRAN compilers we
use and avoids this copying.  If you don't have PGI or Intel you still
might be able to adapt it to your compiler.

(Before figuring this out I did try having mpiexec put the MPICH-P4
arguments at the end, or at the beginning, but there were still codes
that were annoyed at just having the extra args in there anywhere.)

		-- Pete
-------------- next part --------------
diff -ruN mpich-1.2.5.2-ib-0.9.2-stock/src/fortran/src/initf.c mpich-1.2.5.2-ib-0.9.2/src/fortran/src/initf.c
--- mpich-1.2.5.2-ib-0.9.2-stock/src/fortran/src/initf.c	2001-12-12 18:36:43.000000000 -0500
+++ mpich-1.2.5.2-ib-0.9.2/src/fortran/src/initf.c	2003-12-24 10:37:26.000000000 -0500
@@ -117,6 +117,40 @@
 void mpir_getarg_ ( MPI_Fint *, char *, MPI_Fint );
 #endif
 
+#if defined(__PGI)
+
+FORTRAN_API void FORT_CALL mpi_init_(MPI_Fint *ierr)
+{
+    extern int __argc_save;
+    extern char **__argv_save;
+
+    *ierr = MPI_Init(&__argc_save, &__argv_save);
+}
+
+#elif defined(__ICC) && (__ICC >= 800)
+
+FORTRAN_API void FORT_CALL mpi_init_(MPI_Fint *ierr)
+{
+    extern int for__l_argc;
+    extern char **for__a_argv;
+
+    *ierr = MPI_Init(&for__l_argc, &for__a_argv);
+}
+
+#elif defined(__ICC)
+
+/* old versions of intel compiler */
+FORTRAN_API void FORT_CALL mpi_init_(MPI_Fint *ierr)
+{
+    extern int xargc;
+    extern char **xargv;
+
+    *ierr = MPI_Init(&xargc, &xargv);
+}
+
+#else
+/* unknown compiler, just copy argc/argv */
+
 FORTRAN_API void FORT_CALL mpi_init_( MPI_Fint *ierr )
 {
     int  Argc;
@@ -185,4 +219,5 @@
        must initialize all languages */
 }
 
+#endif  /* unknown compiler, copying argc/argv */
 #endif


More information about the mpiexec mailing list