[2f6525] | 1 | dnl @synopsis ACX_MPI([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
|
---|
| 2 | dnl
|
---|
| 3 | dnl This macro tries to find out how to compile programs that
|
---|
| 4 | dnl use MPI (Message Passing Interface), a standard API for
|
---|
| 5 | dnl parallel process communication (see http://www-unix.mcs.anl.gov/mpi/)
|
---|
| 6 | dnl
|
---|
| 7 | dnl On success, it sets the MPICC, MPICXX, or MPIF77 output variable to
|
---|
| 8 | dnl the name of the MPI compiler, depending upon the current language.
|
---|
| 9 | dnl (This may just be $CC/$CXX/$F77, but is more often something like
|
---|
| 10 | dnl mpicc/mpiCC/mpif77.) It also sets MPILIBS to any libraries that are
|
---|
| 11 | dnl needed for linking MPI (e.g. -lmpi, if a special MPICC/MPICXX/MPIF77
|
---|
| 12 | dnl was not found).
|
---|
| 13 | dnl
|
---|
| 14 | dnl If you want to compile everything with MPI, you should set:
|
---|
| 15 | dnl
|
---|
| 16 | dnl CC="$MPICC" #OR# CXX="$MPICXX" #OR# F77="$MPIF77"
|
---|
| 17 | dnl LIBS="$MPILIBS $LIBS"
|
---|
| 18 | dnl
|
---|
| 19 | dnl The user can force a particular library/compiler by setting the
|
---|
| 20 | dnl MPICC/MPICXX/MPIF77 and/or MPILIBS environment variables.
|
---|
| 21 | dnl
|
---|
| 22 | dnl ACTION-IF-FOUND is a list of shell commands to run if an MPI
|
---|
| 23 | dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands
|
---|
| 24 | dnl to run it if it is not found. If ACTION-IF-FOUND is not specified,
|
---|
| 25 | dnl the default action will define HAVE_MPI.
|
---|
| 26 | dnl
|
---|
| 27 | dnl @version $Id: acx_mpi.m4,v 1.2 2004-01-02 14:51:12 wildenhu Exp $
|
---|
| 28 | dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
|
---|
| 29 |
|
---|
| 30 | AC_DEFUN([ACX_MPI], [
|
---|
| 31 | AC_PREREQ(2.50) dnl for AC_LANG_CASE
|
---|
| 32 |
|
---|
| 33 | AC_LANG_CASE([C], [
|
---|
| 34 | AC_REQUIRE([AC_PROG_CC])
|
---|
| 35 | AC_ARG_VAR(MPICC,[MPI C compiler command])
|
---|
| 36 | AC_CHECK_PROGS(MPICC, mpicc hcc mpcc mpcc_r mpxlc, $CC)
|
---|
| 37 | acx_mpi_save_CC="$CC"
|
---|
| 38 | CC="$MPICC"
|
---|
| 39 | AC_SUBST(MPICC)
|
---|
| 40 | ],
|
---|
| 41 | [C++], [
|
---|
| 42 | AC_REQUIRE([AC_PROG_CXX])
|
---|
| 43 | AC_ARG_VAR(MPICXX,[MPI C++ compiler command])
|
---|
| 44 | AC_CHECK_PROGS(MPICXX, mpiCC mpCC hcp mpic++, $CXX)
|
---|
| 45 | acx_mpi_save_CXX="$CXX"
|
---|
| 46 | CXX="$MPICXX"
|
---|
| 47 | AC_SUBST(MPICXX)
|
---|
| 48 | ],
|
---|
| 49 | [Fortran 77], [
|
---|
| 50 | AC_REQUIRE([AC_PROG_F77])
|
---|
| 51 | AC_ARG_VAR(MPIF77,[MPI Fortran compiler command])
|
---|
| 52 | AC_CHECK_PROGS(MPIF77, mpif77 hf77 mpxlf mpf77 mpif90 mpf90 mpxlf90 mpxlf95 mpxlf_r, $F77)
|
---|
| 53 | acx_mpi_save_F77="$F77"
|
---|
| 54 | F77="$MPIF77"
|
---|
| 55 | AC_SUBST(MPIF77)
|
---|
| 56 | ])
|
---|
| 57 |
|
---|
| 58 | if test x = x"$MPILIBS"; then
|
---|
| 59 | AC_LANG_CASE([C], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
|
---|
| 60 | [C++], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
|
---|
| 61 | [Fortran 77], [AC_MSG_CHECKING([for MPI_Init])
|
---|
| 62 | AC_TRY_LINK([],[ call MPI_Init], [MPILIBS=" "
|
---|
| 63 | AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])])
|
---|
| 64 | fi
|
---|
| 65 | if test x = x"$MPILIBS"; then
|
---|
| 66 | AC_CHECK_LIB(mpi, MPI_Init, [MPILIBS="-lmpi"])
|
---|
| 67 | fi
|
---|
| 68 | if test x = x"$MPILIBS"; then
|
---|
| 69 | AC_CHECK_LIB(mpich, MPI_Init, [MPILIBS="-lmpich"])
|
---|
| 70 | fi
|
---|
| 71 |
|
---|
| 72 | dnl We have to use AC_TRY_COMPILE and not AC_CHECK_HEADER because the
|
---|
| 73 | dnl latter uses $CPP, not $CC (which may be mpicc).
|
---|
| 74 | AC_LANG_CASE([C], [if test x != x"$MPILIBS"; then
|
---|
| 75 | AC_MSG_CHECKING([for mpi.h])
|
---|
| 76 | AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
|
---|
| 77 | AC_MSG_RESULT(no)])
|
---|
| 78 | fi],
|
---|
| 79 | [C++], [if test x != x"$MPILIBS"; then
|
---|
| 80 | AC_MSG_CHECKING([for mpi.h])
|
---|
| 81 | AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
|
---|
| 82 | AC_MSG_RESULT(no)])
|
---|
| 83 | fi])
|
---|
| 84 | dnl There are b0rked implementations that '#define main mpi_main' in their mpi.h
|
---|
| 85 | dnl which will cause all tests above to fail miserably (e.g. MPICH-SCore).
|
---|
| 86 | dnl TODO: prototype checking, exit instead of return from main, test C++, implement F77.
|
---|
| 87 | dnl TODO: use the information already gathered...
|
---|
| 88 | if test x = x"$MPILIBS"; then
|
---|
| 89 | AC_MSG_CHECKING([for last resort: compile and link a small MPI test program])
|
---|
| 90 | AC_LANG_CASE([C], [AC_LINK_IFELSE([#include <mpi.h>
|
---|
| 91 | int main(int argc, char **argv)
|
---|
| 92 | {
|
---|
| 93 | MPI_Init(&argc, &argv);
|
---|
| 94 | return 0;
|
---|
| 95 | }
|
---|
| 96 | ], [MPILIBS=" "
|
---|
| 97 | AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])],
|
---|
| 98 | [C++], [AC_LINK_IFELSE([#include <mpi.h>
|
---|
| 99 | int main(int argc, char **argv)
|
---|
| 100 | {
|
---|
| 101 | MPI_Init(&argc, &argv);
|
---|
| 102 | return 0;
|
---|
| 103 | }
|
---|
| 104 | ], [MPILIBS=" "
|
---|
| 105 | AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])],
|
---|
| 106 | [Fortran 77], [])
|
---|
| 107 | fi
|
---|
| 108 |
|
---|
| 109 | AC_LANG_CASE([C], [CC="$acx_mpi_save_CC"],
|
---|
| 110 | [C++], [CXX="$acx_mpi_save_CXX"],
|
---|
| 111 | [Fortran 77], [F77="$acx_mpi_save_F77"])
|
---|
| 112 |
|
---|
| 113 | AC_SUBST(MPILIBS)
|
---|
| 114 |
|
---|
| 115 | # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
|
---|
| 116 | if test x = x"$MPILIBS"; then
|
---|
| 117 | $2
|
---|
| 118 | :
|
---|
| 119 | else
|
---|
| 120 | ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1])
|
---|
| 121 | :
|
---|
| 122 | fi
|
---|
| 123 | ])dnl ACX_MPI
|
---|