/
aclocal_mpi.m4
461 lines (454 loc) · 14.8 KB
/
aclocal_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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
dnl
dnl PAC_MPI_COMPILE_CC_FUNC( MPI_CC, MPI_CFLAGS,
dnl HEADERS, MPI_VARS, MPI_FUNC,
dnl [action if working], [action if not working] )
dnl - MPI_CC is the MPI parallel compiler, like mpich/mpicc, AIX/mpcc
dnl - MPI_CFLAGS is the CFLAGS to MPI_CC, like "-I/usr/include" for mpi.h
dnl - HEADERS is the headers, e.g. <pthread.h>.
dnl - MPI_VARS is the the declaration of variables needed to call MPI_FUNC
dnl - MPI_FUNC is the body of MPI function call to be checked for existence
dnl e.g. MPI_VARS="MPI_Request request; MPI_Fint a;"
dnl MPI_FUNC="a = MPI_Request_c2f( request );"
dnl if MPI_FUNC is empty, assume linking with basic MPI program.
dnl i.e. check if MPI definitions are valid
dnl
AC_DEFUN(PAC_MPI_COMPILE_CC_FUNC,[
dnl - set local parallel compiler environments
dnl so input variables can be CC, CFLAGS or LIBS
pac_MPI_CC="$1"
pac_MPI_CFLAGS="$2"
dnl - save the original environment
pac_saved_CC="$CC"
pac_saved_CFLAGS="$CFLAGS"
dnl - set the parallel compiler environment
AC_LANG_PUSH([C])
CC="$pac_MPI_CC"
CFLAGS="$pac_MPI_CFLAGS"
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([
/* <stdlib.h> is included to get NULL defined */
#if defined( STDC_HEADERS ) || defined( HAVE_STDLIB_H )
#include <stdlib.h>
#else
#if !defined( NULL )
#define NULL 0
#endif
#endif
$3
#include "mpi.h"
],[
int argc; char **argv;
$4 ;
MPI_Init(&argc, &argv);
$5 ;
MPI_Finalize();
])
],[pac_mpi_working=yes],[pac_mpi_working=no])
CC="$pac_saved_CC"
CFLAGS="$pac_saved_CFLAGS"
AC_LANG_POP([C])
if test "$pac_mpi_working" = "yes" ; then
ifelse([$6],,:,[$6])
else
ifelse([$7],,:,[$7])
fi
])dnl
dnl
dnl PAC_MPI_LINK_CC_FUNC( MPI_CC, MPI_CFLAGS, MPI_LIBS,
dnl HEADERS, MPI_VARS, MPI_FUNC,
dnl [action if working], [action if not working] )
dnl - MPI_CC is the MPI parallel compiler, like mpich/mpicc, AIX/mpcc
dnl - MPI_CFLAGS is the CFLAGS to MPI_CC, like "-I/usr/include" for mpi.h
dnl - MPI_LIBS is the LIBS to MPI_CC, like "-L/usr/lib -lmpi" for libmpi.a
dnl - HEADERS is the headers, e.g. <pthread.h>.
dnl - MPI_VARS is the the declaration of variables needed to call MPI_FUNC
dnl - MPI_FUNC is the body of MPI function call to be checked for existence
dnl e.g. MPI_VARS="MPI_Request request; MPI_Fint a;"
dnl MPI_FUNC="a = MPI_Request_c2f( request );"
dnl if MPI_FUNC is empty, assume linking with basic MPI program.
dnl i.e. check if MPI definitions are valid
dnl
AC_DEFUN(PAC_MPI_LINK_CC_FUNC,[
dnl - set local parallel compiler environments
dnl so input variables can be CC, CFLAGS or LIBS
pac_MPI_CC="$1"
pac_MPI_CFLAGS="$2"
pac_MPI_LIBS="$3"
dnl - save the original environment
pac_saved_CC="$CC"
pac_saved_CFLAGS="$CFLAGS"
pac_saved_LIBS="$LIBS"
dnl - set the parallel compiler environment
AC_LANG_PUSH([C])
CC="$pac_MPI_CC"
CFLAGS="$pac_MPI_CFLAGS"
LIBS="$pac_MPI_LIBS"
AC_LINK_IFELSE([
AC_LANG_PROGRAM([
/* <stdlib.h> is included to get NULL defined */
#if defined( STDC_HEADERS ) || defined( HAVE_STDLIB_H )
#include <stdlib.h>
#else
#if !defined( NULL )
#define NULL 0
#endif
#endif
$4
#include "mpi.h"
],[
int argc; char **argv;
$5 ;
MPI_Init(&argc, &argv);
$6 ;
MPI_Finalize();
])
],[pac_mpi_working=yes],[pac_mpi_working=no])
CC="$pac_saved_CC"
CFLAGS="$pac_saved_CFLAGS"
LIBS="$pac_saved_LIBS"
AC_LANG_POP([C])
if test "$pac_mpi_working" = "yes" ; then
ifelse([$7],,:,[$7])
else
ifelse([$8],,:,[$8])
fi
])dnl
dnl
dnl PAC_MPI_LINK_F77_FUNC( MPI_F77, MPI_FFLAGS, MPI_LIBS,
dnl MPI_VARS, MPI_FUNC,
dnl [action if working], [action if not working] )
dnl - MPI_F77 is the MPI parallel compiler, like mpich/mpif77, AIX/mpxlf
dnl - MPI_FFLAGS is the FFLAGS to MPI_F77, like "-I/usr/include" for mpif.h
dnl - MPI_LIBS is the LIBS to MPI_F77, like "-L/usr/lib -lmpi" for libmpi.a
dnl - MPI_VARS is the the declaration of variables needed to call MPI_FUNC
dnl - MPI_FUNC is the body of MPI function call to be checked for existence
dnl e.g. MPI_VARS="MPI_Request request; MPI_Fint a;"
dnl MPI_FUNC="a = MPI_Request_c2f( request );"
dnl if MPI_FUNC is empty, assume linking with basic MPI program.
dnl i.e. check if MPI definitions are valid
dnl
AC_DEFUN(PAC_MPI_LINK_F77_FUNC,[
dnl - set local parallel compiler environments
dnl so input variables can be F77, FFLAGS or LIBS
pac_MPI_F77="$1"
pac_MPI_FFLAGS="$2"
pac_MPI_LIBS="$3"
dnl - save the original environment
pac_saved_F77="$F77"
pac_saved_FFLAGS="$FFLAGS"
pac_saved_LIBS="$LIBS"
dnl - set the parallel compiler environment for TRY_LINK
AC_LANG_PUSH([Fortran 77])
F77="$pac_MPI_F77"
FFLAGS="$pac_MPI_FFLAGS"
LIBS="$pac_MPI_LIBS"
AC_LINK_IFELSE([
AC_LANG_SOURCE([
include 'mpif.h'
integer pac_ierr
$4
call MPI_Init( pac_ierr )
$5
call MPI_Finalize( pac_ierr )
end
])
],[pac_mpi_working=yes],[pac_mpi_working=no])
F77="$pac_saved_F77"
FFLAGS="$pac_saved_FFLAGS"
LIBS="$pac_saved_LIBS"
AC_LANG_POP([Fortran 77])
if test "$pac_mpi_working" = "yes" ; then
ifelse([$6],,:,[$6])
else
ifelse([$7],,:,[$7])
fi
])dnl
dnl
dnl PAC_MPI_RUN_CC_PGM( MPI_CC, MPI_CFLAGS,
dnl SER_CC, SER_CFLAGS, SER_LIBS,
dnl PGM_BODY,
dnl [action if working], [action if not working] )
dnl - MPI_CC MPI parallel compiler for compilation of the PGM_BODY
dnl e.g. mpich/mpicc & AIX/mpcc
dnl - MPI_CFLAGS FFLAGS to MPI_CC for compilation of the PGM_BODY
dnl e.g. "-I/usr/include" for mpi.h
dnl - SER_CC serial compiler, like AIX/xlc, to generate of serial exeutable
dnl - SER_CFLAGS FFLAGS to SER_CC, used to generate serial executable
dnl - SER_LIBS LIBS to SER_CC, used to generate serial executable
dnl - PGM_BODY C program body
dnl
AC_DEFUN(PAC_MPI_RUN_CC_PGM,[
dnl - set local parallel and serial compiler environments
dnl so input variables can be CC, CFLAGS or LIBS
pac_MPI_CC="$1"
pac_MPI_CFLAGS="$2"
pac_SER_CC="$3"
pac_SER_CFLAGS="$4"
pac_SER_LIBS="$5"
AC_LANG_PUSH([C])
dnl - save the original environment
pac_saved_CC="$CC"
pac_saved_CFLAGS="$CFLAGS"
pac_saved_LIBS="$LIBS"
dnl - set the parallel compiler environment
CC="$pac_MPI_CC"
CFLAGS="$pac_MPI_CFLAGS"
dnl
pac_mpi_working=no
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([$6])
], [
PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
CC="$pac_SER_CC"
CFLAGS="$pac_SER_CFLAGS"
LIBS="pac_conftest.$OBJEXT $pac_SER_LIBS"
dnl - To use pac_conftest.$OBJEXT as a main, a conftest.c is needed.
dnl - Theoretically, a blank source file is all we need, but some compiler
dnl - may complain, so use a irrelevent function here.
AC_RUN_IFELSE([
AC_LANG_SOURCE([void foo(){}])
], [pac_mpi_working=yes])
rm -f pac_conftest.$OBJEXT
])
CC="$pac_saved_CC"
CFLAGS="$pac_saved_CFLAGS"
LIBS="$pac_saved_LIBS"
AC_LANG_POP([C])
if test "$pac_mpi_working" = "yes" ; then
ifelse([$7],,:,[$7])
else
ifelse([$8],,:,[$8])
fi
])dnl
dnl
dnl PAC_MPI_RUN_F77_PGM( MPI_F77, MPI_FFLAGS,
dnl SER_F77, SER_FFLAGS, SER_LIBS,
dnl PGM_BODY,
dnl [action if working], [action if not working] )
dnl - MPI_F77 MPI parallel compiler for compilation of the PGM_BODY
dnl e.g. mpich/mpif77 & AIX/mpxlf
dnl - MPI_FFLAGS FFLAGS to MPI_F77 for compilation of the PGM_BODY
dnl e.g. "-I/usr/include" for mpif.h
dnl - SER_F77 serial compiler, like AIX/xlf, to generate of serial exeutable
dnl - SER_FFLAGS FFLAGS to SER_F77, used to generate serial executable
dnl - SER_LIBS LIBS to SER_F77, used to generate serial executable
dnl - PGM_BODY F77 program body
dnl
AC_DEFUN(PAC_MPI_RUN_F77_PGM,[
dnl - set local parallel and serial compiler environments
dnl so input variables can be F77, FFLAGS or LIBS
pac_MPI_F77="$1"
pac_MPI_FFLAGS="$2"
pac_SER_F77="$3"
pac_SER_FFLAGS="$4"
pac_SER_LIBS="$5"
AC_LANG_PUSH([Fortran 77])
dnl - save the original environment
pac_saved_F77="$F77"
pac_saved_FFLAGS="$FFLAGS"
pac_saved_LIBS="$LIBS"
dnl - set the parallel compiler environment
F77="$pac_MPI_F77"
FFLAGS="$pac_MPI_FFLAGS"
dnl
pac_mpi_working=no
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([
$6
])
], [
PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT])
F77="$pac_SER_F77"
FFLAGS="$pac_SER_FFLAGS"
LIBS="pac_f77conftest.$OBJEXT $pac_SER_LIBS"
dnl - To use pac_f77conftest.$OBJEXT as a main, a conftest.f is needed.
dnl - Theoretically, a blank source file is all we need, but some compiler
dnl - may complain, e.g. af77/af90, so use a irrelevent subroutine here.
AC_RUN_IFELSE([
AC_LANG_SOURCE([
subroutine foo()
end
])
], [pac_mpi_working=yes])
rm -f pac_f77conftest.$OBJEXT
])
F77="$pac_saved_F77"
FFLAGS="$pac_saved_FFLAGS"
LIBS="$pac_saved_LIBS"
AC_LANG_POP([Fortran 77])
if test "$pac_mpi_working" = "yes" ; then
ifelse([$7],,:,[$7])
else
ifelse([$8],,:,[$8])
fi
])dnl
dnl
dnl PAC_MPI_RUN_F77_FUNC_FROM_C( MPI_F77, MPI_FFLAGS,
dnl MPI_CC, MPI_CFLAGS,
dnl SER_CC, SER_CFLAGS, SER_LIBS,
dnl [ FORTRAN routine ], [ C program ],
dnl [action if working], [action if not working] )
dnl - MPI_F77 MPI parallel compiler for compilation of the FORTRAN routine
dnl e.g. mpich/mpif77 & AIX/mpxlf. It can be serial compiler if
dnl no MPI variables in the FORTRAN routine
dnl - MPI_FFLAGS FFLAGS to MPI_F77 for compilation of the FORTRAN routine
dnl e.g. "-I/usr/include" for mpif.h
dnl - MPI_CC MPI parallel compiler for compilation of the C program
dnl e.g. mpich/mpicc & AIX/mpcc. It can be serial compiler if
dnl no MPI variables in the C program
dnl - MPI_CFLAGS FFLAGS to MPI_CC for compilation of the C program
dnl e.g. "-I/usr/include" for mpi.h
dnl - SER_CC serial compiler, like AIX/xlc, to generate of serial exeutable
dnl - SER_CFLAGS FFLAGS to SER_CC, used to generate serial executable
dnl - SER_LIBS LIBS to SER_CC, used to generate serial executable
dnl User needs to put in #define F77_NAME_xxxx to get C code to understand
dnl the fortran subroutine name.
dnl
AC_DEFUN(PAC_MPI_RUN_F77_FUNC_FROM_C,[
dnl - set local parallel compiler environments
dnl so input variables can be CC, CFLAGS or LIBS
pac_MPI_F77="$1"
pac_MPI_FFLAGS="$2"
pac_MPI_CC="$3"
pac_MPI_CFLAGS="$4"
pac_SER_CC="$5"
pac_SER_CFLAGS="$6"
pac_SER_LIBS="$7"
dnl
dnl - save the original environment
pac_saved_F77="$F77"
pac_saved_FFLAGS="$FFLAGS"
pac_saved_LIBS="$LIBS"
dnl - set the parallel compiler environment
F77="$pac_MPI_F77"
FFLAGS="$pac_MPI_FFLAGS"
dnl
AC_LANG_PUSH([Fortran 77])
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([
$8
])
], [
PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT])
dnl - set the parallel compiler environment
AC_LANG_PUSH([C])
CC="$pac_MPI_CC"
CFLAGS="$pac_MPI_CFLAGS"
pac_mpi_working=no
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([$9])
], [
PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
CC="$pac_SER_CC"
CFLAGS="$pac_SER_CFLAGS"
LIBS="pac_conftest.$OBJEXT pac_f77conftest.$OBJEXT $pac_SER_LIBS"
dnl - To use pac_conftest.$OBJEXT as a main, a conftest.c is needed.
dnl - Theoretically, a blank source file is all we need, but some compiler
dnl - may complain, so use a irrelevent function here.
AC_RUN_IFELSE([
AC_LANG_SOURCE([ void foo(){} ])
], [pac_mpi_working=yes])
rm -f pac_conftest.$OBJEXT
])
CC="$pac_saved_CC"
CFLAGS="$pac_saved_CFLAGS"
LIBS="$pac_saved_LIBS"
AC_LANG_POP([C])
rm -f pac_f77conftest.$OBJEXT
])
AC_LANG_POP([Fortran 77])
F77="$pac_saved_F77"
FFLAGS="$pac_saved_FFLAGS"
dnl
if test "$pac_mpi_working" = "yes" ; then
ifelse([$10],,:,[$10])
else
ifelse([$11],,:,[$11])
fi
])
AC_DEFUN([PAC_PROG_MPICC],[
# Find the compilers, if they aren't set with the environment variables
if test -z "$MPICC" ; then
AC_MSG_CHECKING([for MPI compile wrappers for C])
# First look for the wrappers
if test -n "$MPI_DIR" ; then
for w in mpicc bin/mpicc mpcc bin/mpcc ; do
if test -x $MPI_DIR/$w ; then
MPICC=$MPI_DIR/$w
break
fi
done
fi
# Still not found
if test -z "$MPICC" ; then
# Try looking in the path
saveIFS=$IFS
IFS=":"
for dir in $PATH ; do
for w in mpicc mpcc ; do
if test -x $dir/$w ; then
MPICC=$dir/$w
break 2
fi
done
done
IFS=$saveIFS
fi
if test -n "$MPICC" ; then
AC_MSG_RESULT($MPICC)
else
AC_MSG_RESULT([none found])
fi
fi
AC_SUBST([MPICC])
])
AC_DEFUN([PAC_PROG_MPIFORT],[
if test -z "$MPIFORT" ; then
AC_MSG_CHECKING([for MPI compile wrappers for Fortran])
if test -x $MPI_DIR/mpifort ; then
MPIFORT=$MPI_DIR/mpifort
elif test -x $MPI_DIR/bin/mpif90 ; then
MPIFORT=$MPI_DIR/bin/mpiff90
elif test -x $MPI_DIR/mpxlf ; then
MPIFORT=$MPIDIR/mpxlf
elif test -x $MPI_DIR/bin/mpxlf90 ; then
MPIFORT=$MPIDIR/bin/mpxlf90
else
saveIFS=$IFS
IFS=":"
for dir in $PATH ; do
if test -x $dir/mpifort ; then
MPIFORT=$dir/mpifort
break
elif test -x $dir/mpif90 ; then
MPIFORT=$dir/mpif90
break
elif test -x $dir/mpxlf ; then
MPIFORT=$dir/mpxlf
break
fi
done
IFS=$saveIFS
fi
if test -n "$MPIFORT" ; then
AC_MSG_RESULT($MPIFORT)
else
AC_MSG_RESULT([none found])
fi
fi
AC_SUBST([MPIFORT])
])
## Add a check for whether the C compiler can handle MPI programs
## as on the Cray.
AC_DEFUN([PAC_MPI_CCWORKS],[
AC_SEARCH_LIBS(MPI_Init,$MPILIB mpi mpich)
if test "$ac_cv_search_MPI_Init" = "no" ; then
ifelse($2,,
AC_MSG_ERROR([Could not find MPI library]),[$2])
fi
AC_CHECK_HEADER(mpi.h,pac_have_mpi_h="yes",pac_have_mpi_h="no")
if test $pac_have_mpi_h = "no" ; then
ifelse($2,,
AC_MSG_ERROR([Could not find mpi.h include file]),[$2])
fi
])