Commit 56573426 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#1466 Make RAII initialization of Petsc and mpi an (internal) independant...

#1466 Make RAII initialization of Petsc and mpi an (internal) independant class - a singleton in fact. This way, more than one instance of MoReFEMData may be run in the same program.
parent eff0846c
......@@ -886,6 +886,9 @@
BE59D6971DDF5212006FF5CB /* FromVertexMatching.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE59D68D1DDF5212006FF5CB /* FromVertexMatching.cpp */; };
BE59D6981DDF5212006FF5CB /* FromVertexMatching.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE59D68E1DDF5212006FF5CB /* FromVertexMatching.hpp */; };
BE59D6991DDF5212006FF5CB /* FromVertexMatching.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE59D68F1DDF5212006FF5CB /* FromVertexMatching.hxx */; };
BE5AA42722E62C3A00A393DE /* RAII.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE5AA42422E62C3A00A393DE /* RAII.cpp */; };
BE5AA42822E62C3A00A393DE /* RAII.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE5AA42522E62C3A00A393DE /* RAII.hxx */; };
BE5AA42922E62C3A00A393DE /* RAII.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE5AA42622E62C3A00A393DE /* RAII.hpp */; };
BE5B6F701C3C1602004A0284 /* VertexMatching.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE5B6F6C1C3C1602004A0284 /* VertexMatching.hpp */; };
BE5B6F711C3C1602004A0284 /* VertexMatching.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE5B6F6D1C3C1602004A0284 /* VertexMatching.hxx */; };
BE5B6F721C3C160D004A0284 /* VertexMatching.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE5B6F6B1C3C1602004A0284 /* VertexMatching.cpp */; };
......@@ -1282,8 +1285,6 @@
BE90E1B21A24929A00CCAFDE /* AccessVectorContent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BEEFEF79196ECCC000C80FF1 /* AccessVectorContent.cpp */; };
BE90E1B31A24929A00CCAFDE /* AccessVectorContent.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BEEFEF7A196ECCC000C80FF1 /* AccessVectorContent.hpp */; };
BE90E1B41A24929A00CCAFDE /* AccessVectorContent.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BEEFEF7B196ECCC000C80FF1 /* AccessVectorContent.hxx */; };
BE90E1B71A24929A00CCAFDE /* Petsc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE9FE82F18CE0A6900177F79 /* Petsc.cpp */; };
BE90E1B81A24929A00CCAFDE /* Petsc.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE9FE83018CE0A6900177F79 /* Petsc.hpp */; };
BE90E1B91A24929A00CCAFDE /* Print.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE9FE83418CE0A6900177F79 /* Print.hpp */; };
BE90E1BD1A24929A00CCAFDE /* Viewer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE9FE83F18CE0A6900177F79 /* Viewer.cpp */; };
BE90E1BE1A24929A00CCAFDE /* Viewer.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE9FE84018CE0A6900177F79 /* Viewer.hpp */; };
......@@ -3856,6 +3857,9 @@
BE5A4E2C1B677CED006822DD /* Model.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Model.cpp; sourceTree = "<group>"; };
BE5A4E2D1B677CED006822DD /* Model.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Model.hpp; sourceTree = "<group>"; };
BE5A4E2E1B677CED006822DD /* Model.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Model.hxx; sourceTree = "<group>"; };
BE5AA42422E62C3A00A393DE /* RAII.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RAII.cpp; sourceTree = "<group>"; };
BE5AA42522E62C3A00A393DE /* RAII.hxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = RAII.hxx; sourceTree = "<group>"; };
BE5AA42622E62C3A00A393DE /* RAII.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = RAII.hpp; sourceTree = "<group>"; };
BE5B6F6B1C3C1602004A0284 /* VertexMatching.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VertexMatching.cpp; sourceTree = "<group>"; };
BE5B6F6C1C3C1602004A0284 /* VertexMatching.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = VertexMatching.hpp; sourceTree = "<group>"; };
BE5B6F6D1C3C1602004A0284 /* VertexMatching.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = VertexMatching.hxx; sourceTree = "<group>"; };
......@@ -4072,6 +4076,10 @@
BE7C94941F605266003D2C52 /* GradPhiTauTauGradPhi.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GradPhiTauTauGradPhi.cpp; sourceTree = "<group>"; };
BE7C94951F605266003D2C52 /* GradPhiTauTauGradPhi.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = GradPhiTauTauGradPhi.hpp; sourceTree = "<group>"; };
BE7C94961F605266003D2C52 /* GradPhiTauTauGradPhi.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = GradPhiTauTauGradPhi.hxx; sourceTree = "<group>"; };
BE7D5BBC22E607DA00C971F5 /* test.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = test.cpp; sourceTree = "<group>"; };
BE7D5BBD22E607DA00C971F5 /* demo.lua */ = {isa = PBXFileReference; lastKnownFileType = text; path = demo.lua; sourceTree = "<group>"; };
BE7D5BBE22E607DA00C971F5 /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
BE7D5BBF22E607DA00C971F5 /* InputData.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = InputData.hpp; sourceTree = "<group>"; };
BE7DE82619CC537000D24C7D /* Op.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Op.cpp; sourceTree = "<group>"; };
BE7DE82719CC537000D24C7D /* Op.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Op.hpp; sourceTree = "<group>"; };
BE7DE82A19CC541D00D24C7D /* Comm.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Comm.cpp; sourceTree = "<group>"; };
......@@ -4363,8 +4371,6 @@
BE9FE82418CE0A6900177F79 /* Petsc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Petsc.cpp; sourceTree = "<group>"; };
BE9FE82518CE0A6900177F79 /* Petsc.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Petsc.hpp; sourceTree = "<group>"; };
BE9FE82618CE0A6900177F79 /* Petsc.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Petsc.hxx; sourceTree = "<group>"; };
BE9FE82F18CE0A6900177F79 /* Petsc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Petsc.cpp; sourceTree = "<group>"; };
BE9FE83018CE0A6900177F79 /* Petsc.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Petsc.hpp; sourceTree = "<group>"; };
BE9FE83418CE0A6900177F79 /* Print.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Print.hpp; sourceTree = "<group>"; };
BE9FE83F18CE0A6900177F79 /* Viewer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Viewer.cpp; sourceTree = "<group>"; };
BE9FE84018CE0A6900177F79 /* Viewer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Viewer.hpp; sourceTree = "<group>"; };
......@@ -6563,7 +6569,6 @@
BEDFFB7B204EE4F400A52F86 /* TypeName */,
BECEF93222DF63CA00D0DDE7 /* Now */,
BE2457AB1E005B0B00677AEF /* InputData */,
BEEDD06322E5A6E8004BD728 /* WriteLuaFile */,
);
path = Utilities;
sourceTree = "<group>";
......@@ -7870,6 +7875,16 @@
path = ConformProjector;
sourceTree = "<group>";
};
BE5AA42322E62BCA00A393DE /* Internal */ = {
isa = PBXGroup;
children = (
BE5AA42422E62C3A00A393DE /* RAII.cpp */,
BE5AA42622E62C3A00A393DE /* RAII.hpp */,
BE5AA42522E62C3A00A393DE /* RAII.hxx */,
);
path = Internal;
sourceTree = "<group>";
};
BE5B6F6A1C3C1602004A0284 /* Interpolator */ = {
isa = PBXGroup;
children = (
......@@ -8481,6 +8496,17 @@
path = Instantiations;
sourceTree = "<group>";
};
BE7D5BBB22E607DA00C971F5 /* WriteLuaFile */ = {
isa = PBXGroup;
children = (
BE7D5BBE22E607DA00C971F5 /* CMakeLists.txt */,
BE7D5BBD22E607DA00C971F5 /* demo.lua */,
BE7D5BBC22E607DA00C971F5 /* test.cpp */,
BE7D5BBF22E607DA00C971F5 /* InputData.hpp */,
);
path = WriteLuaFile;
sourceTree = "<group>";
};
BE7DE82519CC537000D24C7D /* MacroEncapsulation */ = {
isa = PBXGroup;
children = (
......@@ -8993,6 +9019,7 @@
BE94539A2100BCA500953B84 /* CommandLineOptions */,
BE390F132108C9BD0049CD3B /* InputData */,
BE94539F2100BCA500953B84 /* InputParameter */,
BE7D5BBB22E607DA00C971F5 /* WriteLuaFile */,
BE160256210A3162009CEE98 /* InitialCondition */,
);
path = MoReFEMData;
......@@ -9256,8 +9283,6 @@
BEEFEF71196ECCC000C80FF1 /* Matrix */,
BEEFEF78196ECCC000C80FF1 /* Vector */,
BEDEB90D1C3C073100B1C71B /* Solver */,
BE9FE82F18CE0A6900177F79 /* Petsc.cpp */,
BE9FE83018CE0A6900177F79 /* Petsc.hpp */,
BE4B17D21AA5B20D0073516A /* Print.cpp */,
BE9FE83418CE0A6900177F79 /* Print.hpp */,
BE4B17CF1AA5AB0E0073516A /* Print.hxx */,
......@@ -9265,6 +9290,7 @@
BE9FE84018CE0A6900177F79 /* Viewer.hpp */,
BECB2E0A213FFBAC0093CB05 /* SnesMacro.hpp */,
BE9FE82318CE0A6900177F79 /* Exceptions */,
BE5AA42322E62BCA00A393DE /* Internal */,
);
path = Petsc;
sourceTree = "<group>";
......@@ -10342,13 +10368,6 @@
path = OutputFormat;
sourceTree = "<group>";
};
BEEDD06322E5A6E8004BD728 /* WriteLuaFile */ = {
isa = PBXGroup;
children = (
);
path = WriteLuaFile;
sourceTree = "<group>";
};
BEEFEF71196ECCC000C80FF1 /* Matrix */ = {
isa = PBXGroup;
children = (
......@@ -11428,6 +11447,7 @@
BE2592141C9ABA6900DF404B /* Utilities.doxygen in Headers */,
BE90E1C31A2492AA00CCAFDE /* SubVector.hpp in Headers */,
BEDEB92F1C3C073100B1C71B /* Snes.hpp in Headers */,
BE5AA42922E62C3A00A393DE /* RAII.hpp in Headers */,
BE76F2511D7D5D900061B50E /* LocalVectorStorage.hxx in Headers */,
BE90E1781A24926E00CCAFDE /* Singleton.hpp in Headers */,
BE768EC01B836022009B24CB /* Section.hpp in Headers */,
......@@ -11438,11 +11458,11 @@
BE41A8CC1A24AA46004E4312 /* MpiScale.hpp in Headers */,
BE76F2501D7D5D900061B50E /* LocalVectorStorage.hpp in Headers */,
BE90E1811A24929A00CCAFDE /* LuaFunction.hxx in Headers */,
BE5AA42822E62C3A00A393DE /* RAII.hxx in Headers */,
BE145A0F1E54BC49000A2BF5 /* ValuesConstraint.h in Headers */,
BE5657421D3CD7470091F063 /* Array.hxx in Headers */,
BE6FFAD91A399E2200D048BD /* Numeric.hxx in Headers */,
BE90E1921A24929A00CCAFDE /* UniqueId.hpp in Headers */,
BE90E1B81A24929A00CCAFDE /* Petsc.hpp in Headers */,
BE90E1C61A2492AA00CCAFDE /* SubVector_Base.hxx in Headers */,
BE145A101E54BC49000A2BF5 /* VersionVisitor.h in Headers */,
BE90E1691A24926E00CCAFDE /* PointerComparison.hxx in Headers */,
......@@ -12714,8 +12734,8 @@
buildActionMask = 2147483647;
files = (
022CDB5622D4973B00504CF9 /* OutputFormat.cpp in Sources */,
BE5AA42722E62C3A00A393DE /* RAII.cpp in Sources */,
BE90E1A71A24929A00CCAFDE /* Parmetis.cpp in Sources */,
BE90E1B71A24929A00CCAFDE /* Petsc.cpp in Sources */,
BE8B5F8020778D1A00DC005E /* StringPair.cpp in Sources */,
BECEF92322DF4A4400D0DDE7 /* ReadBinaryFile.cpp in Sources */,
BE53FC251E0D81A000C5D6F5 /* Traits.cpp in Sources */,
......@@ -65,9 +65,9 @@ namespace MoReFEM
* \copydoc doxygen_hide_mpi_param
*/
explicit InputData(const std::string& filename,
const Wrappers::Mpi& mpi,
Utilities::InputDataNS::DoTrackUnusedFields do_track_unused_fields =
Utilities::InputDataNS::DoTrackUnusedFields::yes);
const Wrappers::Mpi& mpi,
Utilities::InputDataNS::DoTrackUnusedFields do_track_unused_fields =
Utilities::InputDataNS::DoTrackUnusedFields::yes);
//! Destructor
~InputData() = default;
......
......@@ -18,8 +18,8 @@
# include "ThirdParty/Wrappers/Mpi/Mpi.hpp"
# include "ThirdParty/Wrappers/Mpi/MpiScale.hpp"
# include "ThirdParty/Wrappers/Petsc/Petsc.hpp"
# include "ThirdParty/Wrappers/Petsc/Print.hpp"
# include "ThirdParty/Wrappers/Petsc/Internal/RAII.hpp"
# include "ThirdParty/Wrappers/Tclap/StringPair.hpp"
# include "ThirdParty/IncludeWithoutWarning/Tclap/Tclap.hpp"
......@@ -128,13 +128,9 @@ namespace MoReFEM
template<MpiScale MpiScaleT>
const std::string& GetResultDirectory() const noexcept;
private:
//! Holds Mpi object.
Wrappers::Mpi::const_unique_ptr mpi_ = nullptr;
//!
//! Holds RAII Petsc object, which ensures PetscFinalize() is called in due time.
Wrappers::Petsc::Petsc::const_unique_ptr petsc_ = nullptr;
private:
//! Holds InputData.
typename InputDataT::const_unique_ptr input_data_ = nullptr;
......
......@@ -29,10 +29,7 @@ namespace MoReFEM
MoReFEMData<InputDataT, DoTrackUnusedFieldsT, AdditionalCommandLineArgumentsPolicyT>
::MoReFEMData(int argc, char** argv)
{
Wrappers::Mpi::InitEnvironment(argc, argv);
mpi_ = std::make_unique<Wrappers::Mpi>(0, Wrappers::MpiNS::Comm::World);
petsc_ = std::make_unique<Wrappers::Petsc::Petsc>(__FILE__, __LINE__);
Internal::PetscNS::RAII::CreateOrGetInstance(__FILE__, __LINE__, argc, argv);
auto& environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
......@@ -113,19 +110,13 @@ namespace MoReFEM
std::string start_time = "MOREFEM_START_TIME";
if (environment.DoExist(start_time))
if (!environment.DoExist(start_time))
{
throw Exception("There is an environment variable named 'MOREFEM_START_TIME'; please unset it before "
"running again your program (it might be set internally to determine the result "
"directory if ${MOREFEM_START_TIME} appears in the chosen path).",
__FILE__, __LINE__);
environment.SetEnvironmentVariable(std::make_pair(start_time, Utilities::Now(mpi)),
__FILE__, __LINE__);
mpi.Barrier();
}
environment.SetEnvironmentVariable(std::make_pair(start_time, Utilities::Now(mpi)),
__FILE__, __LINE__);
mpi.Barrier();
}
......@@ -161,7 +152,7 @@ namespace MoReFEM
{
Utilities::InputDataNS::CreateDefaultInputFile<typename InputDataT::Tuple>(input_data_file);
std::cout << '\n' << input_data_file << " wasn't existing and has just been created on processor 0; "
std::cout << '\n' << input_data_file << " wasn't existing and has just been created on root processor; "
"please edit it and then copy it onto all machines intended to run the code in parallel." << std::endl;
throw Exception("Input data file to edit and complete!", __FILE__, __LINE__);
......@@ -184,8 +175,8 @@ namespace MoReFEM
// We can be here only if the file exists...
input_data_ = std::make_unique<InputDataT>(input_data_file,
mpi,
DoTrackUnusedFieldsT);
mpi,
DoTrackUnusedFieldsT);
namespace ipl = Utilities::InputDataNS;
using Result = InputDataNS::Result;
......@@ -248,8 +239,8 @@ namespace MoReFEM
MoReFEMData<InputDataT, DoTrackUnusedFieldsT, AdditionalCommandLineArgumentsPolicyT>
::GetMpi() const noexcept
{
assert(!(!mpi_));
return *mpi_;
decltype(auto) raii = Internal::PetscNS::RAII::GetInstance(__FILE__, __LINE__);
return raii.GetMpi();
}
......
//! \file
//
//
// RAII.cpp
// MoReFEM
//
// Created by sebastien on 22/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#include "Utilities/Exceptions/Exception.hpp"
#include "ThirdParty/Wrappers/Petsc/Internal/RAII.hpp"
#include "ThirdParty/Wrappers/Petsc/Exceptions/Petsc.hpp"
namespace MoReFEM::Internal::PetscNS
{
RAII::RAII(int argc, char** argv)
{
::MoReFEM::Wrappers::Mpi::InitEnvironment(argc, argv);
mpi_ = std::make_unique<::MoReFEM::Wrappers::Mpi>(0, ::MoReFEM::Wrappers::MpiNS::Comm::World);
int error_code = PetscInitialize(PETSC_NULL, PETSC_NULL, PETSC_NULL, "");
if (error_code)
throw ::MoReFEM::Wrappers::Petsc::ExceptionNS::Exception(error_code,
"PetscInitialize",
__FILE__, __LINE__);
}
RAII::~RAII()
{
int error_code = PetscFinalize();
assert(!error_code && "Error in PetscFinalize call!"); // No exception in destructors...
static_cast<void>(error_code); // avoid warning in release compilation.
}
const std::string& RAII::ClassName()
{
static std::string ret("Internal::PetscNS::RAII");
return ret;
}
} // namespace MoReFEM::Internal::PetscNS
//! \file
//
//
// RAII.hpp
// MoReFEM
//
// Created by sebastien on 22/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef MOREFEM_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_INTERNAL_x_R_A_I_I_HPP_
# define MOREFEM_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_INTERNAL_x_R_A_I_I_HPP_
#include "Utilities/Singleton/Singleton.hpp"
#include "ThirdParty/Wrappers/Mpi/Mpi.hpp"
namespace MoReFEM::Internal::PetscNS
{
/*!
* \brief RAII class to initialize / close properly PETSc and mpi.
*/
class RAII final : public Utilities::Singleton<RAII>
{
private:
/// \name Special members.
///@{
//! Constructor.
explicit RAII(int argc, char** argv);
//! Destructor.
virtual ~RAII() override;
//! Friendship declaration to Singleton template class (to enable call to constructor).
friend class Utilities::Singleton<RAII>;
//! Name of the class.
static const std::string& ClassName();
///@}
public:
//! Accessor to mpi.
const ::MoReFEM::Wrappers::Mpi& GetMpi() const noexcept;
private:
//! Holds Mpi object.
::MoReFEM::Wrappers::Mpi::const_unique_ptr mpi_ = nullptr;
};
} // namespace MoReFEM::Internal::PetscNS
# include "ThirdParty/Wrappers/Petsc/Internal/RAII.hxx"
#endif // MOREFEM_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_INTERNAL_x_R_A_I_I_HPP_
//! \file
//
//
// RAII.hxx
// MoReFEM
//
// Created by sebastien on 22/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef MOREFEM_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_INTERNAL_x_R_A_I_I_HXX_
# define MOREFEM_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_INTERNAL_x_R_A_I_I_HXX_
namespace MoReFEM::Internal::PetscNS
{
inline const ::MoReFEM::Wrappers::Mpi& RAII::GetMpi() const noexcept
{
assert(!(!mpi_));
return *mpi_;
}
} // namespace MoReFEM::Internal::PetscNS
#endif // MOREFEM_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_INTERNAL_x_R_A_I_I_HXX_
### ===================================================================================
### This file is generated automatically by Scripts/generate_cmake_source_list.py.
### Do not edit it manually!
### Convention is that:
### - When a CMake file is manually managed, it is named canonically CMakeLists.txt.
###. - When it is generated automatically, it is named SourceList.cmake.
### ===================================================================================
target_sources(${MOREFEM_UTILITIES}
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/RAII.cpp"
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/RAII.hpp"
"${CMAKE_CURRENT_LIST_DIR}/RAII.hxx"
)
/*!
//
// \file
//
//
// Created by Sebastien Gilles <sebastien.gilles@inria.fr> on the Fri, 20 Sep 2013 14:51:15 +0200
// Copyright (c) Inria. All rights reserved.
//
// \ingroup ThirdPartyGroup
// \addtogroup ThirdPartyGroup
// \{
*/
#include <cassert>
#include "ThirdParty/Wrappers/Petsc/Petsc.hpp"
#include "ThirdParty/Wrappers/Petsc/Exceptions/Petsc.hpp"
namespace MoReFEM
{
namespace Wrappers
{
namespace Petsc
{
Petsc::Petsc(const char* invoking_file, int invoking_line)
{
int error_code = PetscInitialize(PETSC_NULL, PETSC_NULL, PETSC_NULL, "");
if (error_code)
throw ExceptionNS::Exception(error_code, "PetscInitialize", invoking_file, invoking_line);
}
Petsc::~Petsc()
{
int error_code = PetscFinalize();
assert(!error_code && "Error in PetscFinalize call!"); // No exception in destructors...
static_cast<void>(error_code); // avoid warning in release compilation.
}
} // namespace Petsc
} // namespace Wrappers
} // namespace MoReFEM
/// @} // addtogroup ThirdPartyGroup
/*!
//
// \file
//
//
// Created by Sebastien Gilles <sebastien.gilles@inria.fr> on the Fri, 20 Sep 2013 14:51:15 +0200
// Copyright (c) Inria. All rights reserved.
//
// \ingroup ThirdPartyGroup
// \addtogroup ThirdPartyGroup
// \{
*/
#ifndef MOREFEM_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_PETSC_HPP_
# define MOREFEM_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_PETSC_HPP_
# include <memory>
namespace MoReFEM
{
namespace Wrappers
{
namespace Petsc
{
/*!
* \brief RAII class to initialize and close PETSc properly.
*/
struct Petsc final
{
//! Convenient alias against the relevant smart pointer to use with this RAII class.
using const_unique_ptr = std::unique_ptr<const Petsc>;
/// \name Special members.
///@{
//! Constructor (call to PetscInitialize)
//! \copydoc doxygen_hide_invoking_file_and_line
explicit Petsc(const char* invoking_file, int invoking_line);
//! Destructor (call to PetscFinalize).
~Petsc();
//! \copydoc doxygen_hide_copy_constructor
Petsc(const Petsc& rhs) = delete;
//! \copydoc doxygen_hide_move_constructor
Petsc(Petsc&& rhs) = delete;
//! \copydoc doxygen_hide_copy_affectation
Petsc& operator=(const Petsc& rhs) = delete;
//! \copydoc doxygen_hide_move_affectation
Petsc& operator=(Petsc&& rhs) = delete;
///@}
};
} // namespace Petsc
} // namespace Wrappers
} // namespace MoReFEM
/// @} // addtogroup ThirdPartyGroup
#endif // MOREFEM_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_PETSC_HPP_
......@@ -10,18 +10,17 @@
target_sources(${MOREFEM_UTILITIES}
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/Petsc.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Print.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Viewer.cpp"
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/Petsc.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Print.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Print.hxx"
"${CMAKE_CURRENT_LIST_DIR}/SnesMacro.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Viewer.hpp"
)
include(${CMAKE_CURRENT_LIST_DIR}/Internal/SourceList.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/Solver/SourceList.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/Exceptions/SourceList.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/Vector/SourceList.cmake)
......
......@@ -186,8 +186,6 @@ namespace MoReFEM
* This follows item 16 of Scott Meyers's "Effective Modern C++", which advises to make const member
* functions thread safe.
*
* However, it is here enclosed in a unique_ptr as mutex doesn't seem to be movable (current implementations
* of both clang and gcc don't define the move constructor and the move assignation; the copy is deleted).
*/
static std::mutex singleton_mutex_;
......
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