2957
by Niclas Jansson
Autoconfiscation started |
1 |
# ===========================================================================
|
2 |
# http://www.gnu.org/software/autoconf-archive/ax_mpi.html
|
|
3 |
# ===========================================================================
|
|
4 |
#
|
|
5 |
# SYNOPSIS
|
|
6 |
#
|
|
7 |
# AX_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 use something
|
|
23 |
# like this for C:
|
|
24 |
#
|
|
25 |
# if test -z "$CC" && test -n "$MPICC"; then
|
|
26 |
# CC="$MPICC"
|
|
27 |
# fi
|
|
28 |
# AC_PROG_CC
|
|
29 |
# AX_MPI
|
|
30 |
# CC="$MPICC"
|
|
31 |
# LIBS="$MPILIBS $LIBS"
|
|
32 |
#
|
|
33 |
# and similar for C++ (change all instances of CC to CXX), Fortran 77
|
|
34 |
# (with F77 instead of CC) or Fortran (with FC instead of CC).
|
|
35 |
#
|
|
36 |
# NOTE: The above assumes that you will use $CC (or whatever) for linking
|
|
37 |
# as well as for compiling. (This is the default for automake and most
|
|
38 |
# Makefiles.)
|
|
39 |
#
|
|
40 |
# The user can force a particular library/compiler by setting the
|
|
41 |
# MPICC/MPICXX/MPIF77/MPIFC and/or MPILIBS environment variables.
|
|
42 |
#
|
|
43 |
# ACTION-IF-FOUND is a list of shell commands to run if an MPI library is
|
|
44 |
# found, and ACTION-IF-NOT-FOUND is a list of commands to run if it is not
|
|
45 |
# found. If ACTION-IF-FOUND is not specified, the default action will
|
|
46 |
# define HAVE_MPI.
|
|
47 |
#
|
|
48 |
# LICENSE
|
|
49 |
#
|
|
50 |
# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
|
|
51 |
# Copyright (c) 2008 Julian C. Cummings <cummings@cacr.caltech.edu>
|
|
52 |
#
|
|
53 |
# This program is free software: you can redistribute it and/or modify it
|
|
54 |
# under the terms of the GNU General Public License as published by the
|
|
55 |
# Free Software Foundation, either version 3 of the License, or (at your
|
|
56 |
# option) any later version.
|
|
57 |
#
|
|
58 |
# This program is distributed in the hope that it will be useful, but
|
|
59 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
60 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
61 |
# Public License for more details.
|
|
62 |
#
|
|
63 |
# You should have received a copy of the GNU General Public License along
|
|
64 |
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
65 |
#
|
|
66 |
# As a special exception, the respective Autoconf Macro's copyright owner
|
|
67 |
# gives unlimited permission to copy, distribute and modify the configure
|
|
68 |
# scripts that are the output of Autoconf when processing the Macro. You
|
|
69 |
# need not follow the terms of the GNU General Public License when using
|
|
70 |
# or distributing such scripts, even though portions of the text of the
|
|
71 |
# Macro appear in them. The GNU General Public License (GPL) does govern
|
|
72 |
# all other use of the material that constitutes the Autoconf Macro.
|
|
73 |
#
|
|
74 |
# This special exception to the GPL applies to versions of the Autoconf
|
|
75 |
# Macro released by the Autoconf Archive. When you make and distribute a
|
|
76 |
# modified version of the Autoconf Macro, you may extend this special
|
|
77 |
# exception to the GPL to apply to your modified version as well.
|
|
78 |
||
79 |
#serial 7
|
|
80 |
||
81 |
AU_ALIAS([ACX_MPI], [AX_MPI]) |
|
82 |
AC_DEFUN([AX_MPI], [ |
|
83 |
AC_PREREQ(2.50) dnl for AC_LANG_CASE |
|
84 |
||
85 |
AC_LANG_CASE([C], [ |
|
86 |
AC_REQUIRE([AC_PROG_CC]) |
|
87 |
AC_ARG_VAR(MPICC,[MPI C compiler command]) |
|
88 |
AC_CHECK_PROGS(MPICC, mpicc hcc mpxlc_r mpxlc mpcc cmpicc, $CC) |
|
89 |
ax_mpi_save_CC="$CC" |
|
90 |
CC="$MPICC" |
|
91 |
AC_SUBST(MPICC) |
|
92 |
],
|
|
93 |
[C++], [ |
|
94 |
AC_REQUIRE([AC_PROG_CXX]) |
|
95 |
AC_ARG_VAR(MPICXX,[MPI C++ compiler command]) |
|
96 |
AC_CHECK_PROGS(MPICXX, mpic++ mpicxx mpiCC hcp mpxlC_r mpxlC mpCC cmpic++, $CXX) |
|
97 |
ax_mpi_save_CXX="$CXX" |
|
98 |
CXX="$MPICXX" |
|
99 |
AC_SUBST(MPICXX) |
|
100 |
],
|
|
101 |
[Fortran 77], [ |
|
102 |
AC_REQUIRE([AC_PROG_F77]) |
|
103 |
AC_ARG_VAR(MPIF77,[MPI Fortran 77 compiler command]) |
|
104 |
AC_CHECK_PROGS(MPIF77, mpif77 hf77 mpxlf_r mpxlf mpf77 cmpifc, $F77) |
|
105 |
ax_mpi_save_F77="$F77" |
|
106 |
F77="$MPIF77" |
|
107 |
AC_SUBST(MPIF77) |
|
108 |
],
|
|
109 |
[Fortran], [ |
|
110 |
AC_REQUIRE([AC_PROG_FC]) |
|
111 |
AC_ARG_VAR(MPIFC,[MPI Fortran compiler command]) |
|
112 |
AC_CHECK_PROGS(MPIFC, mpif90 mpxlf95_r mpxlf90_r mpxlf95 mpxlf90 mpf90 cmpif90c, $FC) |
|
113 |
ax_mpi_save_FC="$FC" |
|
114 |
FC="$MPIFC" |
|
115 |
AC_SUBST(MPIFC) |
|
116 |
])
|
|
117 |
||
118 |
if test x = x"$MPILIBS"; then |
|
119 |
AC_LANG_CASE([C], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])], |
|
120 |
[C++], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])], |
|
121 |
[Fortran 77], [AC_MSG_CHECKING([for MPI_Init]) |
|
122 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" " |
|
123 |
AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])], |
|
124 |
[Fortran], [AC_MSG_CHECKING([for MPI_Init]) |
|
125 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" " |
|
126 |
AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])]) |
|
127 |
fi
|
|
128 |
AC_LANG_CASE([Fortran 77], [ |
|
129 |
if test x = x"$MPILIBS"; then |
|
130 |
AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"]) |
|
131 |
fi
|
|
132 |
if test x = x"$MPILIBS"; then |
|
133 |
AC_CHECK_LIB(fmpich, MPI_Init, [MPILIBS="-lfmpich"]) |
|
134 |
fi
|
|
135 |
],
|
|
136 |
[Fortran], [ |
|
137 |
if test x = x"$MPILIBS"; then |
|
138 |
AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"]) |
|
139 |
fi
|
|
140 |
if test x = x"$MPILIBS"; then |
|
141 |
AC_CHECK_LIB(mpichf90, MPI_Init, [MPILIBS="-lmpichf90"]) |
|
142 |
fi
|
|
143 |
])
|
|
144 |
if test x = x"$MPILIBS"; then |
|
145 |
AC_CHECK_LIB(mpi, MPI_Init, [MPILIBS="-lmpi"]) |
|
146 |
fi
|
|
147 |
if test x = x"$MPILIBS"; then |
|
148 |
AC_CHECK_LIB(mpich, MPI_Init, [MPILIBS="-lmpich"]) |
|
149 |
fi
|
|
150 |
||
151 |
dnl We have to use AC_TRY_COMPILE and not AC_CHECK_HEADER because the |
|
152 |
dnl latter uses $CPP, not $CC (which may be mpicc). |
|
153 |
AC_LANG_CASE([C], [if test x != x"$MPILIBS"; then |
|
154 |
AC_MSG_CHECKING([for mpi.h]) |
|
155 |
AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS="" |
|
156 |
AC_MSG_RESULT(no)]) |
|
157 |
fi], |
|
158 |
[C++], [if test x != x"$MPILIBS"; then |
|
159 |
AC_MSG_CHECKING([for mpi.h]) |
|
160 |
AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS="" |
|
161 |
AC_MSG_RESULT(no)]) |
|
162 |
fi], |
|
163 |
[Fortran 77], [if test x != x"$MPILIBS"; then |
|
164 |
AC_MSG_CHECKING([for mpif.h]) |
|
165 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS="" |
|
166 |
AC_MSG_RESULT(no)]) |
|
167 |
fi], |
|
168 |
[Fortran], [if test x != x"$MPILIBS"; then |
|
169 |
AC_MSG_CHECKING([for mpif.h]) |
|
170 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS="" |
|
171 |
AC_MSG_RESULT(no)]) |
|
172 |
fi]) |
|
173 |
||
174 |
AC_LANG_CASE([C], [CC="$ax_mpi_save_CC"], |
|
175 |
[C++], [CXX="$ax_mpi_save_CXX"], |
|
176 |
[Fortran 77], [F77="$ax_mpi_save_F77"], |
|
177 |
[Fortran], [FC="$ax_mpi_save_FC"]) |
|
178 |
||
179 |
AC_SUBST(MPILIBS) |
|
180 |
||
181 |
# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
|
|
182 |
if test x = x"$MPILIBS"; then |
|
183 |
$2 |
|
184 |
:
|
|
185 |
else
|
|
186 |
ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1]) |
|
187 |
:
|
|
188 |
fi
|
|
189 |
])dnl AX_MPI |