DisCostiC v2.0.0
Distributed Cost in Cluster: a cross-architecture simulator for massively parallel MPI programs
Loading...
Searching...
No Matches
YAMLParser.hpp
Go to the documentation of this file.
1
7
8#ifndef YAMLPARSER_HPP
9#define YAMLPARSER_HPP
10
11#pragma once
12
13#include <sstream>
14#include <fstream>
15#include <string>
16#include <iostream>
17#include <map>
18#include <typeinfo>
19#include <mpi.h>
20#include "macro.hpp"
21
25namespace UserInterface
26{
28 {
29 public:
30 std::map<std::string, std::string> data;
31 std::string fileName;
32 std::string micro_architecture;
38 std::vector<real_t> MEM_bandwidth;
39 bool flag;
40
44 void removeComment(std::string &line) const
45 {
46 if (line.find('#') != line.npos)
47 line.erase(line.find('#'));
48 }
49
53 bool whitespace(const std::string &line) const
54 {
55 return (line.find_first_not_of(' ') == line.npos);
56 }
57
65 void parseLine(const std::string &line, size_t const lineNum)
66 {
67 if (line.find("clock:") != std::string::npos)
68 clk_freq_in_GHz = std::stod(line.substr(line.find(":") + 1, 4));
69
70 if (line.find("cores per socket:") != std::string::npos)
71 cores_per_chip = std::stoi(line.substr(line.find(":") + 1, 3));
72
73 if (line.find("cores per NUMA domain:") != std::string::npos)
74 cores_per_numa_domain = std::stoi(line.substr(line.find(":") + 1, 3));
75
76 if (line.find("DP:") != std::string::npos)
77 FP_ops_per_instruction_DP = std::stoi(line.substr(line.find("total:") + 6, 3));
78
79 if (line.find("SP:") != std::string::npos)
80 FP_ops_per_instruction_SP = std::stoi(line.substr(line.find("total:") + 6, 3));
81
82 if (line.find("sockets:") != std::string::npos)
83 chips_per_node = std::stoi(line.substr(line.find(":") + 1, 3));
84
85 if (line.find("cacheline size:") != std::string::npos)
86 cachelinesize = std::stoi(line.substr(line.find(":") + 1, 4));
87
88 if (line.find(" MEM:") != std::string::npos)
89 {
90 flag = false;
91 }
92 if (flag == false && (line.find("copy:") != std::string::npos))
93 {
94
95 std::string val = line.substr(line.find("[") + 1, line.find("]") - 17);
96
97 std::string a;
98 for (std::stringstream sst(val); std::getline(sst, a, ',');)
99 MEM_bandwidth.push_back(stod(a.replace(a.find("GB/s"), 4, "")));
100 flag = true;
101 }
102 }
103
107 YAMLParser(const std::string &fileName)
108 {
109
110 std::ifstream file;
111 fileopen(file, fileName);
112
113 std::string line;
114 size_t lineNum = 0;
115 flag = true;
116
117 micro_architecture = fileName.substr(24, fileName.substr(24, 50).find(".yml"));
118
119 while (std::getline(file, line))
120 {
121 lineNum++;
122 std::string temp = line;
123
124 if (temp.empty())
125 continue;
126
127 removeComment(temp);
128
129 if (whitespace(temp))
130 continue;
131
132 parseLine(temp, lineNum);
133 }
134
135 fileclose(file, fileName);
136 }
137
138 };
139}
140#endif
std::size_t DisCosTiC_Datatype
Definition DataType.hpp:52
double real_t
Definition DataType.hpp:48
end class YAMLParser
DisCosTiC_Datatype cores_per_numa_domain
DisCosTiC_Datatype cores_per_chip
bool whitespace(const std::string &line) const
a function that returns false if a non-space character was found, true otherwise. The function is "co...
DisCosTiC_Datatype FP_ops_per_instruction_SP
std::map< std::string, std::string > data
which will hold pairs of key-value
std::vector< real_t > MEM_bandwidth
DisCosTiC_Datatype FP_ops_per_instruction_DP
DisCosTiC_Datatype cachelinesize
std::string fileName
As member variables, we will only have a std::string, which will hold the name of the configuration f...
YAMLParser(const std::string &fileName)
a class to set the name of the configuration file and extracts and parses the data
void removeComment(std::string &line) const
a function that removes everything from the semicolon (including it) to the end of the line.
DisCosTiC_Datatype FP_instructions_per_cycle
DisCosTiC_Datatype chips_per_node
void parseLine(const std::string &line, size_t const lineNum)
a function that extracts the key from the pair of key = value
#define fileopen(myfile, filename)
open an open file
Definition macro.hpp:233
#define fileclose(myfile, filename)
close an open file
Definition macro.hpp:251
it parses the user-defined configuration file (.cfg)