Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] Open MPI programs with autoconf/automake?
From: Jeff Squyres (jsquyres_at_[hidden])
Date: 2008-11-10 11:27:11


On Nov 10, 2008, at 6:41 AM, Jed Brown wrote:

>> With #define's and compiler flags, I think that can be easily done
>> --
>> was wondering if this is something that developers using MPI do and
>> whether AC/AM supports it.

AC will allow you to #define whatever you want -- look at the
documentation for AC_DEFINE and AC_DEFINE_UNQUOTED. You can also tell
your configure script to accept various --with-<foo> and --enable-
<foo> arguments; see the docs for AC_ARG_WITH and AC_ARG_ENABLE.

> The normal way to do this is by building against a serial
> implementation
> of MPI. Lots of parallel numerical libraries bundle such an
> implementation so you could just grab one of those. For example, see
> PETSc's mpiuni ($PETSC_DIR/include/mpiuni/mpi.h and
> $PETSC_DIR/src/sys/mpiuni/mpi.c) which implements many MPI calls as
> macros.
>
> Note that your serial implementation only needs to provide the
> subset of
> MPI that your program actually uses. For instance, if you never send
> messages to yourself, you can implement MPI_Send as MPI_Abort since it
> should never be called in serial.

This is one viable way to do it. Another way that I have seen is to
use #define's (via AC_DEFINE / AC_DEFINE_UNQUOTED) to both define
BUILDING_WITH_MPI to 0 or 1 (or some variant) and conditionally use
the MPI wrapper compilers (or not) to build your application. This
technique is best suited to applications have are highly modular and
can easily segregate all your calls to MPI in a single area that can
be turned on / off with a #define.

To put this more concretely, you can have this:
    ./configure --with-mpi
that does two things:

1. set CC=mpicc (and friends) before calling AC_PROG_CC (and
friends). This will setup your app to be compiled with the MPI
wrapper compilers, and therefore automatically link in libmpi, etc.
2. #define BUILDING_WITH_MPI to 1, so in your code you can do stuff like
     #if BUILDING_WITH_MPI
     MPI_Send(...);
     #endif

If --with-mpi is not specified, the following will happen:

1. You don't set CC (and friends), so AC_PROG_CC will find the default
compilers. Hence, your app will not be compiled and linked against
the MPI libraries.
2. #define BUILDING_WITH_MPI to 0, so the code above will compile out
the call to MPI_Send().

Both of these are valid techniques -- use whichever suits your app the
best.

-- 
Jeff Squyres
Cisco Systems