OpenLB 1.7
Loading...
Searching...
No Matches
blockLoadBalancer.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2007 Mathias Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef BLOCK_LOAD_BALANCER_HH
25#define BLOCK_LOAD_BALANCER_HH
26
27#include <vector>
28#include <map>
33#include "core/olbDebug.h"
34
35namespace olb {
36
37template<typename T>
38BlockLoadBalancer<T>::BlockLoadBalancer(int rank, int size, int globChunkSize, int offset)
39{
40 init_chunkD(rank, size, globChunkSize, offset);
41}
42
43template<typename T>
45{
46 init_chunkD(singleton::mpi().getRank(), singleton::mpi().getSize(), cGeometry.getNc(), 0);
47}
48
49template<typename T>
51{
52 init_chunkD(singleton::mpi().getRank(), singleton::mpi().getSize(), cGeometry.getNc(), 0);
53}
54
55template<typename T>
56void BlockLoadBalancer<T>::init_chunkD(int rank, int size, int globChunkSize, int offset)
57{
58
59 OLB_PRECONDITION(rank>=0 && size>=1 && offset>=0)
60 OLB_PRECONDITION(size<=globChunkSize && rank<size);
61
62 // nice way to calculate # of chunks per processor
63 this->_locChunkSize = (globChunkSize+size-rank-1)/size;
64 this->_size = _locChunkSize;
65 if (rank+1 <= globChunkSize-(globChunkSize/size)*size) {
66 this->_firstGlobNum = globChunkSize/size * rank + rank + offset;
67 this->_lastGlobNum = this->_firstGlobNum + this->_locChunkSize - 1;
68 }
69 else {
70 this->_firstGlobNum = globChunkSize/size * rank + globChunkSize - (globChunkSize/size)*size + offset;
71 this->_lastGlobNum = this->_firstGlobNum + this->_locChunkSize - 1;
72 }
73 for (int i=0; i<this->_locChunkSize; i++) {
74 this->_loc[this->_firstGlobNum + i] = i;
75 this->_glob.push_back(this->_firstGlobNum + i);
76 }
77 int temp = offset;
78 for (int iRank=0; iRank<size; iRank++) {
79 int iLocChunkSize = (globChunkSize+size-iRank-1)/size;
80 for (int i=0; i<iLocChunkSize; i++) {
81 this->_rank[temp] = iRank;
82 temp++;
83 }
84 }
85}
86
87template<typename T>
89{
90 return _locChunkSize;
91}
92
93template<typename T>
95{
96 return _firstGlobNum;
97}
98
99template<typename T>
101{
102 return _lastGlobNum;
103}
104
105} // namespace olb
106#endif
void init_chunkD(int rank, int size, int globChunkSize, int offset)
A cuboid structure represents the grid of a considered domain.
int getNc() const
Returns the number of cuboids in t < 2he structure.
A cuboid geometry represents a voxel mesh.
int getNc() const
Returns the number of cuboids in the structure.
The description of a vector of 2D cuboid – header file.
The description of a vector of 3D cuboid – header file.
Wrapper functions that simplify the use of MPI.
MpiManager & mpi()
Top level namespace for all of OpenLB.
#define OLB_PRECONDITION(COND)
Definition olbDebug.h:46