[de061d] | 1 | # ===========================================================================
|
---|
| 2 | # http://www.nongnu.org/autoconf-archive/acx_mpi.html
|
---|
| 3 | # ===========================================================================
|
---|
| 4 | #
|
---|
| 5 | # SYNOPSIS
|
---|
| 6 | #
|
---|
| 7 | # ACX_MPI([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
|
---|
| 8 | #
|
---|
| 9 | # DESCRIPTION
|
---|
| 10 | #
|
---|
| 11 | # This macro tries to find out how to compile programs that use MPI
|
---|
| 12 | # (Message Passing Interface), a standard API for parallel process
|
---|
| 13 | # communication (see http://www-unix.mcs.anl.gov/mpi/)
|
---|
| 14 | #
|
---|
| 15 | # On success, it sets the MPICC, MPICXX, MPIF77, or MPIFC output variable
|
---|
| 16 | # to the name of the MPI compiler, depending upon the current language.
|
---|
| 17 | # (This may just be $CC/$CXX/$F77/$FC, but is more often something like
|
---|
| 18 | # mpicc/mpiCC/mpif77/mpif90.) It also sets MPILIBS to any libraries that
|
---|
| 19 | # are needed for linking MPI (e.g. -lmpi or -lfmpi, if a special
|
---|
| 20 | # MPICC/MPICXX/MPIF77/MPIFC was not found).
|
---|
| 21 | #
|
---|
| 22 | # If you want to compile everything with MPI, you should set:
|
---|
| 23 | #
|
---|
| 24 | # CC="MPICC" #OR# CXX="MPICXX" #OR# F77="MPIF77" #OR# FC="MPIFC"
|
---|
| 25 | # LIBS="$MPILIBS $LIBS"
|
---|
| 26 | #
|
---|
| 27 | # NOTE: The above assumes that you will use $CC (or whatever) for linking
|
---|
| 28 | # as well as for compiling. (This is the default for automake and most
|
---|
| 29 | # Makefiles.)
|
---|
| 30 | #
|
---|
| 31 | # The user can force a particular library/compiler by setting the
|
---|
| 32 | # MPICC/MPICXX/MPIF77/MPIFC and/or MPILIBS environment variables.
|
---|
| 33 | #
|
---|
| 34 | # ACTION-IF-FOUND is a list of shell commands to run if an MPI library is
|
---|
| 35 | # found, and ACTION-IF-NOT-FOUND is a list of commands to run if it is not
|
---|
| 36 | # found. If ACTION-IF-FOUND is not specified, the default action will
|
---|
| 37 | # define HAVE_MPI.
|
---|
| 38 | #
|
---|
| 39 | # LICENSE
|
---|
| 40 | #
|
---|
| 41 | # Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
|
---|
| 42 | # Copyright (c) 2008 Julian C. Cummings <cummings@cacr.caltech.edu>
|
---|
| 43 | #
|
---|
| 44 | # This program is free software: you can redistribute it and/or modify it
|
---|
| 45 | # under the terms of the GNU General Public License as published by the
|
---|
| 46 | # Free Software Foundation, either version 3 of the License, or (at your
|
---|
| 47 | # option) any later version.
|
---|
| 48 | #
|
---|
| 49 | # This program is distributed in the hope that it will be useful, but
|
---|
| 50 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 51 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
---|
| 52 | # Public License for more details.
|
---|
| 53 | #
|
---|
| 54 | # You should have received a copy of the GNU General Public License along
|
---|
| 55 | # with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 56 | #
|
---|
| 57 | # As a special exception, the respective Autoconf Macro's copyright owner
|
---|
| 58 | # gives unlimited permission to copy, distribute and modify the configure
|
---|
| 59 | # scripts that are the output of Autoconf when processing the Macro. You
|
---|
| 60 | # need not follow the terms of the GNU General Public License when using
|
---|
| 61 | # or distributing such scripts, even though portions of the text of the
|
---|
| 62 | # Macro appear in them. The GNU General Public License (GPL) does govern
|
---|
| 63 | # all other use of the material that constitutes the Autoconf Macro.
|
---|
| 64 | #
|
---|
| 65 | # This special exception to the GPL applies to versions of the Autoconf
|
---|
| 66 | # Macro released by the Autoconf Archive. When you make and distribute a
|
---|
| 67 | # modified version of the Autoconf Macro, you may extend this special
|
---|
| 68 | # exception to the GPL to apply to your modified version as well.
|
---|
| 69 |
|
---|
| 70 | AC_DEFUN([ACX_MPI], [
|
---|
| 71 | AC_PREREQ(2.50) dnl for AC_LANG_CASE
|
---|
| 72 |
|
---|
| 73 | AC_LANG_CASE([C], [
|
---|
| 74 | AC_REQUIRE([AC_PROG_CC])
|
---|
| 75 | AC_ARG_VAR(MPICC,[MPI C compiler command])
|
---|
| 76 | AC_CHECK_PROGS(MPICC, mpicc hcc mpxlc_r mpxlc mpcc cmpicc, $CC)
|
---|
| 77 | acx_mpi_save_CC="$CC"
|
---|
| 78 | CC="$MPICC"
|
---|
| 79 | AC_SUBST(MPICC)
|
---|
| 80 | ],
|
---|
| 81 | [C++], [
|
---|
| 82 | AC_REQUIRE([AC_PROG_CXX])
|
---|
| 83 | AC_ARG_VAR(MPICXX,[MPI C++ compiler command])
|
---|
| 84 | AC_CHECK_PROGS(MPICXX, mpic++ mpicxx mpiCC hcp mpxlC_r mpxlC mpCC cmpic++, $CXX)
|
---|
| 85 | acx_mpi_save_CXX="$CXX"
|
---|
| 86 | CXX="$MPICXX"
|
---|
| 87 | AC_SUBST(MPICXX)
|
---|
| 88 | ],
|
---|
| 89 | [Fortran 77], [
|
---|
| 90 | AC_REQUIRE([AC_PROG_F77])
|
---|
| 91 | AC_ARG_VAR(MPIF77,[MPI Fortran 77 compiler command])
|
---|
| 92 | AC_CHECK_PROGS(MPIF77, mpif77 hf77 mpxlf_r mpxlf mpf77 cmpifc, $F77)
|
---|
| 93 | acx_mpi_save_F77="$F77"
|
---|
| 94 | F77="$MPIF77"
|
---|
| 95 | AC_SUBST(MPIF77)
|
---|
| 96 | ],
|
---|
| 97 | [Fortran], [
|
---|
| 98 | AC_REQUIRE([AC_PROG_FC])
|
---|
| 99 | AC_ARG_VAR(MPIFC,[MPI Fortran compiler command])
|
---|
| 100 | AC_CHECK_PROGS(MPIFC, mpif90 mpxlf95_r mpxlf90_r mpxlf95 mpxlf90 mpf90 cmpif90c, $FC)
|
---|
| 101 | acx_mpi_save_FC="$FC"
|
---|
| 102 | FC="$MPIFC"
|
---|
| 103 | AC_SUBST(MPIFC)
|
---|
| 104 | ])
|
---|
| 105 |
|
---|
| 106 | if test x = x"$MPILIBS"; then
|
---|
| 107 | AC_LANG_CASE([C], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
|
---|
| 108 | [C++], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
|
---|
| 109 | [Fortran 77], [AC_MSG_CHECKING([for MPI_Init])
|
---|
| 110 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" "
|
---|
| 111 | AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])],
|
---|
| 112 | [Fortran], [AC_MSG_CHECKING([for MPI_Init])
|
---|
| 113 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" "
|
---|
| 114 | AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])])
|
---|
| 115 | fi
|
---|
| 116 | AC_LANG_CASE([Fortran 77], [
|
---|
| 117 | if test x = x"$MPILIBS"; then
|
---|
| 118 | AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"])
|
---|
| 119 | fi
|
---|
| 120 | if test x = x"$MPILIBS"; then
|
---|
| 121 | AC_CHECK_LIB(fmpich, MPI_Init, [MPILIBS="-lfmpich"])
|
---|
| 122 | fi
|
---|
| 123 | ],
|
---|
| 124 | [Fortran], [
|
---|
| 125 | if test x = x"$MPILIBS"; then
|
---|
| 126 | AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"])
|
---|
| 127 | fi
|
---|
| 128 | if test x = x"$MPILIBS"; then
|
---|
| 129 | AC_CHECK_LIB(mpichf90, MPI_Init, [MPILIBS="-lmpichf90"])
|
---|
| 130 | fi
|
---|
| 131 | ])
|
---|
| 132 | if test x = x"$MPILIBS"; then
|
---|
| 133 | AC_CHECK_LIB(mpi, MPI_Init, [MPILIBS="-lmpi"])
|
---|
| 134 | fi
|
---|
| 135 | if test x = x"$MPILIBS"; then
|
---|
| 136 | AC_CHECK_LIB(mpich, MPI_Init, [MPILIBS="-lmpich"])
|
---|
| 137 | fi
|
---|
| 138 |
|
---|
| 139 | dnl We have to use AC_TRY_COMPILE and not AC_CHECK_HEADER because the
|
---|
| 140 | dnl latter uses $CPP, not $CC (which may be mpicc).
|
---|
| 141 | AC_LANG_CASE([C], [if test x != x"$MPILIBS"; then
|
---|
| 142 | AC_MSG_CHECKING([for mpi.h])
|
---|
| 143 | AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
|
---|
| 144 | AC_MSG_RESULT(no)])
|
---|
| 145 | fi],
|
---|
| 146 | [C++], [if test x != x"$MPILIBS"; then
|
---|
| 147 | AC_MSG_CHECKING([for mpi.h])
|
---|
| 148 | AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
|
---|
| 149 | AC_MSG_RESULT(no)])
|
---|
| 150 | fi],
|
---|
| 151 | [Fortran 77], [if test x != x"$MPILIBS"; then
|
---|
| 152 | AC_MSG_CHECKING([for mpif.h])
|
---|
| 153 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS=""
|
---|
| 154 | AC_MSG_RESULT(no)])
|
---|
| 155 | fi],
|
---|
| 156 | [Fortran], [if test x != x"$MPILIBS"; then
|
---|
| 157 | AC_MSG_CHECKING([for mpif.h])
|
---|
| 158 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS=""
|
---|
| 159 | AC_MSG_RESULT(no)])
|
---|
| 160 | fi])
|
---|
| 161 | dnl There are b0rked implementations that '#define main mpi_main' in their mpi.h
|
---|
| 162 | dnl which will cause all tests above to fail miserably (e.g. MPICH-SCore).
|
---|
| 163 | dnl TODO: prototype checking, exit instead of return from main, test C++, implement F77.
|
---|
| 164 | dnl TODO: use the information already gathered...
|
---|
| 165 | if test x = x"$MPILIBS"; then
|
---|
| 166 | AC_MSG_CHECKING([for last resort: compile and link a small MPI test program])
|
---|
| 167 | AC_LANG_CASE([C], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <mpi.h>]], [[
|
---|
| 168 | int main(int argc, char **argv)
|
---|
| 169 | {
|
---|
| 170 | MPI_Init(&argc, &argv);
|
---|
| 171 | return 0;
|
---|
| 172 | }
|
---|
| 173 | ]])], [MPILIBS=" "
|
---|
| 174 | AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])],
|
---|
| 175 | [C++], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <mpi.h>]], [[
|
---|
| 176 | int main(int argc, char **argv)
|
---|
| 177 | {
|
---|
| 178 | MPI_Init(&argc, &argv);
|
---|
| 179 | return 0;
|
---|
| 180 | }
|
---|
| 181 | ]])], [MPILIBS=" "
|
---|
| 182 | AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])],
|
---|
| 183 | [Fortran 77], [])
|
---|
| 184 | fi
|
---|
| 185 |
|
---|
| 186 | AC_LANG_CASE([C], [CC="$acx_mpi_save_CC"],
|
---|
| 187 | [C++], [CXX="$acx_mpi_save_CXX"],
|
---|
| 188 | [Fortran 77], [F77="$acx_mpi_save_F77"],
|
---|
| 189 | [Fortran], [FC="$acx_mpi_save_FC"])
|
---|
| 190 |
|
---|
| 191 | AC_SUBST(MPILIBS)
|
---|
| 192 |
|
---|
| 193 | # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
|
---|
| 194 | if test x = x"$MPILIBS"; then
|
---|
| 195 | $2
|
---|
| 196 | :
|
---|
| 197 | else
|
---|
| 198 | ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1])
|
---|
| 199 | :
|
---|
| 200 | fi
|
---|
| 201 | ])dnl ACX_MPI
|
---|