From 9d18cc098b9718ab4c3202b5e70b6e6a7fba863c Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Wed, 25 Oct 2017 18:40:56 +0200
Subject: [PATCH] Storing MPIEXEC in Makefile.conf and config.txt

Can be retrieved with

plumed config mpiexec
---
 Makefile.conf.in                   |  1 +
 configure                          | 18 ++++++++++++++++++
 configure.ac                       | 11 +++++++++++
 scripts/config.sh                  | 11 +++++++++++
 src/config/Makefile                |  4 +++-
 src/maketools/update-config-txt.sh |  2 ++
 6 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/Makefile.conf.in b/Makefile.conf.in
index 1ac40a4ca..b196254e7 100644
--- a/Makefile.conf.in
+++ b/Makefile.conf.in
@@ -32,3 +32,4 @@ datarootdir=@datarootdir@
 datadir=@datadir@
 docdir=@docdir@
 htmldir=@htmldir@
+mpiexec=@MPIEXEC@
diff --git a/configure b/configure
index abfc5c163..0bfb79df8 100755
--- a/configure
+++ b/configure
@@ -651,6 +651,7 @@ CPPFLAGS
 LDFLAGS
 CXXFLAGS
 CXX
+MPIEXEC
 LDSHARED
 STATIC_LIBS
 SOEXT
@@ -735,6 +736,7 @@ target_alias
 SOEXT
 STATIC_LIBS
 LDSHARED
+MPIEXEC
 CXX
 CXXFLAGS
 LDFLAGS
@@ -1409,6 +1411,9 @@ Some influential environment variables:
               configure will add here -ldl if necessary
   LDSHARED    command for linking shared library - configure will use CXX plus
               the proper flags
+  MPIEXEC     command to run mpi programs in tests - default not specified,
+              which means use PLUMED_MPIRUN env var at runtime for backward
+              compatibility
   CXX         C++ compiler command
   CXXFLAGS    C++ compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
@@ -3009,6 +3014,7 @@ fi
 
 
 
+
 # by default use -O flag
 # we override the autoconf default (-g) because in release build we do not want to
 # include symbol information (obj files are huge)
@@ -8365,6 +8371,8 @@ $as_echo "#define _REENTRANT 1" >>confdefs.h
 # these are libraries that should be linked also to MD engines
 
 
+
+
 if test "$shared" == true ; then
   case `(uname)` in
   (Darwin)
@@ -8755,6 +8763,16 @@ fi
 
 fi
 
+if test $mpi_found == ok ; then
+  if test -n "$MPIEXEC" ; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: Regtest suite will use $MPIEXEC command to run MPI tests" >&5
+$as_echo "$as_me: Regtest suite will use $MPIEXEC command to run MPI tests" >&6;}
+  else
+    { $as_echo "$as_me:${as_lineno-$LINENO}: Regtest suite will use env var PLUMED_MPIRUN to run MPI tests (default: mpirun)" >&5
+$as_echo "$as_me: Regtest suite will use env var PLUMED_MPIRUN to run MPI tests (default: mpirun)" >&6;}
+  fi
+fi
+
 #### This further tests are required to allow linking with non c++ compiler
 { $as_echo "$as_me:${as_lineno-$LINENO}: PLUMED seems to be configured properly!" >&5
 $as_echo "$as_me: PLUMED seems to be configured properly!" >&6;}
diff --git a/configure.ac b/configure.ac
index 2f6df3a5e..08eddd60a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -260,6 +260,7 @@ PLUMED_CONFIG_ENABLE([fftw],[search for fftw],[no])
 AC_ARG_VAR(SOEXT,[extension of dynamic libraries (so/dylib)])
 AC_ARG_VAR(STATIC_LIBS,[variables that should be linked statically directly to MD code - configure will add here -ldl if necessary ])
 AC_ARG_VAR(LDSHARED,[command for linking shared library - configure will use CXX plus the proper flags ])
+AC_ARG_VAR(MPIEXEC,[command to run mpi programs in tests - default not specified, which means use PLUMED_MPIRUN env var at runtime for backward compatibility])
 
 
 # by default use -O flag
@@ -673,6 +674,8 @@ AC_SUBST(LDSHARED)
 # these are libraries that should be linked also to MD engines
 AC_SUBST(STATIC_LIBS)
 
+AC_SUBST(MPIEXEC)
+
 if test "$shared" == true ; then
   case `(uname)` in
   (Darwin)
@@ -839,6 +842,14 @@ int main(int argc,char*argv[[]]){
 )
 fi
 
+if test $mpi_found == ok ; then
+  if test -n "$MPIEXEC" ; then
+    AC_MSG_NOTICE([Regtest suite will use $MPIEXEC command to run MPI tests])
+  else
+    AC_MSG_NOTICE([Regtest suite will use env var PLUMED_MPIRUN to run MPI tests (default: mpirun)])
+  fi
+fi
+
 #### This further tests are required to allow linking with non c++ compiler
 AC_MSG_NOTICE([PLUMED seems to be configured properly!])
 AC_MSG_NOTICE([**************************])
diff --git a/scripts/config.sh b/scripts/config.sh
index a5a0df583..197aa7a90 100755
--- a/scripts/config.sh
+++ b/scripts/config.sh
@@ -50,6 +50,7 @@ do
     ;;
   (has) action=has ;;
   (module) action=module ;;
+  (mpiexec) action=mpiexec ;;
   (makefile_conf)
     echo "$configfile" | awk '{if($1=="makefile_conf") { gsub("^makefile_conf ",""); print} }'
     exit 0
@@ -95,5 +96,15 @@ case $action in
   git=$(echo "$configfile" | grep -v \# | awk '{ if($1=="version" && $2=="git") print $3 }')
   echo "Version: $long (git: $git)"
  ;;
+(mpiexec)
+  mpi=$(echo "$configfile" | grep -v \# | awk '{ if($1=="mpiexec") print $2 }')
+  if test -n "$mpi" ; then
+    retval=0
+    test "$quiet" = no && echo "$mpi"
+  else
+    retval=1
+    test "$quiet" = no && echo "mpiexec not found"
+  fi
+  exit $retval
 esac
 
diff --git a/src/config/Makefile b/src/config/Makefile
index 815ca6972..2828e6099 100644
--- a/src/config/Makefile
+++ b/src/config/Makefile
@@ -23,7 +23,9 @@ obj: all
 
 config.txt: ../../Makefile.conf
 	@echo "Updating config.txt file"
-	@makefile_conf="$(realpath ../../Makefile.conf)" ../maketools/update-config-txt.sh config.txt $(CPPFLAGS)
+	@makefile_conf="$(realpath ../../Makefile.conf)" \
+         mpiexec="$(mpiexec)" \
+         ../maketools/update-config-txt.sh config.txt $(CPPFLAGS)
 
 version.h:
 	@echo "Updating version.h"
diff --git a/src/maketools/update-config-txt.sh b/src/maketools/update-config-txt.sh
index 887e0c747..7a604f6c9 100755
--- a/src/maketools/update-config-txt.sh
+++ b/src/maketools/update-config-txt.sh
@@ -101,6 +101,8 @@ echo "# version strings"
 echo "# syntax: version short/long/git number"
 echo "$version"
 echo
+echo "mpiexec $mpiexec"
+echo
 echo "# list of 'has' options"
 echo "# syntax: has name on/of"
 echo "# if option xx is on then plumed has beeen compiled with -D__PLUMED_HAS_XX"
-- 
GitLab