Skip to content

Commit dc30fc2

Browse files
committed
Add generation of key-value output, remove YAML output, fix white space
1 parent 156e3e7 commit dc30fc2

File tree

4 files changed

+595
-314
lines changed

4 files changed

+595
-314
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ HPCG_DEPS = src/CG.o src/CG_ref.o src/TestCG.o src/ComputeResidual.o \
1515
src/ComputeDotProduct_ref.o src/finalize.o src/init.o src/mytimer.o src/ComputeSPMV.o \
1616
src/ComputeSPMV_ref.o src/ComputeSYMGS.o src/ComputeSYMGS_ref.o src/ComputeWAXPBY.o src/ComputeWAXPBY_ref.o \
1717
src/ComputeMG_ref.o src/ComputeMG.o src/ComputeProlongation_ref.o src/ComputeRestriction_ref.o src/GenerateCoarseProblem.o \
18-
src/ComputeOptimalShapeXYZ.o src/MixedBaseCounter.o src/CheckAspectRatio.o
18+
src/ComputeOptimalShapeXYZ.o src/MixedBaseCounter.o src/CheckAspectRatio.o src/OutputFile.o
1919

2020
bin/xhpcg: src/main.o $(HPCG_DEPS)
2121
$(LINKER) $(LINKFLAGS) src/main.o $(HPCG_DEPS) -o bin/xhpcg $(HPCG_LIBS)

src/OutputFile.cpp

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
2+
//@HEADER
3+
// ***************************************************
4+
//
5+
// HPCG: High Performance Conjugate Gradient Benchmark
6+
//
7+
// Contact:
8+
// Michael A. Heroux ( [email protected])
9+
// Jack Dongarra ([email protected])
10+
// Piotr Luszczek ([email protected])
11+
//
12+
// ***************************************************
13+
//@HEADER
14+
15+
16+
#include <fstream>
17+
#include <list>
18+
#include <sstream>
19+
#include <string>
20+
21+
#include "OutputFile.hpp"
22+
23+
using std::string;
24+
using std::stringstream;
25+
using std::list;
26+
using std::ofstream;
27+
28+
OutputFile::OutputFile(const string & name_arg, const string & version_arg)
29+
: name(name_arg), version(version_arg) {}
30+
31+
OutputFile::OutputFile(void) {}
32+
33+
void
34+
OutputFile::add(const string & key_arg, const string & value_arg) {
35+
descendants.push_back(allocKeyVal(key_arg, value_arg));
36+
}
37+
38+
void
39+
OutputFile::add(const string & key_arg, double value_arg) {
40+
stringstream ss;
41+
ss << value_arg;
42+
descendants.push_back(allocKeyVal(key_arg, ss.str()));
43+
}
44+
45+
void
46+
OutputFile::add(const string & key_arg, int value_arg) {
47+
stringstream ss;
48+
ss << value_arg;
49+
descendants.push_back(allocKeyVal(key_arg, ss.str()));
50+
}
51+
52+
#ifndef HPCG_NO_LONG_LONG
53+
54+
void
55+
OutputFile::add(const string & key_arg, long long value_arg) {
56+
stringstream ss;
57+
ss << value_arg;
58+
descendants.push_back(allocKeyVal(key_arg, ss.str()));
59+
}
60+
61+
#endif
62+
63+
void
64+
OutputFile::add(const string & key_arg, size_t value_arg) {
65+
stringstream ss;
66+
ss << value_arg;
67+
descendants.push_back(allocKeyVal(key_arg, ss.str()));
68+
}
69+
70+
void
71+
OutputFile::setKeyValue(const string & key_arg, const string & value_arg) {
72+
key = key_arg;
73+
value = value_arg;
74+
}
75+
76+
OutputFile *
77+
OutputFile::get(const string & key_arg) {
78+
for (list<OutputFile*>::iterator it = descendants.begin(); it != descendants.end(); ++it) {
79+
if ((*it)->key == key_arg)
80+
return *it;
81+
}
82+
83+
return 0;
84+
}
85+
86+
string
87+
OutputFile::generateRecursive(string prefix) {
88+
string result = "";
89+
90+
result += prefix + key + "=" + value + eol;
91+
92+
for (list<OutputFile*>::iterator it = descendants.begin(); it != descendants.end(); ++it) {
93+
result += (*it)->generateRecursive(prefix + key + keySeparator);
94+
}
95+
96+
return result;
97+
}
98+
99+
string
100+
OutputFile::generate(void) {
101+
string result = name + "\nversion=" + version + eol;
102+
103+
for (list<OutputFile*>::iterator it = descendants.begin(); it != descendants.end(); ++it) {
104+
result += (*it)->generateRecursive("");
105+
}
106+
107+
time_t rawtime;
108+
time(&rawtime);
109+
tm * ptm = localtime(&rawtime);
110+
char sdate[25];
111+
//use tm_mon+1 because tm_mon is 0 .. 11 instead of 1 .. 12
112+
sprintf (sdate,"%04d-%02d-%02d_%02d-%02d-%02d",ptm->tm_year + 1900, ptm->tm_mon+1,
113+
ptm->tm_mday, ptm->tm_hour, ptm->tm_min,ptm->tm_sec);
114+
115+
string filename = name + "_" + version + "_";
116+
filename += string(sdate) + ".txt";
117+
118+
ofstream myfile(filename.c_str());
119+
myfile << result;
120+
myfile.close();
121+
122+
return result;
123+
}
124+
125+
OutputFile * OutputFile::allocKeyVal(const std::string & key_arg, const std::string & value_arg) {
126+
OutputFile * of = new OutputFile();
127+
of->setKeyValue(key_arg, value_arg);
128+
return of;
129+
}

src/OutputFile.hpp

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
2+
//@HEADER
3+
// ***************************************************
4+
//
5+
// HPCG: High Performance Conjugate Gradient Benchmark
6+
//
7+
// Contact:
8+
// Michael A. Heroux ( [email protected])
9+
// Jack Dongarra ([email protected])
10+
// Piotr Luszczek ([email protected])
11+
//
12+
// ***************************************************
13+
//@HEADER
14+
15+
/*!
16+
@file Output_File.hpp
17+
18+
HPCG output file classes
19+
*/
20+
21+
#ifndef OUTPUTFILE_HPP
22+
#define OUTPUTFILE_HPP
23+
24+
#include <list>
25+
#include <string>
26+
27+
//! The OutputFile class for the uniform collecting and reporting of performance data for HPCG
28+
29+
/*!
30+
31+
The OutputFile class facilitates easy collecting and reporting of
32+
key-value-formatted data that can be then registered with the HPCG results
33+
collection website. The keys may have hierarchy key1::key2::key3=val with
34+
double colon :: as a seperator. A sample output may look like this (note how
35+
"major" and "micro" keys repeat with different ancestor keys):
36+
37+
\code
38+
39+
version=3.2.1alpha
40+
version::major=3
41+
version::minor=2
42+
version::micro=1
43+
version::release=alpha
44+
axis=xyz
45+
axis::major=x
46+
axis::minor=y
47+
48+
\endcode
49+
50+
*/
51+
class OutputFile {
52+
protected:
53+
std::list<OutputFile *> descendants; //!< descendant elements
54+
std::string name; //!< name of the benchmark
55+
std::string version; //!< version of the benchmark
56+
std::string key; //!< the key under which the element is stored
57+
std::string value; //!< the value of the stored element
58+
std::string eol = "\n"; //!< end-of-line character sequence in the output file
59+
std::string keySeparator = "::"; //!< character sequence to seperate keys in the output file
60+
61+
//! Recursively generate output string from descendent list, and their descendendents and so on
62+
std::string generateRecursive(std::string prefix);
63+
64+
public:
65+
static OutputFile * allocKeyVal(const std::string & key, const std::string & value);
66+
67+
//! Constructor: accepts name and version as strings that are used to create a file name for printing results.
68+
/*!
69+
This constructor accepts and name and version number for the benchmark that
70+
are used to form a file name information for results that are generated by
71+
the generate() method.
72+
\param name (in) string containing name of the benchmark
73+
\param version (in) string containing the version of the benchmark
74+
*/
75+
OutputFile(const std::string & name, const std::string & version);
76+
77+
//! Default constructor: no-arguments accepted, should be used for descendant nodes
78+
/*!
79+
This no-argument constructor can be used for leaf nodes to provide
80+
key1::key2::key3=val output.
81+
*/
82+
OutputFile(void);
83+
84+
//! Create and add a descendant element with value of type "string"
85+
/*!
86+
Create and add a descendant element identified by "key" and associated with
87+
"value". The element is added at the end of a list of previously added
88+
elements.
89+
90+
@param[in] key The key that identifies the added element and under which the element is stored
91+
@param[in] value The value stored by the element
92+
*/
93+
void add(const std::string & key, const std::string & value);
94+
95+
//! Create and add a descendant element with value of type "double"
96+
/*!
97+
Create and add a descendant element identified by "key" and associated with
98+
"value". The element is added at the end of a list of previously added
99+
elements.
100+
101+
@param[in] key The key that identifies the added element and under which the element is stored
102+
@param[in] value The value stored by the element
103+
*/
104+
void add(const std::string & key, double value);
105+
106+
//! Create and add a descendant element with value of type "int"
107+
/*!
108+
Create and add a descendant element identified by "key" and associated with
109+
"value". The element is added at the end of a list of previously added
110+
elements.
111+
112+
@param[in] key The key that identifies the added element and under which the element is stored
113+
@param[in] value The value stored by the element
114+
*/
115+
void add(const std::string & key, int value);
116+
117+
#ifndef HPCG_NO_LONG_LONG
118+
//! Create and add a descendant element with value of type "long long"
119+
/*!
120+
Create and add a descendant element identified by "key" and associated with
121+
"value". The element is added at the end of a list of previously added
122+
elements.
123+
124+
@param[in] key The key that identifies the added element and under which the element is stored
125+
@param[in] value The value stored by the element
126+
*/
127+
void add(const std::string & key, long long value);
128+
#endif
129+
130+
//! Create and add a descendant element with value of type "size_t"
131+
/*!
132+
Create and add a descendant element identified by "key" and associated with
133+
"value". The element is added at the end of a list of previously added
134+
elements.
135+
136+
@param[in] key The key that identifies the added element and under which the element is stored
137+
@param[in] value The value stored by the element
138+
*/
139+
void add(const std::string & key, size_t value);
140+
141+
//! Key-Value setter method
142+
/*!
143+
Set the key and the value of this element.
144+
145+
@param[in] key The key that identifies this element and under which the element is stored
146+
@param[in] value The value stored by the element
147+
*/
148+
void setKeyValue(const std::string & key, const std::string & value);
149+
150+
//! Get the element in the list with the given key or return NULL if not found
151+
OutputFile * get(const std::string & key);
152+
153+
//! Generate output string with results based on the stored key-value hierarchy
154+
std::string generate(void);
155+
};
156+
157+
#endif // OUTPUTFILE_HPP

0 commit comments

Comments
 (0)