Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 90 additions & 17 deletions m4/mpi.m4
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,43 @@ dnl check for the required MPI library
dnl ---------------------------------------------------------------------------
AC_DEFUN([ACX_MPI], [

dnl if MPIHOME is empty, set it to /usr
AS_IF([test "x$MPIHOME" = "x"], [MPIHOME="/usr"])
dnl if MPIHOME is empty, set it to an invalid directory and try to find the correct location.
AS_IF([test "x$MPIHOME" = "x"], [MPIHOME="/.."])

AC_ARG_WITH([mpi],
AS_HELP_STRING([--with-mpi=PATH],
[Prefix where MPI is installed (MPIHOME)]),
[MPI="$withval"],
[
AS_ECHO(["note: MPI library path not given... trying prefix=$MPIHOME"])
AS_ECHO(["note: MPI library path not given... trying to find it myself"])
MPI=$MPIHOME
])

AS_IF([test -z "$MPI"], [MPI="/usr"])
AS_IF([test -z "$MPI"], [MPI="/.."])

dnl if MPI is not set in the config, search it via the $INCLUDE and $LD_LIBRARY_PATH variables;
dnl with this we can hope to get a configure that is consistent with the environment.
AS_IF([test "$MPI" = "/.."],
[
for i in $(echo $LD_LIBRARY_PATH | tr ':' '\n')
do
AS_IF([ test -e $i/libmpi.a || test -e $MPI_LIBS_PATH/libmpi.so ],
[MPI=$(dirname $i)
break])
done
])
AS_IF([test "$MPI" = "/.."],
[
for i in $(echo $INCLUDE | tr ':' '\n')
do
AS_IF([ test -e $i/mpi.h ],
[MPI=$(dirname $i)
break ])
done
])

dnl if we don't find it, default to standard-values and proceed as before:
AS_IF([test "$MPI" = "/.."], [MPI="/usr"])

MPI_LIBS_PATH="$MPI/lib"
MPI_INCLUDES_PATH="$MPI/include"
Expand Down Expand Up @@ -150,7 +174,7 @@ AS_IF([test "x$MPI_IMPL" != x],
AC_LANG_CPLUSPLUS
CPPFLAGS="-I$MPI_INCLUDES_PATH $CPPFLAGS"
AC_CHECK_HEADER([mpi.h],
[AC_DEFINE(HAVE_MPI, 1, [Flag indicating whether or not MPI is available])],
[AC_MSG_RESULT([MPI-headers are working as expected.])],
[AC_MSG_RESULT([Could not compile in the MPI headers...]); enablempi=no])
MPI_INCLUDES_PATHS="-I$MPI_INCLUDES_PATH"
AC_LANG_RESTORE
Expand All @@ -165,9 +189,8 @@ AS_IF([test "x$MPI_IMPL" != x],
AC_LANG_CPLUSPLUS
CPPFLAGS="-I$MPI_INCLUDES_PATH $CPPFLAGS"
AC_CHECK_HEADER([mpi.h],
[AC_DEFINE(HAVE_MPI, 1, [Flag indicating whether or not MPI is available])],
[AC_MSG_RESULT([Could not compile in the MPI headers...]); enablempi=no] )
MPI_INCLUDES_PATHS="-I$MPI_INCLUDES_PATH"
[AC_MSG_RESULT([MPI-headers are working as expected.])],
[AC_MSG_RESULT([Could not compile in the MPI headers...]); enablempi=no] ) MPI_INCLUDES_PATHS="-I$MPI_INCLUDES_PATH"
AC_LANG_RESTORE
CPPFLAGS=$tmpCPPFLAGS
],
Expand All @@ -184,17 +207,67 @@ AS_IF([test "x$MPI_IMPL" != x],
[
MPI_IMPL="built-in"
AC_MSG_RESULT( [$CXX Compiler Supports MPI] )
AC_DEFINE(HAVE_MPI, 1, [Flag indicating whether or not MPI is available])
],
[AC_MSG_RESULT([$CXX Compiler Does NOT Support MPI...]); enablempi=no])
])
dnl Save variables...
AC_SUBST(MPI)
AC_SUBST(MPI_IMPL)
AC_SUBST(MPI_LIBS)
AC_SUBST(MPI_LIBS_PATH)
AC_SUBST(MPI_LIBS_PATHS)
AC_SUBST(MPI_INCLUDES_PATH)
AC_SUBST(MPI_INCLUDES_PATHS)

VERSION_MPI
])


AC_DEFUN([VERSION_MPI], [

dnl Save variables...
AC_SUBST(MPI)
AC_SUBST(MPI_IMPL)
AC_SUBST(MPI_LIBS)
AC_SUBST(MPI_LIBS_PATH)
AC_SUBST(MPI_LIBS_PATHS)
AC_SUBST(MPI_INCLUDES_PATH)
AC_SUBST(MPI_INCLUDES_PATHS)
AC_MSG_RESULT([Checking Version of MPI now:])
AS_IF([test "x$enablempi" != xno],
[
dnl check that MPI_VERSION and MPI_SUBVERSION are defined.
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
dnl first catch undefined (evaluated to 0) and 1.X cases
AC_TRY_LINK([@%:@include <mpi.h>],
[
@%:@if MPI_VERSION < 2
@%:@error "MPI-version 1.X is not supported."
@%:@endif
],
[ dnl true: Check which version it is:
AC_TRY_LINK([@%:@include <mpi.h>],
[ @%:@if MPI_VERSION > 4
@%:@error "MPI-version too high. There is some error."
@%:@endif
],
[
dnl if MPI_VERSION is 2, through a warning
AC_TRY_LINK([@%:@include <mpi.h>],
[@%:@if MPI_VERSION == 2
@%:@error "deprecated MPI-version"
@%:@endif
int np; MPI_Comm_size (MPI_COMM_WORLD, &np)
],
[
AC_MSG_RESULT([ MPI was found with version >= 3.0. ]);
],
[
AC_MSG_WARN([MPI-version is 2.X. This feature is deprecated. ]);
])
dnl set necessary variables etc: Here, all enablempi-cases are in one place.
AC_DEFINE(HAVE_MPI, 1, [Flag indicating whether or not MPI is available])
],
[
AC_MSG_WARN(["ERROR: MPI-version seems to be unreasonably high. Please check your library. Disable MPI now..."]); enablempi=no
])
],
[ dnl MPI_VERSION is not defined or has unexpected value.
AC_MSG_WARN(["ERROR: MPI-version seems to be too low: Need MPI 2.X or compatible. Disable MPI now..."]); enablempi=no
])
AC_LANG_RESTORE
])
])
2 changes: 1 addition & 1 deletion m4/petsc.m4
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ AC_DEFUN([CONFIGURE_PETSC],
AC_SUBST(MPI_IMPL)

AS_IF([test "x$PETSC_MPI" != x],
[AC_DEFINE(HAVE_MPI, 1, [Flag indicating whether or not MPI is available])])
[VERSION_MPI])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I'm clear: we don't run the risk of detecting/using a different MPI from the one PETSc is using by running the VERSION_MPI check right here, right? Many systems have multiple MPIs installed on them, and we have to be careful not to link against more than one by accident...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't set any variables (except for HAVE_MPI) in the VERSION_MPI-function, I don't think this leads to problems of actually linking against different MPI-libraries.
But the detection of another library than that used by Petsc is of course an issue; in my understanding the AC_LANG_SAVE and AC_LANG_CPLUSPLUS should take care of this:

  1. The the current status is saved
  2. The cpp-preferences are loaded (such as LD-LIBRARY_PATH etc).
    This should avoid cases that wrong libraries are loaded.

I tried testing this but I always got errors due to compiler-inconsistencies and so the Petsc-dependency was removed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct me if I am wrong, but at this point it is ensured that we use the same compiler as that used to compile PETSc; this should ensure that we have the same MPI, since it is linked with the compiler.

Moreover, if there is a way to link to the wrong MPI-library in VERSION_MPI, than we are using an inconsistent setup anyway; this should be ensured before already.


AS_IF([test $petsc_have_hypre -gt 0],
[AC_DEFINE(HAVE_PETSC_HYPRE, 1, [Flag indicating whether or not PETSc was compiled with Hypre support])])
Expand Down