ls1-MarDyn
ls1-MarDyn molecular dynamics code
VectorizationTuner.h
1#ifndef SRC_IO_VECTORIZATIONTUNER_H_
2#define SRC_IO_VECTORIZATIONTUNER_H_
3
5enum MoleculeCntIncreaseTypeEnum{
6 linear,
7 exponential,
8 both
9};
10
11
12#include <vector>
13#include <string>
14
15#include "particleContainer/adapter/CellProcessor.h"
17#include "plugins/PluginBase.h"
18#include "ensemble/EnsembleBase.h"
19#include "parallel/LoadCalc.h"
20
21class Component;
22#include "particleContainer/ParticleCellForwardDeclaration.h"
23
24
32
33public:
37 VectorizationTuner() = default;
38
42 ~VectorizationTuner() override = default;
43
44 //documentation in PluginBase
45 void init(ParticleContainer *particleContainer,
46 DomainDecompBase *domainDecomp, Domain *domain) override;
47
62 void readXML(XMLfileUnits& xmlconfig) override;
63
64 static PluginBase* createInstance() { return new VectorizationTuner(); }
65
66 //documentation in PluginBase, does nothing.
67 void endStep(ParticleContainer * /*particleContainer*/, DomainDecompBase * /*domainDecomp*/,
68 Domain * /*domain*/, unsigned long /*simstep*/) override {}
69
70 //documentation in PluginBase, does nothing.
71 void finish(ParticleContainer * /*particleContainer*/,
72 DomainDecompBase * /*domainDecomp*/, Domain * /*domain*/) override;
73
74 //documentation in PluginBase.
76 return std::string("VectorizationTuner");
77 }
78
89 void tune(std::vector<Component>& ComponentList, TunerLoad& times, std::vector<int> particleNums, bool generateNewFiles, bool useExistingFiles, bool allowMPIReduce);
90
91private:
93 std::string _outputPrefix{"MarDyn"};
94
96 unsigned int _minMoleculeCnt{2};
97
99 unsigned int _maxMoleculeCnt{512};
100
102 MoleculeCntIncreaseTypeEnum _moleculeCntIncreaseType{both};
103
105 CellProcessor* _cellProcessor{nullptr};
106
108 double _cutoffRadius{};
109
111 double _LJCutoffRadius{};
112
115 unsigned int _numRepetitionsMax{4000000};
116
118 static constexpr double _cutoffRadiusBig{5.};
119
121 static constexpr double _LJCutoffRadiusBig{5.};
122
124 std::unique_ptr<FlopCounter> _flopCounterBigRc;
125
127 std::unique_ptr<FlopCounter> _flopCounterNormalRc;
128
130 std::unique_ptr<FlopCounter> _flopCounterZeroRc;
131
132 /*
133 * Writes the given TunerTimes to a file
134 */
135 void writeFile(const TunerLoad& vecs);
136
137 /*
138 * Fills the TunerTimes object with values read from a file
139 *
140 * returns true on success
141 */
142 bool readFile(TunerLoad& times);
143
150 void tune(std::vector<Component>& ComponentList);
151
161 void iterate(std::vector<Component>& ComponentList, unsigned int numMols, double& gflopsOwnBig, double& gflopsPairBig, double& gflopsOwnNormal, double& gflopsPairNormalFace,
162 double& gflopsPairNormalEdge, double& gflopsPairNormalCorner, double& gflopsOwnZero, double& gflopsPairZero);
163
164 void iteratePair (unsigned int numRepetitions,
165 ParticleCell& firstCell, ParticleCell& secondCell, double& time);
166
167 void iterateOwn (unsigned int numRepetitions,
168 ParticleCell& cell, double& time);
169
177 void runOwn(CellProcessor& cp, ParticleCell& cell1, unsigned int numRepetitions);
178
186 void runPair(CellProcessor& cp, ParticleCell& cell1, ParticleCell& cell2, unsigned int numRepetitions);
187
197 void initMeshOfMolecules(const double boxMin[3], const double boxMax[3], Component& comp, ParticleCell& cell1, ParticleCell& cell2);
198
207 void initUniformRandomMolecules(Component& comp, ParticleCell& cell, unsigned int numMols);
208
209 void initUniformRandomMolecules(Component& comp1, Component& comp2, ParticleCell& cell, unsigned int numMolsFirst, unsigned int numMolsSecond);
210
211
218 void moveMolecules(double direction[3], ParticleCell& cell);
219
231 void initNormalRandomMolecules(double boxMin[3], double boxMax[3], Component& comp, ParticleCell& cell1, ParticleCell& cell2, unsigned int numMols);
232
238 void clearMolecules(ParticleCell& cell);
239
240 void initCells(ParticleCell& main, ParticleCell& face, ParticleCell& edge, ParticleCell& corner);
241
242 void iterateOwn(unsigned int numRepetitions,
243 ParticleCell& cell,
244 double& gflopsPair, FlopCounter& flopCounter);
245 void iteratePair(unsigned int numRepetitions,
246 ParticleCell& firstCell, ParticleCell& secondCell,
247 double& gflopsPair, FlopCounter& flopCounter);
248
249 class VTWriterI {
250 public:
251 virtual ~~VTWriterI() = default;
252 virtual void initWrite(const std::string& outputPrefix, double cutoffRadius, double LJCutoffRadius,
253 double cutoffRadiusBig, double LJCutoffRadiusBig)=0;
254 virtual void writeHeader(const std::string& distributionTypeString)=0;
255 virtual void write(unsigned int numMols, double gflopsOwnBig, double gflopsPairBig, double gflopsOwnNormal,
256 double gflopsPairNormalFace, double gflopsPairNormalEdge, double gflopsPairNormalCorner,
257 double gflopsOwnZero, double gflopsPairZero)=0;
258 virtual void close()=0;
259 protected:
260 int _rank;
261 };
262
263 class VTWriter: public VTWriterI {
264 public:
265 void initWrite(const std::string& outputPrefix, double cutoffRadius, double LJCutoffRadius,
266 double cutoffRadiusBig, double LJCutoffRadiusBig) override;
267 void writeHeader(const std::string& distributionTypeString) override;
268 void write(unsigned int numMols, double gflopsOwnBig, double gflopsPairBig, double gflopsOwnNormal,
269 double gflopsPairNormalFace, double gflopsPairNormalEdge, double gflopsPairNormalCorner,
270 double gflopsOwnZero, double gflopsPairZero) override;
271 void close() override;
272 private:
273 ofstream _myfile;
274 };
275
276 class VTWriterStatistics: public VTWriterI {
277 public:
278 void initWrite(const std::string& outputPrefix, double cutoffRadius, double LJCutoffRadius,
279 double cutoffRadiusBig, double LJCutoffRadiusBig) override;
280 void writeHeader(const std::string& distributionTypeString) override;
281 void write(unsigned int numMols, double gflopsOwnBig, double gflopsPairBig, double gflopsOwnNormal,
282 double gflopsPairNormalFace, double gflopsPairNormalEdge, double gflopsPairNormalCorner,
283 double gflopsOwnZero, double gflopsPairZero) override;
284 void close() override;
285 private:
286 void writeStatistics(double input, const std::string& name);
287 };
288
289 std::unique_ptr<VTWriterI> vtWriter{new VTWriter()};
290};
291
292#endif // SRC_IO_VECTORIZATIONTUNER_H_
A CellProcessor that produces Flop information.
Definition: CellProcessor.h:29
Class implementing molecules as rigid rotators consisting out of different interaction sites (LJcente...
Definition: Component.h:14
handle boundary region and multiple processes
Definition: DomainDecompBase.h:51
This class is used to read in the phasespace and to handle macroscopic values.
Definition: Domain.h:47
Definition: FlopCounter.h:60
FullParticleCell data structure. Renamed from ParticleCell.
Definition: FullParticleCell.h:49
This Interface is used to get access to particles and pairs of particles.
Definition: ParticleContainer.h:69
The PluginBase class provides the interface for any kind of output/plugin classes - called "(output) ...
Definition: PluginBase.h:47
Definition: LoadCalc.h:44
VectorizationTuner class.
Definition: VectorizationTuner.h:31
void tune(std::vector< Component > &ComponentList, TunerLoad &times, std::vector< int > particleNums, bool generateNewFiles, bool useExistingFiles, bool allowMPIReduce)
Definition: VectorizationTuner.cpp:243
void endStep(ParticleContainer *, DomainDecompBase *, Domain *, unsigned long) override
Method endStep will be called at the end of each time step.
Definition: VectorizationTuner.h:67
void init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) override
Method init will be called at the begin of the simulation.
Definition: VectorizationTuner.cpp:749
VectorizationTuner()=default
Constructor of VectorizationTuner for the xml input mode.
void finish(ParticleContainer *, DomainDecompBase *, Domain *) override
Method finish will be called at the end of the simulation.
Definition: VectorizationTuner.cpp:72
~VectorizationTuner() override=default
std::string getPluginName() override
return the name of the plugin
Definition: VectorizationTuner.h:75
void readXML(XMLfileUnits &xmlconfig) override
Read in XML configuration for the VectorizationTuner.
Definition: VectorizationTuner.cpp:28
XML file with unit attributes abstraction.
Definition: xmlfileUnits.h:25
::xsd::cxx::tree::name< char, token > name
C++ type corresponding to the Name XML Schema built-in type.
Definition: vtk-punstructured.h:288
::xsd::cxx::tree::time< char, simple_type > time
C++ type corresponding to the time XML Schema built-in type.
Definition: vtk-punstructured.h:438
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Definition: vtk-punstructured.h:270