19 #ifndef PARALLEL_RESTART_HPP
20 #define PARALLEL_RESTART_HPP
26 #include <opm/common/ErrorMacros.hpp>
27 #include <opm/common/utility/TimeService.hpp>
29 #include <dune/common/version.hh>
30 #include <dune/common/parallel/mpihelper.hh>
32 #include <opm/simulators/utils/ParallelCommunication.hpp>
41 #include <unordered_map>
42 #include <unordered_set>
56 struct CarterTracyData;
59 struct CurrentControl;
61 class GroupAndNetworkValues;
62 struct GroupConstraints;
64 struct GroupGuideRates;
67 struct NumericAquiferData;
83 std::size_t packSize(
const T*, std::size_t, Opm::Parallel::MPIComm,
84 std::integral_constant<bool, false>);
87 std::size_t packSize(
const T*, std::size_t l, Opm::Parallel::MPIComm comm,
88 std::integral_constant<bool, true>);
91 std::size_t packSize(
const T* data, std::size_t l, Opm::Parallel::MPIComm comm);
94 std::size_t packSize(
const T&, Opm::Parallel::MPIComm,
95 std::integral_constant<bool, false>)
97 std::string msg = std::string{
"Packing not (yet) supported for non-pod type: "} +
typeid(T).name();
98 OPM_THROW(std::logic_error, msg);
102 std::size_t packSize(
const T&, Opm::Parallel::MPIComm comm,
103 std::integral_constant<bool, true>)
107 MPI_Pack_size(1, Dune::MPITraits<T>::getType(), comm, &size);
116 std::size_t packSize(
const T& data, Opm::Parallel::MPIComm comm)
118 return packSize(data, comm,
typename std::is_pod<T>::type());
121 template<
class T1,
class T2>
122 std::size_t packSize(
const std::pair<T1,T2>& data, Opm::Parallel::MPIComm comm);
125 std::size_t packSize(
const std::optional<T>& data, Opm::Parallel::MPIComm comm);
127 template<
class T,
class A>
128 std::size_t packSize(
const std::vector<T,A>& data, Opm::Parallel::MPIComm comm);
130 template<
class K,
class C,
class A>
131 std::size_t packSize(
const std::set<K,C,A>& data,
132 Opm::Parallel::MPIComm comm);
134 template<
class T,
class H,
class KE,
class A>
135 std::size_t packSize(
const std::unordered_set<T,H,KE,A>& data,
136 Opm::Parallel::MPIComm comm);
139 std::size_t packSize(
const std::vector<bool,A>& data, Opm::Parallel::MPIComm comm);
141 template<
class... Ts>
142 std::size_t packSize(
const std::tuple<Ts...>& data, Opm::Parallel::MPIComm comm);
144 template<
class T, std::
size_t N>
145 std::size_t packSize(
const std::array<T,N>& data, Opm::Parallel::MPIComm comm);
147 std::size_t packSize(
const char* str, Opm::Parallel::MPIComm comm);
149 template<
class T1,
class T2,
class C,
class A>
150 std::size_t packSize(
const std::map<T1,T2,C,A>& data, Opm::Parallel::MPIComm comm);
152 template<
class T1,
class T2,
class H,
class P,
class A>
153 std::size_t packSize(
const std::unordered_map<T1,T2,H,P,A>& data, Opm::Parallel::MPIComm comm);
158 void pack(
const T*, std::size_t, std::vector<char>&,
int&,
159 Opm::Parallel::MPIComm, std::integral_constant<bool, false>);
162 void pack(
const T* data, std::size_t l, std::vector<char>& buffer,
int& position,
163 Opm::Parallel::MPIComm comm, std::integral_constant<bool, true>);
166 void pack(
const T* data, std::size_t l, std::vector<char>& buffer,
int& position,
167 Opm::Parallel::MPIComm comm);
170 void pack(
const T&, std::vector<char>&,
int&,
171 Opm::Parallel::MPIComm, std::integral_constant<bool, false>)
173 OPM_THROW(std::logic_error,
"Packing not (yet) supported for this non-pod type.");
177 void pack(
const T& data, std::vector<char>& buffer,
int& position,
178 Opm::Parallel::MPIComm comm, std::integral_constant<bool, true>)
181 MPI_Pack(&data, 1, Dune::MPITraits<T>::getType(), buffer.data(),
182 buffer.size(), &position, comm);
192 void pack(
const T& data, std::vector<char>& buffer,
int& position,
193 Opm::Parallel::MPIComm comm)
195 pack(data, buffer, position, comm,
typename std::is_pod<T>::type());
198 template<
class T1,
class T2>
199 void pack(
const std::pair<T1,T2>& data, std::vector<char>& buffer,
int& position,
200 Opm::Parallel::MPIComm comm);
203 void pack(
const std::optional<T>& data, std::vector<char>& buffer,
int& position,
204 Opm::Parallel::MPIComm comm);
206 template<
class T,
class A>
207 void pack(
const std::vector<T,A>& data, std::vector<char>& buffer,
int& position,
208 Opm::Parallel::MPIComm comm);
211 void pack(
const std::vector<bool,A>& data, std::vector<char>& buffer,
int& position,
212 Opm::Parallel::MPIComm comm);
214 template<
class... Ts>
215 void pack(
const std::tuple<Ts...>& data, std::vector<char>& buffer,
216 int& position, Opm::Parallel::MPIComm comm);
218 template<
class K,
class C,
class A>
219 void pack(
const std::set<K,C,A>& data,
220 std::vector<char>& buffer,
int& position,
221 Opm::Parallel::MPIComm comm);
223 template<
class T,
class H,
class KE,
class A>
224 void pack(
const std::unordered_set<T,H,KE,A>& data,
225 std::vector<char>& buffer,
int& position,
226 Opm::Parallel::MPIComm comm);
228 template<
class T,
size_t N>
229 void pack(
const std::array<T,N>& data, std::vector<char>& buffer,
int& position,
230 Opm::Parallel::MPIComm comm);
232 template<
class T1,
class T2,
class C,
class A>
233 void pack(
const std::map<T1,T2,C,A>& data, std::vector<char>& buffer,
int& position,
234 Opm::Parallel::MPIComm comm);
236 template<
class T1,
class T2,
class H,
class P,
class A>
237 void pack(
const std::unordered_map<T1,T2,H,P,A>& data, std::vector<char>& buffer,
int& position,
238 Opm::Parallel::MPIComm comm);
240 void pack(
const char* str, std::vector<char>& buffer,
int& position,
241 Opm::Parallel::MPIComm comm);
246 void unpack(T*,
const std::size_t&, std::vector<char>&,
int&,
247 Opm::Parallel::MPIComm, std::integral_constant<bool, false>);
250 void unpack(T* data,
const std::size_t& l, std::vector<char>& buffer,
int& position,
251 Opm::Parallel::MPIComm comm,
252 std::integral_constant<bool, true>);
255 void unpack(T* data,
const std::size_t& l, std::vector<char>& buffer,
int& position,
256 Opm::Parallel::MPIComm comm);
259 void unpack(T&, std::vector<char>&,
int&,
260 Opm::Parallel::MPIComm, std::integral_constant<bool, false>)
262 OPM_THROW(std::logic_error,
"Packing not (yet) supported for this non-pod type.");
266 void unpack(T& data, std::vector<char>& buffer,
int& position,
267 Opm::Parallel::MPIComm comm, std::integral_constant<bool, true>)
270 MPI_Unpack(buffer.data(), buffer.size(), &position, &data, 1,
271 Dune::MPITraits<T>::getType(), comm);
281 void unpack(T& data, std::vector<char>& buffer,
int& position,
282 Opm::Parallel::MPIComm comm)
284 unpack(data, buffer, position, comm,
typename std::is_pod<T>::type());
287 template<
class T1,
class T2>
288 void unpack(std::pair<T1,T2>& data, std::vector<char>& buffer,
int& position,
289 Opm::Parallel::MPIComm comm);
292 void unpack(std::optional<T>& data, std::vector<char>& buffer,
int& position,
293 Opm::Parallel::MPIComm comm);
295 template<
class T,
class A>
296 void unpack(std::vector<T,A>& data, std::vector<char>& buffer,
int& position,
297 Opm::Parallel::MPIComm comm);
300 void unpack(std::vector<bool,A>& data, std::vector<char>& buffer,
int& position,
301 Opm::Parallel::MPIComm comm);
303 template<
class... Ts>
304 void unpack(std::tuple<Ts...>& data, std::vector<char>& buffer,
305 int& position, Opm::Parallel::MPIComm comm);
307 template<
class K,
class C,
class A>
308 void unpack(std::set<K,C,A>& data,
309 std::vector<char>& buffer,
int& position,
310 Opm::Parallel::MPIComm comm);
312 template<
class T,
class H,
class KE,
class A>
313 void unpack(std::unordered_set<T,H,KE,A>& data,
314 std::vector<char>& buffer,
int& position,
315 Opm::Parallel::MPIComm comm);
317 template<
class T,
size_t N>
318 void unpack(std::array<T,N>& data, std::vector<char>& buffer,
int& position,
319 Opm::Parallel::MPIComm comm);
321 template<
class T1,
class T2,
class C,
class A>
322 void unpack(std::map<T1,T2,C,A>& data, std::vector<char>& buffer,
int& position,
323 Opm::Parallel::MPIComm comm);
325 template<
class T1,
class T2,
class H,
class P,
class A>
326 void unpack(std::unordered_map<T1,T2,H,P,A>& data, std::vector<char>& buffer,
int& position,
327 Opm::Parallel::MPIComm comm);
329 void unpack(
char* str, std::size_t length, std::vector<char>& buffer,
int& position,
330 Opm::Parallel::MPIComm comm);
334 #define ADD_PACK_PROTOTYPES(T) \
335 std::size_t packSize(const T& data, Opm::Parallel::MPIComm comm); \
336 void pack(const T& data, std::vector<char>& buffer, int& position, \
337 Opm::Parallel::MPIComm comm); \
338 void unpack(T& data, std::vector<char>& buffer, int& position, \
339 Opm::Parallel::MPIComm comm);
341 ADD_PACK_PROTOTYPES(data::AquiferData)
342 ADD_PACK_PROTOTYPES(data::CarterTracyData)
343 ADD_PACK_PROTOTYPES(data::CellData)
344 ADD_PACK_PROTOTYPES(data::Connection)
345 ADD_PACK_PROTOTYPES(data::CurrentControl)
346 ADD_PACK_PROTOTYPES(data::FetkovichData)
347 ADD_PACK_PROTOTYPES(data::Rates)
348 ADD_PACK_PROTOTYPES(data::Segment)
349 ADD_PACK_PROTOTYPES(data::Solution)
350 ADD_PACK_PROTOTYPES(data::GuideRateValue)
351 ADD_PACK_PROTOTYPES(data::GroupConstraints)
352 ADD_PACK_PROTOTYPES(data::GroupGuideRates)
353 ADD_PACK_PROTOTYPES(data::GroupData)
354 ADD_PACK_PROTOTYPES(data::NodeData)
355 ADD_PACK_PROTOTYPES(data::GroupAndNetworkValues)
356 ADD_PACK_PROTOTYPES(data::NumericAquiferData)
357 ADD_PACK_PROTOTYPES(data::Well)
358 ADD_PACK_PROTOTYPES(data::Wells)
359 ADD_PACK_PROTOTYPES(RestartKey)
360 ADD_PACK_PROTOTYPES(RestartValue)
361 ADD_PACK_PROTOTYPES(std::string)
362 ADD_PACK_PROTOTYPES(time_point)
364 template<
typename T,
typename... Args>
365 void variadic_packsize(
size_t& size, Parallel::Communication comm, T& first, Args&&... args)
367 size += packSize(first, comm);
368 if constexpr (
sizeof...(args) > 0)
369 variadic_packsize(size, comm, std::forward<Args>(args)...);
372 template<typename T, typename... Args>
373 void variadic_pack(
int& pos, std::vector<
char>& buffer, Parallel::Communication comm, T& first, Args&&... args)
375 pack(first, buffer, pos, comm);
376 if constexpr (
sizeof...(args) > 0)
377 variadic_pack(pos, buffer, comm, std::forward<Args>(args)...);
380 template<typename T, typename... Args>
381 void variadic_unpack(
int& pos, std::vector<
char>& buffer, Parallel::Communication comm, T& first, Args&&... args)
383 unpack(first, buffer, pos, comm);
384 if constexpr (
sizeof...(args) > 0)
385 variadic_unpack(pos, buffer, comm, std::forward<Args>(args)...);
389 template<
typename... Args>
390 void broadcast(Parallel::Communication comm,
int root, Args&&... args)
392 if (comm.size() == 1)
396 if (comm.rank() == root)
397 variadic_packsize(size, comm, std::forward<Args>(args)...);
399 comm.broadcast(&size, 1, root);
400 std::vector<char> buffer(size);
401 if (comm.rank() == root) {
403 variadic_pack(pos, buffer, comm, std::forward<Args>(args)...);
405 comm.broadcast(buffer.data(), size, root);
406 if (comm.rank() != root) {
408 variadic_unpack(pos, buffer, comm, std::forward<Args>(args)...);
412 template<
typename... Args>
413 void broadcast(Parallel::Communication,
int, Args&&...)
419 RestartValue loadParallelRestart(
const EclipseIO* eclIO, Action::State& actionState, SummaryState& summaryState,
420 const std::vector<RestartKey>& solutionKeys,
421 const std::vector<RestartKey>& extraKeys,
422 Parallel::Communication comm);
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27