OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
MemoryWriter.cpp
Go to the documentation of this file.
1//
2// Class MemoryWriter
3// This class writes a SDDS file with virtual memory usage information.
4//
5// Copyright (c) 2019, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// Implemented as part of the PhD thesis
9// "Precise Simulations of Multibunches in High Intensity Cyclotrons"
10//
11// This file is part of OPAL.
12//
13// OPAL is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// You should have received a copy of the GNU General Public License
19// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20//
21#include "MemoryWriter.h"
22
25#include "Utilities/Timer.h"
26#include "Physics/Units.h"
27#include "Ippl.h"
28
29MemoryWriter::MemoryWriter(const std::string& fname, bool restart)
30 : SDDSWriter(fname, restart)
31{ }
32
33
35
36 if (this->hasColumns()) {
37 return;
38 }
39
40 columns_m.addColumn("t", "double", "ns", "Time");
41
42 columns_m.addColumn("s", "double", "m", "Path length");
43
45 columns_m.addColumn("memory", "double", memory->getUnit(), "Total Memory");
46
47 for (int p = 0; p < Ippl::getNodes(); ++p) {
48 std::stringstream tmp1;
49 tmp1 << "\"processor-" << p << "\"";
50
51 std::stringstream tmp2;
52 tmp2 << "Memory per processor " << p;
53 columns_m.addColumn(tmp1.str(), "double", memory->getUnit(), tmp2.str());
54 }
55
56 if ( mode_m == std::ios::app )
57 return;
58
59 OPALTimer::Timer simtimer;
60
61 std::string dateStr(simtimer.date());
62 std::string timeStr(simtimer.time());
63
64
65 std::stringstream ss;
66
67 ss << "Memory statistics '"
68 << OpalData::getInstance()->getInputFn() << "' "
69 << dateStr << "" << timeStr;
70
71 this->addDescription(ss.str(), "memory parameters");
72
74
75
76 this->addInfo("ascii", 1);
77}
78
79
81{
83 memory->sample();
84
85 if (Ippl::myNode() != 0) {
86 return;
87 }
88
89 double pathLength = beam->get_sPos();
90
91 fillHeader();
92
93 this->open();
94
95 this->writeHeader();
96
97 columns_m.addColumnValue("t", beam->getT() * Units::s2ns); // 1
98 columns_m.addColumnValue("s", pathLength); // 2
99
100 int nProcs = Ippl::getNodes();
101 double total = 0.0;
102 for (int p = 0; p < nProcs; ++p) {
103 total += memory->getMemoryUsage(p);
104 }
105
106 columns_m.addColumnValue("memory", total);
107
108 for (int p = 0; p < nProcs; p++) {
109 std::stringstream ss;
110 ss << "\"processor-" << p << "\"";
111 columns_m.addColumnValue(ss.str(), memory->getMemoryUsage(p));
112 }
113
114 this->writeRow();
115
116 this->close();
117}
constexpr double s2ns
Definition: Units.h:44
double get_sPos() const
double getT() const
std::string getInputFn()
get opals input filename
Definition: OpalData.cpp:665
static OpalData * getInstance()
Definition: OpalData.cpp:196
void write(const PartBunchBase< double, 3 > *beam) override
MemoryWriter(const std::string &fname, bool restart)
void fillHeader()
void addColumn(const std::string &name, const std::string &type, const std::string &unit, const std::string &desc, std::ios_base::fmtflags flags=std::ios_base::scientific, unsigned short precision=15)
void addColumnValue(const std::string &name, const T &val)
Definition: SDDSColumnSet.h:63
SDDSColumnSet columns_m
Definition: SDDSWriter.h:126
bool hasColumns() const
Definition: SDDSWriter.h:207
void addDefaultParameters()
Definition: SDDSWriter.cpp:211
void addDescription(const std::string &text, const std::string &content)
Definition: SDDSWriter.h:164
void open()
Definition: SDDSWriter.cpp:134
void writeHeader()
Write SDDS header.
Definition: SDDSWriter.cpp:151
std::ios_base::openmode mode_m
First write to the statistics output file.
Definition: SDDSWriter.h:124
void close()
Definition: SDDSWriter.cpp:144
void writeRow()
Definition: SDDSWriter.h:192
void addInfo(const std::string &mode, const size_t &no_row_counts)
Definition: SDDSWriter.h:185
std::string date() const
Return date.
Definition: Timer.cpp:35
std::string time() const
Return time.
Definition: Timer.cpp:42
static int getNodes()
Definition: IpplInfo.cpp:670
static int myNode()
Definition: IpplInfo.cpp:691
const std::string & getUnit() const
static IpplMemory_p getInstance(Unit unit=Unit::GB, bool reset=true)
double getMemoryUsage(int core) const