Fenix @develop
 
Loading...
Searching...
No Matches
member.hpp
1/*
2//@HEADER
3// ************************************************************************
4//
5//
6// _|_|_|_| _|_|_|_| _| _| _|_|_| _| _|
7// _| _| _|_| _| _| _| _|
8// _|_|_| _|_|_| _| _| _| _| _|
9// _| _| _| _|_| _| _| _|
10// _| _|_|_|_| _| _| _|_|_| _| _|
11//
12//
13//
14//
15// Copyright (C) 2016 Rutgers University and Sandia Corporation
16//
17// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18// the U.S. Government retains certain rights in this software.
19//
20// Redistribution and use in source and binary forms, with or without
21// modification, are permitted provided that the following conditions are
22// met:
23//
24// 1. Redistributions of source code must retain the above copyright
25// notice, this list of conditions and the following disclaimer.
26//
27// 2. Redistributions in binary form must reproduce the above copyright
28// notice, this list of conditions and the following disclaimer in the
29// documentation and/or other materials provided with the distribution.
30//
31// 3. Neither the name of the Corporation nor the names of the
32// contributors may be used to endorse or promote products derived from
33// this software without specific prior written permission.
34//
35// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
36// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
39// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
40// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
41// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
42// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
43// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
44// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46//
47// Author Marc Gamell, Eric Valenzuela, Keita Teranishi, Manish Parashar
48// Michael Heroux, and Matthew Whitlock
49//
50// Questions? Contact Keita Teranishi (knteran@sandia.gov) and
51// Marc Gamell (mgamell@cac.rutgers.edu)
52//
53// ************************************************************************
54//@HEADER
55*/
56#ifndef __FENIX_DATA_MEMBER_H__
57#define __FENIX_DATA_MEMBER_H__
58
59#include <optional>
60#include <deque>
61#include <memory>
62#include <source_location>
63
64#include "fenix/data/subset.hpp"
65#include "fenix/data/util/buffer.hpp"
66#include "fenix/data/snapshot.hpp"
67#include "fenix/data/util/data_ref.hpp"
68#include "fenix/data/util/serializer.hpp"
69#include "fenix/tasks/task.hpp"
70#include "fenix/mpixx/datatype.hpp"
71
72namespace fenix::data {
73
74struct DataGroup;
75
77 public:
79 using CommitSet =
80 std::set<std::unique_ptr<DataSnapshot>, DataSnapshotTimestampComparator>;
81 using CommitIter = CommitSet::iterator;
82
83 DataMember() = delete;
84
86 DataGroup& g, int id, void* data, int count, MPI_Datatype datatype,
87 int depth, std::optional<SerializeFunc> s = {}
88 );
89 DataMember(DataGroup& g, const util::DataBuffer& serialized, int depth);
90
91 DataMember(DataMember&& other);
92
93 // Serialize member metadata (memberid, count, datatype)
94 util::DataBuffer serialize() const;
95
96 int memberid = -1;
97 mpixx::Datatype datatype_;
98 util::DataRef user_data;
99 DataGroup* group;
100
101 int elm_count() const;
102
103 // Create a (possibly policy-specific) snapshot with specified capacity
104 virtual std::unique_ptr<DataSnapshot> create_snapshot(
105 int size, int max_count
106 );
107
108 // Data operations with default local-only implementations
109 virtual void stage(const DataSubset& subset);
110 virtual void stage_inplace(void* buf, const DataSubset& subset);
111 virtual void stage_begin(FILE** fp);
112 virtual void stage_begin(std::iostream** strm);
113 virtual void stage_end();
114 virtual void load_begin(FILE** fp, int timestamp, DataSubset& subset);
115 virtual void load_begin(
116 std::iostream** strm, int timestamp, DataSubset& subset
117 );
118 virtual void load_end();
119 virtual void load(
120 void* target, int target_count, int timestamp, DataSubset& data_found
121 );
122 virtual int store(const DataSubset& subset);
123 virtual int storev(const DataSubset& subset);
124 virtual tasks::Task<int> istore(const DataSubset& subset);
125 virtual tasks::Task<int> istorev(const DataSubset& subset);
126 virtual tasks::Task<int> iprotect();
127 virtual void repair();
128 virtual void commit(int timestamp);
129 virtual void snapshot_delete(int timestamp);
130
131 void snapshot_delete(CommitIter it);
132
133 virtual void attr_set(int attr, void* value);
134 virtual void attr_get(int attr, void* value);
135
136 // Returns true if staging snapshot contains unstored data
137 virtual bool has_unstored_data();
138
139 // Essentially an inplace allgather within the cohort - each rank sends the
140 // subset at its cohort rank index.
141 tasks::Task<void> exchange_subsets(std::vector<DataSubset>& subsets);
142
143 // Broadcast subset vector from root to all ranks in cohort
144 tasks::Task<void> broadcast_subsets(
145 const std::vector<DataSubset>& input, std::vector<DataSubset>& output,
146 int root
147 );
148 tasks::Task<void> broadcast_subsets(
149 std::vector<DataSubset>& subsets, int root
150 ) {
151 return broadcast_subsets(subsets, subsets, root);
152 }
153
154 virtual ~DataMember() = default;
155
156 // Must be called AFTER this class's constructor completes, else virtual
157 // emplace_snapshot overrides won't be used.
158 void init_snapshots();
159
160 std::optional<SerializeFunc> ser_func;
161
162 // Set iff stage_begin called with no matching stage_end
163 std::optional<Serializer> open_serializer;
164
165 protected:
166 // Snapshot storage - three separate locations
167
168 // Current uncommitted staging snapshot
169 std::unique_ptr<DataSnapshot> stage_snapshot_;
170
171 // Committed snapshots ordered by timestamp (oldest to newest)
172 CommitSet commit_snapshots_;
173
174 // Pool of unused snapshots ready for reuse
175 std::vector<std::unique_ptr<DataSnapshot>> avail_snapshots_;
176
177 // Maximum allowed snapshots (from group depth)
178 int depth_ = 0;
179
186
187 // search for committed timestamp, returning null if not found
188 // Throws if timestamp is not valid (including FENIX_DATA_SNAPSHOT_ALL)
189 DataSnapshot* search_snapshot(
190 int timestamp, std::source_location loc = std::source_location::current()
191 );
192 // As search_snapshot, but throw if not found
193 DataSnapshot* find_snapshot(
194 int timestamp, std::source_location loc = std::source_location::current()
195 );
196
197 // Remove committed snapshots not in the provided timestamp set
198 // Used by DataGroup::sync_timestamps() to clean up after recovery
199 void cleanup_timestamps(
200 const std::set<int, std::greater<int>>& valid_timestamps
201 );
202
203 friend class DataGroup;
204
205 private:
206 // Note that Serializers aren't guaranteed to have written their data to the
207 // buffer until their destructor is called. So these should usually only be
208 // used to construct temporaries that go to a subset's copy_data call
209};
210
212 using is_transparent = void; // Enables heterogeneous lookup
213
214 bool operator()(
215 const std::shared_ptr<DataMember>& a, const std::shared_ptr<DataMember>& b
216 ) const {
217 return a->memberid < b->memberid;
218 }
219
220 bool operator()(const std::shared_ptr<DataMember>& a, int id) const {
221 return a->memberid < id;
222 }
223
224 bool operator()(int id, const std::shared_ptr<DataMember>& a) const {
225 return id < a->memberid;
226 }
227};
228
229} // namespace fenix::data
230#endif // FENIX_DATA_MEMBER_H
Definition member.hpp:76
DataSnapshot & current_snapshot()
Get reference to the current staging snapshot.
Definition member.cpp:539
Definition snapshot.hpp:17
Definition buffer.hpp:68
Definition data_ref.hpp:50
Definition serializer.hpp:14
Definition datatype.hpp:20
Definition task.hpp:15
Definition subset.hpp:152
Definition group.hpp:78
Definition member.hpp:211