OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::LoadBalancer< T > Class Template Reference

Base class for all LoadBalancer. More...

#include <loadBalancer.h>

+ Inheritance diagram for olb::LoadBalancer< T >:
+ Collaboration diagram for olb::LoadBalancer< T >:

Public Member Functions

 LoadBalancer (int size=1)
 Default empty constructor.
 
 LoadBalancer (int size, std::map< int, int > &loc, std::vector< int > &glob, std::map< int, int > &rank)
 Constructor accepting existing balancing.
 
 LoadBalancer (int size, std::map< int, int > &loc, std::vector< int > &glob, std::map< int, int > &rank, std::map< int, Platform > &platform)
 Constructor accepting existing heterogeneous balancing.
 
virtual ~LoadBalancer ()
 Default empty destructor.
 
void swap (LoadBalancer< T > &loadBalancer)
 Swap method.
 
bool isLocal (const int &glob) const
 returns whether glob is on this process
 
bool isLocal (Platform platform) const
 returns whether there is a block on platform in this process
 
int loc (const int &glob)
 
int loc (int glob) const
 
int glob (int loc) const
 
int rank (int glob) const
 
int size () const
 
int getRankSize () const
 
virtual Platform platform (int loc) const
 
virtual void setPlatform (int loc, Platform platform)
 
virtual bool doOutput (int glob) const
 
virtual void setDoOutput (int glob, bool doOutput)
 
bool operator== (const LoadBalancer< T > &rhs) const
 equal operator
 
std::size_t getNblock () const override
 Number of data blocks for the serializable interface.
 
std::size_t getSerializableSize () const override
 Binary size for the serializer.
 
bool * getBlock (std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
 Return a pointer to the memory of the current block and its size for the serializable interface.
 
void print (bool multiOutput=false) const
 
- Public Member Functions inherited from olb::Serializable
virtual ~Serializable ()=default
 
template<bool includeLogOutputDir = true>
bool save (std::string fileName="", const bool enforceUint=false)
 Save Serializable into file fileName
 
template<bool includeLogOutputDir = true>
bool load (std::string fileName="", const bool enforceUint=false)
 Load Serializable from file fileName
 
bool save (std::uint8_t *buffer)
 Save Serializable into buffer of length getSerializableSize
 
bool load (const std::uint8_t *buffer)
 Load Serializable from buffer of length getSerializableSize
 
virtual void postLoad ()
 

Protected Attributes

int _size
 number of cuboids after shrink -1 in appropriate thread
 
std::map< int, int > _loc
 maps global cuboid to (local) thread cuboid
 
std::vector< int > _glob
 content is 0,1,2,...,_size
 
std::map< int, int > _rank
 maps global cuboid number to the processing thread
 
std::map< int, Platform_platform
 maps global cuboid number to local platform
 
std::map< int, bool > _doOutput
 defines if global cuboid number has state doOutput
 
- Protected Attributes inherited from olb::BufferSerializable
std::vector< bool * > _dataBuffer
 Data buffer for data that has to be buffered between two getBlock() iterations.
 
std::vector< size_t > _sizeBuffer
 std::vector of integer buffers (e.g. for std::vector size) to be buffered for the whole iteration process
 

Additional Inherited Members

- Protected Member Functions inherited from olb::BufferSerializable
template<typename DataType >
void registerSerializable (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, size_t &sizeBufferIndex, bool *&dataPtr, DataType &data, const bool loadingMode=false)
 Register Serializable object of dynamic size.
 
template<typename DataType >
void registerStdVectorOfVars (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, size_t &sizeBufferIndex, bool *&dataPtr, std::vector< DataType > &data, const bool loadingMode=false)
 Method for registering a std::vector<DataType> of primitive DataType (int, double, ...)
 
template<typename DataType >
void registerStdVectorOfSerializablesOfConstSize (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, size_t &sizeBufferIndex, bool *&dataPtr, std::vector< DataType > &data, const bool loadingMode=false)
 Method for registering a std::vector<DataType> of constant-sized Serializable
 
template<typename DataType >
void registerStdVectorOfSerializables (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, size_t &sizeBufferIndex, bool *&dataPtr, std::vector< DataType > &data, const bool loadingMode=false)
 Method for registering a std::vector<DataType> of dynamic-sized DataType
 
template<typename DataTypeKey , typename DataTypeValue >
void registerMap (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, size_t &sizeBufferIndex, bool *&dataPtr, std::map< DataTypeKey, DataTypeValue > &data, const bool loadingMode=false)
 Method for registering a std::map<DataTypeKey, DataTypeValue> of fixed-sized types (i.e. int, double)
 
size_t addSizeToBuffer (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, size_t &sizeBufferIndex, bool *&dataPtr, const size_t data) const
 Add a size_t to the sizeBuffer in the n-th util::round and return that size_t in all successive rounds.
 
- Protected Member Functions inherited from olb::Serializable
template<typename DataType >
void registerVar (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, const DataType &data, const size_t arrayLength=1) const
 Register primitive data types (int, double, ...) or arrays of those.
 
template<typename DataType >
void registerSerializableOfConstSize (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, DataType &data, const bool loadingMode=false)
 Register Serializable object of constant size.
 
template<typename DataType >
void registerSerializablesOfConstSize (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, DataType *data, const size_t arrayLength, const bool loadingMode=false)
 Register an array of Serializable objects of constant size.
 

Detailed Description

template<typename T>
class olb::LoadBalancer< T >

Base class for all LoadBalancer.

Sketch: assume we have 6 cuboids and 2 threads. Thread number 1 owns cuboid 0 and 1. Thread number 2 owns cuboid 2, 3, 4 and 5. Then we get the following configuration:

global cuboid number: 0 1 2 3 4 5 local cuboid number of thread 0: 0 1 local cuboid number of thread 1: 0 1 2 3

Parameters
_globis a vector from 0,1,...,numberOfCuboids-1
_locindicates local cuboid number in actual thread, for given global cuboid number
_rankindicates the processing thread of a global cuboid number

Definition at line 42 of file vtiWriter.h.

Constructor & Destructor Documentation

◆ LoadBalancer() [1/3]

template<typename T >
olb::LoadBalancer< T >::LoadBalancer ( int size = 1)

Default empty constructor.

Definition at line 34 of file loadBalancer.hh.

34 : _size(size)
35{}
int _size
number of cuboids after shrink -1 in appropriate thread

◆ LoadBalancer() [2/3]

template<typename T >
olb::LoadBalancer< T >::LoadBalancer ( int size,
std::map< int, int > & loc,
std::vector< int > & glob,
std::map< int, int > & rank )

Constructor accepting existing balancing.

Definition at line 38 of file loadBalancer.hh.

43{}
int rank(int glob) const
int glob(int loc) const
std::vector< int > _glob
content is 0,1,2,...,_size
std::map< int, int > _rank
maps global cuboid number to the processing thread
std::map< int, int > _loc
maps global cuboid to (local) thread cuboid
int loc(const int &glob)

◆ LoadBalancer() [3/3]

template<typename T >
olb::LoadBalancer< T >::LoadBalancer ( int size,
std::map< int, int > & loc,
std::vector< int > & glob,
std::map< int, int > & rank,
std::map< int, Platform > & platform )

Constructor accepting existing heterogeneous balancing.

Definition at line 46 of file loadBalancer.hh.

52{}
virtual Platform platform(int loc) const
std::map< int, Platform > _platform
maps global cuboid number to local platform

◆ ~LoadBalancer()

template<typename T >
olb::LoadBalancer< T >::~LoadBalancer ( )
virtual

Default empty destructor.

Definition at line 55 of file loadBalancer.hh.

56{}

Member Function Documentation

◆ doOutput()

template<typename T >
virtual bool olb::LoadBalancer< T >::doOutput ( int glob) const
inlinevirtual

Definition at line 124 of file loadBalancer.h.

124 {
125 try {
126 return _doOutput.at(glob);
127 } catch (std::out_of_range& ex) {
128 return true;
129 }
130 }
std::map< int, bool > _doOutput
defines if global cuboid number has state doOutput

References olb::LoadBalancer< T >::_doOutput, and olb::LoadBalancer< T >::glob().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBlock()

template<typename T >
bool * olb::LoadBalancer< T >::getBlock ( std::size_t iBlock,
std::size_t & sizeBlock,
bool loadingMode )
overridevirtual

Return a pointer to the memory of the current block and its size for the serializable interface.

Implements olb::Serializable.

Definition at line 155 of file loadBalancer.hh.

156{
157 std::size_t currentBlock = 0;
158 size_t sizeBufferIndex = 0;
159 bool* dataPtr = nullptr;
160
161 this->registerVar<int> (iBlock, sizeBlock, currentBlock, dataPtr, _size);
162 this->registerMap<int, int> (iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, _loc, loadingMode);
163 this->registerStdVectorOfVars<int>(iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, _glob, loadingMode);
164 this->registerMap<int, int> (iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, _rank, loadingMode);
165
166 return dataPtr;
167}
void registerStdVectorOfVars(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, size_t &sizeBufferIndex, bool *&dataPtr, std::vector< DataType > &data, const bool loadingMode=false)
Method for registering a std::vector<DataType> of primitive DataType (int, double,...
Definition serializer.h:371
void registerMap(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, size_t &sizeBufferIndex, bool *&dataPtr, std::map< DataTypeKey, DataTypeValue > &data, const bool loadingMode=false)
Method for registering a std::map<DataTypeKey, DataTypeValue> of fixed-sized types (i....
Definition serializer.h:522
void registerVar(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, const DataType &data, const size_t arrayLength=1) const
Register primitive data types (int, double, ...) or arrays of those.
Definition serializer.h:212

◆ getNblock()

template<typename T >
size_t olb::LoadBalancer< T >::getNblock ( ) const
overridevirtual

Number of data blocks for the serializable interface.

Implements olb::Serializable.

Definition at line 134 of file loadBalancer.hh.

135{
136 return 4 // _size, plus vector length of _loc, _glob and _rank
137 + _loc.size()
138 + _rank.size()
139 + _glob.size();
140}

◆ getRankSize()

template<typename T >
int olb::LoadBalancer< T >::getRankSize ( ) const
Returns
read size of _rank

Definition at line 118 of file loadBalancer.hh.

119{
120 return _rank.size();
121}
+ Here is the caller graph for this function:

◆ getSerializableSize()

template<typename T >
size_t olb::LoadBalancer< T >::getSerializableSize ( ) const
overridevirtual

Binary size for the serializer.

Implements olb::Serializable.

Definition at line 144 of file loadBalancer.hh.

145{
146 return sizeof(int) // _size
147 + 3 * sizeof(size_t) // vector length of _loc, _glob and _rank
148 + _loc.size() * sizeof(std::pair<int, int>)
149 + _rank.size() * sizeof(std::pair<int, int>)
150 + _glob.size() * sizeof(int);
151}

◆ glob()

template<typename T >
int olb::LoadBalancer< T >::glob ( int loc) const
Returns
global cuboid number of given local cuboid

Definition at line 99 of file loadBalancer.hh.

100{
101 return _glob[loc];
102}
+ Here is the caller graph for this function:

◆ isLocal() [1/2]

template<typename T >
bool olb::LoadBalancer< T >::isLocal ( const int & glob) const

returns whether glob is on this process

Definition at line 69 of file loadBalancer.hh.

70{
71 return rank(glob) == singleton::mpi().getRank();
72}
int getRank() const
Returns the process ID.
MpiManager & mpi()

References olb::singleton::MpiManager::getRank(), and olb::singleton::mpi().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isLocal() [2/2]

template<typename T >
bool olb::LoadBalancer< T >::isLocal ( Platform platform) const

returns whether there is a block on platform in this process

Definition at line 75 of file loadBalancer.hh.

76{
77 for (auto [loc, _] : _loc) {
78 if (this->platform(loc) == platform) {
79 return true;
80 }
81 }
82 return false;
83}

◆ loc() [1/2]

template<typename T >
int olb::LoadBalancer< T >::loc ( const int & glob)
Returns
local cuboid number of relevant thread

Definition at line 86 of file loadBalancer.hh.

87{
88 return _loc[glob];
89}
+ Here is the caller graph for this function:

◆ loc() [2/2]

template<typename T >
int olb::LoadBalancer< T >::loc ( int glob) const
Returns
local cuboid number of relevant thread

Definition at line 92 of file loadBalancer.hh.

93{
94 std::map<int,int>::const_iterator iter = _loc.find(glob);
95 return iter->second;
96}

◆ operator==()

template<typename T >
bool olb::LoadBalancer< T >::operator== ( const LoadBalancer< T > & rhs) const

equal operator

Definition at line 124 of file loadBalancer.hh.

125{
126 return _size == rhs._size &&
127 _loc == rhs._loc &&
128 _glob == rhs._glob &&
129 _rank == rhs._rank;
130}

References olb::LoadBalancer< T >::_glob, olb::LoadBalancer< T >::_loc, olb::LoadBalancer< T >::_rank, and olb::LoadBalancer< T >::_size.

◆ platform()

template<typename T >
virtual Platform olb::LoadBalancer< T >::platform ( int loc) const
inlinevirtual
Returns
target platform for processing of local cuboid

Reimplemented in olb::HeterogeneousLoadBalancer< T >, and olb::OrthogonalHeterogeneousLoadBalancer< T >.

Definition at line 103 of file loadBalancer.h.

103 {
104 auto iter = _platform.find(glob(loc));
105 if (iter != _platform.end()) {
106 return std::get<1>(*iter);
107 } else {
108 #ifdef PLATFORM_GPU_CUDA
109 return Platform::GPU_CUDA;
110 #else
111 #ifdef PLATFORM_CPU_SIMD
112 return Platform::CPU_SIMD;
113 #else
114 return Platform::CPU_SISD;
115 #endif
116 #endif
117 }
118 }
@ CPU_SIMD
Basic scalar CPU.
@ GPU_CUDA
Vector CPU (AVX2 / AVX-512 collision)

References olb::LoadBalancer< T >::_platform, olb::CPU_SIMD, olb::CPU_SISD, olb::LoadBalancer< T >::glob(), olb::GPU_CUDA, and olb::LoadBalancer< T >::loc().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print()

template<typename T >
void olb::LoadBalancer< T >::print ( bool multiOutput = false) const

Definition at line 171 of file loadBalancer.hh.

172{
173 OstreamManager clout(std::cout,"LoadBalancer");
174 clout.setMultiOutput(multiOutput);
175 for (unsigned i = 0; i < this->_glob.size(); i++) {
176 clout << "glob[" << i << "]=" << this->_glob[i] << std::endl;
177 }
178 for (const auto& [globC, locC] : this->_loc) {
179 clout << "loc[" << globC << "]=" << locC << std::endl;
180 }
181 for (const auto& [globC, rank] : this->_rank) {
182 clout << "rank[" << globC << "]=" << rank << std::endl;
183 }
184 clout.setMultiOutput(false);
185}

References olb::OstreamManager::setMultiOutput().

+ Here is the call graph for this function:

◆ rank()

template<typename T >
int olb::LoadBalancer< T >::rank ( int glob) const
Parameters
globis the global cuboid number
Returns
rank that owns the given global cuboid number

Definition at line 105 of file loadBalancer.hh.

106{
107 std::map<int,int>::const_iterator iter = _rank.find(glob);
108 return iter->second;
109}
+ Here is the caller graph for this function:

◆ setDoOutput()

template<typename T >
virtual void olb::LoadBalancer< T >::setDoOutput ( int glob,
bool doOutput )
inlinevirtual

Definition at line 131 of file loadBalancer.h.

131 {
133 }
virtual bool doOutput(int glob) const

References olb::LoadBalancer< T >::_doOutput, olb::LoadBalancer< T >::doOutput(), and olb::LoadBalancer< T >::glob().

+ Here is the call graph for this function:

◆ setPlatform()

template<typename T >
virtual void olb::LoadBalancer< T >::setPlatform ( int loc,
Platform platform )
inlinevirtual

◆ size()

template<typename T >
int olb::LoadBalancer< T >::size ( ) const
Returns
read only acess to _size

Definition at line 112 of file loadBalancer.hh.

113{
114 return _size;
115}
+ Here is the caller graph for this function:

◆ swap()

template<typename T >
void olb::LoadBalancer< T >::swap ( LoadBalancer< T > & loadBalancer)

Swap method.

Definition at line 59 of file loadBalancer.hh.

60{
61 std::swap(_size, loadBalancer._size);
62 _loc.swap(loadBalancer._loc);
63 _glob.swap(loadBalancer._glob);
64 _rank.swap(loadBalancer._rank);
65 _platform.swap(loadBalancer._platform);
66}

References olb::LoadBalancer< T >::_glob, olb::LoadBalancer< T >::_loc, olb::LoadBalancer< T >::_platform, olb::LoadBalancer< T >::_rank, and olb::LoadBalancer< T >::_size.

+ Here is the caller graph for this function:

Member Data Documentation

◆ _doOutput

template<typename T >
std::map<int,bool> olb::LoadBalancer< T >::_doOutput
protected

defines if global cuboid number has state doOutput

Definition at line 72 of file loadBalancer.h.

◆ _glob

template<typename T >
std::vector<int> olb::LoadBalancer< T >::_glob
protected

content is 0,1,2,...,_size

Definition at line 66 of file loadBalancer.h.

◆ _loc

template<typename T >
std::map<int,int> olb::LoadBalancer< T >::_loc
protected

maps global cuboid to (local) thread cuboid

Definition at line 64 of file loadBalancer.h.

◆ _platform

template<typename T >
std::map<int,Platform> olb::LoadBalancer< T >::_platform
protected

maps global cuboid number to local platform

Definition at line 70 of file loadBalancer.h.

◆ _rank

template<typename T >
std::map<int,int> olb::LoadBalancer< T >::_rank
protected

maps global cuboid number to the processing thread

Definition at line 68 of file loadBalancer.h.

◆ _size

template<typename T >
int olb::LoadBalancer< T >::_size
protected

number of cuboids after shrink -1 in appropriate thread

Definition at line 62 of file loadBalancer.h.


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