Commit f1aa6de6 authored by GILLES Sebastien's avatar GILLES Sebastien

#1473 Now create a dedicated Parallelism directory, which is no longer a...

#1473 Now create a dedicated Parallelism directory, which is no longer a subdirectory of the output directory.
parent 8c0d5c7d
......@@ -78,9 +78,17 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-i ${HOME}/Codes/MoReFEM/CoreLibrary/Sources/ModelInstances/Hyperelasticity/demo_result_directory_start_time.lua"
argument = "--overwrite_directory"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-i ${HOME}/Codes/MoReFEM/CoreLibrary/Sources/ModelInstances/Hyperelasticity/demo_test.lua"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-i ${HOME}/Codes/MoReFEM/CoreLibrary/Sources/ModelInstances/Hyperelasticity/demo_result_directory_start_time.lua"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
......
......@@ -66,6 +66,10 @@
argument = "-i ${HOME}/Codes/MoReFEM/CoreLibrary/Sources/ModelInstances/Hyperelasticity/demo_input_hyperelasticity.lua"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--overwrite_directory"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-i ${HOME}/Codes/MoReFEM/CoreLibrary/Sources/ModelInstances/Hyperelasticity/demo_result_directory_start_time.lua"
isEnabled = "NO">
......
......@@ -51,28 +51,27 @@ namespace MoReFEM::Internal::InputDataNS::ParallelismNS
}
const std::string& Path::NameInFile()
const std::string& Directory::NameInFile()
{
static std::string ret("path");
static std::string ret("directory");
return ret;
}
const std::string& Path::Description()
const std::string& Directory::Description()
{
static std::string ret("If Policy is 'RunFromPreprocessed', path to the directory which contains the pre-"
"processed data.");
static std::string ret("Directory in which parallelism data will be written or read (depending on the policy).");
return ret;
}
const std::string& Path::Constraint()
const std::string& Directory::Constraint()
{
return Utilities::EmptyString();
}
const std::string& Path::DefaultValue()
const std::string& Directory::DefaultValue()
{
static std::string ret("''"); // not empty string on purpose: I want the default value to be this!
return ret;
......
......@@ -80,7 +80,7 @@ namespace MoReFEM::Internal::InputDataNS::ParallelismNS
/*!
* \brief Path that might be useful (depending on the \a Policy choice).
*/
struct Path
struct Directory
{
//! Name of the input parameter in Lua input file.
static const std::string& NameInFile();
......
......@@ -64,8 +64,8 @@ namespace MoReFEM::InputDataNS
/*!
* \brief Path that might be useful (depending on the \a Policy choice).
*/
struct Path : public Crtp::InputData<Path, self, std::string>,
public Internal::InputDataNS::ParallelismNS::Path
struct Directory : public Crtp::InputData<Directory, self, std::string>,
public Internal::InputDataNS::ParallelismNS::Directory
{ };
......@@ -73,7 +73,7 @@ namespace MoReFEM::InputDataNS
using section_content_type = std::tuple
<
Policy,
Path
Directory
>;
......
......@@ -68,8 +68,8 @@ namespace MoReFEM::Internal
///@}
//! Get the path of the preprocessed directory. Only for the relevant policy.
const std::string& GetPreprocessedDirectory() const noexcept;
//! Get the path of the parallelism directory.
const std::string& GetDirectory() const noexcept;
//! Get the parallelism strategy.
::MoReFEM::Advanced::parallelism_strategy GetParallelismStrategy() const noexcept;
......@@ -80,8 +80,8 @@ namespace MoReFEM::Internal
::MoReFEM::Advanced::parallelism_strategy parallelism_strategy_ =
::MoReFEM::Advanced::parallelism_strategy::none;
//! Path to the directory in which preprocessed data are stored (for 'run_from_preprocessed' strategy only).
std::string preprocessed_directory_ = "";
//! Path to the parallelism directory.
std::string directory_ = "";
};
......
......@@ -20,6 +20,7 @@ namespace MoReFEM::Internal
Parallelism::Parallelism(const InputDataT& input_data)
{
namespace ipl = Utilities::InputDataNS;
using Parallelism = ::MoReFEM::InputDataNS::Parallelism;
std::string policy = ipl::Extract<Parallelism::Policy>::Value(input_data);
......@@ -38,26 +39,33 @@ namespace MoReFEM::Internal
exit(EXIT_FAILURE);
}
if (parallelism_strategy_ == ::MoReFEM::Advanced::parallelism_strategy::run_from_preprocessed)
preprocessed_directory_ = ipl::Extract<Parallelism::Path>::Folder(input_data);
else
switch(parallelism_strategy_)
{
// Do nothing: just a trick to indicate the field was 'used' in the run of the program.
ipl::Extract<Parallelism::Path>::Value(input_data);
case ::MoReFEM::Advanced::parallelism_strategy::precompute:
case ::MoReFEM::Advanced::parallelism_strategy::parallel:
{
using directory = ::MoReFEM::InputDataNS::Parallelism::Directory;
directory_ = ipl::Extract<directory>::Path(input_data);
break;
}
case ::MoReFEM::Advanced::parallelism_strategy::parallel_no_write:
break;
case ::MoReFEM::Advanced::parallelism_strategy::run_from_preprocessed:
directory_ = ipl::Extract<Parallelism::Directory>::Folder(input_data);
break;
case ::MoReFEM::Advanced::parallelism_strategy::none:
break;
}
}
inline const std::string& Parallelism::GetPreprocessedDirectory() const noexcept
inline const std::string& Parallelism::GetDirectory() const noexcept
{
assert(parallelism_strategy_ == ::MoReFEM::Advanced::parallelism_strategy::run_from_preprocessed
&& "Should not be called for others strategies...");
return preprocessed_directory_;
assert(!directory_.empty());
return directory_;
}
//! Get the parallelism strategy.
inline ::MoReFEM::Advanced::parallelism_strategy Parallelism::GetParallelismStrategy() const noexcept
{
assert(parallelism_strategy_ != ::MoReFEM::Advanced::parallelism_strategy::none && "Must be initialized!");
......
......@@ -130,6 +130,13 @@ namespace MoReFEM
//! Accessor to the object which keeps the data related to parallelism strategy.
const Internal::Parallelism* GetParallelismPtr() const noexcept;
private:
//! Accessor to the object which keeps the data related to parallelism strategy.
//! No pointer here, but it assumes parallelism_ is not nullptr (should be called only under the
//! if constexpr (InputDataT::template Find<InputDataNS::Parallelism>()) condition).
const Internal::Parallelism& GetParallelism() const noexcept;
private:
//! Holds InputData.
......
......@@ -75,15 +75,30 @@ namespace MoReFEM
if constexpr(ProgramTypeT == program_type::model)
{
Internal::MoReFEMDataNS::AskResultDirectoryRemoval(result_directory_, do_overwrite_directory);
if constexpr (InputDataT::template Find<InputDataNS::Parallelism>())
Internal::MoReFEMDataNS::AskResultDirectoryRemoval(GetParallelism().GetDirectory(),
do_overwrite_directory);
}
else if constexpr(ProgramTypeT == program_type::test)
{
if (FilesystemNS::Folder::DoExist(result_directory_))
{
std::cout << "Removing pre-existing directory " << result_directory_ << " before recreating it."
<< std::endl;
std::cout << "Removing pre-existing directory " << result_directory_ << " before "
"recreating it." << std::endl;
FilesystemNS::Folder::Remove(result_directory_, __FILE__, __LINE__);
}
if constexpr (InputDataT::template Find<InputDataNS::Parallelism>())
{
const auto parallelism_directory = GetParallelism().GetDirectory();
if (FilesystemNS::Folder::DoExist(parallelism_directory))
{
std::cout << "Removing pre-existing directory " << parallelism_directory << " before "
"recreating it." << std::endl;
FilesystemNS::Folder::Remove(parallelism_directory, __FILE__, __LINE__);
}
}
}
}
......@@ -206,6 +221,22 @@ namespace MoReFEM
}
template
<
class InputDataT,
program_type ProgramTypeT,
Utilities::InputDataNS::DoTrackUnusedFields DoTrackUnusedFieldsT,
class AdditionalCommandLineArgumentsPolicyT
>
const Internal::Parallelism&
MoReFEMData<InputDataT, ProgramTypeT, DoTrackUnusedFieldsT, AdditionalCommandLineArgumentsPolicyT>
::GetParallelism() const noexcept
{
assert(!(!parallelism_));
return *parallelism_;
}
template<class MoReFEMDataT>
void PrecomputeExit(const MoReFEMDataT& morefem_data)
{
......@@ -217,8 +248,10 @@ namespace MoReFEM
{
case Advanced::parallelism_strategy::precompute:
{
std::cout << "The parallelism elements have been precomputed; the program will now end."
<< std::endl;
if (morefem_data.GetMpi().IsRootProcessor())
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:
......
......@@ -888,7 +888,10 @@ namespace MoReFEM
case Advanced::parallelism_strategy::parallel:
case Advanced::parallelism_strategy::precompute:
{
const auto parallelism_directory = GetOutputDirectory() + "/Parallelism";
const auto parallelism_directory = parallelism.GetDirectory() +
"/Rank_" + std::to_string(mpi.GetRank<int>()) +
"/Mesh_" + std::to_string(mesh.GetUniqueId());
FilesystemNS::Folder::Create(parallelism_directory, __FILE__, __LINE__);
......
......@@ -54,7 +54,6 @@ namespace MoReFEM
};
namespace Ensight
{
......
......@@ -98,6 +98,7 @@ namespace MoReFEM
# include "Geometry/Mesh/Internal/Format/Medit.hpp"
# include "Geometry/Mesh/Internal/Format/Ensight.hpp"
# include "Geometry/Mesh/Internal/Format/VTK_PolygonalData.hpp"
#endif // MOREFEM_x_GEOMETRY_x_MESH_x_INTERNAL_x_FORMAT_x_FORMAT_HPP_
......@@ -14,6 +14,7 @@
#include "Utilities/Containers/UnorderedMap.hpp"
#include "Geometry/Mesh/Internal/Format/Format.hpp"
#include "Geometry/Mesh/Internal/MeshManager.hpp"
......@@ -114,13 +115,16 @@ namespace MoReFEM
void MeshManager::LoadFromPrepartitionedData(const ::MoReFEM::Wrappers::Mpi& mpi,
unsigned int unique_id,
const std::string& mesh_file,
LuaOptionFile& prepartitioned_data,
unsigned dimension,
::MoReFEM::MeshNS::Format format)
LuaOptionFile& prepartitioned_data)
{
double space_unit {};
bool do_build_edges, do_build_faces, do_build_volumes;
unsigned int mesh_dimension {};
std::string mesh_file, mesh_format;
prepartitioned_data.Read("mesh_file", "", mesh_file, __FILE__, __LINE__);
prepartitioned_data.Read("mesh_dimension", "", mesh_dimension, __FILE__, __LINE__);
prepartitioned_data.Read("mesh_format", "", mesh_format, __FILE__, __LINE__);
prepartitioned_data.Read("space_unit", "", space_unit, __FILE__, __LINE__);
prepartitioned_data.Read("do_build_edges", "", do_build_edges, __FILE__, __LINE__);
prepartitioned_data.Read("do_build_faces", "", do_build_faces, __FILE__, __LINE__);
......@@ -132,8 +136,8 @@ namespace MoReFEM
unique_id,
mesh_file,
prepartitioned_data,
dimension,
format,
mesh_dimension,
Internal::MeshNS::FormatNS::GetType(mesh_format),
space_unit,
do_build_edges ? Mesh::BuildEdge::yes : Mesh::BuildEdge::no,
do_build_faces ? Mesh::BuildFace::yes : Mesh::BuildFace::no,
......
......@@ -134,7 +134,6 @@ namespace MoReFEM
* \brief Create a new Mesh from data that were computed in a previous run.
*
* \copydoc doxygen_hide_mpi_param
* \copydoc doxygen_hide_mesh_constructor_5
* \param[in] unique_id Unique identifier of the \a Mesh to be created.
* \param[in] prepartitioned_data Lua file which gives the data needed to reconstruct the data
* from pre-computed partitioned data. Note: it is not const as such objects relies on a Lua stack
......@@ -144,10 +143,7 @@ namespace MoReFEM
*/
void LoadFromPrepartitionedData(const ::MoReFEM::Wrappers::Mpi& mpi,
unsigned int unique_id,
const std::string& mesh_file,
LuaOptionFile& prepartitioned_data,
unsigned dimension,
::MoReFEM::MeshNS::Format format);
LuaOptionFile& prepartitioned_data);
/*!
......
......@@ -536,7 +536,7 @@ Parallelism = {
-- If Policy is 'RunFromPreprocessed', path to the directory which contains the pre-processed data.
-- Expected format: "VALUE"
path = ''
directory = ''
} -- Parallelism
......
......@@ -463,7 +463,7 @@ Parallelism = {
-- If Policy is 'RunFromPreprocessed', path to the directory which contains the pre-processed data.
-- Expected format: "VALUE"
path = ''
directory = ''
} -- Parallelism
......
......@@ -536,10 +536,11 @@ Parallelism = {
-- If Policy is 'RunFromPreprocessed', path to the directory which contains the pre-processed data.
-- Expected format: "VALUE"y
path = ''
directory = '${MOREFEM_RESULT_DIR}/Hyperelasticity_Parallelism'
} -- Parallelism
Result = {
......
......@@ -50,10 +50,7 @@ namespace MoReFEM::TestNS::LoadPrepartitionedMeshNS
mesh_manager.LoadFromPrepartitionedData(mpi,
10,
partition_data_facility.GetReducedMeshFile(),
mesh_prepartitioned_data,
mesh.GetDimension(),
MeshNS::Format::Medit);
mesh_prepartitioned_data);
}
......
......@@ -226,7 +226,7 @@ PrepartitionedData = {
-- Directory in which prepartitioned data are stored. Leave it empty if irrelevant.
-- Expected format: "VALUE"
Directory = "${MOREFEM_TEST_OUTPUT_DIR}/PrepartionedData/Test/LoadPrepartitionedMesh",
directory = "${MOREFEM_TEST_OUTPUT_DIR}/PrepartionedData/Test/LoadPrepartitionedMesh",
-- If True, the program runs to generate prepartition data and will stop once it's done. If False, mode
......
......@@ -267,7 +267,6 @@ namespace MoReFEM
std::string ReadHelperPath() const;
private:
/*!
......
......@@ -125,6 +125,14 @@ namespace MoReFEM
{
std::string folder_name = ReadHelperPath<InputDataT>();
if (folder_name.empty())
{
std::ostringstream oconv;
oconv << "The directory given in field '" << InputDataT::GetIdentifier() << "' is an empty "
"string!";
throw Exception(oconv.str(), __FILE__, __LINE__);
}
if (!FilesystemNS::Folder::DoExist(folder_name))
{
switch(UnexistentFolderPolicyT)
......
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