MPICH software installations and programming hacks

From Research Computing

MPICH versions

MPICH version 1.2.7, compiled for the PGI CDK version 5.2-2 compiler, is installed under /usr/pgi/mpich/mpich-1.2.7

MPICH version 1.2.7, compiled for g++, gcc and g77 (./configure was invoked after setting CC=gcc, CXX=g++ and F77=g77), is installed under /usr/pgi/mpich/mpich-1.2.7

Using the MPICH libraries

One way to compile and link against one of the MPICH libraries is to add the bin directory of the desired installation to the path, and use one of the compiler wrapper scripts that come with MPICH; e.g.,

PATH=/usr/pgi/mpich/mpich-1.2.7/bin:$PATH
mpif77 -o pong pingpong.f

The test program pingpong.f is available under

/usr/pgi/mpich/mpich-1.2.7/examples/test/pt2pt/pingpong.f

The notorious double-underscore problem

The mpich libraries are compiled with annoying double underscores in function names. Some compilers must be directed to insert a second undersore in the object; mpif90 is an example. Circumventing the problem is a two-step process. The steps given apply to the pgf90 compiler.

Step one: the following function farg.f must be compiled with second underscores appended.

     integer function mpir_iargc()
 
     mpir_iargc = IARGC()
     return
     end
c
     subroutine mpir_getarg( i, s )
 
     integer       i
     character (LEN=*) s
     external getarg
     call GETARG(i,s)
     return
     end

The file farg.f is available in the following location.

/usr/pgi/mpich/mpich-1.2.7/src/fortran/src/farg.f

The compilation is as follows:

pgf90 -c farg.f -Msecond_underscore

Step two: the object file farg.o must be linked with the program (in this example troy_3.f), which also must be compiled with the -Msecond_underscore flag.

export MPICH_HOME=/usr/pgi/mpich/mpich-1.2.7
$MPICH_HOME/bin/mpif90 -Msecond_underscore -O3 troy_3.f -o troy_3R1 farg.o

Note what happens if the -Msecond_underscore flag is omitted:

[flengyel@m254 troy_3]$ $MPICH_HOME/bin/mpif90 -O3 troy_3.f -o troy_3R1 farg.o
troy_3.o(.text+0x3b): In function `MAIN_':
: undefined reference to `mpi_init_'
troy_3.o(.text+0x5a): In function `MAIN_':
: undefined reference to `mpi_comm_rank_'
troy_3.o(.text+0x79): In function `MAIN_':
: undefined reference to `mpi_comm_size_'

Has this ever happened to you? Then set the -Msecond_underscore flag. If you set this flag, but don't include the object file farg.o from Step One, you will get the following linker error.

[flengyel@m254 troy_3]$ $MPICH_HOME/bin/mpif90 -O3 -Msecond_underscore troy_3.f -o troy_3R1
/usr/pgi/mpich/mpich-1.2.7/lib/libmpich.a(farg.o)(.text+0x7): In function `mpir_iargc__':
: undefined reference to `f__xargc'