MADNESS  0.10.1
parallel_dc_archive.h
Go to the documentation of this file.
1 #ifndef MAD_PARALLEL_DC_ARCHIVE_H_INCLUDED
2 #define MAD_PARALLEL_DC_ARCHIVE_H_INCLUDED
3 
7 
8 namespace madness {
9 
10 
11 
12  namespace archive {
13 
15  public:
16  using keyT = long;
17  private:
21  containerT& dc; // lifetime???
22  std::vector<unsigned char> v;
24 
25  public:
26 
29  , key(key)
30  , dc(dc)
31  , v()
32  , ar(v)
33  {}
34 
36  {
37  close();
38  }
39 
41  return ar;
42  }
43  template <class T>
44  inline
45  typename std::enable_if< madness::is_trivially_serializable<T>::value, void >::type
46  store(const T* t, long n) const {
47  MADNESS_CHECK(subworld.rank() == 0);
48  ar.store(t, n);
49  }
50 
51  void open() {}
52 
53  void flush() {}
54 
55  void close() {
56  if (subworld.rank() == 0) dc.replace(key,v);
57  }
58  };
59 
61  using keyT = long;
64  std::vector<unsigned char> v;
66 
67  public:
68  ContainerRecordInputArchive(World& subworld, const containerT& dc, const keyT& key)
69  : rank(subworld.rank())
70  , v()
71  , ar(v)
72  {
73  if (rank==0) {
74  containerT::const_iterator it = dc.find(key).get();
75  if (it != dc.end()) {
76  v = it->second;
77  }
78  else {
79  std::cout << "key " << key << " in world " << subworld.id()
80  << "dc.world " << dc.get_world().id() << std::endl;
81  MADNESS_EXCEPTION("record not found", key);
82  }
83  }
84  }
85 
87  {}
88 
89  template <class T>
90  inline
91  typename std::enable_if< madness::is_trivially_serializable<T>::value, void >::type
92  load(T* t, long n) const {
93  MADNESS_CHECK(rank == 0);
94  ar.load(t,n);
95  }
96 
97  void open() {}
98 
99  void flush() {}
100 
101  void close() {}
102  };
103 
104 
105  /// Implementation of functions for storing the pre/postamble in ContainerRecord archives.
106 
107  /// \attention No type checking over Vector buffers, for efficiency.
108  /// \tparam T The data type.
109  template <class T>
111  /// Store the preamble.
112 
113  /// \param[in] ar The archive.
114  static void preamble_store(const ContainerRecordOutputArchive& ar) {};
115 
116  /// Store the postamble.
117 
118  /// \param[in] ar The archive.
119  static inline void postamble_store(const ContainerRecordOutputArchive& ar) {};
120  };
121 
122  /// Implementation of functions for loading the pre/postamble in ContainerRecord archives.
123 
124  /// \attention No type checking over ContainerRecord buffers, for efficiency.
125  /// \tparam T The data type.
126  template <class T>
128  /// Load the preamble.
129 
130  /// \param[in] ar The archive.
131  static inline void preamble_load(const ContainerRecordInputArchive& ar) {};
132 
133  /// Load the postamble.
134 
135  /// \param[in] ar The archive.
136  static inline void postamble_load(const ContainerRecordInputArchive& ar) {};
137  };
138 
139  // Forward storing to VectorOutputArchive
140  template <class keyT, class valueT>
143  std::vector<unsigned char> v;
144  VectorOutputArchive dummyar(v,0);
145  const int me = ar.get_world()->rank();
146 
147  // Need to pass local archive by reference
148  ParallelOutputArchive<VectorOutputArchive> par(*(ar.get_world()), (me==0) ? ar.local_archive().get_archive() : dummyar);
149  par & t;
150 
151  }
152  };
153 
154 
155 
156  }
157 
158 
159 }
160 
161 #endif
This header should include pretty much everything needed for the parallel runtime.
Iterator for distributed container wraps the local iterator.
Definition: worlddc.h:244
Makes a distributed container with specified attributes.
Definition: worlddc.h:866
bool find(accessor &acc, const keyT &key)
Write access to LOCAL value by key. Returns true if found, false otherwise (always false for remote).
Definition: worlddc.h:987
void replace(const pairT &datum)
Inserts/replaces key+value pair (non-blocking communication if key not local)
Definition: worlddc.h:974
iterator end()
Returns an iterator past the end of the local data (no communication)
Definition: worlddc.h:1084
World & get_world() const
Returns the world associated with this container.
Definition: worlddc.h:955
A parallel world class.
Definition: world.h:132
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition: world.h:318
unsigned long id() const
Definition: world.h:313
Base class for input archive classes.
Definition: archive.h:374
Base class for output archive classes.
Definition: archive.h:382
Archive & local_archive() const
Returns a reference to the local archive.
Definition: parallel_archive.h:248
World * get_world() const
Returns a pointer to the world.
Definition: parallel_archive.h:130
Definition: parallel_dc_archive.h:60
ProcessID rank
Definition: parallel_dc_archive.h:63
void close()
Definition: parallel_dc_archive.h:101
long keyT
Definition: parallel_dc_archive.h:61
void open()
Definition: parallel_dc_archive.h:97
std::vector< unsigned char > v
Definition: parallel_dc_archive.h:64
ContainerRecordInputArchive(World &subworld, const containerT &dc, const keyT &key)
Definition: parallel_dc_archive.h:68
void flush()
Definition: parallel_dc_archive.h:99
std::enable_if< madness::is_trivially_serializable< T >::value, void >::type load(T *t, long n) const
Definition: parallel_dc_archive.h:92
VectorInputArchive ar
Definition: parallel_dc_archive.h:65
~ContainerRecordInputArchive()
Definition: parallel_dc_archive.h:86
Definition: parallel_dc_archive.h:14
ContainerRecordOutputArchive(World &subworld, containerT &dc, const keyT &key)
Definition: parallel_dc_archive.h:27
std::vector< unsigned char > v
Definition: parallel_dc_archive.h:22
void open()
Definition: parallel_dc_archive.h:51
void flush()
Definition: parallel_dc_archive.h:53
VectorOutputArchive ar
Definition: parallel_dc_archive.h:23
~ContainerRecordOutputArchive()
Definition: parallel_dc_archive.h:35
VectorOutputArchive & get_archive()
Definition: parallel_dc_archive.h:40
keyT key
Definition: parallel_dc_archive.h:20
World & subworld
Definition: parallel_dc_archive.h:19
long keyT
Definition: parallel_dc_archive.h:16
containerT & dc
Definition: parallel_dc_archive.h:21
std::enable_if< madness::is_trivially_serializable< T >::value, void >::type store(const T *t, long n) const
Definition: parallel_dc_archive.h:46
void close()
Definition: parallel_dc_archive.h:55
An archive for storing local or parallel data wrapping a BinaryFstreamOutputArchive.
Definition: parallel_archive.h:321
Wraps an archive around an STL vector for input.
Definition: vector_archive.h:101
std::enable_if< madness::is_trivially_serializable< T >::value, void >::type load(T *t, long n) const
Load data from the vector.
Definition: vector_archive.h:121
Wraps an archive around an STL vector for output.
Definition: vector_archive.h:55
std::enable_if< madness::is_trivially_serializable< T >::value, void >::type store(const T *t, long n) const
Appends data to the end of the vector.
Definition: vector_archive.h:79
auto T(World &world, response_space &f) -> response_space
Definition: global_functions.cc:34
static const double v
Definition: hatom_sf_dirac.cc:20
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition: madness_exception.h:190
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition: madness_exception.h:119
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
std::string type(const PairType &n)
Definition: PNOParameters.h:18
static void postamble_load(const ContainerRecordInputArchive &ar)
Load the postamble.
Definition: parallel_dc_archive.h:136
static void preamble_load(const ContainerRecordInputArchive &ar)
Load the preamble.
Definition: parallel_dc_archive.h:131
static void postamble_store(const ContainerRecordOutputArchive &ar)
Store the postamble.
Definition: parallel_dc_archive.h:119
static void preamble_store(const ContainerRecordOutputArchive &ar)
Store the preamble.
Definition: parallel_dc_archive.h:114
Default implementation of the pre/postamble for type checking.
Definition: archive.h:509
static void store(const ParallelOutputArchive< ContainerRecordOutputArchive > &ar, const WorldContainer< keyT, valueT > &t)
Definition: parallel_dc_archive.h:142
Default store of an object via serialize(ar, t).
Definition: archive.h:611
std::pair< int, double > valueT
Definition: test_binsorter.cc:6
int me
Definition: test_binsorter.cc:10
Implements an archive wrapping an STL vector.
Implements WorldContainer.
int ProcessID
Used to clearly identify process number/rank.
Definition: worldtypes.h:43