Skip to content
Snippets Groups Projects
Commit 5cdc0296 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add checkpoint/resume info for user functions

This is useful boundary condition descriptors for instance
parent 67ef4ce6
No related branches found
No related tags found
1 merge request!199Integrate checkpointing
#include <utils/checkpointing/ResumingData.hpp> #include <utils/checkpointing/ResumingData.hpp>
#include <language/utils/SymbolTable.hpp>
#include <mesh/ConnectivityDescriptor.hpp> #include <mesh/ConnectivityDescriptor.hpp>
#include <mesh/Mesh.hpp> #include <mesh/Mesh.hpp>
#include <utils/Exceptions.hpp> #include <utils/Exceptions.hpp>
...@@ -231,10 +232,58 @@ ResumingData::_getMeshVariantList(const HighFive::Group& checkpoint) ...@@ -231,10 +232,58 @@ ResumingData::_getMeshVariantList(const HighFive::Group& checkpoint)
} }
void void
ResumingData::readData(const HighFive::Group& checkpoint) ResumingData::_getFunctionIds(const HighFive::Group& checkpoint, std::shared_ptr<SymbolTable> p_symbol_table)
{
size_t symbol_table_id = 0;
const HighFive::Group function_group = checkpoint.getGroup("functions");
while (p_symbol_table.use_count() > 0) {
for (auto symbol : p_symbol_table->symbolList()) {
if (symbol.attributes().dataType() == ASTNodeDataType::function_t) {
if (not function_group.exist(symbol.name())) {
std::ostringstream error_msg;
error_msg << "cannot find function " << rang::fgB::yellow << symbol.name() << rang::fg::reset << " in "
<< rang::fgB::cyan << checkpoint.getFile().getName() << rang::fg::reset;
throw NormalError(error_msg.str());
} else {
const HighFive::Group function = function_group.getGroup(symbol.name());
const size_t stored_function_id = function.getAttribute("id").read<size_t>();
const size_t function_id = std::get<size_t>(symbol.attributes().value());
if (symbol_table_id != function.getAttribute("symbol_table_id").read<size_t>()) {
std::ostringstream error_msg;
error_msg << "symbol table of function " << rang::fgB::yellow << symbol.name() << rang::fg::reset
<< " does not match the one stored in " << rang::fgB::cyan << checkpoint.getFile().getName()
<< rang::fg::reset;
throw NormalError(error_msg.str());
} else if (function_id != stored_function_id) {
std::ostringstream error_msg;
error_msg << "id (" << function_id << ") of function " << rang::fgB::yellow << symbol.name()
<< rang::fg::reset << " does not match the one stored in " << rang::fgB::cyan
<< checkpoint.getFile().getName() << rang::fg::reset << "(" << stored_function_id << ")";
throw NormalError(error_msg.str());
} else {
if (m_id_to_function_symbol_id_map.contains(function_id)) {
std::ostringstream error_msg;
error_msg << "id (" << function_id << ") of function " << rang::fgB::yellow << symbol.name()
<< rang::fg::reset << " is duplicated";
throw UnexpectedError(error_msg.str());
}
m_id_to_function_symbol_id_map[function_id] =
std::make_shared<FunctionSymbolId>(function_id, p_symbol_table);
}
}
}
}
p_symbol_table = p_symbol_table->parentTable();
++symbol_table_id;
}
}
void
ResumingData::readData(const HighFive::Group& checkpoint, std::shared_ptr<SymbolTable> p_symbol_table)
{ {
this->_getConnectivityList(checkpoint); this->_getConnectivityList(checkpoint);
this->_getMeshVariantList(checkpoint); this->_getMeshVariantList(checkpoint);
this->_getFunctionIds(checkpoint, p_symbol_table);
} }
const std::shared_ptr<const IConnectivity>& const std::shared_ptr<const IConnectivity>&
...@@ -259,6 +308,17 @@ ResumingData::meshVariant(const size_t mesh_id) const ...@@ -259,6 +308,17 @@ ResumingData::meshVariant(const size_t mesh_id) const
} }
} }
const std::shared_ptr<const FunctionSymbolId>&
ResumingData::functionSymbolId(const size_t function_symbol_id) const
{
auto i_id_to_function_symbol_id = m_id_to_function_symbol_id_map.find(function_symbol_id);
if (i_id_to_function_symbol_id == m_id_to_function_symbol_id_map.end()) {
throw UnexpectedError("cannot find function_symbol_id of id " + std::to_string(function_symbol_id));
} else {
return i_id_to_function_symbol_id->second;
}
}
void void
ResumingData::create() ResumingData::create()
{ {
......
...@@ -8,12 +8,15 @@ ...@@ -8,12 +8,15 @@
class IConnectivity; class IConnectivity;
class MeshVariant; class MeshVariant;
class SymbolTable;
class FunctionSymbolId;
class ResumingData class ResumingData
{ {
private: private:
std::map<size_t, std::shared_ptr<const IConnectivity>> m_id_to_iconnectivity_map; std::map<size_t, std::shared_ptr<const IConnectivity>> m_id_to_iconnectivity_map;
std::map<size_t, std::shared_ptr<const MeshVariant>> m_id_to_mesh_variant_map; std::map<size_t, std::shared_ptr<const MeshVariant>> m_id_to_mesh_variant_map;
std::map<size_t, std::shared_ptr<const FunctionSymbolId>> m_id_to_function_symbol_id_map;
ResumingData() = default; ResumingData() = default;
~ResumingData() = default; ~ResumingData() = default;
...@@ -25,12 +28,14 @@ class ResumingData ...@@ -25,12 +28,14 @@ class ResumingData
void _getConnectivityList(const HighFive::Group& checkpoint); void _getConnectivityList(const HighFive::Group& checkpoint);
void _getMeshVariantList(const HighFive::Group& checkpoint); void _getMeshVariantList(const HighFive::Group& checkpoint);
void _getFunctionIds(const HighFive::Group& checkpoint, std::shared_ptr<SymbolTable> p_symbol_table);
public: public:
void readData(const HighFive::Group& checkpoint); void readData(const HighFive::Group& checkpoint, std::shared_ptr<SymbolTable> p_symbol_table);
const std::shared_ptr<const IConnectivity>& iConnectivity(const size_t connectivity_id) const; const std::shared_ptr<const IConnectivity>& iConnectivity(const size_t connectivity_id) const;
const std::shared_ptr<const MeshVariant>& meshVariant(const size_t mesh_id) const; const std::shared_ptr<const MeshVariant>& meshVariant(const size_t mesh_id) const;
const std::shared_ptr<const FunctionSymbolId>& functionSymbolId(const size_t function_symbol_id) const;
static void create(); static void create();
static void destroy(); static void destroy();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment