OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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//
22
25#include "Physics/Units.h"
26#include "Utilities/Timer.h"
27
28#include "Ippl.h"
29
30MemoryWriter::MemoryWriter(const std::string& fname, bool restart)
31 : SDDSWriter(fname, restart)
32{ }
33
34
36
37 if (this->hasColumns()) {
38 return;
39 }
40
41 columns_m.addColumn("t", "double", "ns", "Time");
42
43 columns_m.addColumn("s", "double", "m", "Path length");
44
46 columns_m.addColumn("memory", "double", memory->getUnit(), "Total Memory");
47
48 for (int p = 0; p < Ippl::getNodes(); ++p) {
49 std::stringstream tmp1;
50 tmp1 << "\"processor-" << p << "\"";
51
52 std::stringstream tmp2;
53 tmp2 << "Memory per processor " << p;
54 columns_m.addColumn(tmp1.str(), "double", memory->getUnit(), tmp2.str());
55 }
56
57 if ( mode_m == std::ios::app )
58 return;
59
60 OPALTimer::Timer simtimer;
61
62 std::string dateStr(simtimer.date());
63 std::string timeStr(simtimer.time());
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 this->addInfo("ascii", 1);
76}
77
78
80
82 memory->sample();
83
84 if (Ippl::myNode() != 0) {
85 return;
86 }
87
88 double pathLength = beam->get_sPos();
89
90 fillHeader();
91
92 this->open();
93
94 this->writeHeader();
95
96 columns_m.addColumnValue("t", beam->getT() * Units::s2ns); // 1
97 columns_m.addColumnValue("s", pathLength); // 2
98
99 int nProcs = Ippl::getNodes();
100 double total = 0.0;
101 for (int p = 0; p < nProcs; ++p) {
102 total += memory->getMemoryUsage(p);
103 }
104
105 columns_m.addColumnValue("memory", total);
106
107 for (int p = 0; p < nProcs; p++) {
108 std::stringstream ss;
109 ss << "\"processor-" << p << "\"";
110 columns_m.addColumnValue(ss.str(), memory->getMemoryUsage(p));
111 }
112
113 this->writeRow();
114
115 this->close();
116}
constexpr double s2ns
Definition Units.h:44
double get_sPos() const
double getT() const
std::string getInputFn()
get opals input filename
Definition OpalData.cpp:670
static OpalData * getInstance()
Definition OpalData.cpp:196
void write(PartBunchBase< double, 3 > *beam) override
MemoryWriter(const std::string &fname, bool restart)
SDDSWriter(const std::string &fname, bool restart)
SDDSColumnSet columns_m
Definition SDDSWriter.h:122
bool hasColumns() const
Definition SDDSWriter.h:200
void addDefaultParameters()
void addDescription(const std::string &text, const std::string &content)
Definition SDDSWriter.h:159
void writeHeader()
Write SDDS header.
std::ios_base::openmode mode_m
First write to the statistics output file.
Definition SDDSWriter.h:120
void writeRow()
Definition SDDSWriter.h:185
void addInfo(const std::string &mode, const size_t &no_row_counts)
Definition SDDSWriter.h:178
std::string date() const
Return date.
std::string time() const
Return time.
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
IpplMemoryUsage * IpplMemory_p