-
Notifications
You must be signed in to change notification settings - Fork 3
/
acsm_mpi.m4
276 lines (255 loc) · 12 KB
/
acsm_mpi.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
dnl ---------------------------------------------------------------------------
dnl check for the required MPI library
dnl ---------------------------------------------------------------------------
AC_DEFUN([ACSM_MPI], [
dnl We need to verify that we've done AC_ARG_ENABLE(mpi) and AC_ARG_WITH(mpi)
dnl which occur in ACSM_COMPILER_CONTROL_ARGS
AC_REQUIRE([ACSM_COMPILER_CONTROL_ARGS])
AS_IF(
[test x"$MPI_USING_WRAPPERS" = x1],
[
AC_LANG_PUSH([C++])
AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <mpi.h>],
[int np; MPI_Comm_size (MPI_COMM_WORLD, &np);])],
[
enablempi=yes
MPI_IMPL="mpi-wrapper-built-in"
AC_DEFINE(HAVE_MPI, 1, [Flag indicating whether or not MPI is available])
],
[
AC_MSG_RESULT([MPI wrapper $CXX cannot compile an MPI program. Disabling MPI...])
enablempi=no
])
AC_LANG_POP([C++])
],
[test -n "$MPI_LIBS_PATH" -a -n "$MPI_INCLUDES_PATH"],
[
AS_ECHO(["note: Checking $MPI_LIBS_PATH and $MPI_INCLUDES_PATH for MPI"])
dnl Default MPI_LIBS_PATH="$MPI/lib"
dnl Default MPI_INCLUDES_PATH="$MPI/include"
MPI_LIBS_TO_TEST=""
AS_IF([test -e $MPI_LIBS_PATH/libmpi.a], [MPI_LIBS_TO_TEST="$MPI_LIBS_PATH/libmpi.a $MPI_LIBS_TO_TEST"])
AS_IF([test -e $MPI_LIBS_PATH/libmpi.so], [MPI_LIBS_TO_TEST="$MPI_LIBS_PATH/libmpi.so $MPI_LIBS_TO_TEST"])
AS_IF([test -e $MPI_LIBS_PATH/libmpi.dylib], [MPI_LIBS_TO_TEST="$MPI_LIBS_PATH/libmpi.dylib $MPI_LIBS_TO_TEST"])
dnl look for LAM or other MPI implementation
AS_IF([test x"$MPI_LIBS_TO_TEST" != x],
[
AS_ECHO(["note: testing $MPI_LIBS_PATH/libmpi(.a/.so/.dylib)"])
dnl Ensure the compiler finds the library...
tmpLIBS=$LIBS
AC_LANG_SAVE
AC_LANG([C++])
LIBS="-L$MPI_LIBS_PATH $LIBS"
dnl look for lam_version_show in liblam.(a/so)
dnl (this is needed in addition to libmpi.(a/so) for
dnl LAM MPI
AC_CHECK_LIB([lam],
[lam_show_version],
[
LIBS="-llam $LIBS"
MPI_LIBS="-llam $MPI_LIBS"
],
[])
dnl Quadrics MPI requires the elan library to be included too
for lib in $MPI_LIBS_TO_TEST
do
if (nm $lib | grep elan > /dev/null); then
AS_ECHO(["note: MPI found to use Quadrics switch, looking for elan library"])
AC_CHECK_LIB([elan],
[elan_init],
[
LIBS="-lelan $LIBS"
MPI_LIBS="-lelan $MPI_LIBS"
],
[AC_MSG_ERROR([Could not find elan library... exiting])])
break
fi
done
AC_CHECK_LIB([mpi],
[MPI_Init],
[
MPI_LIBS="-lmpi $MPI_LIBS"
MPI_LDFLAGS="-L$MPI_LIBS_PATH"
MPI_IMPL="mpi"
AC_MSG_RESULT([Found valid MPI installation...])
],
[AC_MSG_RESULT([Could not link in the MPI library...]); enablempi=no])
AC_LANG_RESTORE
LIBS=$tmpLIBS
],
[
AS_ECHO(["note: Could not find $MPI_LIBS_PATH/libmpi(.a/.so/.dylib)"])
])
dnl have we not found an implementation yet?
AS_IF([test x"$MPI_IMPL" = x],
[
AS_IF([test -e $MPI_LIBS_PATH/libmpich.a || test -e $MPI_LIBS_PATH/libmpich.so],
[
AS_ECHO(["note: using $MPI_LIBS_PATH/libmpich(.a/.so)"])
dnl Ensure the compiler finds the library...
tmpLIBS=$LIBS
AC_LANG_SAVE
AC_LANG([C++])
LIBS="-L$MPI_LIBS_PATH $LIBS"
dnl Myricomm MPICH requires the gm library to be included too
if (nm $MPI_LIBS_PATH/libmpich.* | grep gm_open > /dev/null); then
AS_ECHO(["note: MPICH found to use Myricomm's Myrinet, looking for gm library"])
AS_IF([test "x$GMHOME" = "x"], [GMHOME="/usr"])
AC_ARG_WITH([gm],
AS_HELP_STRING([--with-gm=PATH],
[Prefix where GM is installed (GMHOME)]),
[GM="$withval"],
[
AS_ECHO(["note: GM library path not given... trying prefix=$MPIHOME"])
GM=$GMHOME
])
LIBS="-L$GM/lib $LIBS"
MPI_LIBS="-L$GM/lib $MPI_LIBS"
AC_CHECK_LIB([gm],
[gm_open],
[
LIBS="$LIBS -lgm"
MPI_LIBS="$MPI_LIBS -lgm"
],
[AC_MSG_ERROR( [Could not find gm library... exiting])])
fi
dnl look for MPI_Init in libmich.(a/so)
dnl try adding libmpl if we see it there; some MPICH2 versions
dnl require it.
AS_IF([test -e $MPI_LIBS_PATH/libmpl.a || test -e $MPI_LIBS_PATH/libmpl.so],
[
LIBS="-L$MPI_LIBS_PATH -lmpl $tmpLIBS"
AC_CHECK_LIB([mpich],
[MPI_Init],
[
MPI_LIBS="-lmpich -lmpl $MPI_LIBS"
MPI_LDFLAGS="-L$MPI_LIBS_PATH"
MPI_IMPL="mpich"
AC_MSG_RESULT([Found valid MPICH installation with libmpl...])
],
[AC_MSG_RESULT([Could not link in the MPI library...]); enablempi=no])
],
[
AC_CHECK_LIB([mpich],
[MPI_Init],
[
MPI_LIBS="-lmpich $MPI_LIBS"
MPI_LDFLAGS="-L$MPI_LIBS_PATH"
MPI_IMPL="mpich"
AC_MSG_RESULT([Found valid MPICH installation...])
],
[AC_MSG_RESULT([Could not link in the MPI library...]); enablempi=no])
])
AC_LANG_RESTORE
LIBS=$tmpLIBS
])
])
dnl ok we've done all the library work. Now let's check the header
AS_IF([test "x$MPI_IMPL" != x],
[
dnl Ensure the compiler finds the header file...
AS_IF([test -e $MPI_INCLUDES_PATH/mpi.h],
[
AS_ECHO(["note: using $MPI_INCLUDES_PATH/mpi.h"])
tmpCPPFLAGS=$CPPFLAGS
AC_LANG_SAVE
AC_LANG([C++])
CPPFLAGS="-I$MPI_INCLUDES_PATH $CPPFLAGS"
AC_CHECK_HEADER([mpi.h],
[
AC_DEFINE(HAVE_MPI, 1, [Flag indicating whether or not MPI is available])
enablempi=yes
],
[AC_MSG_RESULT([Could not compile in the MPI headers...]); enablempi=no])
MPI_INCLUDES="-I$MPI_INCLUDES_PATH"
AC_LANG_RESTORE
CPPFLAGS=$tmpCPPFLAGS
],
[test -e $MPI_INCLUDES_PATH/mpi/mpi.h],
[
MPI_INCLUDES_PATH=$MPI_INCLUDES_PATH/mpi
AS_ECHO(["note: using $MPI_INCLUDES_PATH/mpi.h"])
tmpCPPFLAGS=$CPPFLAGS
AC_LANG_SAVE
AC_LANG([C++])
CPPFLAGS="-I$MPI_INCLUDES_PATH $CPPFLAGS"
AC_CHECK_HEADER([mpi.h],
[
AC_DEFINE(HAVE_MPI, 1, [Flag indicating whether or not MPI is available])
enablempi=yes
],
[AC_MSG_RESULT([Could not compile in the MPI headers...]); enablempi=no] )
MPI_INCLUDES="-I$MPI_INCLUDES_PATH"
AC_LANG_RESTORE
CPPFLAGS=$tmpCPPFLAGS
],
[
AC_MSG_RESULT([Could not find MPI header <mpi.h>...])
enablempi=no
])
],
[
dnl no MPI install found, see if the compiler "natively" supports it by
dnl attempting to link a test application without any special flags.
AC_LANG_SAVE
AC_LANG([C++])
AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <mpi.h>],
[int np; MPI_Comm_size (MPI_COMM_WORLD, &np);])],
[
MPI_IMPL="CXX-built-in"
AC_MSG_RESULT( [$CXX Compiler Supports MPI] )
AC_DEFINE(HAVE_MPI, 1, [Flag indicating whether or not MPI is available])
enablempi=yes
],
[AC_MSG_RESULT([$CXX Compiler Does NOT Support MPI...]); enablempi=no])
AC_LANG_RESTORE
])
],
dnl We weren't supplied --with-mpi and no MPI environment variables were set
dnl Let's check to see if we got anything from PETSc
[test x"$PETSC_HAVE_MPI" = x1],
[
tmpCPPFLAGS=$CPPFLAGS
tmpLIBS=$LIBS
AC_LANG_PUSH([C++])
LIBS="$PETSC_MPI_LINK_LIBS $LIBS"
CPPFLAGS="$PETSC_MPI_INCLUDE_DIRS $CPPFLAGS"
AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <mpi.h>],
[int np; MPI_Comm_size (MPI_COMM_WORLD, &np);])],
[
enablempi=yes
MPI_IMPL="petsc"
AC_DEFINE(HAVE_MPI, 1, [Flag indicating whether or not MPI is available])
AS_IF([test x"$PETSC_MPI_INCLUDE_DIRS" != x], [MPI_INCLUDES="$PETSC_MPI_INCLUDE_DIRS"])
AS_IF([test x"$PETSC_MPI_LINK_LIBS" != x], [MPI_LIBS="$PETSC_MPI_LINK_LIBS"])
],
[
AC_MSG_RESULT([PETSc MPI cannot compile an MPI program. Disabling MPI...])
enablempi=no
])
AC_LANG_POP([C++])
LIBS=$tmpLIBS
CPPFLAGS=$tmpCPPFLAGS
],
dnl We weren't supplied --with-mpi and no MPI environment variables were set. Also we didn't
dnl get any MPI info from a PETSc install. Let's check to see if CXX natively supports MPI
[
AC_LANG_SAVE
AC_LANG([C++])
AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <mpi.h>],
[int np; MPI_Comm_size (MPI_COMM_WORLD, &np);])],
[
MPI_IMPL="CXX-built-in"
AC_MSG_RESULT( [$CXX Compiler Supports MPI] )
AC_DEFINE(HAVE_MPI, 1, [Flag indicating whether or not MPI is available])
enablempi=yes
],
[AC_MSG_RESULT([$CXX Compiler Does NOT Support MPI...]); enablempi=no])
AC_LANG_RESTORE
])
dnl Save variables...
AC_SUBST(MPI_IMPL)
AC_SUBST(MPI_LIBS)
AC_SUBST(MPI_LDFLAGS)
AC_SUBST(MPI_INCLUDES)
])