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