MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
StructuredDecomposition< nDim > Class Template Reference

Class for the decomposition (partition) of structured grids. More...

#include <structuredpartition.h>

Collaboration diagram for StructuredDecomposition< nDim >:
[legend]

Public Member Functions

 StructuredDecomposition (const MInt, const MString, MPI_Comm, const MInt)
 Constructor for HDF5 grid file name Reads the size of the coordinate datasets for all blocks. More...
 
 StructuredDecomposition (const MInt, ParallelIoHdf5 *pio, MPI_Comm, const MInt)
 Constructor for HDF5 grid file handle Reads the size of the coordinate datasets for all blocks. More...
 
 ~StructuredDecomposition ()
 
void decompose ()
 Decompose the grid into partitions for the set number of domains. More...
 
MBool readFromFile ()
 Read a precomputed partition info from an external file. More...
 
MInt getBlockIdFromPartition (const MInt domainId_)
 
MInt getPartitionOffset (const MInt domainId_, const MInt dim)
 
MInt getPartitionSize (const MInt domainId_, const MInt dim)
 
MInt getBlockOffset (const MInt domainId_, const MInt dim)
 
MInt getBlockSize (const MInt domainId_, const MInt dim)
 

Private Member Functions

MInt rounding (MFloat x)
 
void initializeChilds (treeNode *&treePointer)
 Initializes the childs of the given tree node. More...
 
void setPartitionInfoHelper (treeNode *&, const MInt, const MInt(&)[nDim], MInt &, MInt(&)[nDim], MInt(&)[nDim], MInt(&)[nDim])
 Helper function for setPartionInfo. More...
 
void setPartitionInfo (treeNode **&, MIntScratchSpace &)
 Computes partition information from given BCT. More...
 
void traverseForInsertionNode (treeNode *&treePointer, const MInt, const MInt(&)[nDim], treeNode *&)
 Recursively traverses the given tree to find the next insertion position. More...
 
void destroyChilds (treeNode *&treePointer)
 Recursively destroy all childs of a tree node. More...
 
MInt sumLeaves (treeNode *&treePointer)
 Compute the number of leaves of a tree nodes. More...
 
void insertChildAtNode (treeNode *&, const MInt, const MInt(&)[nDim])
 Inserts new child node below given tree node. More...
 
void addLeaf (treeNode **&treeRoot, MIntScratchSpace &level2dimension)
 Add a leaf into the tree. More...
 
MInt noDomains () const
 

Private Attributes

const MInt m_noBlocks
 
const MPI_Comm m_mpiComm
 
const MInt m_noDomains
 
MInt m_noPartitions
 
const MFloat m_eps
 
std::vector< std::unique_ptr< PartitionInfo< nDim > > > m_blockInfo {}
 
std::vector< std::unique_ptr< PartitionInfo< nDim > > > m_partitionInfo {}
 

Detailed Description

template<MInt nDim>
class StructuredDecomposition< nDim >

The class will decompose a given multi-block grid into a number of partitions using the balanced cut trees method described in

G. Geiser, W. Schröder, Structured multi-block grid partitioning using balanced cut trees, J. Parallel Distrib. Comput. 138 (2020)

Note that throughout the class the term 'block' and the corresponding 'blockId' refer to input block, i.e., the blocks of the grid file, whereas the term 'partition' refers to the partitions created by the decomposition. Finally, the number of partitions should be equal to the given number of MPI domains.

Definition at line 59 of file structuredpartition.h.

Constructor & Destructor Documentation

◆ StructuredDecomposition() [1/2]

template<MInt nDim>
StructuredDecomposition< nDim >::StructuredDecomposition ( const MInt  noBlocks_,
const MString  fileName_,
MPI_Comm  comm_,
const MInt  noDomains_ 
)
Parameters
[in]noBlockNumber of blocks in the grid file
[in]fileNameFile name of the grid file
[in]commMPI communicator
[in]noDomains_Number of MPI domains to be used for decomposition

Definition at line 26 of file structuredpartition.cpp.

30 : m_noBlocks(noBlocks_),
31 m_mpiComm(comm_),
32 m_noDomains(noDomains_),
34 m_eps(std::numeric_limits<MFloat>::epsilon()) {
35 for(MInt j = 0; j < m_noBlocks; j++) {
36 m_blockInfo.push_back(make_unique<PartitionInfo<nDim>>());
37 }
38
39 MIntScratchSpace dataSetSize(m_noBlocks * nDim, AT_, "dataSetSize");
40 MFloatScratchSpace weight(m_noBlocks, AT_, "weights");
41
42 dataSetSize.fill(0);
43
44 if(globalDomainId() == 0) {
45 ParallelIoHdf5 pio(fileName_, maia::parallel_io::PIO_APPEND, MPI_COMM_SELF);
46 for(MInt i = 0; i < m_noBlocks; i++) {
47 MString sBlockName = "/block" + std::to_string(i);
48 std::vector<ParallelIo::size_type> tmp(nDim, 0);
49 pio.getArraySize("x", sBlockName, &tmp[0]);
50 std::copy(tmp.begin(), tmp.end(), &dataSetSize[i * nDim]);
51 weight[i] = 1.0;
52 if(pio.hasAttribute("weight", sBlockName)) { // get the weighting factor
53 pio.getAttribute<MFloat>(&weight[i], "weight", sBlockName);
54 }
55 }
56
57 MPI_Bcast(&dataSetSize[0], m_noBlocks * nDim, MPI_INT, 0, m_mpiComm, AT_, "dataSetSize.getPointer()");
58 MPI_Bcast(weight.getPointer(), m_noBlocks, MPI_DOUBLE, 0, m_mpiComm, AT_, "weight.getPointer()");
59 } else {
60 MPI_Bcast(&dataSetSize[0], m_noBlocks * nDim, MPI_INT, 0, m_mpiComm, AT_, "dataSetSize.getPointer()");
61 MPI_Bcast(weight.getPointer(), m_noBlocks, MPI_DOUBLE, 0, m_mpiComm, AT_, "weight.getPointer()");
62 }
63
64 for(MInt i = 0; i < m_noBlocks; i++) {
65 m_blockInfo[i]->blockId = i;
66 for(MInt j = 0; j < nDim; j++) {
67 m_blockInfo[i]->size[j] = dataSetSize[i * nDim + j] - 1;
68 m_blockInfo[i]->weight = weight[i];
69 m_blockInfo[i]->offset[j] = 0;
70 }
71 }
72}
This class is a ScratchSpace.
Definition: scratch.h:758
std::vector< std::unique_ptr< PartitionInfo< nDim > > > m_blockInfo
MInt globalDomainId()
Return global domain id.
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm, const MString &name, const MString &varname)
same as MPI_Bcast
const MInt PIO_APPEND
Definition: parallelio.h:38

◆ StructuredDecomposition() [2/2]

template<MInt nDim>
StructuredDecomposition< nDim >::StructuredDecomposition ( const MInt  noBlocks_,
ParallelIoHdf5 pio,
MPI_Comm  comm_,
const MInt  noDomains_ 
)
Parameters
[in]noBlockNumber of blocks in the grid file
[in]pioParallelIO file handle of the grid file
[in]noDomains_Number of MPI domains to be used for decomposition
[in]commMPI communicator

Definition at line 85 of file structuredpartition.cpp.

89 : m_noBlocks(noBlocks_),
90 m_mpiComm(comm_),
91 m_noDomains(noDomains_),
93 m_eps(std::numeric_limits<MFloat>::epsilon()) {
94 for(MInt j = 0; j < m_noBlocks; j++) {
95 m_blockInfo.push_back(make_unique<PartitionInfo<nDim>>());
96 }
97
98 ParallelIo::size_type ijk_max[3] = {0};
99 for(MInt i = 0; i < m_noBlocks; i++) {
100 m_blockInfo[i]->blockId = i;
101 MString sBlockName = "/block" + std::to_string(i);
102 pio->getArraySize("x", sBlockName, &ijk_max[0]);
103
104 // assign ijk_max to m_blockInfo and also assign the offset
105 for(MInt j = 0; j < nDim; j++) {
106 m_blockInfo[i]->size[j] = ijk_max[j] - 1;
107 m_blockInfo[i]->offset[j] = 0;
108 }
109 }
110}
size_type getArraySize(const MString &name, const size_type dimensionId=0)
Get the length of an array in the file.
Definition: parallelio.h:667

◆ ~StructuredDecomposition()

template<MInt nDim>
StructuredDecomposition< nDim >::~StructuredDecomposition ( )
inline

Definition at line 63 of file structuredpartition.h.

63{};

Member Function Documentation

◆ addLeaf()

template<MInt nDim>
void StructuredDecomposition< nDim >::addLeaf ( treeNode **&  treeRoot,
MIntScratchSpace level2dimension 
)
private
Parameters
[in]treeRootRoots of the trees, same number as number of blocks
[in]level2dimensionArray to map the current level to the space dimension

Definition at line 340 of file structuredpartition.cpp.

340 {
341 // select the block id which currently contains the largest partition
342 MInt blockId = 0;
343 MLongFloat maxWeightedSize = 0;
344 for(MInt i = 0; i < m_noPartitions; i++) {
345 const MLongFloat weightedSize = m_partitionInfo[i]->totalSize * m_partitionInfo[i]->weight;
346 if(weightedSize > maxWeightedSize) {
347 blockId = m_partitionInfo[i]->blockId;
348 maxWeightedSize = weightedSize;
349 }
350 }
351
352 // set this tree root for further processing
353 treeNode* myTreeRootPointer = treeRoot[blockId];
354 treeNode* myInsertTreePointer = treeRoot[blockId];
355
356 // pick corresponding level->dimension map
357 MInt level2dimension1D[nDim];
358 for(MInt i = 0; i < nDim; i++) {
359 level2dimension1D[i] = level2dimension(i, blockId);
360 }
361
362 // now find insertion point
363 traverseForInsertionNode(myTreeRootPointer, blockId, level2dimension1D, myInsertTreePointer);
364 insertChildAtNode(myInsertTreePointer, blockId, level2dimension1D);
365 myTreeRootPointer->noLeaves = sumLeaves(myTreeRootPointer);
366
367 // update partition information
369 setPartitionInfo(treeRoot, level2dimension);
370}
MInt sumLeaves(treeNode *&treePointer)
Compute the number of leaves of a tree nodes.
void setPartitionInfo(treeNode **&, MIntScratchSpace &)
Computes partition information from given BCT.
void insertChildAtNode(treeNode *&, const MInt, const MInt(&)[nDim])
Inserts new child node below given tree node.
void traverseForInsertionNode(treeNode *&treePointer, const MInt, const MInt(&)[nDim], treeNode *&)
Recursively traverses the given tree to find the next insertion position.
std::vector< std::unique_ptr< PartitionInfo< nDim > > > m_partitionInfo
long double MLongFloat
Definition: maiatypes.h:53

◆ decompose()

template<MInt nDim>
void StructuredDecomposition< nDim >::decompose

Definition at line 376 of file structuredpartition.cpp.

376 {
377 treeNode* myTreeRootPointer;
378 treeNode** myTreeRoot;
379 MInt countBlock;
381 myTreeRoot = new treeNode*[m_noBlocks];
382
383 // Create one tree root for each block
384 for(MInt i = 0; i < m_noBlocks; i++) {
385 myTreeRoot[i] = new treeNode;
386 }
387
388 for(countBlock = 0; countBlock < m_noBlocks; countBlock++) {
389 myTreeRootPointer = myTreeRoot[countBlock];
390 initializeChilds(myTreeRootPointer);
391 }
392
393 // prepare by filling level2dimension
394 MIntScratchSpace level2dimensionA(nDim, m_noBlocks, AT_, "level2dimensionA");
395 level2dimensionA.fill(0);
396
397 for(MInt k = 0; k < m_noBlocks; k++) {
398 std::vector<std::pair<MInt, MInt>> dummy{};
399 for(MInt i = 0; i < nDim; i++) {
400 dummy.push_back({m_blockInfo[k]->size[i], i});
401 }
402 // sort pairs by first value in descending order
403 std::sort(dummy.begin(), dummy.end(), [](auto& left, auto& right) { return left.first > right.first; });
404 for(MInt i = 0; i < nDim; i++) {
405 level2dimensionA(i, k) = dummy[i].second;
406 }
407 }
408
409 setPartitionInfo(myTreeRoot, level2dimensionA);
410
411 // now add leaves successively
412 while(m_noPartitions < m_noDomains) {
413 addLeaf(myTreeRoot, level2dimensionA);
414 }
415
416 // Clean up tree
417 for(MInt i = 0; i < m_noBlocks; i++) {
418 myTreeRootPointer = myTreeRoot[i];
419 destroyChilds(myTreeRootPointer);
420 }
421
422 for(MInt j = 0; j < m_noBlocks; j++) {
423 delete myTreeRoot[j];
424 }
425
426 delete[] myTreeRoot;
427}
void addLeaf(treeNode **&treeRoot, MIntScratchSpace &level2dimension)
Add a leaf into the tree.
void destroyChilds(treeNode *&treePointer)
Recursively destroy all childs of a tree node.
void initializeChilds(treeNode *&treePointer)
Initializes the childs of the given tree node.

◆ destroyChilds()

template<MInt nDim>
void StructuredDecomposition< nDim >::destroyChilds ( treeNode *&  treePointer)
private
Parameters
[in]treePointerPointer to a tree node

Definition at line 276 of file structuredpartition.cpp.

276 {
277 if(treePointer->level < (nDim - 1)) {
278 for(MInt i = 0; i < treePointer->noChilds; i++) {
279 treeNode* myTreePointer = treePointer->childs[i];
280 destroyChilds(myTreePointer);
281 }
282 delete[] treePointer->childs;
283 }
284}
treeNode ** childs

◆ getBlockIdFromPartition()

template<MInt nDim>
MInt StructuredDecomposition< nDim >::getBlockIdFromPartition ( const MInt  domainId_)
inline

Definition at line 66 of file structuredpartition.h.

66{ return m_partitionInfo[domainId_]->blockId; };

◆ getBlockOffset()

template<MInt nDim>
MInt StructuredDecomposition< nDim >::getBlockOffset ( const MInt  domainId_,
const MInt  dim 
)
inline

Definition at line 69 of file structuredpartition.h.

69{ return m_blockInfo[domainId_]->offset[dim]; };

◆ getBlockSize()

template<MInt nDim>
MInt StructuredDecomposition< nDim >::getBlockSize ( const MInt  domainId_,
const MInt  dim 
)
inline

Definition at line 70 of file structuredpartition.h.

70{ return m_blockInfo[domainId_]->size[dim]; };

◆ getPartitionOffset()

template<MInt nDim>
MInt StructuredDecomposition< nDim >::getPartitionOffset ( const MInt  domainId_,
const MInt  dim 
)
inline

Definition at line 67 of file structuredpartition.h.

67{ return m_partitionInfo[domainId_]->offset[dim]; };

◆ getPartitionSize()

template<MInt nDim>
MInt StructuredDecomposition< nDim >::getPartitionSize ( const MInt  domainId_,
const MInt  dim 
)
inline

Definition at line 68 of file structuredpartition.h.

68{ return m_partitionInfo[domainId_]->size[dim]; };

◆ initializeChilds()

template<MInt nDim>
void StructuredDecomposition< nDim >::initializeChilds ( treeNode *&  treePointer)
private
Parameters
[in]treePointerPointer to the tree

Definition at line 257 of file structuredpartition.cpp.

257 {
258 if(treePointer->level < (nDim - 1)) {
259 treePointer->childs = new treeNode*[treePointer->noChilds];
260 for(MInt i = 0; i < treePointer->noChilds; i++) {
261 treePointer->childs[i] = new treeNode;
262 }
263 for(MInt countChild = 0; countChild < treePointer->noChilds; countChild++) {
264 treePointer->childs[countChild]->level = (treePointer->level) + 1;
265 treeNode* myTreePointer = treePointer->childs[countChild];
266 initializeChilds(myTreePointer);
267 }
268 }
269}

◆ insertChildAtNode()

template<MInt nDim>
void StructuredDecomposition< nDim >::insertChildAtNode ( treeNode *&  insertTreePointer,
const MInt  blockId,
const  MInt(&)[nDim] 
)
private
Parameters
[in]insertTreePointerPointer to the tree node below which new child is inserted
[in]blockIdblock id of the current subtree
[in]level2dimension1DArray of level to space dimension mapping

Definition at line 316 of file structuredpartition.cpp.

318 {
319 destroyChilds(insertTreePointer);
320 insertTreePointer->noChilds++;
321 MInt myNoLeaves = insertTreePointer->noLeaves + 1;
322 initializeChilds(insertTreePointer);
323
324 if(insertTreePointer->level < (nDim - 1)) {
325 for(MInt i = insertTreePointer->noChilds + 1; i <= myNoLeaves; i++) {
326 treeNode* myInsertTreePointer = insertTreePointer;
327 traverseForInsertionNode(insertTreePointer, blockId, level2dimension1D, myInsertTreePointer);
328 insertChildAtNode(myInsertTreePointer, blockId, level2dimension1D);
329 insertTreePointer->noLeaves = sumLeaves(insertTreePointer);
330 }
331 }
332}

◆ noDomains()

template<MInt nDim>
MInt StructuredDecomposition< nDim >::noDomains ( ) const
inlineprivate

Definition at line 83 of file structuredpartition.h.

83{ return m_noDomains; }

◆ readFromFile()

template<MInt nDim>
MBool StructuredDecomposition< nDim >::readFromFile
Returns
true or false depending on the success

Definition at line 434 of file structuredpartition.cpp.

434 {
435 // temporary scratch to send/receive the partition Info
436 MIntScratchSpace filePartitionInfo((3 + 3 + 4) * m_noDomains, "filePartitionInfo", AT_);
437 filePartitionInfo.fill(0);
438 MInt noCPUs = 0;
439
440 if(globalDomainId() == 0) { // only root reads in the information
441 ParallelIoHdf5 pio("partitionFile.hdf5", maia::parallel_io::PIO_APPEND, MPI_COMM_SELF);
442 pio.getAttribute<MInt>(&noCPUs, "noCPUs", "");
443 }
444
445 // broadcast the number of cpus
446 MPI_Bcast(&noCPUs, 1, MPI_INT, 0, m_mpiComm, AT_, "noCPUs");
447 if(noCPUs != m_noDomains) {
448 m_log << "WARNING no CPUs is not equal to ones given in partitionFile" << endl;
449 return false;
450 }
451
452 if(globalDomainId() == 0) {
453 // read the information out of the file
454 ParallelIoHdf5 pio("partitionFile.hdf5", maia::parallel_io::PIO_APPEND, MPI_COMM_SELF);
455 ParallelIo::size_type asize[2] = {noCPUs, 10};
456 pio.readArray(filePartitionInfo.getPointer(), "", "partitionData", 2, asize);
457 }
458
459 MPI_Bcast(filePartitionInfo.getPointer(), noCPUs * (10), MPI_INT, 0, m_mpiComm, AT_,
460 "filePartitionInfo.getPointer()");
461
462 m_noPartitions = noCPUs;
463 for(MInt j = 0; j < m_noPartitions; j++) {
464 m_partitionInfo.push_back(make_unique<PartitionInfo<nDim>>());
465 }
466
467 // put the information into the right place
468 for(MInt j = 0; j < m_noPartitions; j++) {
469 for(MInt dim = 0; dim < nDim; dim++) {
470 m_partitionInfo[j]->size[dim] = filePartitionInfo[j * 10 + dim];
471 m_partitionInfo[j]->offset[dim] = filePartitionInfo[j * 10 + 3 + dim];
472 }
473
474 m_partitionInfo[j]->blockId = filePartitionInfo[j * 10 + 6];
475 m_partitionInfo[j]->partitionId = filePartitionInfo[j * 10 + 7];
476 m_partitionInfo[j]->cpu = filePartitionInfo[j * 10 + 8];
477 m_partitionInfo[j]->totalSize = filePartitionInfo[j * 10 + 9];
478 }
479
480 return true;
481}
InfoOutFile m_log

◆ rounding()

template<MInt nDim>
MInt StructuredDecomposition< nDim >::rounding ( MFloat  x)
private

Definition at line 484 of file structuredpartition.cpp.

484 {
485 MFloat a;
486 ((x - floor(x)) >= 0.5) ? a = ceil(x) : a = floor(x);
487 return (MInt)a;
488}
Definition: contexttypes.h:19

◆ setPartitionInfo()

template<MInt nDim>
void StructuredDecomposition< nDim >::setPartitionInfo ( treeNode **&  treeRoot,
MIntScratchSpace level2dimension 
)
private
Parameters
[in]treeRootNode of a (sub)tree
[in]level2dimensionArray of level to space dimension mapping

Definition at line 185 of file structuredpartition.cpp.

185 {
186 treeNode* myTreeRootPointer{};
187 MInt beginPartitionHelper[nDim]{0};
188 MInt endPartitionHelper[nDim]{0};
189 MInt divisor[nDim]{0};
190
191 m_partitionInfo.clear();
192 for(MInt j = 0; j < m_noPartitions; j++) {
193 m_partitionInfo.push_back(make_unique<PartitionInfo<nDim>>());
194 }
195
196 MInt partitionCounter = 0;
197 for(MInt i = 0; i < m_noBlocks; i++) {
198 myTreeRootPointer = treeRoot[i];
199 MInt level2dimension1D[nDim]{0};
200
201 for(MInt j = 0; j < nDim; j++) {
202 level2dimension1D[j] = level2dimension(j, i);
203 }
204
205 setPartitionInfoHelper(myTreeRootPointer, i, level2dimension1D, partitionCounter, beginPartitionHelper,
206 endPartitionHelper, divisor);
207 }
208}
void setPartitionInfoHelper(treeNode *&, const MInt, const MInt(&)[nDim], MInt &, MInt(&)[nDim], MInt(&)[nDim], MInt(&)[nDim])
Helper function for setPartionInfo.

◆ setPartitionInfoHelper()

template<MInt nDim>
void StructuredDecomposition< nDim >::setPartitionInfoHelper ( treeNode *&  treePointer,
const MInt  blockId,
const  MInt(&)[nDim],
MInt partitionCounter,
MInt(&)  beginPartitionHelper[nDim],
MInt(&)  endPartitionHelper[nDim],
MInt(&)  divisor[nDim] 
)
private

Goes trough the tree recursively and computes the partition information

Parameters
[in]treePointerPointer to a tree node
[in]blockIdblock id of the subtree
[in]level2dimension1DArray of level to dimension mapping
[in]partitionCounterCounter of the number of partitions
[in]beginPartitionCounter
[in]endPartitionCounter
[in]divisor
Returns

Definition at line 127 of file structuredpartition.cpp.

133 {
134 treeNode* myTreePointer;
135 MInt beginBlock[nDim]{0};
136 MInt endBlock[nDim]{0};
137
138 divisor[level2dimension1D[treePointer->level]] = treePointer->noLeaves;
139
140 if(treePointer->level < (nDim - 1)) {
141 beginPartitionHelper[level2dimension1D[treePointer->level]] = 0;
142 for(MInt i = 0; i < treePointer->noChilds; i++) {
143 if(i > 0) {
144 beginPartitionHelper[level2dimension1D[treePointer->level]] =
145 beginPartitionHelper[level2dimension1D[treePointer->level]] + treePointer->childs[i - 1]->noLeaves;
146 }
147 endPartitionHelper[level2dimension1D[treePointer->level]] =
148 beginPartitionHelper[level2dimension1D[treePointer->level]] + treePointer->childs[i]->noLeaves;
149 myTreePointer = treePointer->childs[i];
150 setPartitionInfoHelper(myTreePointer, blockId, level2dimension1D, partitionCounter, beginPartitionHelper,
151 endPartitionHelper, divisor);
152 }
153 } else {
154 for(MInt i = 0; i < treePointer->noChilds; i++) {
155 beginPartitionHelper[level2dimension1D[treePointer->level]] = i;
156 endPartitionHelper[level2dimension1D[treePointer->level]] = i + 1;
157 for(MInt j = 0; j < nDim; j++) {
158 beginBlock[j] = rounding(((MFloat)m_blockInfo[blockId]->size[j]) * ((MFloat)beginPartitionHelper[j])
159 / ((MFloat)divisor[j]));
160 endBlock[j] =
161 rounding(((MFloat)m_blockInfo[blockId]->size[j]) * ((MFloat)endPartitionHelper[j]) / ((MFloat)divisor[j]));
162 }
163 m_partitionInfo[partitionCounter]->weight = m_blockInfo[blockId]->weight;
164 m_partitionInfo[partitionCounter]->totalSize = 1;
165
166 for(MInt j = 0; j < nDim; j++) {
167 m_partitionInfo[partitionCounter]->size[j] = endBlock[j] - beginBlock[j] + 1;
168 m_partitionInfo[partitionCounter]->totalSize *= (m_partitionInfo[partitionCounter]->size[j]);
169 m_partitionInfo[partitionCounter]->offset[j] = beginBlock[j];
170 }
171
172 m_partitionInfo[partitionCounter]->blockId = blockId;
173 m_partitionInfo[partitionCounter]->partitionId = partitionCounter;
174 partitionCounter++;
175 }
176 }
177}

◆ sumLeaves()

template<MInt nDim>
MInt StructuredDecomposition< nDim >::sumLeaves ( treeNode *&  treePointer)
private
Parameters
[in]treePointerPointer to a tree node
Returns
Number of leaves

Definition at line 292 of file structuredpartition.cpp.

292 {
293 treeNode* myTreePointer{};
294 MInt sumLeaf{};
295
296 if(treePointer->level < (nDim - 1)) {
297 sumLeaf = 0;
298 for(MInt i = 0; i < treePointer->noChilds; i++) {
299 myTreePointer = treePointer->childs[i];
300 sumLeaf += sumLeaves(myTreePointer);
301 }
302 } else {
303 sumLeaf = treePointer->noChilds;
304 }
305 treePointer->noLeaves = sumLeaf;
306 return sumLeaf;
307}

◆ traverseForInsertionNode()

template<MInt nDim>
void StructuredDecomposition< nDim >::traverseForInsertionNode ( treeNode *&  treePointer,
const MInt  blockId,
const  MInt(&)[nDim],
treeNode *&  insertTreePointer 
)
private
Parameters
[in]level2dimension1DArray of level to space dimension mapping
[in]insertTreePointerPointer to the node where new node is inserted

Definition at line 216 of file structuredpartition.cpp.

219 {
220 treeNode* myTreePointer{};
221
222 // compare visited nodes with current candidate insertion node
223 // by their normalized number of children
224 if(((((MFloat)treePointer->noChilds)
225 * ((MFloat)m_blockInfo[blockId]->size[level2dimension1D[insertTreePointer->level]] + 1.0))
226 < (((MFloat)insertTreePointer->noChilds)
227 * ((MFloat)m_blockInfo[blockId]->size[level2dimension1D[treePointer->level]] + 1.0)))
228 || (approx(((MFloat)(treePointer->noChilds)
229 * ((MFloat)(m_blockInfo[blockId]->size[level2dimension1D[insertTreePointer->level]]) + 1.0)),
230 ((MFloat)(insertTreePointer->noChilds)
231 * ((MFloat)(m_blockInfo[blockId]->size[level2dimension1D[treePointer->level]]) + 1.0)),
232 m_eps)
233 && (treePointer->level < insertTreePointer->level))) {
234 insertTreePointer = treePointer;
235 }
236
237 if(treePointer->level < (nDim - 1)) {
238 // look for leftmost child with least leaves
239 myTreePointer = treePointer->childs[0];
240 for(MInt i = 1; i < treePointer->noChilds; i++) {
241 if(treePointer->childs[i]->noLeaves < myTreePointer->noLeaves) {
242 myTreePointer = treePointer->childs[i];
243 }
244 }
245
246 // now traverse in the leftmost child with least leaves
247 traverseForInsertionNode(myTreePointer, blockId, level2dimension1D, insertTreePointer);
248 }
249}
MBool approx(const T &, const U &, const T)
Definition: functions.h:272

Member Data Documentation

◆ m_blockInfo

template<MInt nDim>
std::vector<std::unique_ptr<PartitionInfo<nDim> > > StructuredDecomposition< nDim >::m_blockInfo {}
private

Definition at line 91 of file structuredpartition.h.

◆ m_eps

template<MInt nDim>
const MFloat StructuredDecomposition< nDim >::m_eps
private

Definition at line 89 of file structuredpartition.h.

◆ m_mpiComm

template<MInt nDim>
const MPI_Comm StructuredDecomposition< nDim >::m_mpiComm
private

Definition at line 86 of file structuredpartition.h.

◆ m_noBlocks

template<MInt nDim>
const MInt StructuredDecomposition< nDim >::m_noBlocks
private

Definition at line 85 of file structuredpartition.h.

◆ m_noDomains

template<MInt nDim>
const MInt StructuredDecomposition< nDim >::m_noDomains
private

Definition at line 87 of file structuredpartition.h.

◆ m_noPartitions

template<MInt nDim>
MInt StructuredDecomposition< nDim >::m_noPartitions
private

Definition at line 88 of file structuredpartition.h.

◆ m_partitionInfo

template<MInt nDim>
std::vector<std::unique_ptr<PartitionInfo<nDim> > > StructuredDecomposition< nDim >::m_partitionInfo {}
private

Definition at line 92 of file structuredpartition.h.


The documentation for this class was generated from the following files: