GemaPCR
The GeMA PCR (Partition-Color-Renumber) Plugin
Loading...
Searching...
No Matches
gmpGemaPCR.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_PLUGIN_GEMA_PCR_H_
25#define _GEMA_PLUGIN_GEMA_PCR_H_
26
27#include "gmpGemaCR.h"
28
31{
32public:
33 GmpPartitionMethod(const QVariantMap& options) : _options(options) {}
34
39 virtual bool checkOptions(const GmLogCategory& logger) = 0;
40
42 virtual void printParameters(const GmLogCategory& logger) const = 0;
43
50 virtual bool partition(GmCellMesh* mesh, int numPartitions, QVector<int>& cellPartition,
51 const GmLogCategory& logger) const = 0;
52
53protected:
54 const QVariantMap& _options;
55};
56
57
58
63template <template <class> class Vector>
64class GMP_GEMA_PCR_API_EXPORT GmpGemaPCRBase : public GmpGemaCRBase<Vector, true>
65{
66public:
68 GmpGemaPCRBase(GmSimulationData* simulation, QString id, QString description, const GmLogCategory& logger)
69 : GmpGemaCRBase(simulation, id, description, logger), _numPartitions(1), _partition(0),
70 _numGlobalNodes(0), _numGlobalGhostNodes(0), _numGlobalCells(0), _partitionMethod(NULL),
71 _haloSides(false), _remoteHalo(false), _debugMode(false), _templateDumpData(NULL),
72 _templateDumpDataSize(0)
73 {}
74
75 virtual ~GmpGemaPCRBase();
76
77 // Comments on the base class
78 virtual const char* pluginType() const { if constexpr(std::is_same<Vector<int>, GmSingleVector<int>>::value) return "pcr"; else return "pcrd"; }
79
80 // Comments on the base class
81 virtual bool hasCapability(QString capabilityName) const
82 {
83 return capabilityName == "partitioning" || GmpGemaCRBase<Vector, true>::hasCapability(capabilityName);
84 }
85
86 virtual bool loadPrivateData(LuaTable& table);
87 virtual void printParameters(const GmLogCategory& logger);
88
89 // --------------------------------------
90 // -- Partition -------------------------
91 // --------------------------------------
92
93 // Comments on the base class
94 virtual int numPartitions() const { return _numPartitions; }
95 virtual int partition() const { return _partition; }
96 virtual int numGlobalNodes() const { assert(_mesh); return _numPartitions > 1 ? _numGlobalNodes : _mesh->numNodes(); } // Before partitioning, we return the mesh information
97 virtual int numGlobalGhostNodes() const { assert(_mesh); return _numPartitions > 1 ? _numGlobalGhostNodes : _mesh->numGhostNodes(); }
98 virtual int numGlobalCells() const { assert(_mesh && dynamic_cast<GmCellMesh*>(_mesh)); return _numPartitions > 1 ? _numGlobalCells : ((GmCellMesh*)_mesh)->numCells(); }
99
100 virtual GmPCR::CellClass cellClass (int cellId) const;
101 virtual int cellClassData (int cellId) const;
102 virtual int numCellsInClass(GmPCR::CellClass cellClass) const;
103 virtual GmPCR::NodeClass nodeClass (int nodeId) const;
104 virtual int nodeClassData (int nodeId) const;
105 virtual int numNodesInClass(GmPCR::NodeClass nodeClass, GmCellFillMode mode = GM_CELL_NODES) const;
106
107 // Comments on the base class
108 virtual int numRemoteRanks(int templateIndex) const { return _debugMode ? 0 : _classData._rankTemplates[templateIndex].first; }
109 virtual const int* remoteRanks (int templateIndex) const { return _debugMode ? NULL : _classData._rankTemplates[templateIndex].second; }
110
111 virtual bool addPartitionInfoAsMeshAttributes (QString cellAttrPrefix, QString nodeAttrPrefix);
112 virtual bool addDebugPartitionInfoAsMeshAttributes(QString cellAttrPrefix, QString nodeAttrPrefix);
113 virtual void printPartitionRankTemplateData (const GmLogCategory& logger) const;
114 virtual void printPartitionClassStatistics (const GmLogCategory& logger) const;
115
116 // -------------------------------------------------
117 // Initialization, control and dump API used by the mesh
118 // -------------------------------------------------
119 virtual bool initPartitions(int numPartitions, int partition);
120 virtual bool initNodeMapping(GmValueAccessor* ac, bool ghost, bool* renumbered,
121 QMap<int, int>& partOrigToLocOrder);
122 virtual bool initCellMapping(bool* renumbered, QMap<int, int>& partOrigToLocOrder,
123 QVector<int>& partLocToOrigOrder);
124
125 virtual bool addNodes (int numNodes);
126 virtual bool addGhostNodes (int numGhostNodes);
127 virtual bool addCells (int numCells);
128
129 virtual void clear();
130
131 virtual bool addStateGeometryData (GmStateDump* state, int groupId);
132 virtual bool fillDumpControlMapData (QVariantMap* map, const GmLogCategory& logger);
133 virtual bool dumpControlMapDataLoaded(QVariantMap* map, const GmLogCategory& logger);
134
135protected:
136
137 virtual size_t partitionMemory() const;
138
139private:
142
144 using ShortVector = Vector<short int>;
145
148 {
149 ClassData();
150 ~ClassData();
151
152 size_t usedMemory() const;
153 void clear();
154
158
162
163 int _nodesPerClass[GM_PCR_NUM_CLASSES];
164 int _ghostPerClass[GM_PCR_NUM_CLASSES];
165 int _cellsPerClass[GM_PCR_NUM_CLASSES];
166
173 };
174
177 {
178 public:
179 // Constructor. Gets as parameter a reference to the ClassData::_rankTemplates list to build
181 : _templateList(templateList) {}
182 int index(const QSet<int>& rankSet);
183 private:
186 };
187
188 int nodeData(int nodeId) const;
189
190 bool classifyNodesAndCells(ClassData* cd, int partition, const QVector<int>& cellPartition) const;
191 bool classifyCells (ClassData* cd, int partition, const QVector<int>& cellPartition, RankTemplateBuilder* builder) const;
192 bool classifyNodes (ClassData* cd, int partition, const QVector<int>& cellPartition, RankTemplateBuilder* builder) const;
193
194 bool adjustClassDataNodeOrder(ClassData* cd, bool ghost, const QMap<int, int>& partOrigToLocOrder) const;
195 bool adjustClassDataCellOrder(ClassData* cd, const QMap<int, int>& partOrigToLocOrder) const;
196
197 template <template<class> class V, class T, class F> bool adjustVector(V<T>& vector, F op) const;
198
199 bool addAndInitClassDataVector(ShortVector& v, int numAddedEntries, int val) const;
200
201 bool auxTemplateBufferLoaded(const GmLogCategory& logger);
202 void releaseDumpMemory();
203
209
214
217
224
227};
228
229
232
235
236
237#endif
An implementation of the CR (color and renumbering) object interface. The partition interface does no...
Definition gmpGemaCR.h:210
virtual void printParameters(const GmLogCategory &logger)
Print plugin parameters.
Definition gmpGemaCR.cpp:211
virtual bool loadPrivateData(LuaTable &table)
Parses configuration options given by the user to create this PCR object. IMPORTANT: This method is c...
Definition gmpGemaCR.cpp:104
Vector< int > IntVector
A Vector<int>
Definition gmpGemaCR.h:366
Helper class used to create rank templates.
Definition gmpGemaPCR.h:177
QVector< QPair< int, int * > > & _templateList
The template list.
Definition gmpGemaPCR.h:184
QMap< quint32, QVector< int > > _listIndex
Map indexed by a hash of the rank list, storing the indices in _templateList sharing that hash.
Definition gmpGemaPCR.h:185
An implementation of the PCR (partition, color and renumbering) object interface. The template parame...
Definition gmpGemaPCR.h:65
int _numGlobalGhostNodes
The number of ghost nodes on the mesh, before partitioning.
Definition gmpGemaPCR.h:207
int * _templateDumpData
A vector storing a temporary serialized version of _classData._rankTemplates, needed for dumping code...
Definition gmpGemaPCR.h:223
bool _debugMode
When the debug mode is turned on, the partition algorithm will be executed and cells will be classifi...
Definition gmpGemaPCR.h:213
GmpPartitionMethod * _partitionMethod
The configured partitioning object. Can be NULL if the user explicitly requested for no partitioning.
Definition gmpGemaPCR.h:210
GmpGemaPCRBase(GmSimulationData *simulation, QString id, QString description, const GmLogCategory &logger)
Default plugin object constructor.
Definition gmpGemaPCR.h:68
bool _remoteHalo
When set to true, includes the remote halo (remote cells adjacent to the partition halo cells) in the...
Definition gmpGemaPCR.h:212
ClassData _classData
The data set for the current partition. Filled only if _debugMode is false and _numPartitions > 1.
Definition gmpGemaPCR.h:216
bool _haloSides
If set to true, a cell belongs to the halo if one of its sides is shared with a remote cell....
Definition gmpGemaPCR.h:211
int _templateDumpDataSize
The size of the vector _templateDumpData.
Definition gmpGemaPCR.h:226
int _numGlobalCells
The number of cells on the mesh, before partitioning.
Definition gmpGemaPCR.h:208
Vector< short int > ShortVector
A Vector<short>. 14 bits (16k) should be more than enough to store ranks and template indices.
Definition gmpGemaPCR.h:144
int _partition
The number of my partition (rank)
Definition gmpGemaPCR.h:205
int _numGlobalNodes
The number of geometric nodes on the mesh, before partitioning.
Definition gmpGemaPCR.h:206
QVector< ClassData * > _rankClassData
A vector with class data for each partition. Filled only if _debugMode is true.
Definition gmpGemaPCR.h:215
int _numPartitions
The number of mesh partitions. Will always equal 1 in debug mode.
Definition gmpGemaPCR.h:204
typename GmpGemaCRBase< Vector, true >::IntVector IntVector
The same Vector<int> from the base class.
Definition gmpGemaPCR.h:141
The abstract interface for a partition method implementation.
Definition gmpGemaPCR.h:31
virtual bool checkOptions(const GmLogCategory &logger)=0
Virtual method responsible for validating the parameters supplied on the class constructor....
virtual bool partition(GmCellMesh *mesh, int numPartitions, QVector< int > &cellPartition, const GmLogCategory &logger) const =0
The cell partition function. It gets as input parameters the cell mesh with a valid cell incidence in...
virtual void printParameters(const GmLogCategory &logger) const =0
Virtual method responsible for printing the partition method description.
const QVariantMap & _options
The user provided options.
Definition gmpGemaPCR.h:54
GmCellFillMode
#define GM_PCR_NUM_CLASSES
Declaration of the GmpGemaCR class & friends.
GmpGemaPCRBase< GmDualVector > GmpGemaPCRD
Typedef for the PCR implementation with dual vector.
Definition gmpGemaPCR.h:234
GmpGemaPCRBase< GmSingleVector > GmpGemaPCR
Typedef for the PCR implementation with single vector.
Definition gmpGemaPCR.h:231
Class data for cells and nodes.
Definition gmpGemaPCR.h:148
ShortVector _cellClass
Vector storing cell classes + associated data for the cells stored in _cells.
Definition gmpGemaPCR.h:161
ShortVector _nodeClass
Vector storing geometric node classes + associated data for the geometric nodes stored in _nodes.
Definition gmpGemaPCR.h:159
IntVector _cells
The ordered set of cells included in the partition. Unless in debug mode, will be cleared after renum...
Definition gmpGemaPCR.h:157
IntVector _nodes
The ordered set of geometric nodes included in the partition. Unless in debug mode,...
Definition gmpGemaPCR.h:155
QVector< QPair< int, int * > > _rankTemplates
A vector storing the templates defining which remote partitions share a halo node / cell owned by the...
Definition gmpGemaPCR.h:172
ShortVector _ghostClass
Vector storing ghost node classes + associated data for the ghost nodes stored in _ghosts.
Definition gmpGemaPCR.h:160
IntVector _ghosts
The ordered set of (0-based) ghost nodes included in the partition. Unless in debug mode,...
Definition gmpGemaPCR.h:156