Commit c0284681 authored by GILLES Sebastien's avatar GILLES Sebastien

#1480 Add catch of GracefulExit in many mains.

parent a39fa673
......@@ -36,65 +36,74 @@ namespace MoReFEM
? nullptr
: this;
Internal::MoReFEMDataNS::overwrite_directory do_overwrite_directory;
try
{
std::string input_data_file =
Internal::MoReFEMDataNS::ParseCommandLine
<ProgramTypeT, AdditionalCommandLineArgumentsPolicyT>(argc, argv,
do_overwrite_directory,
ptr);
Internal::MoReFEMDataNS::overwrite_directory do_overwrite_directory;
decltype(auto) mpi = GetMpi();
std::string input_data_file =
Internal::MoReFEMDataNS::ParseCommandLine
<ProgramTypeT, AdditionalCommandLineArgumentsPolicyT>(argc, argv,
do_overwrite_directory,
ptr);
Internal::MoReFEMDataNS::DefineEnvironmentVariable(mpi);
decltype(auto) mpi = GetMpi();
if (mpi.IsRootProcessor())
// Stops the program after creating it for root processor.
Internal::MoReFEMDataNS::CreateIfNotExisting<typename InputDataT::Tuple>(input_data_file);
Internal::MoReFEMDataNS::DefineEnvironmentVariable(mpi);
Internal::MoReFEMDataNS::CheckExistingForAllRank(mpi, input_data_file);
if (mpi.IsRootProcessor())
// Stops the program after creating it for root processor.
Internal::MoReFEMDataNS::CreateIfNotExisting<typename InputDataT::Tuple>(input_data_file);
// We can be here only if the file exists...
input_data_ = std::make_unique<InputDataT>(input_data_file,
mpi,
DoTrackUnusedFieldsT);
Internal::MoReFEMDataNS::CheckExistingForAllRank(mpi, input_data_file);
// We can be here only if the file exists...
input_data_ = std::make_unique<InputDataT>(input_data_file,
mpi,
DoTrackUnusedFieldsT);
namespace ipl = Utilities::InputDataNS;
using Result = InputDataNS::Result;
{
std::string path = ipl::Extract<Result::OutputDirectory>::Path(*input_data_);
FilesystemNS::behaviour directory_behaviour;
if constexpr(ProgramTypeT == program_type::model)
directory_behaviour = do_overwrite_directory == Internal::MoReFEMDataNS::overwrite_directory::yes
? FilesystemNS::behaviour::overwrite
: FilesystemNS::behaviour::ask;
else if constexpr(ProgramTypeT == program_type::test)
directory_behaviour = FilesystemNS::behaviour::overwrite;
else if constexpr(ProgramTypeT == program_type::post_processing)
directory_behaviour = FilesystemNS::behaviour::read;
result_directory_ = std::make_unique<FilesystemNS::Directory>(mpi,
path,
directory_behaviour,
__FILE__, __LINE__);
// Parallelism is an optional field: it might not be present in the Lua file (for tests for instance it is not
// meaningful).
if constexpr (InputDataT::template Find<InputDataNS::Parallelism>())
parallelism_ = std::make_unique<Internal::Parallelism>(mpi, *input_data_, directory_behaviour);
}
namespace ipl = Utilities::InputDataNS;
using Result = InputDataNS::Result;
{
std::string path = ipl::Extract<Result::OutputDirectory>::Path(*input_data_);
FilesystemNS::behaviour directory_behaviour;
if constexpr(ProgramTypeT == program_type::model)
directory_behaviour = do_overwrite_directory == Internal::MoReFEMDataNS::overwrite_directory::yes
? FilesystemNS::behaviour::overwrite
: FilesystemNS::behaviour::ask;
else if constexpr(ProgramTypeT == program_type::test)
directory_behaviour = FilesystemNS::behaviour::overwrite;
else if constexpr(ProgramTypeT == program_type::post_processing)
directory_behaviour = FilesystemNS::behaviour::read;
result_directory_ = std::make_unique<FilesystemNS::Directory>(mpi,
path,
directory_behaviour,
__FILE__, __LINE__);
// Parallelism is an optional field: it might not be present in the Lua file (for tests for instance it is not
// meaningful).
if constexpr (InputDataT::template Find<InputDataNS::Parallelism>())
parallelism_ = std::make_unique<Internal::Parallelism>(mpi, *input_data_, directory_behaviour);
}
mpi.Barrier();
mpi.Barrier();
InitTimeKeepLog(GetResultDirectory());
InitTimeKeepLog(GetResultDirectory());
const auto& binary_output = ipl::Extract<Result::BinaryOutput>::Value(*input_data_);
Utilities::OutputFormat::CreateOrGetInstance(__FILE__, __LINE__, binary_output);
const auto& binary_output = ipl::Extract<Result::BinaryOutput>::Value(*input_data_);
Utilities::OutputFormat::CreateOrGetInstance(__FILE__, __LINE__, binary_output);
}
catch(const ExceptionNS::GracefulExit& e)
{
std::cout << e.what() << std::endl;
throw;
}
}
......
......@@ -41,10 +41,6 @@ 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());
......@@ -54,11 +50,15 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
oconv << "Exception caught from MoReFEMData<InputData>: " << e.what() << std::endl;
std::cout << oconv.str();
return EXIT_FAILURE;
}
......
......@@ -104,6 +104,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -54,6 +54,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -102,6 +102,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -44,10 +44,6 @@ 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());
......@@ -57,6 +53,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -103,6 +103,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -54,6 +54,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -102,6 +102,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -54,6 +54,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -102,6 +102,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -54,6 +54,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -104,6 +104,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -130,6 +130,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -93,6 +93,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -57,6 +57,10 @@ int main(int argc, char** argv)
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -53,6 +53,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -56,6 +56,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -52,6 +52,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -54,6 +54,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -54,6 +54,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -114,6 +114,10 @@ int main(int argc, char * argv[])
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -50,6 +50,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -56,6 +56,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -55,6 +55,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -54,6 +54,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -53,6 +53,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -78,6 +78,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -50,6 +50,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
......@@ -96,6 +96,10 @@ int main(int argc, char** argv)
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
std::ostringstream oconv;
......
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