From 9e01bb2d33476563ce4219499c3e57b484267195 Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Mon, 15 Jul 2024 12:54:01 +0200
Subject: [PATCH] Improve detection of MPI capability and optional feature
 configuration

---
 build/Makefile.am         |   1 -
 build/Makefile.in         |   1 -
 build/build_aux/ltmain.sh |   4 +-
 build/configure           | 869 +++++++++++++++++++++++++++++++++-----
 build/configure.ac        | 111 +++--
 5 files changed, 843 insertions(+), 143 deletions(-)

diff --git a/build/Makefile.am b/build/Makefile.am
index dcb4cfcf..eb8b8935 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -1,4 +1,3 @@
-AUTOMAKE_OPTIONS=subdir-objects
 LDADD=libnptm/libnptm.la -L/usr/lib64 ${USER_LDFLAGS} ${HDF5_LDFLAGS} ${LAPACKLDFLAGS} ${MAGMALDFLAGS}
 lib_LTLIBRARIES=libnptm/libnptm.la
 libnptm_libnptm_la_SOURCES=../src/libnptm/algebraic.cpp ../src/libnptm/clu_subs.cpp ../src/libnptm/Commons.cpp ../src/libnptm/Configuration.cpp ../src/libnptm/file_io.cpp ../src/libnptm/lapack_calls.cpp ../src/libnptm/logging.cpp ../src/libnptm/magma_calls.cpp ../src/libnptm/Parsers.cpp ../src/libnptm/sph_subs.cpp ../src/libnptm/tfrfme.cpp ../src/libnptm/TransitionMatrix.cpp ../src/libnptm/tra_subs.cpp ../src/libnptm/types.cpp
diff --git a/build/Makefile.in b/build/Makefile.in
index fed24361..85cae453 100644
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -519,7 +519,6 @@ target_alias = @target_alias@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-AUTOMAKE_OPTIONS = subdir-objects
 LDADD = libnptm/libnptm.la -L/usr/lib64 ${USER_LDFLAGS} ${HDF5_LDFLAGS} ${LAPACKLDFLAGS} ${MAGMALDFLAGS}
 lib_LTLIBRARIES = libnptm/libnptm.la
 libnptm_libnptm_la_SOURCES = ../src/libnptm/algebraic.cpp ../src/libnptm/clu_subs.cpp ../src/libnptm/Commons.cpp ../src/libnptm/Configuration.cpp ../src/libnptm/file_io.cpp ../src/libnptm/lapack_calls.cpp ../src/libnptm/logging.cpp ../src/libnptm/magma_calls.cpp ../src/libnptm/Parsers.cpp ../src/libnptm/sph_subs.cpp ../src/libnptm/tfrfme.cpp ../src/libnptm/TransitionMatrix.cpp ../src/libnptm/tra_subs.cpp ../src/libnptm/types.cpp
diff --git a/build/build_aux/ltmain.sh b/build/build_aux/ltmain.sh
index 1dea62ab..977e5237 100755
--- a/build/build_aux/ltmain.sh
+++ b/build/build_aux/ltmain.sh
@@ -31,7 +31,7 @@
 
 PROGRAM=libtool
 PACKAGE=libtool
-VERSION="2.4.7 Debian-2.4.7-7"
+VERSION="2.4.7 Debian-2.4.7-7build1"
 package_revision=2.4.7
 
 
@@ -2296,7 +2296,7 @@ include the following information:
        compiler:       $LTCC
        compiler flags: $LTCFLAGS
        linker:         $LD (gnu? $with_gnu_ld)
-       version:        $progname $scriptversion Debian-2.4.7-7
+       version:        $progname $scriptversion Debian-2.4.7-7build1
        automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
        autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
 
diff --git a/build/configure b/build/configure
index d6291c94..8b5c5382 100755
--- a/build/configure
+++ b/build/configure
@@ -1486,8 +1486,8 @@ Optional Packages:
   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
   --with-sysroot[=DIR]    Search for dependent libraries within DIR (or the
                           compiler's sysroot if not specified).
-  --with-lapack           use LAPACK [default=check]
-  --with-magma            use MAGMA [default=check]
+  --with-lapack           use LAPACK [default=auto]
+  --with-magma            use MAGMA [default=auto]
   --with-include          additional include folders [default=none]
   --with-fflags=flags     FORTRAN compiler flags [default="-std=legacy -O3"]
   --with-ldflags=flags    custom linker flags [default=none]
@@ -3006,6 +3006,8 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 # Folder structure safety check
 
+ac_config_files="$ac_config_files Makefile"
+
 
 # Auxiliary build folder
 
@@ -6147,7 +6149,8 @@ printf "%s\n" "$as_me: Using $CXX" >&6;}
       MPIFLAGS=""
 
     elif test "x$enableval" = "xauto"; then
-      ac_ext=cpp
+      if test "x$CXX" = "x"; then
+        ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
@@ -6157,7 +6160,7 @@ if test -z "$CXX"; then
     CXX=$CCC
   else
     if test -n "$ac_tool_prefix"; then
-  for ac_prog in mpicxx mpic++ mpiCC
+  for ac_prog in mpicxx.openmpi mpicxx.mpich mpic++.openmpi mpiCC.openmpi
   do
     # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
@@ -6207,7 +6210,7 @@ fi
 fi
 if test -z "$CXX"; then
   ac_ct_CXX=$CXX
-  for ac_prog in mpicxx mpic++ mpiCC
+  for ac_prog in mpicxx.openmpi mpicxx.mpich mpic++.openmpi mpiCC.openmpi
 do
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
@@ -6659,10 +6662,549 @@ else
 fi
 
 
-      if test "x$CXX" != "x"; then
-        MPIFLAGS=-DUSE_MPI
+        if test "x$CXX" != "x"; then
+          MPIFLAGS=-DUSE_MPI
 
-      else
+        else
+          ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+if test -z "$CXX"; then
+  if test -n "$CCC"; then
+    CXX=$CCC
+  else
+    if test -n "$ac_tool_prefix"; then
+  for ac_prog in g++ clang++
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+printf %s "checking for $ac_word... " >&6; }
+if test ${ac_cv_prog_CXX+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) if test -n "$CXX"; then
+  ac_cv_prog_CXX="$CXX" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  case $as_dir in #(((
+    '') as_dir=./ ;;
+    */) ;;
+    *) as_dir=$as_dir/ ;;
+  esac
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CXX="$ac_tool_prefix$ac_prog"
+    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi ;;
+esac
+fi
+CXX=$ac_cv_prog_CXX
+if test -n "$CXX"; then
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5
+printf "%s\n" "$CXX" >&6; }
+else
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+fi
+
+
+    test -n "$CXX" && break
+  done
+fi
+if test -z "$CXX"; then
+  ac_ct_CXX=$CXX
+  for ac_prog in g++ clang++
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+printf %s "checking for $ac_word... " >&6; }
+if test ${ac_cv_prog_ac_ct_CXX+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) if test -n "$ac_ct_CXX"; then
+  ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  case $as_dir in #(((
+    '') as_dir=./ ;;
+    */) ;;
+    *) as_dir=$as_dir/ ;;
+  esac
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CXX="$ac_prog"
+    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi ;;
+esac
+fi
+ac_ct_CXX=$ac_cv_prog_ac_ct_CXX
+if test -n "$ac_ct_CXX"; then
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5
+printf "%s\n" "$ac_ct_CXX" >&6; }
+else
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_CXX" && break
+done
+
+  if test "x$ac_ct_CXX" = x; then
+    CXX="g++"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CXX=$ac_ct_CXX
+  fi
+fi
+
+  fi
+fi
+# Provide some information about the compiler.
+printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+printf "%s\n" "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+  fi
+  rm -f conftest.er1 conftest.err
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C++" >&5
+printf %s "checking whether the compiler supports GNU C++... " >&6; }
+if test ${ac_cv_cxx_compiler_gnu+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"
+then :
+  ac_compiler_gnu=yes
+else case e in #(
+  e) ac_compiler_gnu=no ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+ac_cv_cxx_compiler_gnu=$ac_compiler_gnu
+ ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5
+printf "%s\n" "$ac_cv_cxx_compiler_gnu" >&6; }
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+if test $ac_compiler_gnu = yes; then
+  GXX=yes
+else
+  GXX=
+fi
+ac_test_CXXFLAGS=${CXXFLAGS+y}
+ac_save_CXXFLAGS=$CXXFLAGS
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5
+printf %s "checking whether $CXX accepts -g... " >&6; }
+if test ${ac_cv_prog_cxx_g+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) ac_save_cxx_werror_flag=$ac_cxx_werror_flag
+   ac_cxx_werror_flag=yes
+   ac_cv_prog_cxx_g=no
+   CXXFLAGS="-g"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"
+then :
+  ac_cv_prog_cxx_g=yes
+else case e in #(
+  e) CXXFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"
+then :
+
+else case e in #(
+  e) ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+	 CXXFLAGS="-g"
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"
+then :
+  ac_cv_prog_cxx_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+   ac_cxx_werror_flag=$ac_save_cxx_werror_flag ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5
+printf "%s\n" "$ac_cv_prog_cxx_g" >&6; }
+if test $ac_test_CXXFLAGS; then
+  CXXFLAGS=$ac_save_CXXFLAGS
+elif test $ac_cv_prog_cxx_g = yes; then
+  if test "$GXX" = yes; then
+    CXXFLAGS="-g -O2"
+  else
+    CXXFLAGS="-g"
+  fi
+else
+  if test "$GXX" = yes; then
+    CXXFLAGS="-O2"
+  else
+    CXXFLAGS=
+  fi
+fi
+ac_prog_cxx_stdcxx=no
+if test x$ac_prog_cxx_stdcxx = xno
+then :
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++11 features" >&5
+printf %s "checking for $CXX option to enable C++11 features... " >&6; }
+if test ${ac_cv_prog_cxx_cxx11+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) ac_cv_prog_cxx_cxx11=no
+ac_save_CXX=$CXX
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_cxx_conftest_cxx11_program
+_ACEOF
+for ac_arg in '' -std=gnu++11 -std=gnu++0x -std=c++11 -std=c++0x -qlanglvl=extended0x -AA
+do
+  CXX="$ac_save_CXX $ac_arg"
+  if ac_fn_cxx_try_compile "$LINENO"
+then :
+  ac_cv_prog_cxx_cxx11=$ac_arg
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam
+  test "x$ac_cv_prog_cxx_cxx11" != "xno" && break
+done
+rm -f conftest.$ac_ext
+CXX=$ac_save_CXX ;;
+esac
+fi
+
+if test "x$ac_cv_prog_cxx_cxx11" = xno
+then :
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+printf "%s\n" "unsupported" >&6; }
+else case e in #(
+  e) if test "x$ac_cv_prog_cxx_cxx11" = x
+then :
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
+printf "%s\n" "none needed" >&6; }
+else case e in #(
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_cxx11" >&5
+printf "%s\n" "$ac_cv_prog_cxx_cxx11" >&6; }
+     CXX="$CXX $ac_cv_prog_cxx_cxx11" ;;
+esac
+fi
+  ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx11
+  ac_prog_cxx_stdcxx=cxx11 ;;
+esac
+fi
+fi
+if test x$ac_prog_cxx_stdcxx = xno
+then :
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++98 features" >&5
+printf %s "checking for $CXX option to enable C++98 features... " >&6; }
+if test ${ac_cv_prog_cxx_cxx98+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) ac_cv_prog_cxx_cxx98=no
+ac_save_CXX=$CXX
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_cxx_conftest_cxx98_program
+_ACEOF
+for ac_arg in '' -std=gnu++98 -std=c++98 -qlanglvl=extended -AA
+do
+  CXX="$ac_save_CXX $ac_arg"
+  if ac_fn_cxx_try_compile "$LINENO"
+then :
+  ac_cv_prog_cxx_cxx98=$ac_arg
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam
+  test "x$ac_cv_prog_cxx_cxx98" != "xno" && break
+done
+rm -f conftest.$ac_ext
+CXX=$ac_save_CXX ;;
+esac
+fi
+
+if test "x$ac_cv_prog_cxx_cxx98" = xno
+then :
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+printf "%s\n" "unsupported" >&6; }
+else case e in #(
+  e) if test "x$ac_cv_prog_cxx_cxx98" = x
+then :
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
+printf "%s\n" "none needed" >&6; }
+else case e in #(
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_cxx98" >&5
+printf "%s\n" "$ac_cv_prog_cxx_cxx98" >&6; }
+     CXX="$CXX $ac_cv_prog_cxx_cxx98" ;;
+esac
+fi
+  ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98
+  ac_prog_cxx_stdcxx=cxx98 ;;
+esac
+fi
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+depcc="$CXX"  am_compiler_list=
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5
+printf %s "checking dependency style of $depcc... " >&6; }
+if test ${am_cv_CXX_dependencies_compiler_type+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named 'D' -- because '-MD' means "put the output
+  # in D".
+  rm -rf conftest.dir
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_CXX_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp`
+  fi
+  am__universal=false
+  case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with
+      # Solaris 10 /bin/sh.
+      echo '/* dummy */' > sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with '-c' and '-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle '-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs.
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # After this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested.
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    msvc7 | msvc7msys | msvisualcpp | msvcmsys)
+      # This compiler won't grok '-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_CXX_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_CXX_dependencies_compiler_type=none
+fi
+ ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_CXX_dependencies_compiler_type" >&5
+printf "%s\n" "$am_cv_CXX_dependencies_compiler_type" >&6; }
+CXXDEPMODE=depmode=$am_cv_CXX_dependencies_compiler_type
+
+ if
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_CXX_dependencies_compiler_type" = gcc3; then
+  am__fastdepCXX_TRUE=
+  am__fastdepCXX_FALSE='#'
+else
+  am__fastdepCXX_TRUE='#'
+  am__fastdepCXX_FALSE=
+fi
+
+
+          MPIFLAGS=""
+
+        fi
+      else
+        # Test if given CXX defines mpi.h
+
+    cat > np_test_mpi.cpp <<EOF
+#ifndef MPI_VERSION
+#include <mpi.h>
+#endif
+int main(int argc, char** argv) {
+  int ierr = MPI_Init(&argc, &argv);
+  MPI_Finalize();
+  return ierr;
+}
+EOF
+    $CXX -c np_test_mpi.cpp > /dev/null 2>&1
+    export CXX_IS_MPI=$?
+    rm np_test_mpi.cpp
+    if test "x$CXX_IS_MPI" = "x0"; then
+      rm np_test_mpi.o
+    fi
+
+
+      fi
+    elif test "x$enableval" = "xyes"; then
+      if test "x$CXX" = "x"; then
         ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -6673,7 +7215,7 @@ if test -z "$CXX"; then
     CXX=$CCC
   else
     if test -n "$ac_tool_prefix"; then
-  for ac_prog in g++ clang++
+  for ac_prog in mpicxx.openmpi mpicxx.mpich mpic++.openmpi mpiCC.openmpi
   do
     # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
@@ -6723,7 +7265,7 @@ fi
 fi
 if test -z "$CXX"; then
   ac_ct_CXX=$CXX
-  for ac_prog in g++ clang++
+  for ac_prog in mpicxx.openmpi mpicxx.mpich mpic++.openmpi mpiCC.openmpi
 do
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
@@ -7175,10 +7717,42 @@ else
 fi
 
 
-        MPIFLAGS=""
+        if test "x$CXX" != "x"; then
+          MPIFLAGS=-DUSE_MPI
+
+        else
+          as_fn_error $? "MPI was requested, but no MPI compiler detected!" "$LINENO" 5
+        fi
+      else
+        # Test if given CXX defines mpi.h
+
+    cat > np_test_mpi.cpp <<EOF
+#ifndef MPI_VERSION
+#include <mpi.h>
+#endif
+int main(int argc, char** argv) {
+  int ierr = MPI_Init(&argc, &argv);
+  MPI_Finalize();
+  return ierr;
+}
+EOF
+    $CXX -c np_test_mpi.cpp > /dev/null 2>&1
+    export CXX_IS_MPI=$?
+    rm np_test_mpi.cpp
+    if test "x$CXX_IS_MPI" = "x0"; then
+      rm np_test_mpi.o
+    fi
+
 
+	if test "x$CXX_IS_MPI" != "x0"; then
+          as_fn_error $? "MPI was requested, but $CXX is not a MPI compiler!" "$LINENO" 5
+	fi
       fi
-    elif test "x$enableval" = "xyes"; then
+    fi
+
+else case e in #(
+  e)
+    if test "x$CXX" = "x"; then
       ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -7189,7 +7763,7 @@ if test -z "$CXX"; then
     CXX=$CCC
   else
     if test -n "$ac_tool_prefix"; then
-  for ac_prog in mpicxx mpic++ mpiCC
+  for ac_prog in mpicxx.openmpi mpicxx.mpich mpic++.openmpi mpiCC.openmpi
   do
     # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
@@ -7239,7 +7813,7 @@ fi
 fi
 if test -z "$CXX"; then
   ac_ct_CXX=$CXX
-  for ac_prog in mpicxx mpic++ mpiCC
+  for ac_prog in mpicxx.openmpi mpicxx.mpich mpic++.openmpi mpiCC.openmpi
 do
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
@@ -7695,14 +8269,7 @@ fi
         MPIFLAGS=-DUSE_MPI
 
       else
-        as_fn_error $? "MPI was requested, but no MPI compiler detected!" "$LINENO" 5
-      fi
-    fi
-
-else case e in #(
-  e)
-    if test "x$CXX" = "x"; then
-      ac_ext=cpp
+        ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
@@ -7712,7 +8279,7 @@ if test -z "$CXX"; then
     CXX=$CCC
   else
     if test -n "$ac_tool_prefix"; then
-  for ac_prog in mpicxx mpic++ mpiCC
+  for ac_prog in g++ clang++
   do
     # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
@@ -7762,7 +8329,7 @@ fi
 fi
 if test -z "$CXX"; then
   ac_ct_CXX=$CXX
-  for ac_prog in mpicxx mpic++ mpiCC
+  for ac_prog in g++ clang++
 do
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
@@ -8214,11 +8781,13 @@ else
 fi
 
 
-      if test "x$CXX" != "x"; then
-        MPIFLAGS=-DUSE_MPI
+        MPIFLAGS=""
 
-      else
-        ac_ext=cpp
+        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: Using $CXX" >&5
+printf "%s\n" "$as_me: Using $CXX" >&6;}
+      fi
+    else
+      ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
@@ -8228,7 +8797,7 @@ if test -z "$CXX"; then
     CXX=$CCC
   else
     if test -n "$ac_tool_prefix"; then
-  for ac_prog in g++ clang++
+  for ac_prog in $CXX
   do
     # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
@@ -8278,7 +8847,7 @@ fi
 fi
 if test -z "$CXX"; then
   ac_ct_CXX=$CXX
-  for ac_prog in g++ clang++
+  for ac_prog in $CXX
 do
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
@@ -8730,13 +9299,38 @@ else
 fi
 
 
+
+    cat > np_test_mpi.cpp <<EOF
+#ifndef MPI_VERSION
+#include <mpi.h>
+#endif
+int main(int argc, char** argv) {
+  int ierr = MPI_Init(&argc, &argv);
+  MPI_Finalize();
+  return ierr;
+}
+EOF
+    $CXX -c np_test_mpi.cpp > /dev/null 2>&1
+    export CXX_IS_MPI=$?
+    rm np_test_mpi.cpp
+    if test "x$CXX_IS_MPI" = "x0"; then
+      rm np_test_mpi.o
+    fi
+
+
+      if test "x$CXX_IS_MPI" = "x0"; then
+        MPIFLAGS=-DUSE_MPI
+
         MPIFLAGS=""
 
-        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: Using $CXX" >&5
-printf "%s\n" "$as_me: Using $CXX" >&6;}
       fi
-    else
-      ac_ext=cpp
+    fi
+
+ ;;
+esac
+fi
+
+ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
@@ -9248,12 +9842,6 @@ else
 fi
 
 
-    fi
-
- ;;
-esac
-fi
-
 ac_ext=f
 ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&5'
 ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
@@ -24231,11 +24819,73 @@ esac
 fi
 
 # Configure the optional features
+# Check whether --enable-openmp was given.
+if test ${enable_openmp+y}
+then :
+  enableval=$enable_openmp;
+    if test "x$enableval" != "xno"; then
+      OMPFLAGS="-fopenmp"
+
+    fi
+
+else case e in #(
+  e)
+    OMPFLAGS="-fopenmp"
+
+
+ ;;
+esac
+fi
+
+
+
+# Check whether --with-lapack was given.
+if test ${with_lapack+y}
+then :
+  withval=$with_lapack;
+    if test "x$withval" = "xno"; then
+      LAPACKFLAGS=""
+
+      LAPACKLDFLAGS=""
+
+    else
+
+    export -p | grep MKL
+    MKL_DEF=$?
+    if test "x$MKL_DEF" = "x0"; then
+      export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL -DLAPACK_ILP64 -DUSE_ILP64 -I{MKLROOT}/include"
+      export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
+    else
+      if test -f /usr/include/lapacke.h; then
+        export LAPACKFLAGS="-DUSE_LAPACK -DLAPACK_ILP64 -DUSE_ILP64"
+	export LAPACKLDFLAGS="-llapacke64"
+      fi
+    fi
+
+
+      if test "x$LAPACKLDFLAGS" != "x"
+then :
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: LAPACK detected." >&5
+printf "%s\n" "$as_me: LAPACK detected." >&6;}
+else case e in #(
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: No LAPACK found." >&5
+printf "%s\n" "$as_me: No LAPACK found." >&6;}
+       ;;
+esac
+fi
+      LAPACKFLAGS=${LAPACKFLAGS}
+
+      LAPACKLDFLAGS=${LAPACKLDFLAGS}
+
+    fi
+
+else case e in #(
+  e)
 
     export -p | grep MKL
     MKL_DEF=$?
     if test "x$MKL_DEF" = "x0"; then
-      export LAPACKFLAGS="-DUSE_LAPACK -DLAPACK_ILP64 -DUSE_ILP64 -I{MKLROOT}/include"
+      export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL -DLAPACK_ILP64 -DUSE_ILP64 -I{MKLROOT}/include"
       export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
     else
       if test -f /usr/include/lapacke.h; then
@@ -24245,18 +24895,38 @@ fi
     fi
 
 
-if test "x$LAPACKLDFLAGS" != "x"
+    if test "x$LAPACKLDFLAGS" != "x"
 then :
-  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: LAPACK detected. Activating by default (use --without-lapack to disable)." >&5
-printf "%s\n" "$as_me: LAPACK detected. Activating by default (use --without-lapack to disable)." >&6;}
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: LAPACK detected. Activating by default (use --without-lapack to disble)." >&5
+printf "%s\n" "$as_me: LAPACK detected. Activating by default (use --without-lapack to disble)." >&6;}
 else case e in #(
   e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: No LAPACK found." >&5
 printf "%s\n" "$as_me: No LAPACK found." >&6;}
+     ;;
+esac
+fi
+    LAPACKFLAGS=${LAPACKFLAGS}
+
+    LAPACKLDFLAGS=${LAPACKLDFLAGS}
+
+
  ;;
 esac
 fi
 
 
+
+# Check whether --with-magma was given.
+if test ${with_magma+y}
+then :
+  withval=$with_magma;
+    if test "x$withval" = "xno"; then
+      MAGMAFLAGS=""
+
+      MAGMALDFLAGS=""
+
+    else
+
     if test "x$CUDA_LIB" = "x"; then
       export -p | grep CUDA
       CUDA_DEF=$?
@@ -24289,84 +24959,67 @@ fi
     fi
 
 
-if test "x$MAGMALDFLAGS" != "x"
+      if test "x$MAGMALDFLAGS" != "x"
 then :
-  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: MAGMA detected. Activating by default (use --without-magma to disable)." >&5
-printf "%s\n" "$as_me: MAGMA detected. Activating by default (use --without-magma to disable)." >&6;}
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: MAGMA detected." >&5
+printf "%s\n" "$as_me: MAGMA detected." >&6;}
 else case e in #(
   e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: MAGMA not found." >&5
 printf "%s\n" "$as_me: MAGMA not found." >&6;}
- ;;
+       ;;
 esac
 fi
+      MAGMAFLAGS=${MAGMAFLAGS}
 
-# Check whether --enable-openmp was given.
-if test ${enable_openmp+y}
-then :
-  enableval=$enable_openmp;
-    if test "x$enableval" != "xno"; then
-      OMPFLAGS="-fopenmp"
+      MAGMALDFLAGS=${MAGMALDFLAGS}
 
     fi
 
 else case e in #(
   e)
-    OMPFLAGS="-fopenmp"
-
-
- ;;
-esac
-fi
-
-
-
-# Check whether --with-lapack was given.
-if test ${with_lapack+y}
-then :
-  withval=$with_lapack;
-    if test "x$withval" = "xno"; then
-      LAPACKFLAGS=""
-
-      LAPACKLDFLAGS=""
 
+    if test "x$CUDA_LIB" = "x"; then
+      export -p | grep CUDA
+      CUDA_DEF=$?
+      if test "x$CUDA_DEF" = "x0"; then
+        CUDA_LIB=${CUDA_HOME}/targets/x86_64-linux/lib
+      else
+        CUDA_LIB=/usr/local/cuda/targets/x86_64-linux/lib
+      fi
+    fi
+    export -p | grep MAGMA
+    MAGMA_DEF=$?
+    if test "x$MAGMA_DEF" = "x0"; then
+      export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 -I${MAGMA_INCLUDE}"
+      export MAGMALDFLAGS="-L${CUDA_LIB} -lcudart -L${MAGMA_LIB} -lmagma"
     else
-      LAPACKFLAGS=${LAPACKFLAGS}
-
-      LAPACKLDFLAGS=${LAPACKLDFLAGS}
-
+      if test "x$MAGMA_INCLUDE" != "x"; then
+        export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64 -I${MAGMA_INCLUDE}"
+      else
+        if test -f /usr/include/magma_v2.h; then
+          export MAGMAFLAGS="-DUSE_MAGMA -DMAGMA_ILP64"
+	fi
+      fi
+      if test "x$MAGMA_LIB" != "x"; then
+        export MAGMALDFLAGS="-L${CUDA_LIB} -lcudart -L${MAGMA_LIB} -lmagma"
+      else
+        if test -f /usr/include/magma_v2.h; then
+          export MAGMALDFLAGS="-L${CUDA_LIB} -lcudart -lmagma"
+	fi
+      fi
     fi
 
-else case e in #(
-  e)
-    LAPACKFLAGS=${LAPACKFLAGS}
-
-    LAPACKLDFLAGS=${LAPACKLDFLAGS}
-
-
- ;;
-esac
-fi
-
-
 
-# Check whether --with-magma was given.
-if test ${with_magma+y}
+    if test "x$MAGMALDFLAGS" != "x"
 then :
-  withval=$with_magma;
-    if test "x$withval" = "xno"; then
-      MAGMAFLAGS=""
-
-      MAGMALDFLAGS=""
-
-    else
-      MAGMAFLAGS=${MAGMAFLAGS}
-
-      MAGMALDFLAGS=${MAGMALDFLAGS}
-
-    fi
-
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: MAGMA detected. Activating by default (use --without-magma to disable)." >&5
+printf "%s\n" "$as_me: MAGMA detected. Activating by default (use --without-magma to disable)." >&6;}
 else case e in #(
-  e)
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: MAGMA not found." >&5
+printf "%s\n" "$as_me: MAGMA not found." >&6;}
+     ;;
+esac
+fi
     MAGMAFLAGS=${MAGMAFLAGS}
 
     MAGMALDFLAGS=${MAGMALDFLAGS}
@@ -24461,10 +25114,6 @@ fi
 CXXFLAGS="$CLANGFLAGS -O3 -ggdb $USER_INCLUDE -I$HDF5_INCLUDE $OMPFLAGS $MPIFLAGS $LAPACKFLAGS $MAGMAFLAGS $NVTXFLAGS"
 SUBDIRS="cluster libnptm sphere testing trapping"
 
-# Send output to Makefiles
-ac_config_files="$ac_config_files Makefile"
-
-
 # Generate the output
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
@@ -24665,6 +25314,10 @@ if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then
   as_fn_error $? "conditional \"am__fastdepCXX\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then
+  as_fn_error $? "conditional \"am__fastdepCXX\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 
 : "${CONFIG_STATUS=./config.status}"
 ac_write_fail=0
@@ -25704,9 +26357,9 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 for ac_config_target in $ac_config_targets
 do
   case $ac_config_target in
+    "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
     "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
     "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
-    "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
 
   *) as_fn_error $? "invalid argument: '$ac_config_target'" "$LINENO" 5;;
   esac
diff --git a/build/configure.ac b/build/configure.ac
index f4397d36..19bd84cc 100644
--- a/build/configure.ac
+++ b/build/configure.ac
@@ -25,7 +25,7 @@ m4_define(
     export -p | grep MKL
     MKL_DEF=$?
     if test "x$MKL_DEF" = "x0"; then
-      export LAPACKFLAGS="-DUSE_LAPACK -DLAPACK_ILP64 -DUSE_ILP64 -I{MKLROOT}/include"
+      export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL -DLAPACK_ILP64 -DUSE_ILP64 -I{MKLROOT}/include"
       export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
     else
       if test -f /usr/include/lapacke.h; then
@@ -71,6 +71,28 @@ m4_define(
     fi
   ]
 )
+
+m4_define(
+  [M4_TEST_MPI],
+  [
+    cat > np_test_mpi.cpp <<EOF
+#ifndef MPI_VERSION
+#include <mpi.h>
+#endif
+int main(int argc, char** argv) {
+  int ierr = MPI_Init(&argc, &argv);
+  MPI_Finalize();
+  return ierr;
+}
+EOF
+    $CXX -c np_test_mpi.cpp > /dev/null 2>&1
+    export CXX_IS_MPI=$?
+    rm np_test_mpi.cpp
+    if test "x$CXX_IS_MPI" = "x0"; then
+      rm np_test_mpi.o
+    fi
+  ]
+)
 # END CAPABILITY TESTING MACROS
 
 # autoconf setup initialization
@@ -78,12 +100,13 @@ AC_INIT([np_tmcode], [8.04], [giovanni.lamura@inaf.it])
 
 # Folder structure safety check
 AC_CONFIG_SRCDIR([../src/libnptm/TransitionMatrix.cpp])
+AC_CONFIG_FILES([Makefile])
 
 # Auxiliary build folder
 AC_CONFIG_AUX_DIR([build_aux])
 
 # automake initialization
-AM_INIT_AUTOMAKE([-Wall -Werror foreign])
+AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
 
 # Compiler detection
 AM_PROG_AR
@@ -100,25 +123,38 @@ AC_ARG_ENABLE(
       AC_MSG_NOTICE([Using $CXX])
       AC_SUBST([MPIFLAGS], [""])
     elif test "x$enableval" = "xauto"; then
-      AC_PROG_CXX([mpicxx mpic++ mpiCC])
-      if test "x$CXX" != "x"; then
-        AC_SUBST([MPIFLAGS], [-DUSE_MPI])
+      if test "x$CXX" = "x"; then
+        AC_PROG_CXX([mpicxx.openmpi mpicxx.mpich mpic++.openmpi mpiCC.openmpi])
+        if test "x$CXX" != "x"; then
+          AC_SUBST([MPIFLAGS], [-DUSE_MPI])
+        else
+          AC_PROG_CXX([g++ clang++])
+          AC_SUBST([MPIFLAGS], [""])
+        fi
       else
-        AC_PROG_CXX([g++ clang++])
-        AC_SUBST([MPIFLAGS], [""])
+        # Test if given CXX defines mpi.h
+	M4_TEST_MPI
       fi
     elif test "x$enableval" = "xyes"; then
-      AC_PROG_CXX([mpicxx mpic++ mpiCC])
-      if test "x$CXX" != "x"; then
-        AC_SUBST([MPIFLAGS], [-DUSE_MPI])
+      if test "x$CXX" = "x"; then
+        AC_PROG_CXX([mpicxx.openmpi mpicxx.mpich mpic++.openmpi mpiCC.openmpi])
+        if test "x$CXX" != "x"; then
+          AC_SUBST([MPIFLAGS], [-DUSE_MPI])
+        else
+          AC_MSG_ERROR([MPI was requested, but no MPI compiler detected!])
+        fi
       else
-        AC_MSG_ERROR([MPI was requested, but no MPI compiler detected!])
+        # Test if given CXX defines mpi.h
+	M4_TEST_MPI
+	if test "x$CXX_IS_MPI" != "x0"; then
+          AC_MSG_ERROR([MPI was requested, but $CXX is not a MPI compiler!])
+	fi
       fi
     fi
   ],
   [
     if test "x$CXX" = "x"; then
-      AC_PROG_CXX([mpicxx mpic++ mpiCC])
+      AC_PROG_CXX([mpicxx.openmpi mpicxx.mpich mpic++.openmpi mpiCC.openmpi])
       if test "x$CXX" != "x"; then
         AC_SUBST([MPIFLAGS], [-DUSE_MPI])
       else
@@ -128,9 +164,15 @@ AC_ARG_ENABLE(
       fi
     else
       AC_PROG_CXX([$CXX])
+      M4_TEST_MPI
+      if test "x$CXX_IS_MPI" = "x0"; then
+        AC_SUBST([MPIFLAGS], [-DUSE_MPI])
+        AC_SUBST([MPIFLAGS], [""])
+      fi
     fi
   ]
 )
+AC_PROG_CXX([$CXX])
 AC_PROG_F77([gfortran f77])
 # Check whether the compiler is clang++ (needs additional flags)
 CXX_IS_CLANG=$($CXX --version | grep clang)
@@ -171,20 +213,6 @@ AS_IF(
 )
 
 # Configure the optional features
-M4_DETECT_LAPACK
-AS_IF(
-  [test "x$LAPACKLDFLAGS" != "x"],
-  [AC_MSG_NOTICE([LAPACK detected. Activating by default (use --without-lapack to disable).])],
-  [AC_MSG_NOTICE([No LAPACK found.])]
-)
-
-M4_DETECT_MAGMA
-AS_IF(
-  [test "x$MAGMALDFLAGS" != "x"],
-  [AC_MSG_NOTICE([MAGMA detected. Activating by default (use --without-magma to disable).])],
-  [AC_MSG_NOTICE([MAGMA not found.])]
-)
-
 AC_ARG_ENABLE(
   [openmp],
   [AS_HELP_STRING([--enable-openmp], [enable OpneMP multi-threading [default=yes]])],
@@ -200,17 +228,29 @@ AC_ARG_ENABLE(
 
 AC_ARG_WITH(
   [lapack],
-  [AS_HELP_STRING([--with-lapack], [use LAPACK @<:@default=check@:>@])],
+  [AS_HELP_STRING([--with-lapack], [use LAPACK @<:@default=auto@:>@])],
   [
     if test "x$withval" = "xno"; then
       AC_SUBST([LAPACKFLAGS], [""])
       AC_SUBST([LAPACKLDFLAGS], [""])
     else
+      M4_DETECT_LAPACK
+      AS_IF(
+        [test "x$LAPACKLDFLAGS" != "x"],
+        [AC_MSG_NOTICE([LAPACK detected.])],
+        [AC_MSG_NOTICE([No LAPACK found.])]
+      )
       AC_SUBST([LAPACKFLAGS], [${LAPACKFLAGS}])
       AC_SUBST([LAPACKLDFLAGS], [${LAPACKLDFLAGS}])
     fi
   ],
   [
+    M4_DETECT_LAPACK
+    AS_IF(
+      [test "x$LAPACKLDFLAGS" != "x"],
+      [AC_MSG_NOTICE([LAPACK detected. Activating by default (use --without-lapack to disble).])],
+      [AC_MSG_NOTICE([No LAPACK found.])]
+    )
     AC_SUBST([LAPACKFLAGS], [${LAPACKFLAGS}])
     AC_SUBST([LAPACKLDFLAGS], [${LAPACKLDFLAGS}])
   ]
@@ -218,17 +258,29 @@ AC_ARG_WITH(
 
 AC_ARG_WITH(
   [magma],
-  [AS_HELP_STRING([--with-magma], [use MAGMA @<:@default=check@:>@])],
+  [AS_HELP_STRING([--with-magma], [use MAGMA @<:@default=auto@:>@])],
   [
     if test "x$withval" = "xno"; then
       AC_SUBST([MAGMAFLAGS], [""])
       AC_SUBST([MAGMALDFLAGS], [""])
     else
+      M4_DETECT_MAGMA
+      AS_IF(
+        [test "x$MAGMALDFLAGS" != "x"],
+        [AC_MSG_NOTICE([MAGMA detected.])],
+        [AC_MSG_NOTICE([MAGMA not found.])]
+      )
       AC_SUBST([MAGMAFLAGS], [${MAGMAFLAGS}])
       AC_SUBST([MAGMALDFLAGS], [${MAGMALDFLAGS}])
     fi
   ],
   [
+    M4_DETECT_MAGMA
+    AS_IF(
+      [test "x$MAGMALDFLAGS" != "x"],
+      [AC_MSG_NOTICE([MAGMA detected. Activating by default (use --without-magma to disable).])],
+      [AC_MSG_NOTICE([MAGMA not found.])]
+    )
     AC_SUBST([MAGMAFLAGS], [${MAGMAFLAGS}])
     AC_SUBST([MAGMALDFLAGS], [${MAGMALDFLAGS}])
   ]
@@ -291,8 +343,5 @@ AC_ARG_WITH(
 CXXFLAGS="$CLANGFLAGS -O3 -ggdb $USER_INCLUDE -I$HDF5_INCLUDE $OMPFLAGS $MPIFLAGS $LAPACKFLAGS $MAGMAFLAGS $NVTXFLAGS"
 SUBDIRS="cluster libnptm sphere testing trapping"
 
-# Send output to Makefiles
-AC_CONFIG_FILES([Makefile])
-
 # Generate the output
 AC_OUTPUT
-- 
GitLab