1
dnl----------------------------------------------------------------------------
2
dnl This file is part of the Code_Saturne Kernel, element of the
3
dnl Code_Saturne CFD tool.
5
dnl Copyright (C) 2009 EDF S.A., France
7
dnl The Code_Saturne Kernel is free software; you can redistribute it
8
dnl and/or modify it under the terms of the GNU General Public License
9
dnl as published by the Free Software Foundation; either version 2 of
10
dnl the License, or (at your option) any later version.
12
dnl The Code_Saturne Kernel is distributed in the hope that it will be
13
dnl useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14
dnl of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
dnl GNU General Public License for more details.
17
dnl You should have received a copy of the GNU General Public Licence
18
dnl along with the Code_Saturne Preprocessor; if not, write to the
19
dnl Free Software Foundation, Inc.,
20
dnl 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
dnl-----------------------------------------------------------------------------
25
# optional MPI support (use CC=mpicc with configure if necessary)
26
# modifies or sets cs_have_mpi, MPI_CPPFLAGS, MPI_LDFLAGS, and MPI_LIBS
27
# depending on libraries found
29
AC_DEFUN([CS_AC_TEST_MPI], [
31
saved_CPPFLAGS="$CPPFLAGS"
32
saved_LDFLAGS="$LDFLAGS"
39
[AS_HELP_STRING([--with-mpi=PATH],
40
[specify prefix directory for MPI])],
41
[if test "x$withval" = "x"; then
47
[AS_HELP_STRING([--with-mpi-exec=PATH],
48
[specify prefix directory for MPI executables])],
49
[if test "x$with_mpi" = "xcheck"; then
52
mpi_bindir="$with_mpi_exec"],
53
[if test "x$with_mpi" != "xno" -a "x$with_mpi" != "xyes" \
54
-a "x$with_mpi" != "xcheck"; then
55
mpi_bindir="$with_mpi/bin"
58
AC_ARG_WITH(mpi-include,
59
[AS_HELP_STRING([--with-mpi-include=PATH],
60
[specify directory for MPI include files])],
61
[if test "x$with_mpi" = "xcheck"; then
64
MPI_CPPFLAGS="-I$with_mpi_include"],
65
[if test "x$with_mpi" != "xno" -a "x$with_mpi" != "xyes" \
66
-a "x$with_mpi" != "xcheck"; then
67
MPI_CPPFLAGS="-I$with_mpi/include"
71
[AS_HELP_STRING([--with-mpi-lib=PATH],
72
[specify directory for MPI library])],
73
[if test "x$with_mpi" = "xcheck"; then
76
MPI_LDFLAGS="-L$with_mpi_lib"
77
mpi_libdir="$with_mpi_lib"],
78
[if test "x$with_mpi" != "xno" -a "x$with_mpi" != "xyes" \
79
-a "x$with_mpi" != "xcheck"; then
80
MPI_LDFLAGS="-L$with_mpi/lib"
81
mpi_libdir="$with_mpi/lib"
85
# Just in case, remove excess whitespace from existing flag and libs variables.
87
if test "$MPI_CPPFLAGS" != "" ; then
88
MPI_CPPFLAGS=`echo $MPI_CPPFLAGS | sed 's/^[ ]*//;s/[ ]*$//'`
90
if test "$MPI_LDFLAGS" != "" ; then
91
MPI_LDFLAGS=`echo $MPI_LDFLAGS | sed 's/^[ ]*//;s/[ ]*$//'`
93
if test "$MPI_LIBS" != "" ; then
94
MPI_LIBS=`echo $MPI_LIBS | sed 's/^[ ]*//;s/[ ]*$//'`
97
# If we do not use an MPI compiler wrapper, we must add compilation
98
# and link flags; we try to detect the correct flags to add.
100
if test "x$with_mpi" != "xno" -a "x$cs_have_mpi" = "xno" ; then
102
# try several tests for MPI
104
# MPI Compiler wrapper test
105
AC_MSG_CHECKING([for MPI (MPI compiler wrapper test)])
106
CPPFLAGS="$saved_CPPFLAGS $MPI_CPPFLAGS"
107
LDFLAGS="$saved_LDFLAGS $MPI_LDFLAGS"
108
LIBS="$saved_LIBS $MPI_LIBS"
109
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <mpi.h>]],
110
[[ MPI_Init(0, (void *)0); ]])],
111
[AC_DEFINE([HAVE_MPI], 1, [MPI support])
114
AC_MSG_RESULT($cs_have_mpi)
116
# If failed, basic test
117
if test "x$cs_have_mpi" = "xno"; then
119
CPPFLAGS="$saved_CPPFLAGS $MPI_CPPFLAGS"
121
# First, check for mpi.h header
122
AC_CHECK_HEADERS([mpi.h],
123
[cs_have_mpi_header=yes],
127
if test $cs_have_mpi_header = no ; then
128
unset ac_cv_header_mpi_h
129
MPI_CPPFLAGS="-I/usr/include/mpi"
130
CPPFLAGS="$saved_CPPFLAGS $MPI_CPPFLAGS"
131
AC_CHECK_HEADERS([mpi.h],
132
[cs_have_mpi_header=yes],
138
AC_MSG_CHECKING([for MPI (basic test)])
139
if test "$MPI_LIBS" = "" ; then
140
MPI_LIBS="-lmpi $PTHREAD_LIBS"
142
LDFLAGS="$saved_LDFLAGS $MPI_LDFLAGS"
143
LIBS="$saved_LIBS $MPI_LIBS"
144
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <mpi.h>]],
145
[[ MPI_Init(0, (void *)0); ]])],
146
[AC_DEFINE([HAVE_MPI], 1, [MPI support])
149
AC_MSG_RESULT($cs_have_mpi)
152
# If failed, test for mpich
153
if test "x$cs_have_mpi" = "xno"; then
154
AC_MSG_CHECKING([for MPI (mpich test)])
155
# First try (simplest)
156
MPI_LIBS="-lmpich $PTHREAD_LIBS"
157
LIBS="$saved_LIBS $MPI_LIBS"
158
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <mpi.h>]],
159
[[ MPI_Init(0, (void *)0); ]])],
160
[AC_DEFINE([HAVE_MPI], 1, [MPI support])
163
if test "x$cs_have_mpi" = "xno"; then
164
# Second try (with lpmpich)
165
MPI_LIBS="-Wl,-lpmpich -Wl,-lmpich -Wl,-lpmpich -Wl,-lmpich"
166
LIBS="$saved_LIBS $MPI_LIBS"
167
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <mpi.h>]],
168
[[ MPI_Init(0, (void *)0); ]])],
169
[AC_DEFINE([HAVE_MPI], 1, [MPI support])
173
AC_MSG_RESULT($cs_have_mpi)
176
# If failed, test for lam-mpi
177
if test "x$cs_have_mpi" = "xno"; then
178
AC_MSG_CHECKING([for MPI (lam-mpi test)])
179
# First try (without MPI-IO)
182
MPI_LIBS="-lmpi -llam $PTHREAD_LIBS";;
184
MPI_LIBS="-lmpi -llam -lpthread";;
186
LIBS="$saved_LIBS $MPI_LIBS"
187
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <mpi.h>]],
188
[[ MPI_Init(0, (void *)0); ]])],
189
[AC_DEFINE([HAVE_MPI], 1, [MPI support])
192
if test "x$cs_have_mpi" = "xno"; then
193
# Second try (with MPI-IO)
196
MPI_LIBS="-lmpi -llam -lutil -ldl $PTHREAD_LIBS";;
198
MPI_LIBS="-lmpi -llam -lutil -ldl -lpthread";;
200
LIBS="$saved_LIBS $MPI_LIBS"
201
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <mpi.h>]],
202
[[ MPI_Init(0, (void *)0); ]])],
203
[AC_DEFINE([HAVE_MPI], 1, [MPI support])
207
AC_MSG_RESULT($cs_have_mpi)
210
if test "x$cs_have_mpi" = "xno"; then
211
if test "x$with_mpi" != "xcheck" ; then
212
AC_MSG_FAILURE([MPI support is requested, but test for MPI failed!])
214
AC_MSG_WARN([no MPI support])
218
# Try to detect MPI variants as this may be useful for the run scripts to
219
# determine the correct mpi startup syntax (especially when multiple
220
# librairies are installed on the same machine).
221
CPPFLAGS="$saved_CPPFLAGS $MPI_CPPFLAGS"
223
if test "x$cs_ibm_bg_type" != "x" ; then
224
if test "x$cs_ibm_bg_type" = "xL" ; then
226
elif test "x$cs_ibm_bg_type" = "xP" ; then
230
if test "x$mpi_type" = "x"; then
231
AC_EGREP_CPP([mpich2],
240
if test "x$mpi_type" = "x"; then
244
#ifdef OMPI_MAJOR_VERSION
250
if test "x$mpi_type" = "x"; then
251
AC_EGREP_CPP([mpibull2],
260
if test "x$mpi_type" = "x"; then
261
AC_EGREP_CPP([lam_mpi],
270
if test "x$mpi_type" = "x"; then
271
AC_EGREP_CPP([hp_mpi],
282
CPPFLAGS="$saved_CPPFLAGS"
283
LDFLAGS="$saved_LDFLAGS"
292
AM_CONDITIONAL(HAVE_MPI, test x$cs_have_mpi = xyes)
294
AC_SUBST(MPI_CPPFLAGS)
295
AC_SUBST(MPI_LDFLAGS)