OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
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)
 returns whether glob is on this process
 
int loc (const int &glob)
 
int loc (int glob) const
 
int glob (int loc) const
 
int rank (const int &glob)
 
int rank (int glob) const
 
int size () const
 
int getRankSize () const
 
virtual Platform platform (int loc) const
 
virtual void setPlatform (int loc, Platform platform)
 
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
 
- 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 59 of file loadBalancer.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(const int &glob)
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

◆ 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 150 of file loadBalancer.hh.

151{
152 std::size_t currentBlock = 0;
153 size_t sizeBufferIndex = 0;
154 bool* dataPtr = nullptr;
155
156 this->registerVar<int> (iBlock, sizeBlock, currentBlock, dataPtr, _size);
157 this->registerMap<int, int> (iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, _loc, loadingMode);
158 this->registerStdVectorOfVars<int>(iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, _glob, loadingMode);
159 this->registerMap<int, int> (iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, _rank, loadingMode);
160
161 return dataPtr;
162}

◆ 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 129 of file loadBalancer.hh.

130{
131 return 4 // _size, plus vector length of _loc, _glob and _rank
132 + _loc.size()
133 + _rank.size()
134 + _glob.size();
135}

◆ getRankSize()

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

Definition at line 113 of file loadBalancer.hh.

114{
115 return _rank.size();
116}
+ 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 139 of file loadBalancer.hh.

140{
141 return sizeof(int) // _size
142 + 3 * sizeof(size_t) // vector length of _loc, _glob and _rank
143 + _loc.size() * sizeof(std::pair<int, int>)
144 + _rank.size() * sizeof(std::pair<int, int>)
145 + _glob.size() * sizeof(int);
146}

◆ glob()

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

Definition at line 88 of file loadBalancer.hh.

89{
90 return _glob[loc];
91}
+ Here is the caller graph for this function:

◆ isLocal()

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

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:

◆ loc() [1/2]

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

Definition at line 75 of file loadBalancer.hh.

76{
77 return _loc[glob];
78}
+ 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 81 of file loadBalancer.hh.

82{
83 std::map<int,int>::const_iterator iter = _loc.find(glob);
84 return iter->second;
85}

◆ operator==()

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

equal operator

Definition at line 119 of file loadBalancer.hh.

120{
121 return _size == rhs._size &&
122 _loc == rhs._loc &&
123 _glob == rhs._glob &&
124 _rank == rhs._rank;
125}

References olb::LoadBalancer< T >::_loc, 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 101 of file loadBalancer.h.

101 {
102 auto iter = _platform.find(glob(loc));
103 if (iter != _platform.end()) {
104 return std::get<1>(*iter);
105 } else {
106 #ifdef PLATFORM_GPU_CUDA
107 return Platform::GPU_CUDA;
108 #else
109 #ifdef PLATFORM_CPU_SIMD
110 return Platform::CPU_SIMD;
111 #else
112 return Platform::CPU_SISD;
113 #endif
114 #endif
115 }
116 }
@ 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 166 of file loadBalancer.hh.

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

References olb::OstreamManager::setMultiOutput().

+ Here is the call graph for this function:

◆ rank() [1/2]

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

Definition at line 94 of file loadBalancer.hh.

95{
96 return _rank[glob];
97}

◆ rank() [2/2]

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 100 of file loadBalancer.hh.

101{
102 std::map<int,int>::const_iterator iter = _rank.find(glob);
103 return iter->second;
104}

◆ 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 107 of file loadBalancer.hh.

108{
109 return _size;
110}
+ 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

◆ _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: