| 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.1.1.1 2007-09-03 16:17:11 heber Exp $ | 
|---|
| 28 | dnl @author Steven G. Johnson <address@hidden> | 
|---|
| 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 cmpicc, $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, mpic++ mpiCC mpCC hcp mpxlC mpxlC_r cmpic++, $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 cmpifc cmpif90c, $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 |  | 
|---|
| 85 | AC_LANG_CASE([C], [CC="$acx_mpi_save_CC"], | 
|---|
| 86 | [C++], [CXX="$acx_mpi_save_CXX"], | 
|---|
| 87 | [Fortran 77], [F77="$acx_mpi_save_F77"]) | 
|---|
| 88 |  | 
|---|
| 89 | AC_SUBST(MPILIBS) | 
|---|
| 90 |  | 
|---|
| 91 | # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: | 
|---|
| 92 | if test x = x"$MPILIBS"; then | 
|---|
| 93 | $2 | 
|---|
| 94 | : | 
|---|
| 95 | else | 
|---|
| 96 | ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1]) | 
|---|
| 97 | : | 
|---|
| 98 | fi | 
|---|
| 99 | ])dnl ACX_MPI | 
|---|