1+ /*
2+ //@HEADER
3+ // *****************************************************************************
4+ //
5+ // PhaseData.h
6+ // DARMA/vt-lb => Virtual Transport/Load Balancers
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 [email protected] 39+ //
40+ // *****************************************************************************
41+ //@HEADER
42+ */
43+
44+ #if !defined INCLUDED_VT_LB_MODEL_PHASE_DATA_H
45+ #define INCLUDED_VT_LB_MODEL_PHASE_DATA_H
46+
47+ #include " types.h"
48+ #include " SharedBlock.h"
49+ #include " Task.h"
50+ #include " Communication.h"
51+ #include < unordered_map>
52+
53+ namespace vt_lb ::model {
54+
55+ struct PhaseData {
56+ PhaseData () = default ;
57+ explicit PhaseData (RankType rank) : rank_(rank) {}
58+
59+ void addTask (Task const & t) { tasks_.emplace (t.getId (), t); }
60+ void addCommunication (Edge const & e) { communications_.push_back (e); }
61+ void addSharedBlock (SharedBlock const & b) { shared_blocks_.emplace (b.getId (), b); }
62+
63+ RankType getRank () const { return rank_; }
64+
65+ Task const * getTask (TaskType id) const {
66+ auto it = tasks_.find (id);
67+ return it != tasks_.end () ? &it->second : nullptr ;
68+ }
69+ bool hasTask (TaskType id) const { return tasks_.find (id) != tasks_.end (); }
70+ void eraseTask (TaskType id) { tasks_.erase (id); }
71+
72+ SharedBlock const * getSharedBlock (SharedBlockType id) const {
73+ auto it = shared_blocks_.find (id);
74+ return it != shared_blocks_.end () ? &it->second : nullptr ;
75+ }
76+ bool hasSharedBlock (SharedBlockType id) const { return shared_blocks_.find (id) != shared_blocks_.end (); }
77+ void eraseSharedBlock (SharedBlockType id) { shared_blocks_.erase (id); }
78+
79+ std::unordered_map<TaskType, Task> const & getTasksMap () const { return tasks_; }
80+ std::vector<Edge> const & getCommunications () const { return communications_; }
81+ std::unordered_map<SharedBlockType, SharedBlock> const & getSharedBlocksMap () const { return shared_blocks_; }
82+
83+ void clear () {
84+ tasks_.clear ();
85+ communications_.clear ();
86+ shared_blocks_.clear ();
87+ }
88+
89+ template <typename Serializer>
90+ void serialize (Serializer& s) {
91+ s | rank_;
92+ s | tasks_;
93+ s | communications_;
94+ s | shared_blocks_;
95+ }
96+
97+ private:
98+ RankType rank_ = invalid_node;
99+ std::unordered_map<TaskType, Task> tasks_;
100+ std::vector<Edge> communications_;
101+ std::unordered_map<SharedBlockType, SharedBlock> shared_blocks_;
102+ };
103+
104+ } /* end namespace vt_lb::model */
105+
106+ #endif /* INCLUDED_VT_LB_MODEL_PHASE_DATA_H*/
0 commit comments