OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
LBalWriter.cpp
Go to the documentation of this file.
1//
2// Class LBalWriter
3// This class writes a SDDS file with MPI load balancing information.
4//
5// Copyright (c) 2019, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
6// Christof Metzger-Kraus, Open Sourcerer
7// All rights reserved
8//
9// This file is part of OPAL.
10//
11// OPAL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 3 of the License, or
14// (at your option) any later version.
15//
16// You should have received a copy of the GNU General Public License
17// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18//
19#include "LBalWriter.h"
20
21#include "OPALconfig.h"
23#include "Utilities/Util.h"
24#include "Utilities/Timer.h"
26#include "Physics/Units.h"
27
28#ifdef ENABLE_AMR
30#endif
31
32LBalWriter::LBalWriter(const std::string& fname, bool restart)
33 : SDDSWriter(fname, restart)
34{ }
35
36
37#ifdef ENABLE_AMR
39#else
41#endif
42 if (this->hasColumns()) {
43 return;
44 }
45
46 columns_m.addColumn("t", "double", "ns", "Time");
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 << "Number of particles of processor " << p;
54
55 columns_m.addColumn(tmp1.str(), "long", "1", tmp2.str());
56 }
57
58#ifdef ENABLE_AMR
59 if ( AmrPartBunch* amrbeam = dynamic_cast<AmrPartBunch*>(beam) ) {
60
61 int nLevel = (amrbeam->getAmrObject())->maxLevel() + 1;
62
63 for (int lev = 0; lev < nLevel; ++lev) {
64 std::stringstream tmp1;
65 tmp1 << "\"level-" << lev << "\"";
66
67 std::stringstream tmp2;
68 tmp2 << "Number of particles at level " << lev;
69 columns_m.addColumn(tmp1.str(), "long", "1", tmp2.str());
70 }
71 }
72#endif
73
74 if ( mode_m == std::ios::app )
75 return;
76
77 OPALTimer::Timer simtimer;
78
79 std::string dateStr(simtimer.date());
80 std::string timeStr(simtimer.time());
81
82 std::stringstream ss;
83 ss << "Processor statistics '"
84 << OpalData::getInstance()->getInputFn() << "' "
85 << dateStr << "" << timeStr;
86
87 this->addDescription(ss.str(), "lbal parameters");
88
90
91
92 this->addInfo("ascii", 1);
93}
94
95
96#ifdef ENABLE_AMR
98
99 if ( AmrPartBunch* amrbeam = dynamic_cast<AmrPartBunch*>(beam) ) {
100 amrbeam->gatherLevelStatistics();
101 }
102#else
104#endif
105
106 if ( Ippl::myNode() != 0 )
107 return;
108
109#ifdef ENABLE_AMR
110 this->fillHeader(beam);
111#else
112 this->fillHeader();
113#endif
114
115 this->open();
116
117 this->writeHeader();
118
119 columns_m.addColumnValue("t", beam->getT() * Units::s2ns); // 1
120
121 size_t nProcs = Ippl::getNodes();
122 for (size_t p = 0; p < nProcs; ++ p) {
123 std::stringstream ss;
124 ss << "\"processor-" << p << "\"";
125 columns_m.addColumnValue(ss.str(), beam->getLoadBalance(p));
126 }
127
128#ifdef ENABLE_AMR
129 if ( AmrPartBunch* amrbeam = dynamic_cast<AmrPartBunch*>(beam) ) {
130 int nLevel = (amrbeam->getAmrObject())->maxLevel() + 1;
131 for (int lev = 0; lev < nLevel; ++lev) {
132 std::stringstream ss;
133 ss << "\"level-" << lev << "\"";
134 columns_m.addColumnValue(ss.str(), amrbeam->getLevelStatistics(lev));
135 }
136 }
137#endif
138
139 this->writeRow();
140
141 this->close();
142}
constexpr double s2ns
Definition: Units.h:44
size_t getLoadBalance(int p) const
double getT() const
std::string getInputFn()
get opals input filename
Definition: OpalData.cpp:665
static OpalData * getInstance()
Definition: OpalData.cpp:196
LBalWriter(const std::string &fname, bool restart)
Definition: LBalWriter.cpp:32
void write(PartBunchBase< double, 3 > *beam)
Definition: LBalWriter.cpp:97
void fillHeader(PartBunchBase< double, 3 > *beam)
Definition: LBalWriter.cpp:38
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