Fenix @develop
 
Loading...
Searching...
No Matches
group.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_GROUP_H__
57#define __FENIX_DATA_GROUP_H__
58
59#include <unordered_map>
60#include <map>
61#include <memory>
62#include <vector>
63#include <set>
64#include <source_location>
65
66#include <mpi.h>
67#include "fenix.h"
68#include "fenix/data/member.hpp"
69#include "fenix/data/subset.hpp"
70#include "fenix/mpixx/comm.hpp"
71#include "fenix/mpixx/group.hpp"
72
73#define __FENIX_DEFAULT_GROUP_SIZE 32
74
75namespace fenix::data {
76
77//We keep basic bookkeeping info here, policy specific
78//information is kept by the policy's data type.
79struct DataGroup {
80 DataGroup(int groupid, MPI_Comm c, int timestart, int depth, int policy);
81
82 virtual ~DataGroup() = default;
83
84 // Create the cohort group for this policy
85 virtual mpixx::Group create_cohort() = 0;
86
87 // Synchronize timestamps across cohort members
88 virtual void sync_timestamps();
89
90 // Initialize group after construction (creates cohort_comm, syncs state)
91 virtual void init();
92
93 int groupid;
94 mpixx::CommRef comm;
95 int comm_size;
96 int current_rank;
97 int timestart;
98 int timestamp;
99 int depth;
100 int policy_name;
101
102 std::set<std::shared_ptr<DataMember>, DataMemberIdComparator> members;
103 std::vector<int> member_order;
104
105 std::set<int, std::greater<int>> timestamps; // Reverse sorted: newest first
106
107 mpixx::Group cohort;
108 mpixx::Comm cohort_comm;
109 int cohort_size = -1;
110 int cohort_rank = -1;
111
112 std::vector<int> get_member_ids();
113 //Search for id, returning null if not found.
114 DataMember* search_member(int id);
115 //As search_member, but throw if not found
116 DataMember* find_member(
117 int id, std::source_location loc = std::source_location::current()
118 );
119 void member_create(int id, void* data, int count, MPI_Datatype datatype);
120 void member_create(
121 int id, void* data, int count, MPI_Datatype datatype, SerializeFunc& s
122 );
123 void member_create(const util::DataBuffer& serialized);
124
125 virtual void member_delete(int memberid);
126
127 // Create and emplace a policy-specific member into members map
128 virtual void emplace_member(DataMember&& member);
129
130 virtual void get_redundant_policy(int* name, void* value) = 0;
131
132 virtual void member_repair(int member_id);
133 virtual void member_restore_from_rank(
134 int member_id, void* target_bugger, int max, int timestamp, int source_rank
135 ) = 0;
136
137 // Default implementations using timestamps
138 virtual void commit();
139 virtual void snapshot_delete(int timestamp);
140 virtual int get_number_of_snapshots();
141 virtual int get_snapshot_at_position(int position);
142 virtual std::vector<int> get_snapshots();
143
144 // Revoke cohort_comm (called before recovery to invalidate communicator)
145 virtual void revoke();
146
147 const mpixx::Group& get_cohort() const { return cohort; }
148
149 // String representation, for debugging
150 std::string str();
151};
152
154 using is_transparent = void; // Enables heterogeneous lookup
155
156 bool operator()(
157 const std::shared_ptr<DataGroup>& a, const std::shared_ptr<DataGroup>& b
158 ) const;
159
160 bool operator()(const std::shared_ptr<DataGroup>& a, int id) const;
161
162 bool operator()(int id, const std::shared_ptr<DataGroup>& a) const;
163};
164
165} //end namespace fenix::data
166
167#endif // FENIX_DATA_GROUP_H
Definition member.hpp:76
Definition buffer.hpp:68
Definition comm.hpp:99
Definition comm.hpp:16
Definition group.hpp:21
Contains all API function calls and Fenix types. This is the only header file a user should include.
Definition group.hpp:153
Definition group.hpp:79
Definition member.hpp:211