Motiv
Marvelous OTF2 Traces Interactive Visualizer
Loading...
Searching...
No Matches
ReaderCallbacks.hpp
1/*
2 * Marvelous OTF2 Traces Interactive Visualizer (MOTIV)
3 * Copyright (C) 2023 Florian Gallrein, Björn Gehrke
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#ifndef MOTIV_READERCALLBACKS_HPP
19#define MOTIV_READERCALLBACKS_HPP
20
21#include <otf2xx/otf2.hpp>
22#include <cstdint>
23
24#include "src/models/Slot.hpp"
25#include "src/models/communication/Communication.hpp"
26#include "src/models/communication/NonBlockingSendEvent.hpp"
27#include "src/models/communication/NonBlockingReceiveEvent.hpp"
28#include "src/models/communication/CollectiveCommunicationEvent.hpp"
29
30template<typename T>
31using BuilderSetLocation = std::function<typename T::Builder *(typename T::Builder &,
32 otf2::definition::location &)>;
33
34template<typename T>
35using BuilderSetTime = std::function<typename T::Builder *(typename T::Builder &,
36 otf2::chrono::duration &)>;
37
38template<typename T>
39using BuilderSetter = std::function<void(typename T::Builder &)>;
40
41typedef std::variant<NonBlockingSendEvent::Builder, NonBlockingReceiveEvent::Builder> NonBlockingCommunicationEventBuilder;
42
49class ReaderCallbacks : public otf2::reader::callback {
50 using otf2::reader::callback::event;
51 using otf2::reader::callback::definition;
52private:
53 std::vector<Slot *> slots_;
54 std::vector<Communication *> communications_;
55 std::vector<CollectiveCommunicationEvent *> collectiveCommunications_;
56
60 std::map<otf2::reference<otf2::definition::location>, std::vector<Slot::Builder> *> slotsBuilding;
61
65 std::map<uint32_t, std::vector<CommunicationEvent *> *> pendingSends;
66
70 std::map<uint32_t, std::vector<CommunicationEvent *> *> pendingReceives;
71
72 std::map<otf2::reference<otf2::definition::location>, CollectiveCommunicationEvent::Member::Builder> ongoingCollectiveCommunicationMembers;
73 CollectiveCommunicationEvent::Builder *ongoingCollectiveCommunication = nullptr;
74
78 std::map<uint64_t, NonBlockingCommunicationEventBuilder> uncompletedRequests;
79
80 otf2::chrono::time_point program_start_;
81 otf2::chrono::time_point program_end_;
82
83 otf2::reader::reader &rdr_;
84public:
89 explicit ReaderCallbacks(otf2::reader::reader &rdr);
90
91 void definition(const otf2::definition::location &loc) override;
92
93 void event(const otf2::definition::location &location, const otf2::event::program_begin &event) override;
94
95 void event(const otf2::definition::location &location, const otf2::event::program_end &event) override;
96
97 void event(const otf2::definition::location &location, const otf2::event::enter &event) override;
98
99 void event(const otf2::definition::location &location, const otf2::event::leave &event) override;
100
101 void event(const otf2::definition::location &location, const otf2::event::mpi_send &send) override;
102
103 void event(const otf2::definition::location &location, const otf2::event::mpi_receive &receive) override;
104
105 void event(const otf2::definition::location &location, const otf2::event::mpi_isend_request &request) override;
106
107 void event(const otf2::definition::location &location, const otf2::event::mpi_isend_complete &complete) override;
108
109 void event(const otf2::definition::location &location, const otf2::event::mpi_ireceive_request &request) override;
110
111 void event(const otf2::definition::location &location, const otf2::event::mpi_ireceive_complete &complete) override;
112
113 void event(const otf2::definition::location &location, const otf2::event::mpi_request_test &test) override;
114
115 void
116 event(const otf2::definition::location &location, const otf2::event::mpi_request_cancelled &cancelled) override;
117
118 void event(const otf2::definition::location &location, const otf2::event::mpi_collective_begin &begin) override;
119
120 void event(const otf2::definition::location &location, const otf2::event::mpi_collective_end &anEnd) override;
121
122 void events_done(const otf2::reader::reader &) override;
123
124public:
132 std::vector<Communication *> getCommunications();
133
134
142 std::vector<CollectiveCommunicationEvent *> getCollectiveCommunications();
143
151 std::vector<Slot *> getSlots();
152
157 [[nodiscard]] otf2::chrono::duration duration() const;
158
159private:
160 template<typename T>
161 void communicationEvent(T *self, uint32_t matching,
162 std::map<uint32_t, std::vector<CommunicationEvent *> *> &selfPending,
163 std::map<uint32_t, std::vector<CommunicationEvent *> *> &matchingPending);
164
165 [[nodiscard]] otf2::chrono::duration relative(otf2::chrono::time_point) const;
166};
167
168#endif //MOTIV_READERCALLBACKS_HPP
Class implementing handlers for the otf readers events.
std::vector< Slot * > getSlots()
Returns all read slots.
std::vector< Communication * > getCommunications()
Returns all read point to point communications.
otf2::chrono::duration duration() const
std::vector< CollectiveCommunicationEvent * > getCollectiveCommunications()
Returns all read collective communications.