ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/ac-tools/ax_mpi.m4
Revision: 1465
Committed: Fri Jul 9 23:08:25 2010 UTC (14 years, 9 months ago) by chuckv
File size: 6636 byte(s)
Log Message:
Creating busticated version of OpenMD

File Contents

# Content
1 # ===========================================================================
2 # http://www.nongnu.org/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 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 AU_ALIAS([ACX_MPI], [AX_MPI])
71 AC_DEFUN([AX_MPI], [
72 AC_PREREQ(2.50) dnl for AC_LANG_CASE
73
74 AC_LANG_CASE([C], [
75 AC_REQUIRE([AC_PROG_CC])
76 AC_ARG_VAR(MPICC,[MPI C compiler command])
77 AC_CHECK_PROGS(MPICC, openmpicc mpicc hcc mpxlc_r mpxlc mpcc cmpicc, $CC)
78 ax_mpi_save_CC="$CC"
79 CC="$MPICC"
80 AC_SUBST(MPICC)
81 ],
82 [C++], [
83 AC_REQUIRE([AC_PROG_CXX])
84 AC_ARG_VAR(MPICXX,[MPI C++ compiler command])
85 AC_CHECK_PROGS(MPICXX, openmpicxx openmpiCC openmpic++ mpic++ mpicxx mpiCC hcp mpxlC_r mpxlC mpCC cmpic++, $CXX)
86 ax_mpi_save_CXX="$CXX"
87 CXX="$MPICXX"
88 AC_SUBST(MPICXX)
89 ],
90 [Fortran 77], [
91 AC_REQUIRE([AC_PROG_F77])
92 AC_ARG_VAR(MPIF77,[MPI Fortran 77 compiler command])
93 AC_CHECK_PROGS(MPIF77, openmpif77 mpif77 hf77 mpxlf_r mpxlf mpf77 cmpifc, $F77)
94 ax_mpi_save_F77="$F77"
95 F77="$MPIF77"
96 AC_SUBST(MPIF77)
97 ],
98 [Fortran], [
99 AC_REQUIRE([AC_PROG_FC])
100 AC_ARG_VAR(MPIFC,[MPI Fortran compiler command])
101 AC_CHECK_PROGS(MPIFC, openmpif90 mpif90 mpxlf95_r mpxlf90_r mpxlf95 mpxlf90 mpf90 cmpif90c, $FC)
102 ax_mpi_save_FC="$FC"
103 FC="$MPIFC"
104 AC_SUBST(MPIFC)
105 ])
106
107 if test x = x"$MPILIBS"; then
108 AC_LANG_CASE([C], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
109 [C++], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
110 [Fortran 77], [AC_MSG_CHECKING([for MPI_Init])
111 AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" "
112 AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])],
113 [Fortran], [AC_MSG_CHECKING([for MPI_Init])
114 AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" "
115 AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])])
116 fi
117 AC_LANG_CASE([Fortran 77], [
118 if test x = x"$MPILIBS"; then
119 AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"])
120 fi
121 if test x = x"$MPILIBS"; then
122 AC_CHECK_LIB(fmpich, MPI_Init, [MPILIBS="-lfmpich"])
123 fi
124 ],
125 [Fortran], [
126 if test x = x"$MPILIBS"; then
127 AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"])
128 fi
129 if test x = x"$MPILIBS"; then
130 AC_CHECK_LIB(mpichf90, MPI_Init, [MPILIBS="-lmpichf90"])
131 fi
132 ])
133 if test x = x"$MPILIBS"; then
134 AC_CHECK_LIB(mpi, MPI_Init, [MPILIBS="-lmpi"])
135 fi
136 if test x = x"$MPILIBS"; then
137 AC_CHECK_LIB(mpich, MPI_Init, [MPILIBS="-lmpich"])
138 fi
139
140 dnl We have to use AC_TRY_COMPILE and not AC_CHECK_HEADER because the
141 dnl latter uses $CPP, not $CC (which may be mpicc).
142 AC_LANG_CASE([C], [if test x != x"$MPILIBS"; then
143 AC_MSG_CHECKING([for mpi.h])
144 AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
145 AC_MSG_RESULT(no)])
146 fi],
147 [C++], [if test x != x"$MPILIBS"; then
148 AC_MSG_CHECKING([for mpi.h])
149 AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
150 AC_MSG_RESULT(no)])
151 fi],
152 [Fortran 77], [if test x != x"$MPILIBS"; then
153 AC_MSG_CHECKING([for mpif.h])
154 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS=""
155 AC_MSG_RESULT(no)])
156 fi],
157 [Fortran], [if test x != x"$MPILIBS"; then
158 AC_MSG_CHECKING([for mpif.h])
159 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS=""
160 AC_MSG_RESULT(no)])
161 fi])
162
163 AC_LANG_CASE([C], [CC="$ax_mpi_save_CC"],
164 [C++], [CXX="$ax_mpi_save_CXX"],
165 [Fortran 77], [F77="$ax_mpi_save_F77"],
166 [Fortran], [FC="$ax_mpi_save_FC"])
167
168 AC_SUBST(MPILIBS)
169
170 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
171 if test x = x"$MPILIBS"; then
172 $2
173 :
174 else
175 ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1])
176 :
177 fi
178 ])dnl AX_MPI