vt 1.6.0
(Virtual Transport)
Loading...
Searching...
No Matches
collective_alg.h
Go to the documentation of this file.
1/*
2//@HEADER
3// *****************************************************************************
4//
5// collective_alg.h
6// DARMA/vt => Virtual Transport
7//
8// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
9// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
10// Government retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are met:
14//
15// * Redistributions of source code must retain the above copyright notice,
16// this list of conditions and the following disclaimer.
17//
18// * Redistributions in binary form must reproduce the above copyright notice,
19// this list of conditions and the following disclaimer in the documentation
20// and/or other materials provided with the distribution.
21//
22// * Neither the name of the copyright holder nor the names of its
23// contributors may be used to endorse or promote products derived from this
24// software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36// POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact darma@sandia.gov
39//
40// *****************************************************************************
41//@HEADER
42*/
43
44#if !defined INCLUDED_VT_COLLECTIVE_COLLECTIVE_ALG_H
45#define INCLUDED_VT_COLLECTIVE_COLLECTIVE_ALG_H
46
47#include "vt/config.h"
58
59#include <memory>
60#include <unordered_map>
61
62namespace vt { namespace collective {
63
65
76 runtime::component::Component<CollectiveAlg>,
78 virtual barrier::Barrier,
79 virtual scatter::Scatter
80{
81/*----------------------------------------------------------------------------
82 *
83 * CollectiveAlg class implements all collective operations:
84 * 1) Barrier
85 * 2) One to all: broadcast, scatter
86 * 3) All to one: reduce, gather
87 * 4) All to all: allreduce, allgather, alltoall, reduce_scatter
88 * 5) Scan etc.
89 *
90 *------------------------------------------------------------------------------
91 */
92
94
95 //----------------------------------------------------------------------------
96 //----------------------------------------------------------------------------
97
98
99 std::string name() override { return "Collective"; }
100
101public:
111 CollectiveScope makeCollectiveScope(TagType scope_tag = no_tag);
112
113private:
114 friend struct CollectiveScope;
115
118 bool in_is_user_tag, TagType in_scope, TagType in_seq, NodeType in_root
119 ) : is_user_tag_(in_is_user_tag),
120 scope_(in_scope),
121 seq_(in_seq),
122 root_(in_root)
123 { }
124
125 bool is_user_tag_ = false;
126 TagType scope_ = no_tag;
127 TagType seq_ = no_tag;
128 NodeType root_ = uninitialized_destination;
129 };
130
131 static void runCollective(CollectiveMsg* msg);
132
133public:
144 bool isDeallocated(bool is_user_tag, TagType scope_bits) const;
145
146 template <typename SerializerT>
147 void serialize(SerializerT& s) {
152 }
153
154private:
155 using ScopeMapType = std::unordered_map<TagType, std::unique_ptr<detail::ScopeImpl>>;
156
160 std::vector<MsgSharedPtr<CollectiveMsg>> postponed_collectives_;
161};
162
164
165}} // end namespace vt::collective
166
167namespace vt {
168
169extern collective::CollectiveAlg *theCollective();
170
171} //end namespace vt
172
175
176#endif /*INCLUDED_VT_COLLECTIVE_COLLECTIVE_ALG_H*/
Definition barrier.cc:49
constexpr CollectiveAlgType const fst_collective_alg
Definition collective_alg.h:64
reduce::operators::ReduceTMsg< NoneType > ReduceNoneMsg
Definition default_msg.h:244
reduce::ReduceMsg ReduceMsg
Definition collective_alg.h:163
Definition activefn.h:51
int32_t TagType
Used to hold an tag, e.g., on messages or reduces.
Definition types_type.h:73
collective::CollectiveAlg * theCollective()
Definition runtime_get.cc:101
PhysicalResourceType NodeType
Used to hold the current node/rank or the number of nodes.
Definition types_type.h:57
uint64_t CollectiveAlgType
Used to identify a collective operation.
Definition types_type.h:77
Definition collective_alg.h:116
NodeType root_
Definition collective_alg.h:128
TagType scope_
Definition collective_alg.h:126
CollectiveMsg(bool in_is_user_tag, TagType in_scope, TagType in_seq, NodeType in_root)
Definition collective_alg.h:117
bool is_user_tag_
Definition collective_alg.h:125
TagType seq_
Definition collective_alg.h:127
void serialize(SerializerT &s)
Definition collective_alg.h:147
CollectiveScope makeCollectiveScope(TagType scope_tag=no_tag)
Create a new scope for sequenced MPI operations. Each scope has a distinct, independent collective se...
Definition collective_alg.cc:57
ScopeMapType user_scope_
Definition collective_alg.h:158
std::string name() override
Get the name of the component.
Definition collective_alg.h:99
friend struct CollectiveScope
Definition collective_alg.h:114
ScopeMapType system_scope_
Definition collective_alg.h:159
static void runCollective(CollectiveMsg *msg)
Definition collective_alg.cc:136
CollectiveAlg()
Definition collective_alg.cc:51
std::unordered_map< TagType, std::unique_ptr< detail::ScopeImpl > > ScopeMapType
Definition collective_alg.h:155
std::vector< MsgSharedPtr< CollectiveMsg > > postponed_collectives_
Definition collective_alg.h:160
TagType next_system_scope_
Definition collective_alg.h:157
bool isDeallocated(bool is_user_tag, TagType scope_bits) const
Check if a scope has been deallocated.
Definition collective_alg.cc:77
A distinct scope for enqueuing ordered collective operations.
Definition collective_scope.h:112
Perform a collective barrier that is safe to use with VT handlers in flight.
Definition barrier.h:80
Manage distinct scopes for reductions.
Definition reduce_manager.h:63
Definition reduce_msg.h:79
Scatter data across all nodes from a single origin.
Definition scatter.h:67
Component class for a generic VT runtime module, CRTP'ed over the component's actual type
Definition component.h:95