Line data Source code
1 1 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : /// \file 5 : /// PUP routines for new C+11 STL containers and other standard 6 : /// library objects Charm does not provide implementations for 7 : 8 : #pragma once 9 : 10 : #include <cstddef> 11 : #include <map> 12 : #include <pup.h> 13 : #include <pup_stl.h> 14 : #include <utility> 15 : 16 : namespace PUP { 17 : 18 : /// \ingroup ParallelGroup 19 : /// Serialization of std::atomic for Charm++ 20 : template <typename T> 21 : void pup(PUP::er& p, std::atomic<T>& d) { // NOLINT 22 : T local_d; 23 : if (p.isUnpacking()) { 24 : p | local_d; 25 : d.store(std::move(local_d)); 26 : } else { 27 : local_d = d.load(); 28 : p | local_d; 29 : } 30 : } 31 : 32 : /// \ingroup ParallelGroup 33 : /// Serialization of std::atomic for Charm++ 34 : template <typename T> 35 : void operator|(er& p, std::atomic<T>& d) { // NOLINT 36 : pup(p, d); 37 : } 38 : } // namespace PUP 39 : 40 : /// \ingroup ParallelGroup 41 : /// Temporary serialization function for a `std::map` with a comparator to 42 : /// circumvent a charm bug. 43 : template <typename K, typename T, typename C> 44 1 : void pup_override(PUP::er& p, std::map<K, T, C>& m) { 45 : if (p.isUnpacking()) { 46 : size_t size; 47 : std::pair<K, T> pair; 48 : p | size; 49 : for (size_t i = 0; i < size; ++i) { 50 : p | pair; 51 : m.insert(pair); 52 : } 53 : } else { 54 : size_t size = m.size(); 55 : p | size; 56 : for (auto& val : m) { 57 : p | val; 58 : } 59 : } 60 : }