mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #3740 from atgeirr/make-split-comm-test-runtime-optional
Replace DEMONSTRATE_RUN_WITH_NONWORLD_COMM macro with runtime bool.
This commit is contained in:
commit
0485c65d16
@ -196,6 +196,48 @@ function(add_test_compare_parallel_restarted_simulation)
|
||||
PROPERTIES RUN_SERIAL 1)
|
||||
endfunction()
|
||||
|
||||
|
||||
###########################################################################
|
||||
# TEST: add_test_split_comm
|
||||
###########################################################################
|
||||
|
||||
# Input:
|
||||
# - casename: basename (no extension)
|
||||
#
|
||||
# Details:
|
||||
# - This test class compares the output from a parallel simulation
|
||||
# to that of a parallel simulation running with a custom communicator.
|
||||
function(add_test_split_comm)
|
||||
set(oneValueArgs CASENAME FILENAME SIMULATOR ABS_TOL REL_TOL DIR)
|
||||
set(multiValueArgs TEST_ARGS)
|
||||
cmake_parse_arguments(PARAM "$" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
|
||||
if(NOT PARAM_DIR)
|
||||
set(PARAM_DIR ${PARAM_CASENAME})
|
||||
endif()
|
||||
set(RESULT_PATH ${BASE_RESULT_PATH}/parallelSplitComm/${PARAM_SIMULATOR}+${PARAM_CASENAME})
|
||||
set(DRIVER_ARGS -i ${OPM_TESTS_ROOT}/${PARAM_DIR}
|
||||
-r ${RESULT_PATH}
|
||||
-b ${PROJECT_BINARY_DIR}/bin
|
||||
-f ${PARAM_FILENAME}
|
||||
-a ${PARAM_ABS_TOL}
|
||||
-t ${PARAM_REL_TOL}
|
||||
-c ${COMPARE_ECL_COMMAND})
|
||||
if(PARAM_MPI_PROCS)
|
||||
list(APPEND DRIVER_ARGS -n ${PARAM_MPI_PROCS})
|
||||
endif()
|
||||
|
||||
opm_add_test(compareParallelSplitComm_${PARAM_SIMULATOR}+${PARAM_FILENAME} NO_COMPILE
|
||||
EXE_NAME ${PARAM_SIMULATOR}
|
||||
DRIVER_ARGS ${DRIVER_ARGS}
|
||||
TEST_ARGS ${PARAM_TEST_ARGS})
|
||||
set_tests_properties(compareParallelSplitComm_${PARAM_SIMULATOR}+${PARAM_FILENAME}
|
||||
PROPERTIES RUN_SERIAL 1)
|
||||
endfunction()
|
||||
|
||||
|
||||
###########################################################################
|
||||
|
||||
|
||||
if(NOT TARGET test-suite)
|
||||
add_custom_target(test-suite)
|
||||
endif()
|
||||
@ -1196,6 +1238,15 @@ if(MPI_FOUND)
|
||||
DIR aquifer-num
|
||||
TEST_ARGS --enable-tuning=true --tolerance-cnv=0.00003 --time-step-control=pid --linsolver=cpr)
|
||||
|
||||
# Single test to verify that we treat custom communicators correctly.
|
||||
opm_set_test_driver(${PROJECT_SOURCE_DIR}/tests/run-split-comm-test.sh "")
|
||||
add_test_split_comm(CASENAME spe1
|
||||
FILENAME SPE1CASE2
|
||||
SIMULATOR flow
|
||||
ABS_TOL 0.0
|
||||
REL_TOL 0.0)
|
||||
|
||||
|
||||
opm_set_test_driver(${PROJECT_SOURCE_DIR}/tests/run-parallel-regressionTest.sh "")
|
||||
|
||||
# Different tolerances for these tests
|
||||
|
@ -153,26 +153,25 @@ public:
|
||||
initMPI();
|
||||
}
|
||||
|
||||
#define DEMONSTRATE_RUN_WITH_NONWORLD_COMM 0
|
||||
|
||||
~Main()
|
||||
{
|
||||
#if DEMONSTRATE_RUN_WITH_NONWORLD_COMM
|
||||
#if HAVE_MPI
|
||||
// Cannot use EclGenericVanguard::comm()
|
||||
// to get world size here, as it may be
|
||||
// a split communication at this point.
|
||||
int world_size;
|
||||
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
|
||||
if (world_size > 1) {
|
||||
MPI_Comm new_comm = EclGenericVanguard::comm();
|
||||
int result;
|
||||
MPI_Comm_compare(MPI_COMM_WORLD, new_comm, &result);
|
||||
assert(result == MPI_UNEQUAL);
|
||||
MPI_Comm_free(&new_comm);
|
||||
if (test_split_comm_) {
|
||||
// Cannot use EclGenericVanguard::comm()
|
||||
// to get world size here, as it may be
|
||||
// a split communication at this point.
|
||||
int world_size;
|
||||
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
|
||||
if (world_size > 1) {
|
||||
MPI_Comm new_comm = EclGenericVanguard::comm();
|
||||
int result;
|
||||
MPI_Comm_compare(MPI_COMM_WORLD, new_comm, &result);
|
||||
assert(result == MPI_UNEQUAL);
|
||||
MPI_Comm_free(&new_comm);
|
||||
}
|
||||
}
|
||||
#endif // HAVE_MPI
|
||||
#endif // DEMONSTRATE_RUN_WITH_NONWORLD_COMM
|
||||
|
||||
EclGenericVanguard::setCommunication(nullptr);
|
||||
|
||||
@ -206,9 +205,10 @@ public:
|
||||
#endif
|
||||
EclGenericVanguard::setCommunication(std::make_unique<Parallel::Communication>());
|
||||
|
||||
#if DEMONSTRATE_RUN_WITH_NONWORLD_COMM
|
||||
handleTestSplitCommunicatorCmdLine_();
|
||||
|
||||
#if HAVE_MPI
|
||||
if (EclGenericVanguard::comm().size() > 1) {
|
||||
if (test_split_comm_ && EclGenericVanguard::comm().size() > 1) {
|
||||
int world_rank = EclGenericVanguard::comm().rank();
|
||||
int color = (world_rank == 0);
|
||||
MPI_Comm new_comm;
|
||||
@ -217,7 +217,6 @@ public:
|
||||
EclGenericVanguard::setCommunication(std::make_unique<Parallel::Communication>(new_comm));
|
||||
}
|
||||
#endif // HAVE_MPI
|
||||
#endif // DEMONSTRATE_RUN_WITH_NONWORLD_COMM
|
||||
}
|
||||
|
||||
int runDynamic()
|
||||
@ -537,6 +536,22 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// This function is a special case, if the program has been invoked
|
||||
// with the argument "--test-split-communicator=true" as the FIRST
|
||||
// argument, it will be removed from the argument list and we set the
|
||||
// test_split_comm_ flag to true.
|
||||
// Note: initializing the parameter system before MPI could make this
|
||||
// use the parameter system instead.
|
||||
void handleTestSplitCommunicatorCmdLine_()
|
||||
{
|
||||
if (argc_ >= 2 && std::strcmp(argv_[1], "--test-split-communicator=true") == 0) {
|
||||
test_split_comm_ = true;
|
||||
--argc_; // We have one less argument.
|
||||
argv_[1] = argv_[0]; // What used to be the first proper argument now becomes the command argument.
|
||||
++argv_; // Pretend this is what it always was.
|
||||
}
|
||||
}
|
||||
|
||||
int runMICP(const Phases& phases)
|
||||
{
|
||||
if (!phases.active(Phase::WATER) || (phases.size() > 2)) {
|
||||
@ -715,6 +730,7 @@ private:
|
||||
std::shared_ptr<SummaryConfig> summaryConfig_{};
|
||||
|
||||
// To demonstrate run with non_world_comm
|
||||
bool test_split_comm_ = false;
|
||||
bool isSimulationRank_ = true;
|
||||
};
|
||||
|
||||
|
70
tests/run-split-comm-test.sh
Executable file
70
tests/run-split-comm-test.sh
Executable file
@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This runs two parallel cases, one of them with one more process
|
||||
# and the --test-split-communicator=true option,
|
||||
# then compares the summary and restart files from the two runs.
|
||||
# Meant to track regression of the treatment of MPI communicators.
|
||||
|
||||
if test $# -eq 0
|
||||
then
|
||||
echo -e "Usage:\t$0 <options> -- [additional simulator options]"
|
||||
echo -e "\tMandatory options:"
|
||||
echo -e "\t\t -i <path> Path to read deck from"
|
||||
echo -e "\t\t -r <path> Path to store results in"
|
||||
echo -e "\t\t -b <path> Path to simulator binary"
|
||||
echo -e "\t\t -f <filename> Deck file name"
|
||||
echo -e "\t\t -a <tol> Absolute tolerance in comparison"
|
||||
echo -e "\t\t -t <tol> Relative tolerance in comparison"
|
||||
echo -e "\t\t -c <path> Path to comparison tool"
|
||||
echo -e "\t\t -e <filename> Simulator binary to use"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASE_MPI_PROCS=3
|
||||
TEST_MPI_PROCS=4 # should be 1 more than the base
|
||||
OPTIND=1
|
||||
while getopts "i:r:b:f:a:t:c:e:n:" OPT
|
||||
do
|
||||
case "${OPT}" in
|
||||
i) INPUT_DATA_PATH=${OPTARG} ;;
|
||||
r) RESULT_PATH=${OPTARG} ;;
|
||||
b) BINPATH=${OPTARG} ;;
|
||||
f) FILENAME=${OPTARG} ;;
|
||||
a) ABS_TOL=${OPTARG} ;;
|
||||
t) REL_TOL=${OPTARG} ;;
|
||||
c) COMPARE_ECL_COMMAND=${OPTARG} ;;
|
||||
e) EXE_NAME=${OPTARG} ;;
|
||||
esac
|
||||
done
|
||||
shift $(($OPTIND-1))
|
||||
TEST_ARGS="$@"
|
||||
|
||||
rm -Rf ${RESULT_PATH}
|
||||
mkdir -p ${RESULT_PATH}
|
||||
|
||||
echo mpirun -np ${BASE_MPI_PROCS} ${BINPATH}/${EXE_NAME} ${INPUT_DATA_PATH}/${FILENAME}.DATA ${TEST_ARGS} --output-dir=${RESULT_PATH}/base
|
||||
mpirun -np ${BASE_MPI_PROCS} ${BINPATH}/${EXE_NAME} ${INPUT_DATA_PATH}/${FILENAME}.DATA ${TEST_ARGS} --output-dir=${RESULT_PATH}/base
|
||||
test $? -eq 0 || exit 1
|
||||
|
||||
echo mpirun -np ${TEST_MPI_PROCS} ${BINPATH}/${EXE_NAME} --test-split-communicator=true ${INPUT_DATA_PATH}/${FILENAME}.DATA ${TEST_ARGS} --output-dir=${RESULT_PATH}/test
|
||||
mpirun -np ${TEST_MPI_PROCS} ${BINPATH}/${EXE_NAME} --test-split-communicator=true ${INPUT_DATA_PATH}/${FILENAME}.DATA ${TEST_ARGS} --output-dir=${RESULT_PATH}/test
|
||||
test $? -eq 0 || exit 1
|
||||
|
||||
ecode=0
|
||||
echo "=== Executing comparison for summary file ==="
|
||||
${COMPARE_ECL_COMMAND} -t SMRY -R ${RESULT_PATH}/base/${FILENAME} ${RESULT_PATH}/test/${FILENAME} ${ABS_TOL} ${REL_TOL}
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
ecode=1
|
||||
${COMPARE_ECL_COMMAND} -t SMRY -a -R ${RESULT_PATH}/base/${FILENAME} ${RESULT_PATH}/test/${FILENAME} ${ABS_TOL} ${REL_TOL}
|
||||
fi
|
||||
|
||||
echo "=== Executing comparison for restart file ==="
|
||||
${COMPARE_ECL_COMMAND} -l -t UNRST ${RESULT_PATH}/base/${FILENAME} ${RESULT_PATH}/test/${FILENAME} ${ABS_TOL} ${REL_TOL}
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
ecode=1
|
||||
${COMPARE_ECL_COMMAND} -a -l -t UNRST ${RESULT_PATH}/base/${FILENAME} ${RESULT_PATH}/test/${FILENAME} ${ABS_TOL} ${REL_TOL}
|
||||
fi
|
||||
|
||||
exit $ecode
|
Loading…
Reference in New Issue
Block a user