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