DisCostiC v2.0.0
Distributed Cost in Cluster: a cross-architecture simulator for massively parallel MPI programs
Loading...
Searching...
No Matches
ItacVtf.hpp
Go to the documentation of this file.
1#ifndef ITACVTF_HPP
2#define ITACVTF_HPP
3
4#pragma once
5
6#include <cmath>
7#include <fstream>
8#include <iostream>
9#include <string>
10
12
13namespace UserInterface
14{
15
21 class ItacVtf
22 {
23 private:
24 std::ofstream ofs;
25 std::string filename;
27
28 static long long ns_of(double t)
29 {
30 if (t < 0.0)
31 {
32 return 0;
33 }
34 return static_cast<long long>(std::llround(t));
35 }
36
37 static std::string sanitize(const std::string &name)
38 {
39 std::string out;
40 out.reserve(name.size());
41 for (char c : name)
42 {
43 if (c == ' ' || c == '\t')
44 {
45 out.push_back('_');
46 }
47 else if (c != '\n' && c != '\r')
48 {
49 out.push_back(c);
50 }
51 }
52 return out.empty() ? std::string("region") : out;
53 }
54
55 static bool skip_message(DisCosTiC_Indextype src, DisCosTiC_Indextype dst, double bytes)
56 {
57 return src == dst || bytes <= 0.0;
58 }
59
60 public:
62 {
63 if (mpi_rank != 0)
64 {
65 this->rank = mpi_rank - 1;
66 this->filename = args_info->getValue<std::string>("chromevizfilename") + std::to_string(this->rank) + ".avt";
67 ofs.open(filename);
68 }
69 }
70
71 void comp(DisCosTiC_Indextype app_rank, double start_ns, double dur_ns, const std::string &name)
72 {
73 if (!ofs.is_open() || dur_ns < 0.0)
74 {
75 return;
76 }
77 ofs << "COMP " << app_rank << " " << ns_of(start_ns) << " " << ns_of(dur_ns) << " " << sanitize(name) << "\n";
78 }
79
80 void send(DisCosTiC_Indextype src, DisCosTiC_Indextype dst, double start_ns, double dur_ns,
81 double bytes, DisCosTiC_Indextype tag)
82 {
83 if (!ofs.is_open() || skip_message(src, dst, bytes))
84 {
85 return;
86 }
87 ofs << "SEND " << src << " " << dst << " " << ns_of(start_ns) << " " << ns_of(dur_ns) << " "
88 << ns_of(bytes) << " " << tag << "\n";
89 }
90
91 void recv(DisCosTiC_Indextype dst, DisCosTiC_Indextype src, double start_ns, double dur_ns,
92 double bytes, DisCosTiC_Indextype tag)
93 {
94 if (!ofs.is_open() || skip_message(src, dst, bytes))
95 {
96 return;
97 }
98 ofs << "RECV " << dst << " " << src << " " << ns_of(start_ns) << " " << ns_of(dur_ns) << " "
99 << ns_of(bytes) << " " << tag << "\n";
100 }
101
102 void collective(DisCosTiC_Indextype app_rank, double start_ns, double dur_ns, const std::string &name)
103 {
104 if (!ofs.is_open() || dur_ns < 0.0)
105 {
106 return;
107 }
108 ofs << "COLL " << app_rank << " " << ns_of(start_ns) << " " << ns_of(dur_ns) << " " << sanitize(name) << "\n";
109 }
110
112 {
113 if (ofs.is_open())
114 {
115 ofs.flush();
116 ofs.close();
117 }
118 }
119
121 {
122 closeFile();
123 }
124 };
125
126}
127#endif
std::size_t DisCosTiC_Indextype
Definition DataType.hpp:53
std::size_t DisCosTiC_Datatype
Definition DataType.hpp:52
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
static std::string sanitize(const std::string &name)
Definition ItacVtf.hpp:37
void comp(DisCosTiC_Indextype app_rank, double start_ns, double dur_ns, const std::string &name)
Definition ItacVtf.hpp:71
DisCosTiC_Indextype rank
Definition ItacVtf.hpp:26
ItacVtf(UserInterface::ConfigParser *args_info, DisCosTiC_Datatype mpi_rank, DisCosTiC_Datatype)
Definition ItacVtf.hpp:61
void send(DisCosTiC_Indextype src, DisCosTiC_Indextype dst, double start_ns, double dur_ns, double bytes, DisCosTiC_Indextype tag)
Definition ItacVtf.hpp:80
void collective(DisCosTiC_Indextype app_rank, double start_ns, double dur_ns, const std::string &name)
Definition ItacVtf.hpp:102
std::ofstream ofs
Definition ItacVtf.hpp:24
static bool skip_message(DisCosTiC_Indextype src, DisCosTiC_Indextype dst, double bytes)
Definition ItacVtf.hpp:55
std::string filename
Definition ItacVtf.hpp:25
void recv(DisCosTiC_Indextype dst, DisCosTiC_Indextype src, double start_ns, double dur_ns, double bytes, DisCosTiC_Indextype tag)
Definition ItacVtf.hpp:91
static long long ns_of(double t)
Definition ItacVtf.hpp:28
it parses the user-defined configuration file (.cfg)