DisCostiC v2.0.0
Distributed Cost in Cluster: a cross-architecture simulator for massively parallel MPI programs
Loading...
Searching...
No Matches
TimeRankOP.hpp
Go to the documentation of this file.
1
2#ifndef TIMETRANKOP_HPP
3#define TIMETRANKOP_HPP
4
5#pragma once
6
7// #include <string>
8#include <sstream>
9#include <fstream>
10#include <iostream>
11
12#include "json.hpp"
13using json = nlohmann::json;
14
16
17namespace UserInterface
18{
19
21 {
23 private:
24 std::string content, filename;
25
30 inline void ranknum(DisCosTiC_Datatype numranks)
31 {
32 std::stringstream os;
33 os << "numranks " << numranks << ";" << std::endl;
34 AppendString(os.str(), content);
35 }
36
41 inline void file_write(bool append)
42 {
43 std::ofstream myfile;
44 if (append)
45 myfile.open(filename.c_str(), std::ios::out | std::ios::app);
46 else
47 myfile.open(filename.c_str(), std::ios::out);
48
49 if (myfile.is_open())
50 {
51 myfile << this->content;
52 myfile.close();
53 }
54 else
55 std::cerr << "error: missing result file definition of " << this->filename << " for writing" << std::endl;
56 }
57
58 public:
64 {
65 filename = args_info->getValue<std::string>("vizfilename") + std::to_string(rank) + ".out";
66 ranknum(totalrank);
67 }
68
73 inline void osend(DisCosTiC_Datatype rank, DisCosTiC_Datatype start, DisCosTiC_Datatype end, DisCosTiC_Datatype cpu, float r = 0.0, float g = 0.0, float b = 1.0)
74 {
75 std::stringstream os;
76 os << "osend " << rank
77 << " " << cpu
78 << " " << start
79 << " " << end
80 << " " << r
81 << " " << g
82 << " " << b
83 << ";" << std::endl;
84 AppendString(os.str(), content);
85 }
86
91 inline void orecv(DisCosTiC_Datatype rank, DisCosTiC_Datatype start, DisCosTiC_Datatype end, DisCosTiC_Datatype cpu, float r = 0.0, float g = 0.0, float b = 1.0)
92 {
93 std::stringstream os;
94 os << "orecv " << rank
95 << " " << cpu
96 << " " << start
97 << " " << end
98 << " " << r
99 << " " << g
100 << " " << b
101 << ";" << std::endl;
102 AppendString(os.str(), content);
103 }
104
109 inline void comp(DisCosTiC_Datatype rank, DisCosTiC_Datatype start, DisCosTiC_Datatype end, DisCosTiC_Datatype cpu, float r = 1.0, float g = 0.0, float b = 0.0)
110 {
111 std::stringstream os;
112 os << "loclop " << rank
113 << " " << cpu
114 << " " << start
115 << " " << end
116 << " " << r
117 << " " << g
118 << " " << b
119 << ";" << std::endl;
120 AppendString(os.str(), content);
121 }
122
127 inline void msg(DisCosTiC_Datatype source, DisCosTiC_Datatype dest, DisCosTiC_Datatype starttime, DisCosTiC_Datatype endtime, DisCosTiC_Datatype size, DisCosTiC_Datatype G, float r = 0.0, float g = 0.0, float b = 1.0)
128 {
129 std::stringstream os;
130 os << "transmission " << source
131 << " " << dest
132 << " " << starttime
133 << " " << endtime
134 << " " << size
135 << " " << G
136 << " " << r
137 << " " << g
138 << " " << b
139 << ";" << std::endl;
140 AppendString(os.str(), content);
141 }
142
147 {
148 // file_write(false);
149 }
150 };
151
153 {
154
155 private:
156 std::ofstream ofs;
157 std::string filename;
162
163 public:
164 std::map<std::string, DisCosTiC_Indextype> arc;
165
167 {
168 if (rank != 0)
169 {
170 this->filename = args_info->getValue<std::string>("chromevizfilename") + std::to_string(rank - 1) + ".dms";
171 ofs.open(filename);
172 // ofs << "{ \"traceEvents\": [\n";
173 this->numRanks = numRanks;
174 this->rank = rank - 1;
175 if ((rank - 1) == 0)
176 {
177 ofs << "{ \"traceEvents\": [\n";
178
179 durationEventBegin("dummy", 0, 0, std::to_string(0));
180 durationEventEnd("dummy", 0, 0, std::to_string(0));
181 }
182 }
183 }
184
185 inline void args(std::string args_name, DisCosTiC_Indextype rank)
186 {
187 auto it = arc.find(args_name);
188 if (it == arc.end())
189 {
190 arc[args_name] = max_tid++;
191 }
192 max_rank_id = std::max(max_rank_id, rank);
193 }
194
195 inline void completeEvents(std::string name,
198 std::string time,
199 std::string duration, std::string color)
200 {
201 json js;
202 js["name"] = name;
203 js["ph"] = "X";
204 js["dur"] = duration;
205 js["pid"] = rank;
206 js["tid"] = tid;
207 js["ts"] = json::parse(time);
208 js["cname"] = color;
209
210 ofs << std::setw(4)
211 << js
212 << ","
213 << std::endl;
214 }
215
216 inline void durationEventBegin(std::string name,
219 std::string time)
220 {
221 json js;
222 js["name"] = name;
223 js["ph"] = "B";
224 js["pid"] = rank;
225 js["tid"] = tid;
226 js["ts"] = json::parse(time);
227 ofs << std::setw(4)
228 << js
229 << ","
230 << std::endl;
231 }
232
233 inline void durationEventEnd(std::string name,
236 std::string time)
237 {
238 json js;
239 js["name"] = name;
240 js["ph"] = "E";
241 js["pid"] = rank;
242 js["tid"] = tid;
243 js["ts"] = json::parse(time);
244 ofs << std::setw(4)
245 << js
246 << ","
247 << std::endl;
248 }
249
250 inline void flowEventBegin(std::string name,
251 DisCosTiC_Indextype source,
252 DisCosTiC_Indextype source_tid,
253 std::string time,
255 {
256 json js;
257 js["name"] = name;
258 js["ph"] = "s";
259 js["id"] = index;
260 js["pid"] = source;
261 js["tid"] = source_tid;
262 js["ts"] = json::parse(time);
263 ofs << std::setw(4)
264 << js
265 << ","
266 << std::endl;
267 }
268
269 inline void flowEventEnd(std::string name,
271 DisCosTiC_Indextype dest_tid,
272 std::string time,
274 {
275 json js;
276 js["name"] = name;
277 js["ph"] = "f";
278 js["id"] = index;
279 js["pid"] = dest;
280 js["tid"] = dest_tid;
281 js["ts"] = json::parse(time);
282 ofs << std::setw(4)
283 << js
284 << ","
285 << std::endl;
286 }
287
288 inline void closeFile()
289 {
290 if (ofs.is_open() && this->rank != -1) // && (rank == (max_rank_id - 1)))
291 {
292 json j2 = {
293 {"name", "thread_name"},
294 {"ph", "M"},
295 {"pid", this->rank},
296 {"tid", 0},
297 {"args", {{"name", "CPU" + std::to_string(this->rank)}}}};
298
299 ofs << std::setw(4) << j2 << "," << std::endl;
300
305 ofs.close();
306 // if(this->rank == (this->numRanks-1))
307 // {
308 // ofs << "{}\n],"
309 // << "\"Name\": \"Trace visualisation ofs DisCosTiC toolkit\", \n "
310 // << "\"Full form\": \"Distributed CosT in Cluster\", \n "
311 // << "\"Version\": \"v0.0.0 (initial release)\", \n "
312 // << "\"Author\": \"Ayesha Afzal <ayesha.afzal@fau.de>\", \n "
313 // << "\"Copyright\": \"© 2019 HPC, FAU Erlangen-Nuremberg. All rights reserved\" \n "
314 // << "}\n";
315
316 // }
317 }
318 }
320 {
321 }
322
323 };
324
325}
326#endif
std::size_t DisCosTiC_Indextype
Definition DataType.hpp:53
std::size_t DisCosTiC_Datatype
Definition DataType.hpp:52
time
Definition DisCosTiC.cpp:46
nlohmann::json json
< JSON for Modern C++ version 2.1.1
void flowEventEnd(std::string name, DisCosTiC_Indextype dest, DisCosTiC_Indextype dest_tid, std::string time, DisCosTiC_Indextype index)
void durationEventBegin(std::string name, DisCosTiC_Indextype rank, DisCosTiC_Indextype tid, std::string time)
void args(std::string args_name, DisCosTiC_Indextype rank)
DisCosTiC_Indextype numRanks
void completeEvents(std::string name, DisCosTiC_Indextype rank, DisCosTiC_Indextype tid, std::string time, std::string duration, std::string color)
void durationEventEnd(std::string name, DisCosTiC_Indextype rank, DisCosTiC_Indextype tid, std::string time)
std::map< std::string, DisCosTiC_Indextype > arc
ChromeTraceViz(UserInterface::ConfigParser *args_info, DisCosTiC_Datatype rank, DisCosTiC_Datatype numRanks)
DisCosTiC_Indextype max_rank_id
DisCosTiC_Indextype max_tid
void flowEventBegin(std::string name, DisCosTiC_Indextype source, DisCosTiC_Indextype source_tid, std::string time, DisCosTiC_Indextype index)
a wrapper class which contains functions for parsing the configuration file end class configParser
scalarT getValue(const std::string &key, scalarT const &defaultValue=scalarT()) const
a function that retrieves the value of a specific key
end class TimeRankOP
TimeRankOP(UserInterface::ConfigParser *args_info, DisCosTiC_Datatype rank, int totalrank)
constructor that initializes the coordinates
void orecv(DisCosTiC_Datatype rank, DisCosTiC_Datatype start, DisCosTiC_Datatype end, DisCosTiC_Datatype cpu, float r=0.0, float g=0.0, float b=1.0)
print time taken by overhead at receiver side to output file
void osend(DisCosTiC_Datatype rank, DisCosTiC_Datatype start, DisCosTiC_Datatype end, DisCosTiC_Datatype cpu, float r=0.0, float g=0.0, float b=1.0)
print time taken by overhead at sender side to output file
void comp(DisCosTiC_Datatype rank, DisCosTiC_Datatype start, DisCosTiC_Datatype end, DisCosTiC_Datatype cpu, float r=1.0, float g=0.0, float b=0.0)
print time taken by execution to output file
void ranknum(DisCosTiC_Datatype numranks)
print number of processes to output file
void msg(DisCosTiC_Datatype source, DisCosTiC_Datatype dest, DisCosTiC_Datatype starttime, DisCosTiC_Datatype endtime, DisCosTiC_Datatype size, DisCosTiC_Datatype G, float r=0.0, float g=0.0, float b=1.0)
print time taken by message transmission to output file
std::string content
private variables
void file_write(bool append)
print all events (i.e., osend, orecv, execution, msg transmission) to output file
#define AppendString(str, content)
append a string
Definition macro.hpp:271
it parses the user-defined configuration file (.cfg)