1 dnl @synopsis ACX_MPI([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
3 dnl @summary figure out how to compile/link code with MPI
5 dnl This macro tries to find out how to compile programs that use MPI
6 dnl (Message Passing Interface), a standard API for parallel process
7 dnl communication (see http://www-unix.mcs.anl.gov/mpi/)
9 dnl On success, it sets the MPICC, MPICXX, or MPIF77 output variable to
10 dnl the name of the MPI compiler, depending upon the current language.
11 dnl (This may just be $CC/$CXX/$F77, but is more often something like
12 dnl mpicc/mpiCC/mpif77.) It also sets MPILIBS to any libraries that are
13 dnl needed for linking MPI (e.g. -lmpi, if a special
14 dnl MPICC/MPICXX/MPIF77 was not found).
16 dnl If you want to compile everything with MPI, you should set:
18 dnl CC="$MPICC" #OR# CXX="$MPICXX" #OR# F77="$MPIF77"
19 dnl LIBS="$MPILIBS $LIBS"
21 dnl NOTE: The above assumes that you will use $CC (or whatever) for
22 dnl linking as well as for compiling. (This is the default for automake
23 dnl and most Makefiles.)
25 dnl The user can force a particular library/compiler by setting the
26 dnl MPICC/MPICXX/MPIF77 and/or MPILIBS environment variables.
28 dnl ACTION-IF-FOUND is a list of shell commands to run if an MPI
29 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
30 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
31 dnl default action will define HAVE_MPI.
33 dnl @category InstalledPackages
34 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
35 dnl @version 2005-09-02
36 dnl @license GPLWithACException
39 AC_PREREQ(2.50) dnl for AC_LANG_CASE
42 AC_REQUIRE([AC_PROG_CC])
43 AC_ARG_VAR(MPICC,[MPI C compiler command])
44 AC_CHECK_PROGS(MPICC, mpicc hcc mpcc mpcc_r mpxlc cmpicc, $CC)
50 AC_REQUIRE([AC_PROG_CXX])
51 AC_ARG_VAR(MPICXX,[MPI C++ compiler command])
52 AC_CHECK_PROGS(MPICXX, mpic++ mpiCC mpicxx mpCC hcp mpxlC mpxlC_r cmpic++, $CXX)
53 acx_mpi_save_CXX="$CXX"
58 AC_REQUIRE([AC_PROG_F77])
59 AC_ARG_VAR(MPIF77,[MPI Fortran compiler command])
60 AC_CHECK_PROGS(MPIF77, mpif77 hf77 mpxlf mpf77 mpif90 mpf90 mpxlf90 mpxlf95 mpxlf_r cmpifc cmpif90c, $F77)
61 acx_mpi_save_F77="$F77"
66 if test x = x"$MPILIBS"; then
67 AC_LANG_CASE([C], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
68 [C++], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
69 [Fortran 77], [AC_MSG_CHECKING([for MPI_Init])
70 AC_TRY_LINK([],[ call MPI_Init], [MPILIBS=" "
71 AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])])
73 if test x = x"$MPILIBS"; then
74 AC_CHECK_LIB(mpi, MPI_Init, [MPILIBS="-lmpi"])
76 if test x = x"$MPILIBS"; then
77 AC_CHECK_LIB(mpich, MPI_Init, [MPILIBS="-lmpich"])
80 dnl We have to use AC_TRY_COMPILE and not AC_CHECK_HEADER because the
81 dnl latter uses $CPP, not $CC (which may be mpicc).
82 AC_LANG_CASE([C], [if test x != x"$MPILIBS"; then
83 AC_MSG_CHECKING([for mpi.h])
84 AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
87 [C++], [if test x != x"$MPILIBS"; then
88 AC_MSG_CHECKING([for mpi.h])
89 AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
93 AC_LANG_CASE([C], [CC="$acx_mpi_save_CC"],
94 [C++], [CXX="$acx_mpi_save_CXX"],
95 [Fortran 77], [F77="$acx_mpi_save_F77"])
99 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
100 if test x = x"$MPILIBS"; then
104 ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1])