1 | dnl @synopsis ACX_MPI([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) |
---|
2 | dnl |
---|
3 | dnl @summary figure out how to compile/link code with MPI |
---|
4 | dnl |
---|
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/) |
---|
8 | dnl |
---|
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). |
---|
15 | dnl |
---|
16 | dnl If you want to compile everything with MPI, you should set: |
---|
17 | dnl |
---|
18 | dnl CC="$MPICC" #OR# CXX="$MPICXX" #OR# F77="$MPIF77" |
---|
19 | dnl LIBS="$MPILIBS $LIBS" |
---|
20 | dnl |
---|
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.) |
---|
24 | dnl |
---|
25 | dnl The user can force a particular library/compiler by setting the |
---|
26 | dnl MPICC/MPICXX/MPIF77 and/or MPILIBS environment variables. |
---|
27 | dnl |
---|
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. |
---|
32 | dnl |
---|
33 | dnl @category InstalledPackages |
---|
34 | dnl @author Steven G. Johnson <stevenj@alum.mit.edu> |
---|
35 | dnl @author Julian Cummings <cummings@cacr.caltech.edu> |
---|
36 | dnl @version 2006-10-13 |
---|
37 | dnl @license GPLWithACException |
---|
38 | |
---|
39 | AC_DEFUN([ACX_MPI], [ |
---|
40 | AC_PREREQ(2.50) dnl for AC_LANG_CASE |
---|
41 | |
---|
42 | AC_LANG_CASE([C], [ |
---|
43 | AC_REQUIRE([AC_PROG_CC]) |
---|
44 | AC_ARG_VAR(MPICC,[MPI C compiler command]) |
---|
45 | AC_CHECK_PROGS(MPICC, mpicc hcc mpxlc_r mpxlc mpcc cmpicc, $CC) |
---|
46 | acx_mpi_save_CC="$CC" |
---|
47 | CC="$MPICC" |
---|
48 | AC_SUBST(MPICC) |
---|
49 | ], |
---|
50 | [C++], [ |
---|
51 | AC_REQUIRE([AC_PROG_CXX]) |
---|
52 | AC_ARG_VAR(MPICXX,[MPI C++ compiler command]) |
---|
53 | AC_CHECK_PROGS(MPICXX, mpic++ mpicxx mpiCC hcp mpxlC_r mpxlC mpCC cmpic++, $CXX) |
---|
54 | acx_mpi_save_CXX="$CXX" |
---|
55 | CXX="$MPICXX" |
---|
56 | AC_SUBST(MPICXX) |
---|
57 | ], |
---|
58 | [Fortran 77], [ |
---|
59 | AC_REQUIRE([AC_PROG_F77]) |
---|
60 | AC_ARG_VAR(MPIF77,[MPI Fortran 77 compiler command]) |
---|
61 | AC_CHECK_PROGS(MPIF77, mpif77 hf77 mpxlf mpf77 mpif90 mpf90 mpxlf90 mpxlf95 mpxlf_r cmpifc cmpif90c, $F77) |
---|
62 | acx_mpi_save_F77="$F77" |
---|
63 | F77="$MPIF77" |
---|
64 | AC_SUBST(MPIF77) |
---|
65 | ], |
---|
66 | [Fortran], [ |
---|
67 | AC_REQUIRE([AC_PROG_FC]) |
---|
68 | AC_ARG_VAR(MPIFC,[MPI Fortran compiler command]) |
---|
69 | AC_CHECK_PROGS(MPIFC, mpif90 hf90 mpxlf90 mpxlf95 mpf90 cmpifc cmpif90c, $FC) |
---|
70 | acx_mpi_save_FC="$FC" |
---|
71 | FC="$MPIFC" |
---|
72 | AC_SUBST(MPIFC) |
---|
73 | ]) |
---|
74 | |
---|
75 | if test x = x"$MPILIBS"; then |
---|
76 | AC_LANG_CASE([C], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])], |
---|
77 | [C++], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])], |
---|
78 | [Fortran 77], [AC_MSG_CHECKING([for MPI_Init]) |
---|
79 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" " |
---|
80 | AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])], |
---|
81 | [Fortran], [AC_MSG_CHECKING([for MPI_Init]) |
---|
82 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" " |
---|
83 | AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])]) |
---|
84 | fi |
---|
85 | AC_LANG_CASE([Fortran 77], [ |
---|
86 | if test x = x"$MPILIBS"; then |
---|
87 | AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"]) |
---|
88 | fi |
---|
89 | if test x = x"$MPILIBS"; then |
---|
90 | AC_CHECK_LIB(fmpich, MPI_Init, [MPILIBS="-lfmpich"]) |
---|
91 | fi |
---|
92 | ], |
---|
93 | [Fortran], [ |
---|
94 | if test x = x"$MPILIBS"; then |
---|
95 | AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"]) |
---|
96 | fi |
---|
97 | if test x = x"$MPILIBS"; then |
---|
98 | AC_CHECK_LIB(mpichf90, MPI_Init, [MPILIBS="-lmpichf90"]) |
---|
99 | fi |
---|
100 | ]) |
---|
101 | if test x = x"$MPILIBS"; then |
---|
102 | AC_CHECK_LIB(mpi, MPI_Init, [MPILIBS="-lmpi"]) |
---|
103 | fi |
---|
104 | if test x = x"$MPILIBS"; then |
---|
105 | AC_CHECK_LIB(mpich, MPI_Init, [MPILIBS="-lmpich"]) |
---|
106 | fi |
---|
107 | |
---|
108 | dnl We have to use AC_TRY_COMPILE and not AC_CHECK_HEADER because the |
---|
109 | dnl latter uses $CPP, not $CC (which may be mpicc). |
---|
110 | AC_LANG_CASE([C], [if test x != x"$MPILIBS"; then |
---|
111 | AC_MSG_CHECKING([for mpi.h]) |
---|
112 | AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS="" |
---|
113 | AC_MSG_RESULT(no)]) |
---|
114 | fi], |
---|
115 | [C++], [if test x != x"$MPILIBS"; then |
---|
116 | AC_MSG_CHECKING([for mpi.h]) |
---|
117 | AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS="" |
---|
118 | AC_MSG_RESULT(no)]) |
---|
119 | fi], |
---|
120 | [Fortran 77], [if test x != x"$MPILIBS"; then |
---|
121 | AC_MSG_CHECKING([for mpif.h]) |
---|
122 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS="" |
---|
123 | AC_MSG_RESULT(no)]) |
---|
124 | fi], |
---|
125 | [Fortran], [if test x != x"$MPILIBS"; then |
---|
126 | AC_MSG_CHECKING([for mpif.h]) |
---|
127 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS="" |
---|
128 | AC_MSG_RESULT(no)]) |
---|
129 | fi]) |
---|
130 | |
---|
131 | AC_LANG_CASE([C], [CC="$acx_mpi_save_CC"], |
---|
132 | [C++], [CXX="$acx_mpi_save_CXX"], |
---|
133 | [Fortran 77], [F77="$acx_mpi_save_F77"], |
---|
134 | [Fortran], [FC="$acx_mpi_save_FC"]) |
---|
135 | |
---|
136 | AC_SUBST(MPILIBS) |
---|
137 | |
---|
138 | # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: |
---|
139 | if test x = x"$MPILIBS"; then |
---|
140 | $2 |
---|
141 | : |
---|
142 | else |
---|
143 | ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1]) |
---|
144 | : |
---|
145 | fi |
---|
146 | ])dnl ACX_MPI |
---|