vt  1.5.0
(Virtual Transport)
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"
49 #include "vt/activefn/activefn.h"
50 #include "vt/messaging/message.h"
58 
59 #include <memory>
60 #include <unordered_map>
61 
62 namespace vt { namespace collective {
63 
65 
75 struct CollectiveAlg :
76  runtime::component::Component<CollectiveAlg>,
77  virtual reduce::ReduceManager,
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 
93  CollectiveAlg();
94 
95  //----------------------------------------------------------------------------
96  //----------------------------------------------------------------------------
97 
98 
99  std::string name() override { return "Collective"; }
100 
101 public:
111  CollectiveScope makeCollectiveScope(TagType scope_tag = no_tag);
112 
113 private:
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 
133 public:
144  bool isDeallocated(bool is_user_tag, TagType scope_bits) const;
145 
146  template <typename SerializerT>
147  void serialize(SerializerT& s) {
149  | user_scope_
150  | system_scope_
152  }
153 
154 private:
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 
167 namespace vt {
168 
169 extern collective::CollectiveAlg *theCollective();
170 
171 } //end namespace vt
172 
175 
176 #endif /*INCLUDED_VT_COLLECTIVE_COLLECTIVE_ALG_H*/
vt::collective::CollectiveAlg::ScopeMapType
std::unordered_map< TagType, std::unique_ptr< detail::ScopeImpl > > ScopeMapType
Definition: collective_alg.h:155
vt::collective::CollectiveAlg::CollectiveMsg::scope_
TagType scope_
Definition: collective_alg.h:126
vt::collective::CollectiveAlg::CollectiveAlg
CollectiveAlg()
Definition: collective_alg.cc:51
vt::collective::CollectiveAlg::runCollective
static void runCollective(CollectiveMsg *msg)
Definition: collective_alg.cc:136
vt::collective::CollectiveScope
A distinct scope for enqueuing ordered collective operations.
Definition: collective_scope.h:112
vt::collective::reduce::ReduceManager
Manage distinct scopes for reductions.
Definition: reduce_manager.h:63
hash_tuple.h
vt::collective::CollectiveAlg::CollectiveMsg::CollectiveMsg
CollectiveMsg(bool in_is_user_tag, TagType in_scope, TagType in_seq, NodeType in_root)
Definition: collective_alg.h:117
reduce_manager.h
activefn.h
vt::collective::CollectiveAlg::serialize
void serialize(SerializerT &s)
Definition: collective_alg.h:147
vt::collective::CollectiveAlg::system_scope_
ScopeMapType system_scope_
Definition: collective_alg.h:159
vt::collective::CollectiveAlg::isDeallocated
bool isDeallocated(bool is_user_tag, TagType scope_bits) const
Check if a scope has been deallocated.
Definition: collective_alg.cc:77
vt::collective::reduce::ReduceMsg
Definition: reduce_msg.h:75
default_msg.h
vt::collective::CollectiveAlg::CollectiveMsg::root_
NodeType root_
Definition: collective_alg.h:128
vt::collective::CollectiveAlg::CollectiveMsg
Definition: collective_alg.h:116
reduce_manager.impl.h
vt::NodeType
PhysicalResourceType NodeType
Used to hold the current node/rank or the number of nodes.
Definition: types_type.h:57
vt::TagType
int32_t TagType
Used to hold an tag, e.g., on messages or reduces.
Definition: types_type.h:73
vt::runtime::component::Component
Component class for a generic VT runtime module, CRTP'ed over the component's actual type
Definition: component.h:95
scatter.h
component_pack.h
message.h
vt::theCollective
collective::CollectiveAlg * theCollective()
Definition: runtime_get.cc:101
vt::collective::CollectiveAlg
Perform asynchronous collectives within VT.
Definition: collective_alg.h:75
vt
Definition: activefn.h:51
vt::collective::scatter::Scatter
Scatter data across all nodes from a single origin.
Definition: scatter.h:67
vt::collective::CollectiveAlg::name
std::string name() override
Get the name of the component.
Definition: collective_alg.h:99
tree.h
vt::collective::reduce::operators::ReduceDataMsg
Definition: default_msg.h:81
vt::collective::barrier::Barrier
Perform a collective barrier that is safe to use with VT handlers in flight.
Definition: barrier.h:80
vt::collective::CollectiveAlg::makeCollectiveScope
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
barrier.h
vt::collective::CollectiveAlg::next_system_scope_
TagType next_system_scope_
Definition: collective_alg.h:157
scatter.impl.h
collective_scope.h
vt::CollectiveAlgType
uint64_t CollectiveAlgType
Used to identify a collective operation.
Definition: types_type.h:77
vt::collective::CollectiveAlg::CollectiveMsg::seq_
TagType seq_
Definition: collective_alg.h:127
config.h
vt::collective::ReduceMsg
reduce::ReduceMsg ReduceMsg
Definition: collective_alg.h:163
vt::collective::fst_collective_alg
constexpr const CollectiveAlgType fst_collective_alg
Definition: collective_alg.h:64
vt::collective::CollectiveAlg::user_scope_
ScopeMapType user_scope_
Definition: collective_alg.h:158
vt::collective::CollectiveAlg::postponed_collectives_
std::vector< MsgSharedPtr< CollectiveMsg > > postponed_collectives_
Definition: collective_alg.h:160
vt::collective::CollectiveAlg::CollectiveMsg::is_user_tag_
bool is_user_tag_
Definition: collective_alg.h:125