Commit 1f55b4a5 authored by GILLES Sebastien's avatar GILLES Sebastien

#1473 The precompute parallelism strategy has been implemented and works with...

#1473 The precompute parallelism strategy has been implemented and works with the hyperelasticity model.
parent bbd9c9eb
......@@ -12,6 +12,7 @@
#include "Utilities/Datetime/Now.hpp"
#include "Utilities/Filesystem/Folder.hpp"
#include "Utilities/Exceptions/GracefulExit.hpp"
#include "Core/MoReFEMData/Internal/Helper.hpp"
......@@ -145,7 +146,7 @@ namespace MoReFEM::Internal::MoReFEMDataNS
if (answer == "n")
{
std::cout << "The program will therefore exit here." << std::endl;
exit(EXIT_SUCCESS);
throw ExceptionNS::GracefulExit(__FILE__, __LINE__);
}
break;
}
......
......@@ -24,6 +24,7 @@
# include "Utilities/TimeKeep/TimeKeep.hpp"
# include "Utilities/OutputFormat/OutputFormat.hpp"
# include "Utilities/Datetime/Now.hpp"
# include "Utilities/Exceptions/GracefulExit.hpp"
# include "Core/InputData/Instances/Result.hpp"
# include "Core/InitTimeKeepLog.hpp"
......@@ -147,6 +148,21 @@ namespace MoReFEM
};
/*!
* \brief Provide the precompute exit.
*
* When the parallelism strategy is "precompute", once all the data are written we want to exit the program as
* soon as possible.
* The proper way to do so is to throw a GracefulExit exception, which should be properly trapped in the main.
*
* This function does so IF the parallelism strategy is "precompute"; if not it does nothing.
*
* \copydoc doxygen_hide_morefem_data_param
*/
template<class MoReFEMDataT>
void PrecomputeExit(const MoReFEMDataT& morefem_data);
///@} // \addtogroup
......
......@@ -206,6 +206,35 @@ namespace MoReFEM
}
template<class MoReFEMDataT>
void PrecomputeExit(const MoReFEMDataT& morefem_data)
{
const auto parallelism_ptr = morefem_data.GetParallelismPtr();
if (!(!parallelism_ptr))
{
switch (parallelism_ptr->GetParallelismStrategy())
{
case Advanced::parallelism_strategy::precompute:
{
std::cout << "The parallelism elements have been precomputed; the program will now end."
<< std::endl;
throw ExceptionNS::GracefulExit(__FILE__, __LINE__);
}
case Advanced::parallelism_strategy::parallel:
case Advanced::parallelism_strategy::run_from_preprocessed:
case Advanced::parallelism_strategy::parallel_no_write:
break;
case Advanced::parallelism_strategy::none:
{
assert(false && "Should not be possible (if so parallelism_ptr should have been nullptr).");
exit(EXIT_FAILURE);
}
}
}
}
} // namespace MoReFEM
......
......@@ -10,6 +10,7 @@
target_sources(${MOREFEM_CORE}
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/Enum.hpp"
"${CMAKE_CURRENT_LIST_DIR}/MoReFEMData.hpp"
"${CMAKE_CURRENT_LIST_DIR}/MoReFEMData.hxx"
)
......
......@@ -284,6 +284,11 @@ namespace MoReFEM
ClearGodOfDofTemporaryData();
ClearAllBoundaryConditionInitialValueList();
// If the point was just to write preprocessed data; stop the program here.
// Note: in the derived model you may want to call this earlier; for instance if the static computation
// is performed in the initialization phase you may want to leave before it happens.
PrecomputeExit(morefem_data);
}
......
......@@ -52,6 +52,9 @@ namespace MoReFEM
god_of_dof,
std::move(bc_list));
}
// Exit the program if the 'precompute' mode was chosen.
PrecomputeExit(morefem_data);
auto& variational_formulation = GetNonCstVariationalFormulation();
......@@ -82,8 +85,7 @@ namespace MoReFEM
void Model::SupplInitializeStep()
{
}
{ }
void Model::Forward()
......@@ -108,8 +110,7 @@ namespace MoReFEM
void Model::SupplFinalize()
{
}
{ }
} // namespace MidpointHyperelasticityNS
......
......@@ -531,7 +531,7 @@ Parallelism = {
-- 'RunFromPreprocessed': Run the code in parallel using pre-processed data.
-- Expected format: "VALUE"
-- Constraint: value_in(v, {'Precompute', 'ParallelNoWrite', 'Parallel', 'RunFromPreprocessed'})
policy = 'Parallel',
policy = 'Precompute',
-- If Policy is 'RunFromPreprocessed', path to the directory which contains the pre-processed data.
......
......@@ -39,6 +39,10 @@ int main(int argc, char** argv)
input_data.PrintUnused(std::cout);
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
ExceptionNS::PrintAndAbort(mpi, e.what());
......@@ -52,10 +56,10 @@ int main(int argc, char** argv)
{
std::ostringstream oconv;
oconv << "Exception caught from MoReFEMData<InputData>: " << e.what() << std::endl;
std::cout << oconv.str();
return EXIT_FAILURE;
}
return 0;
return EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment