OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
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
22#include "OPALconfig.h"
23#include "PartBunch/PartBunch.h"
24#include "Physics/Units.h"
25#include "Utilities/Timer.h"
26#include "Utilities/Util.h"
27
28LBalWriter::LBalWriter(const std::string& fname, bool restart) : SDDSWriter(fname, restart) {
29
30}
31
33 if (this->hasColumns()) {
34 return;
35 }
36
37 columns_m.addColumn("t", "double", "ns", "Time");
38
39 for (int p = 0; p < ippl::Comm->size(); ++p) {
40 std::stringstream tmp1;
41 tmp1 << "\"processor-" << p << "\"";
42
43 std::stringstream tmp2;
44 tmp2 << "Number of particles of processor " << p;
45
46 columns_m.addColumn(tmp1.str(), "long", "1", tmp2.str());
47 }
48
49 if (mode_m == std::ios::app)
50 return;
51
52 OPALTimer::Timer simtimer;
53
54 std::string dateStr(simtimer.date());
55 std::string timeStr(simtimer.time());
56
57 std::stringstream ss;
58 ss << "Processor statistics '" << OpalData::getInstance()->getInputFn() << "' " << dateStr << ""
59 << timeStr;
60
61 this->addDescription(ss.str(), "lbal parameters");
62
64
65 this->addInfo("ascii", 1);
66}
67
68void LBalWriter::write(const PartBunch_t* beam) {
69 if (ippl::Comm->rank() != 0)
70 return;
71
72 this->fillHeader();
73
74 this->open();
75
76 this->writeHeader();
77
78 columns_m.addColumnValue("t", beam->getT() * Units::s2ns); // 1
79
80 size_t nProcs = ippl::Comm->size();
81
82 for (size_t p = 0; p < nProcs; ++p) {
83 std::stringstream ss;
84 ss << "\"processor-" << p << "\"";
85 size_t a = 10; // beam->getLoadBalance(p);
86 columns_m.addColumnValue(ss.str(), a);
87 }
88
89 this->writeRow();
90
91 this->close();
92}
PartBunch< PLayout_t< double, 3 >, double, 3 > PartBunch_t
constexpr double s2ns
Definition Units.h:44
std::string getInputFn()
get opals input filename
Definition OpalData.cpp:681
static OpalData * getInstance()
Definition OpalData.cpp:195
double getT() const
void write(const PartBunch_t *beam) override
LBalWriter(const std::string &fname, bool restart)
void fillHeader()
SDDSWriter(const std::string &fname, bool restart)
SDDSColumnSet columns_m
Definition SDDSWriter.h:110
bool hasColumns() const
Definition SDDSWriter.h:171
void addDefaultParameters()
void addDescription(const std::string &text, const std::string &content)
Definition SDDSWriter.h:142
void writeHeader()
Write SDDS header.
std::ios_base::openmode mode_m
First write to the statistics output file.
Definition SDDSWriter.h:108
void writeRow()
Definition SDDSWriter.h:159
void addInfo(const std::string &mode, const size_t &no_row_counts)
Definition SDDSWriter.h:155
std::string time() const
Return time.
Definition Timer.cpp:42
std::string date() const
Return date.
Definition Timer.cpp:35