Skip to content

Commit

Permalink
Merge branch 'master' into c++17
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanniBussi committed May 22, 2023
2 parents 03032e2 + f99433e commit 97ef479
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 38 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ jobs:
echo "CXX=mpic++" >> $GITHUB_ENV
echo "OMPI_MCA_btl_base_warn_component_unused=0" >> $GITHUB_ENV
echo "OMPI_MCA_btl_base_verbose=0" >> $GITHUB_ENV
echo "MPIEXEC=mpirun --oversubscribe" >> $GITHUB_ENV
echo "OMPI_MCA_plm=isolated" >> $GITHUB_ENV
echo "OMPI_MCA_btl_vader_single_copy_mechanism=none" >> $GITHUB_ENV
echo "OMPI_MCA_rmaps_base_oversubscribe=yes" >> $GITHUB_ENV
pip install --user mpi4py
python -c "import mpi4py"
- name: Build PLUMED
Expand Down Expand Up @@ -206,23 +208,21 @@ jobs:
make -C src/lib/ dirslinks
make codecheck
# We test on fedora37 to make sure we have compatibility with newer compilers (gcc 12)
fedora37:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Build and run tests
run: |
make -C docker fedora37
# We test on rockylinux8 as well
rocky8:
runs-on: ubuntu-20.04
docker:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
# fedora38 (gcc 13)
# rockylinux8
variant:
- fedora38
- rocky8
steps:
- uses: actions/checkout@v3
- name: Build and run tests
run: |
make -C docker rocky8
make -C docker ${{ matrix.variant }}
macports:
runs-on: macos-11
Expand Down
6 changes: 3 additions & 3 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

.PHONY: ubuntu plumed2.tgz clean fedora37 rocky8
.PHONY: ubuntu plumed2.tgz clean fedora38 rocky8

ubuntu: plumed2.tgz
docker build -t plumed .

fedora37: plumed2.tgz
docker build -t plumed -f fedora37 .
fedora38: plumed2.tgz
docker build -t plumed -f fedora38 .

rocky8: plumed2.tgz
docker build -t plumed -f rocky8 .
Expand Down
7 changes: 5 additions & 2 deletions docker/fedora37 → docker/fedora38
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM fedora:37
FROM fedora:38

# note: at variance with centos7, here we have to explicitly install gcc
# mdtraj 1.9.7 does not compile with python 3.11 unless installed from source
Expand Down Expand Up @@ -27,7 +27,10 @@ COPY plumed2.tgz /home/plumed
RUN . /etc/bashrc \
&& module load mpi \
&& export OMPI_MCA_btl_base_warn_component_unused=0 \
&& export MPIEXEC="mpirun --oversubscribe" \
&& export OMPI_MCA_btl_base_verbose=0 \
&& export OMPI_MCA_plm=isolated \
&& export OMPI_MCA_btl_vader_single_copy_mechanism=none \
&& export OMPI_MCA_rmaps_base_oversubscribe=yes \
&& export PATH=$HOME/opt/bin:$PATH \
&& export CPATH=$HOME/opt/include:$CPATH \
&& export INCLUDE=$HOME/opt/include:$INCLUDE \
Expand Down
5 changes: 4 additions & 1 deletion docker/rocky8
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ COPY plumed2.tgz /home/plumed
RUN . /etc/bashrc \
&& module load mpi \
&& export OMPI_MCA_btl_base_warn_component_unused=0 \
&& export MPIEXEC="mpirun --oversubscribe" \
&& export OMPI_MCA_btl_base_verbose=0 \
&& export OMPI_MCA_plm=isolated \
&& export OMPI_MCA_btl_vader_single_copy_mechanism=none \
&& export OMPI_MCA_rmaps_base_oversubscribe=yes \
&& export PATH=$HOME/opt/bin:$PATH \
&& export CPATH=$HOME/opt/include:$CPATH \
&& export INCLUDE=$HOME/opt/include:$INCLUDE \
Expand Down
1 change: 1 addition & 0 deletions regtest/basic/rt-errormessages/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../scripts/test.make
3 changes: 3 additions & 0 deletions regtest/basic/rt-errormessages/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type=make
# this is needed because we are explicitly checking some exception message
export PLUMED_STACK_TRACE=no
1 change: 1 addition & 0 deletions regtest/basic/rt-errormessages/output.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
METAD WALKER_MPI : Exception thrown, correct message
77 changes: 77 additions & 0 deletions regtest/basic/rt-errormessages/testWALKERS_MPI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <fstream>

#include "plumed/wrapper/Plumed.h"
#include "plumed/tools/Communicator.h"

constexpr unsigned nat=10;
//it is a struct because we don't need getter/setters (for now)
struct plumedThrowChecker{
unsigned natoms=nat;
std::vector<double> positions=[](unsigned natoms){
std::vector<double> toret(natoms*3,0.0);
for(unsigned i=0; i<3*natoms; i++) toret[i]=i;
return toret;
}(nat);
std::vector<double> masses{nat,1.0};
std::vector<double> forces{3*nat,0.0};
std::vector<double> box{9,0.0};
std::vector<double> virial{9,0.0};
///This initializes a new plumed to test each throw in the cleanliest way possible
int checkThrow (std::ostream& out,std::string name, std::string cmd, std::string expectedMessage){
//GIVEN an initialized Plumed interface
PLMD::Plumed plumed;

plumed.cmd("setNatoms",&natoms);
int step=0;
plumed.cmd("setLogFile","test.log");
plumed.cmd("init");
plumed.cmd("setStep",&step);
plumed.cmd("setPositions",positions.data());
plumed.cmd("setBox",box.data());
plumed.cmd("setForces",forces.data());
plumed.cmd("setVirial",virial.data());
plumed.cmd("setMasses",masses.data());

plumed.cmd("readInputLine","d: DISTANCE ATOMS=1,2");
plumed.cmd("readInputLine","d1: DISTANCE ATOMS={1 2}");
///TODO: expand with a "readInputLines" to give the possibility to test in more situations
try {
//WHEN the user ask for the given input
plumed.cmd("readInputLine",cmd.c_str());
//THEN plumed should gracefully exit with a clear error message
} catch(PLMD::Plumed::ExceptionError &e) { //correct throw, we are happy
std::string exceptionText{e.what()};
out << name << " : ";
if (exceptionText.find(expectedMessage) != std::string::npos) {
out << "Exception thrown, correct message\n";
return 0;
}

out << "Exception thrown, wrong message: "
<< e.what() ;
out << "\tExpected message should contain: \""
<< expectedMessage << "\"\n";
return 1;
}
out << "Exception not thrown\n";
return 1;
}
};

int main(int, char**) {
std::ofstream out("output");
plumedThrowChecker ptc;
//When the user aks for a WALKERS_MPI in the METAD action,
//if MPI is not installed then the user must be informed
//if MPI is installed then the comunications must be already set up
//WHEN PLUMED is not compiled with MPI or the MPI routines are not initialized
std::string expectedMessage="WALKERS_MPI flag requires MPI compilation";
if (PLMD::Communicator::plumedHasMPI()) {
expectedMessage="WALKERS_MPI needs the communicator correctly initialized";
}
ptc.checkThrow(out,"METAD WALKER_MPI",
"METAD ARG=d,d1 SIGMA=0.1,0.2 HEIGHT=0.1 PACE=2 RESTART=YES WALKERS_MPI",
expectedMessage);

//add other throw messages checks
}
1 change: 0 additions & 1 deletion regtest/multicolvar/rt-link/config
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
mpiprocs=2
type=make
1 change: 0 additions & 1 deletion regtest/multicolvar/rt-link/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "mpi.h"
#include "plumed/tools/Communicator.h"
#include "plumed/tools/Tools.h"
#include "plumed/tools/Vector.h"
Expand Down
34 changes: 20 additions & 14 deletions regtest/scripts/run
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ echo "++ Arguments: $arg"
echo "++ Processors: $mpiprocs"

mpi=env

# this is the executable used for running the tests:
plumed="${PLUMED_PROGRAM_NAME:-plumed}"

root=$($plumed --no-mpi info --root)
# this is the executable used for getting the configuration:
plumed_nompi="$plumed --no-mpi"

root=$($plumed_nompi info --root)

if test -z "$root" ; then
echo "FAILURE: plumed executable not available"
Expand All @@ -76,16 +81,16 @@ cd -

if ((mpiprocs>0)); then
mpi=""
if $plumed --no-mpi config -q mpiexec
if $plumed_nompi config -q mpiexec
then
mpi="$($plumed --no-mpi config mpiexec)"
mpi="$($plumed_nompi config mpiexec)"
fi
if test -z "$mpi" ; then
mpi="${PLUMED_MPIRUN:-mpirun}"
fi
mpi="$mpi -np $mpiprocs"

if ! $plumed config -q has mpi
if ! $plumed_nompi config -q has mpi
then
if [ "$TRAVIS" = true ] || [ "$GITHUB_ACTIONS" = true ] ; then
if [ -z "$PLUMED_ALLOW_SKIP_ON_TRAVIS" ] ; then
Expand Down Expand Up @@ -122,7 +127,7 @@ fi
for need in $plumed_needs
do
echo "Checking for $need"
if ! $plumed config -q has $need
if ! $plumed_nompi config -q has $need
then
if [ "$TRAVIS" = true ] || [ "$GITHUB_ACTIONS" = true ] ; then
if [ -z "$PLUMED_ALLOW_SKIP_ON_TRAVIS" ] ; then
Expand All @@ -140,7 +145,7 @@ done
for module in $plumed_modules
do
echo "Checking for $module"
if ! $plumed config -q module $module
if ! $plumed_nompi config -q module $module
then
if [ "$TRAVIS" = true ] || [ "$GITHUB_ACTIONS" = true ] ; then
if [ -z "$PLUMED_ALLOW_SKIP_ON_TRAVIS" ] ; then
Expand Down Expand Up @@ -170,10 +175,12 @@ if type -t plumed_custom_skip 1>/dev/null ; then
fi
fi

if $plumed --is-installed ; then
export PLUMED_KERNEL="$root/../lib${PLUMED_PROGRAM_NAME:-plumed}Kernel.$($plumed info --soext)"
if $plumed_nompi --is-installed ; then
export PLUMED_KERNEL="$root/../lib${PLUMED_PROGRAM_NAME:-plumed}Kernel.$($plumed_nompi info --soext)"
export PLUMED_LIB="$root/../lib${PLUMED_PROGRAM_NAME:-plumed}.$($plumed_nompi info --soext)"
else
export PLUMED_KERNEL="$root/src/lib/libplumedKernel.$($plumed info --soext)"
export PLUMED_KERNEL="$root/src/lib/libplumedKernel.$($plumed_nompi info --soext)"
export PLUMED_LIB="$root/src/lib/libplumed.$($plumed_nompi info --soext)"
fi
if type -t plumed_regtest_before 1>/dev/null ; then
plumed_regtest_before
Expand All @@ -194,12 +201,11 @@ case "$type" in
$mpi $valgrind $plumed sum_hills $arg > out 2> err
;;
(make)
$plumed info --configuration > Makefile.conf
$plumed --is-installed || ln -s "$root/src" plumed
$plumed_nompi --is-installed || ln -s "$root/src" plumed
if test "$plumed_language" = fortran || test "$plumed_language" = fortran08 || test "$plumed_language" = c ; then
cat <($plumed info --configuration) "$root/src/lib/Plumed.inc.shared" ../../../scripts/exe.make > Makefile
cat <($plumed_nompi info --configuration) "$root/src/lib/Plumed.inc.shared" ../../../scripts/exe.make > Makefile
else
cat <($plumed info --configuration) "$root/src/lib/Plumed.inc.static" ../../../scripts/exe.make > Makefile
cat <($plumed_nompi info --configuration) "$root/src/lib/Plumed.inc.static" ../../../scripts/exe.make > Makefile
fi
if test "$plumed_language" = fortran || test "$plumed_language" = fortran08 ; then
if make print-fortran | grep "FC=$" 1>/dev/null ; then
Expand Down Expand Up @@ -271,7 +277,7 @@ EOF
;;
(python)
# make sure the right python module is in the path based on plumed root
PYTHONPATH="$root/python:$PYTHONPATH" $($plumed config python_bin) $arg > out 2> err
PYTHONPATH="$root/python:$PYTHONPATH" $($plumed_nompi config python_bin) $arg > out 2> err
;;
(*) echo "FAILURE: unknown test type" ; exit 1 ;;
esac
Expand Down
6 changes: 6 additions & 0 deletions src/bias/MetaD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,12 @@ MetaD::MetaD(const ActionOptions& ao):
// MPI version
parseFlag("WALKERS_MPI",walkers_mpi_);

//If this Action is not compiled with MPI the user is informed and we exit gracefully
if(walkers_mpi_) {
plumed_assert(Communicator::plumedHasMPI()) << "Invalid walkers configuration: WALKERS_MPI flag requires MPI compilation";
plumed_assert(Communicator::initialized()) << "Invalid walkers configuration: WALKERS_MPI needs the communicator correctly initialized.";
}

// Flying Gaussian
parseFlag("FLYING_GAUSSIAN", flying_);

Expand Down
2 changes: 1 addition & 1 deletion src/opes/ECVmultiThermalBaric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ ECVmultiThermalBaric::ECVmultiThermalBaric(const ActionOptions&ao)
log.printf(" and a pressure range from PRESSURE_MIN=%g to PRESSURE_MAX=%g\n",pres_min,pres_max);
if(pres_min==pres_max)
log.printf(" +++ WARNING +++ if you only need a multithermal simulation it is more efficient to set it up with ECV_MULTITHERMAL\n");
if(geom_spacing_)
if(!geom_spacing_)
log.printf(" -- NO_GEOM_SPACING: inverse temperatures will be linearly spaced\n");
if(coeff_!=0)
log.printf(" -- CUT_CORNER: ignoring some high temperature and low pressure values\n");
Expand Down
4 changes: 4 additions & 0 deletions src/opes/OPESexpanded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ OPESexpanded::OPESexpanded(const ActionOptions&ao)
parseFlag("WALKERS_MPI",walkers_mpi);
if(walkers_mpi)
{
//If this Action is not compiled with MPI the user is informed and we exit gracefully
plumed_massert(Communicator::plumedHasMPI(),"Invalid walkers configuration: WALKERS_MPI flag requires MPI compilation");
plumed_massert(Communicator::initialized(),"Invalid walkers configuration: WALKERS_MPI needs the communicator correctly initialized.");

if(comm.Get_rank()==0) //multi_sim_comm works on first rank only
{
NumWalkers_=multi_sim_comm.Get_size();
Expand Down
10 changes: 9 additions & 1 deletion src/opes/OPESmetad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ void OPESmetad<mode>::registerKeywords(Keywords& keys)
keys.use("ARG");
keys.add("compulsory","TEMP","-1","temperature. If not set, it is taken from MD engine, but not all MD codes provide it");
keys.add("compulsory","PACE","the frequency for kernel deposition");
keys.add("compulsory","SIGMA","ADAPTIVE","the initial widths of the kernels. If not set, adaptive sigma will be used with the given ADAPTIVE_SIGMA_STRIDE");
std::string info_sigma("the initial widths of the kernels");
if(mode::explore)
info_sigma+=", divided by \\f$\\sqrt{\\gamma}\\f$";
info_sigma+=". If not set, an adaptive sigma will be used with the given ADAPTIVE_SIGMA_STRIDE";
keys.add("compulsory","SIGMA","ADAPTIVE",info_sigma);
keys.add("compulsory","BARRIER","the free energy barrier to be overcome. It is used to set BIASFACTOR, EPSILON, and KERNEL_CUTOFF to reasonable values");
keys.add("compulsory","COMPRESSION_THRESHOLD","1","merge kernels if closer than this threshold, in units of sigma");
//extra options
Expand Down Expand Up @@ -554,6 +558,10 @@ OPESmetad<mode>::OPESmetad(const ActionOptions& ao)
parseFlag("WALKERS_MPI",walkers_mpi);
if(walkers_mpi)
{
//If this Action is not compiled with MPI the user is informed and we exit gracefully
plumed_massert(Communicator::plumedHasMPI(),"Invalid walkers configuration: WALKERS_MPI flag requires MPI compilation");
plumed_massert(Communicator::initialized(),"Invalid walkers configuration: WALKERS_MPI needs the communicator correctly initialized.");

if(comm.Get_rank()==0)//multi_sim_comm works on first rank only
{
NumWalkers_=multi_sim_comm.Get_size();
Expand Down
8 changes: 8 additions & 0 deletions src/tools/Communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@

namespace PLMD {

bool Communicator::plumedHasMPI() {
#ifdef __PLUMED_HAS_MPI
return true;
#else
return false;
#endif
}

Communicator::Communicator()
#ifdef __PLUMED_HAS_MPI
: communicator(MPI_COMM_SELF)
Expand Down
3 changes: 3 additions & 0 deletions src/tools/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class Communicator {
}
};
public:
///Runtime acces to the __PLUMED_HAS_MPI definition
static bool plumedHasMPI();

/// Wrapper class for MPI_Status
class Status {
int Get_count(MPI_Datatype)const;
Expand Down
1 change: 1 addition & 0 deletions user-doc/Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ As far as we know, the following MD codes can be used with PLUMED out of the box
- [DFTB+](https://www.dftbplus.org/), since release 20.1.
- [Metalwalls](https://gitlab.com/ampere2/metalwalls)
- [ASE](https://wiki.fysik.dtu.dk/ase/)
- [GPUMD](https://gpumd.org/)

Please refer to the documentation of the MD code to know how to use it with the latest PLUMED release.
If you maintain another MD code that is PLUMED-ready let us know and we will add it to this list.
Expand Down

0 comments on commit 97ef479

Please sign in to comment.