cannam@167: dnl @synopsis ACX_MPI([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) cannam@167: dnl @summary figure out how to compile/link code with MPI cannam@167: dnl @category InstalledPackages cannam@167: dnl cannam@167: dnl This macro tries to find out how to compile programs that cannam@167: dnl use MPI (Message Passing Interface), a standard API for cannam@167: dnl parallel process communication (see http://www-unix.mcs.anl.gov/mpi/) cannam@167: dnl cannam@167: dnl On success, it sets the MPICC, MPICXX, or MPIF77 output variable to cannam@167: dnl the name of the MPI compiler, depending upon the current language. cannam@167: dnl (This may just be $CC/$CXX/$F77, but is more often something like cannam@167: dnl mpicc/mpiCC/mpif77.) It also sets MPILIBS to any libraries that are cannam@167: dnl needed for linking MPI (e.g. -lmpi, if a special MPICC/MPICXX/MPIF77 cannam@167: dnl was not found). cannam@167: dnl cannam@167: dnl If you want to compile everything with MPI, you should set: cannam@167: dnl cannam@167: dnl CC="$MPICC" #OR# CXX="$MPICXX" #OR# F77="$MPIF77" cannam@167: dnl LIBS="$MPILIBS $LIBS" cannam@167: dnl cannam@167: dnl NOTE: The above assumes that you will use $CC (or whatever) cannam@167: dnl for linking as well as for compiling. (This is the cannam@167: dnl default for automake and most Makefiles.) cannam@167: dnl cannam@167: dnl The user can force a particular library/compiler by setting the cannam@167: dnl MPICC/MPICXX/MPIF77 and/or MPILIBS environment variables. cannam@167: dnl cannam@167: dnl ACTION-IF-FOUND is a list of shell commands to run if an MPI cannam@167: dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands cannam@167: dnl to run it if it is not found. If ACTION-IF-FOUND is not specified, cannam@167: dnl the default action will define HAVE_MPI. cannam@167: dnl cannam@167: dnl @version 2005-09-02 cannam@167: dnl @license GPLWithACException cannam@167: dnl @author Steven G. Johnson cannam@167: cannam@167: AC_DEFUN([ACX_MPI], [ cannam@167: AC_PREREQ(2.50) dnl for AC_LANG_CASE cannam@167: cannam@167: AC_LANG_CASE([C], [ cannam@167: AC_REQUIRE([AC_PROG_CC]) cannam@167: AC_ARG_VAR(MPICC,[MPI C compiler command]) cannam@167: AC_CHECK_PROGS(MPICC, mpicc hcc mpcc mpcc_r mpxlc cmpicc, $CC) cannam@167: acx_mpi_save_CC="$CC" cannam@167: CC="$MPICC" cannam@167: AC_SUBST(MPICC) cannam@167: ], cannam@167: [C++], [ cannam@167: AC_REQUIRE([AC_PROG_CXX]) cannam@167: AC_ARG_VAR(MPICXX,[MPI C++ compiler command]) cannam@167: AC_CHECK_PROGS(MPICXX, mpic++ mpiCC mpicxx mpCC hcp mpxlC mpxlC_r cmpic++, $CXX) cannam@167: acx_mpi_save_CXX="$CXX" cannam@167: CXX="$MPICXX" cannam@167: AC_SUBST(MPICXX) cannam@167: ], cannam@167: [Fortran 77], [ cannam@167: AC_REQUIRE([AC_PROG_F77]) cannam@167: AC_ARG_VAR(MPIF77,[MPI Fortran compiler command]) cannam@167: AC_CHECK_PROGS(MPIF77, mpif77 hf77 mpxlf mpf77 mpif90 mpf90 mpxlf90 mpxlf95 mpxlf_r cmpifc cmpif90c, $F77) cannam@167: acx_mpi_save_F77="$F77" cannam@167: F77="$MPIF77" cannam@167: AC_SUBST(MPIF77) cannam@167: ]) cannam@167: cannam@167: if test x = x"$MPILIBS"; then cannam@167: AC_LANG_CASE([C], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])], cannam@167: [C++], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])], cannam@167: [Fortran 77], [AC_MSG_CHECKING([for MPI_Init]) cannam@167: AC_TRY_LINK([],[ call MPI_Init], [MPILIBS=" " cannam@167: AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])]) cannam@167: fi cannam@167: if test x = x"$MPILIBS"; then cannam@167: AC_CHECK_LIB(mpi, MPI_Init, [MPILIBS="-lmpi"]) cannam@167: fi cannam@167: if test x = x"$MPILIBS"; then cannam@167: AC_CHECK_LIB(mpich, MPI_Init, [MPILIBS="-lmpich"]) cannam@167: fi cannam@167: cannam@167: dnl We have to use AC_TRY_COMPILE and not AC_CHECK_HEADER because the cannam@167: dnl latter uses $CPP, not $CC (which may be mpicc). cannam@167: AC_LANG_CASE([C], [if test x != x"$MPILIBS"; then cannam@167: AC_MSG_CHECKING([for mpi.h]) cannam@167: AC_TRY_COMPILE([#include ],[],[AC_MSG_RESULT(yes)], [MPILIBS="" cannam@167: AC_MSG_RESULT(no)]) cannam@167: fi], cannam@167: [C++], [if test x != x"$MPILIBS"; then cannam@167: AC_MSG_CHECKING([for mpi.h]) cannam@167: AC_TRY_COMPILE([#include ],[],[AC_MSG_RESULT(yes)], [MPILIBS="" cannam@167: AC_MSG_RESULT(no)]) cannam@167: fi]) cannam@167: cannam@167: AC_LANG_CASE([C], [CC="$acx_mpi_save_CC"], cannam@167: [C++], [CXX="$acx_mpi_save_CXX"], cannam@167: [Fortran 77], [F77="$acx_mpi_save_F77"]) cannam@167: cannam@167: AC_SUBST(MPILIBS) cannam@167: cannam@167: # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: cannam@167: if test x = x"$MPILIBS"; then cannam@167: $2 cannam@167: : cannam@167: else cannam@167: ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1]) cannam@167: : cannam@167: fi cannam@167: ])dnl ACX_MPI