Advanced Multi-Physics (AMP)
On-Line Documentation
RestartManager.h
Go to the documentation of this file.
1#ifndef included_AMP_RestartManager
2#define included_AMP_RestartManager
3
4#include "AMP/IO/HDF.h"
5#include "AMP/utils/TypeTraits.h"
6
7#include <map>
8#include <string>
9
10
11namespace AMP::IO {
12
13
15class RestartManager final
16{
17public: // User functions
20
22 RestartManager( const std::string &filename );
23
25 RestartManager( const RestartManager & ) = delete;
26
29
32
35
38
40 void reset();
41
49 void write( const std::string &filename, Compression compress = Compression::None );
50
59 void load( const std::string &filename );
60
67 template<class TYPE>
68 void registerData( const TYPE &data, const std::string &name );
69
75 template<class TYPE>
76 std::shared_ptr<TYPE> getData( const std::string &name );
77
78
79public: // Developer functions
85 template<class TYPE>
86 uint64_t registerObject( const TYPE &data );
87
93 uint64_t registerComm( const AMP::AMP_MPI &comm );
94
100 template<class TYPE>
101 std::shared_ptr<TYPE> getData( uint64_t hash );
102
103
109 AMP_MPI getComm( uint64_t hash );
110
111
117 template<class TYPE>
118 uint64_t registerSAMRAIData( std::shared_ptr<const TYPE &> data );
119
125 template<class TYPE>
126 std::shared_ptr<TYPE> getSAMRAIData( uint64_t hash );
127
128
134 bool isRegistered( uint64_t hash );
135
136
137public:
140 {
141 public:
142 virtual ~DataStore() = default;
143 inline uint64_t getHash() const { return d_hash; }
144 virtual void write( hid_t fid, const std::string &name ) const = 0;
145
146 protected:
147 uint64_t d_hash = 0;
148 };
149
151 template<class TYPE>
153 {
154 public:
155 DataStoreType( hid_t fid, uint64_t hash, RestartManager *manager );
156 DataStoreType( std::shared_ptr<const TYPE>, RestartManager * );
157 virtual ~DataStoreType() = default;
158 void write( hid_t fid, const std::string &name ) const override;
159 virtual std::shared_ptr<TYPE>
160 read( hid_t fid, const std::string &name, RestartManager * ) const;
161 auto getData() { return std::const_pointer_cast<TYPE>( d_data ); }
162
163 protected:
164 DataStoreType() = default;
165 std::shared_ptr<const TYPE> d_data;
166 };
167
168 // Specialization for SAMRAI data object
169 template<class TYPE>
170 class SAMRAIDataStore : public DataStoreType<TYPE>
171 {
172 public:
173 SAMRAIDataStore( hid_t fid, uint64_t hash, RestartManager *manager );
174 SAMRAIDataStore( std::shared_ptr<const TYPE>, RestartManager * );
175 virtual ~SAMRAIDataStore() = default;
176 void write( hid_t fid, const std::string &name ) const override;
177 std::shared_ptr<TYPE>
178 read( hid_t fid, const std::string &name, RestartManager * ) const override;
179 };
180 using DataStorePtr = std::shared_ptr<DataStore>;
181
182
183private: // Private functions
184 template<class TYPE>
185 RestartManager::DataStorePtr create( std::shared_ptr<const TYPE> );
186
187 void writeCommData( const std::string &file, Compression compress );
188 void readCommData( const std::string &file );
189 static std::string hash2String( uint64_t );
190
191private: // Data members
192 hid_t d_fid; // fid for reading
193 std::map<uint64_t, DataStorePtr> d_data; // Object data
194 std::map<std::string, uint64_t> d_names; // Names to associate with the hashes
195 std::map<uint64_t, AMP_MPI> d_comms; // Registered communicators
196};
197
198
199} // namespace AMP::IO
200
201
202#include "AMP/IO/RestartManager.hpp"
203
204
205#endif
int64_t hid_t
Definition HDF.h:23
Provides C++ wrapper around MPI routines.
Definition AMP_MPI.h:63
Class to store a single object to write/read.
std::shared_ptr< const TYPE > d_data
DataStoreType(hid_t fid, uint64_t hash, RestartManager *manager)
DataStoreType(std::shared_ptr< const TYPE >, RestartManager *)
virtual std::shared_ptr< TYPE > read(hid_t fid, const std::string &name, RestartManager *) const
void write(hid_t fid, const std::string &name) const override
Base class for writing an object.
virtual void write(hid_t fid, const std::string &name) const =0
std::shared_ptr< TYPE > read(hid_t fid, const std::string &name, RestartManager *) const override
SAMRAIDataStore(hid_t fid, uint64_t hash, RestartManager *manager)
void write(hid_t fid, const std::string &name) const override
SAMRAIDataStore(std::shared_ptr< const TYPE >, RestartManager *)
Class to manage reading/writing restart data.
RestartManager(const std::string &filename)
Create a reader for restart data.
std::shared_ptr< TYPE > getData(uint64_t hash)
Get data from the restart manager.
std::shared_ptr< TYPE > getData(const std::string &name)
Get data from the restart manager.
bool isRegistered(uint64_t hash)
Check if an object is registered.
void load(const std::string &filename)
Read a restart file.
uint64_t registerObject(const TYPE &data)
Register data with the restart manager.
std::shared_ptr< TYPE > getSAMRAIData(uint64_t hash)
Get SAMRAI data from the restart manager.
AMP_MPI getComm(uint64_t hash)
Get the communicator from the restart manager.
RestartManager & operator=(RestartManager &&)
Move assignment.
void readCommData(const std::string &file)
std::map< uint64_t, AMP_MPI > d_comms
std::map< std::string, uint64_t > d_names
static std::string hash2String(uint64_t)
~RestartManager()
Destructor.
void writeCommData(const std::string &file, Compression compress)
void reset()
Reset internal data.
RestartManager(const RestartManager &)=delete
Copy constructor.
uint64_t registerSAMRAIData(std::shared_ptr< const TYPE & > data)
Register SAMRAI data with the restart manager.
RestartManager(RestartManager &&)
Move operator.
RestartManager & operator=(const RestartManager &)=delete
Assignment operator.
std::shared_ptr< DataStore > DataStorePtr
RestartManager()
Create a writer for restart data.
void registerData(const TYPE &data, const std::string &name)
Register data with the restart manager.
uint64_t registerComm(const AMP::AMP_MPI &comm)
Register a communicator with the restart manager.
RestartManager::DataStorePtr create(std::shared_ptr< const TYPE >)
void write(const std::string &filename, Compression compress=Compression::None)
Write the data.
std::map< uint64_t, DataStorePtr > d_data
std::string filename(const std::string &filename)
Return the filename (strip the path)
Compression
Definition HDF.h:31



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:40.
Comments on this page