ls1-MarDyn
ls1-MarDyn molecular dynamics code
KDNode.h
1#ifndef KDNODE_H_
2#define KDNODE_H_
3
4// include because of macro KDDIM
5#include "parallel/KDDecomposition.h" /* TODO seriously..? */
6
7#include "parallel/MPIKDNode.h"
8
9#include <vector>
10
12
28class KDNode {
29
30public:
31
38
39 KDNode() :_numProcs(0), _nodeID(0), _owningProc(0),
40 _child1(nullptr), _child2(nullptr), _load(0.0), _optimalLoadPerProcess(0.0),
42 {
43 }
44
45
49 KDNode(const KDNode& other) : _numProcs(other._numProcs), _nodeID(other._nodeID),
50 _owningProc(other._owningProc), _child1(nullptr), _child2(nullptr),
51 _load(other._load), _optimalLoadPerProcess(other._optimalLoadPerProcess),
53 _level(other._level)
54 {
55 for (int dim = 0; dim < KDDIM; dim++) {
56 _lowCorner[dim] = other._lowCorner[dim];
57 _highCorner[dim] = other._highCorner[dim];
58 _coversWholeDomain[dim] = other._coversWholeDomain[dim];
59 }
60 }
61
62 KDNode(int numP, const int low[KDDIM], const int high[KDDIM], int id, int owner, bool coversAll[KDDIM], int level)
63 : _numProcs(numP), _nodeID(id), _owningProc(owner),
64 _child1(nullptr), _child2(nullptr), _load(0.0), _optimalLoadPerProcess(0.0),
65 _deviationLowerBound(0.0), _deviation(0.0), _level(level)
66 {
67 for (int dim = 0; dim < KDDIM; dim++) {
68 _lowCorner[dim] = low[dim];
69 _highCorner[dim] = high[dim];
70 _coversWholeDomain[dim] = coversAll[dim];
71 }
72 }
73
77 bool equals(KDNode& other);
78
81 delete _child1;
82 delete _child2;
83 }
84
91 KDNode* findAreaForProcess(int rank);
92
97 void buildKDTree();
98
103 bool isResolvable();
104
108 unsigned int getNumMaxProcs();
109
110 double calculateAvgLoadPerProc() const {
111 return _load / ((double) _numProcs);
112 }
113
118 void calculateDeviationLowerBound(std::vector<double>* accumulatedProcessorSpeeds = nullptr) {
119 double meanProcessorSpeed[] = { 1., 1. };
120 double totalMeanProcessorSpeed = 1.;
121 if (accumulatedProcessorSpeeds and not accumulatedProcessorSpeeds->empty()) {
122 meanProcessorSpeed[0] = ((*accumulatedProcessorSpeeds)[_child2->_owningProc]
123 - (*accumulatedProcessorSpeeds)[_owningProc]) / (_child1->_numProcs);
124 meanProcessorSpeed[1] = ((*accumulatedProcessorSpeeds)[_child2->_owningProc + _child2->_numProcs]
125 - (*accumulatedProcessorSpeeds)[_child2->_owningProc]) / (_child2->_numProcs);
126 size_t numProcs = accumulatedProcessorSpeeds->size() - 1;
127 totalMeanProcessorSpeed = (*accumulatedProcessorSpeeds)[numProcs] / numProcs;
128 }
129 double child1Dev = _child1->calculateAvgLoadPerProc()
130 - _optimalLoadPerProcess * meanProcessorSpeed[0] / totalMeanProcessorSpeed;
131 child1Dev = child1Dev * child1Dev;
132 double child2Dev = _child2->calculateAvgLoadPerProc()
133 - _optimalLoadPerProcess * meanProcessorSpeed[1] / totalMeanProcessorSpeed;
134 child2Dev = child2Dev * child2Dev;
135 _deviationLowerBound = child1Dev * static_cast<double>( _child1->_numProcs) + child2Dev * static_cast<double>(_child2->_numProcs);
136 }
137
138 void calculateDeviation(std::vector<double>* processorSpeeds = nullptr, const double &totalMeanProcessorSpeed = 1.) {
139 if (_numProcs == 1) {
140 double speed = 1.;
141 if (processorSpeeds != nullptr && processorSpeeds->size() > (unsigned int)_owningProc) {
142 speed = (*processorSpeeds)[_owningProc];
143 }
144 //_deviation = _load - _optimalLoadPerProcess;
145 double dev = _load - _optimalLoadPerProcess * speed / totalMeanProcessorSpeed;
146 _deviation = dev * dev;
147 } else {
149 }
150 }
151
159 void getOwningProcs(const int low[KDDIM], const int high[KDDIM], std::vector<int>& procIDs, std::vector<int>& neighbHaloAreas) const;
160
161
173 void split(int divDimension, int splitIndex, int numProcsLeft);
174
181 void printTree(const std::string& prefix, std::ostream& ostream);
182
187 void serialize(const std::string& fileName);
188
192 void deserialize(const std::string& fileName);
193
197 void plotNode(const std::string& vtkFile, const std::vector<double>* processorSpeeds=nullptr) const;
198
202 static void initMPIDataType() {
204 }
205
209 static void shutdownMPIDataType() {
210 MPIKDNode::shutdownDatatype();
211 }
212
217
226
230 int _owningProc; // only used if the node is a leaf
231
236
237 double _load;
238 double _optimalLoadPerProcess;
239
248
251
252private:
253
254 void serialize(std::ostream& file);
255
256 void deserialize(std::istream& file);
257
258 void plotNode(VTKGridWriterImplementation& writer) const;
259
260};
261
262#endif /* KDNODE_H_ */
represents a node in the decomposition tree when using KDDecomposition
Definition: KDNode.h:28
double _deviation
Definition: KDNode.h:247
bool equals(KDNode &other)
Definition: KDNode.cpp:34
int _owningProc
process which owns this KDNode (only possible for leaf nodes)
Definition: KDNode.h:230
MPIKDNodePacked MPIKDNode
Definition: KDNode.h:37
int _lowCorner[3]
in cells relative to global domain
Definition: KDNode.h:221
KDNode * _child1
"left" child of this KDNode (only used if the child is no leaf)
Definition: KDNode.h:233
void plotNode(const std::string &vtkFile, const std::vector< double > *processorSpeeds=nullptr) const
Definition: KDNode.cpp:281
double _deviationLowerBound
Definition: KDNode.h:243
void getOwningProcs(const int low[KDDIM], const int high[KDDIM], std::vector< int > &procIDs, std::vector< int > &neighbHaloAreas) const
Definition: KDNode.cpp:321
void serialize(const std::string &fileName)
Definition: KDNode.cpp:206
int _nodeID
ID of this KDNode.
Definition: KDNode.h:228
KDNode * _child2
"left" child of this KDNode (only used if the child is no leaf)
Definition: KDNode.h:235
void deserialize(const std::string &fileName)
Definition: KDNode.cpp:243
bool isResolvable()
Definition: KDNode.cpp:142
void calculateDeviationLowerBound(std::vector< double > *accumulatedProcessorSpeeds=nullptr)
Definition: KDNode.h:118
void split(int divDimension, int splitIndex, int numProcsLeft)
Definition: KDNode.cpp:160
int _highCorner[3]
in cells relative to global domain
Definition: KDNode.h:223
KDNode(const KDNode &other)
Definition: KDNode.h:49
~KDNode()
The destructor deletes the childs (recursive call of destructors)
Definition: KDNode.h:80
int _numProcs
number of procs which share this area
Definition: KDNode.h:219
KDNode * findAreaForProcess(int rank)
Definition: KDNode.cpp:18
static void initMPIDataType()
Definition: KDNode.h:202
int _level
level of this node (at root node, level = 0)
Definition: KDNode.h:250
MPIKDNode getMPIKDNode()
Definition: KDNode.cpp:118
void buildKDTree()
create an initial decomposition of the domain represented by this node.
Definition: KDNode.cpp:68
bool _coversWholeDomain[KDDIM]
true if the domain in the given dimension is not divided into more than one process
Definition: KDNode.h:225
static void shutdownMPIDataType()
Definition: KDNode.h:209
void printTree(const std::string &prefix, std::ostream &ostream)
prints this (sub-) tree to stdout
Definition: KDNode.cpp:91
unsigned int getNumMaxProcs()
Definition: KDNode.cpp:151
Definition: MPIKDNode.h:19
static void initDatatype()
Definition: MPIKDNode.cpp:305
Definition: VTKGridWriterImplementation.h:23
::xsd::cxx::tree::id< char, ncname > id
C++ type corresponding to the ID XML Schema built-in type.
Definition: vtk-punstructured.h:322
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Definition: vtk-punstructured.h:270