OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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 "PartBunch/PartBunch.h"
23#include "Physics/Units.h"
24#include "Utilities/Timer.h"
25#include "Utilities/Util.h"
26
27LBalWriter::LBalWriter(const std::string& fname, bool restart) : SDDSWriter(fname, restart) {}
28
30 if (this->hasColumns()) {
31 return;
32 }
33
34 columns_m.addColumn("t", "double", "ns", "Time");
35
36 for (int p = 0; p < ippl::Comm->size(); ++p) {
37 std::stringstream tmp1;
38 tmp1 << "\"processor-" << p << "\"";
39
40 std::stringstream tmp2;
41 tmp2 << "Number of particles of processor " << p;
42
43 columns_m.addColumn(tmp1.str(), "long", "1", tmp2.str());
44 }
45
46 if (mode_m == std::ios::app) return;
47
48 OPALTimer::Timer simtimer;
49
50 std::string dateStr(simtimer.date());
51 std::string timeStr(simtimer.time());
52
53 std::stringstream ss;
54 ss << "Processor statistics '" << OpalData::getInstance()->getInputFn() << "' " << dateStr << ""
55 << timeStr;
56
57 this->addDescription(ss.str(), "lbal parameters");
58
60
61 this->addInfo("ascii", 1);
62}
63
64void LBalWriter::write(const PartBunch_t& beam) {
65 if (ippl::Comm->rank() != 0) return;
66
67 this->fillHeader();
68
69 this->open();
70
71 this->writeHeader();
72
73 columns_m.addColumnValue("t", beam.getT() * Units::s2ns); // 1
74
75 size_t nProcs = ippl::Comm->size();
76
77 for (size_t p = 0; p < nProcs; ++p) {
78 std::stringstream ss;
79 ss << "\"processor-" << p << "\"";
80 size_t a = 10; // beam->getLoadBalance(p);
81 columns_m.addColumnValue(ss.str(), a);
82 }
83
84 this->writeRow();
85
86 this->close();
87}
Template PIC bunch: IPPL PicManager, shared field mesh/solver, and multiple particle containers.
LBalWriter(const std::string &fname, bool restart)
void write(const PartBunch_t &beam) override
void fillHeader()
std::string time() const
Return time.
Definition Timer.cpp:36
std::string date() const
Return date.
Definition Timer.cpp:30
std::string getInputFn()
get opals input filename
Definition OpalData.cpp:569
static OpalData * getInstance()
Definition OpalData.cpp:193
double getT() const
Get the current simulation time.
Definition PartBunch.h:651
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)
SDDSColumnSet columns_m
Definition SDDSWriter.h:111
bool hasColumns() const
Definition SDDSWriter.h:168
void addDefaultParameters()
void addDescription(const std::string &text, const std::string &content)
Definition SDDSWriter.h:141
void writeHeader()
Write SDDS header.
std::ios_base::openmode mode_m
First write to the statistics output file.
Definition SDDSWriter.h:109
void writeRow()
Definition SDDSWriter.h:158
void addInfo(const std::string &mode, const size_t &no_row_counts)
Definition SDDSWriter.h:154
constexpr double s2ns
Definition Units.h:44