OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::RefinedLoadBalancer< T, D > Class Template Referencefinal

Load balancer for refined lattice hierarchies. More...

#include <loadBalancer.h>

+ Inheritance diagram for olb::RefinedLoadBalancer< T, D >:
+ Collaboration diagram for olb::RefinedLoadBalancer< T, D >:

Public Member Functions

 RefinedLoadBalancer (CuboidDecomposition< T, D > &coarseGeometry, LoadBalancer< T > &coarseBalancer, CuboidDecomposition< T, D > &fineGeometry)
 
int cloc (int fineLoc) const
 Returns coarse loc for given fine loc.
 
- Public Member Functions inherited from olb::LoadBalancer< T >
 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 ()
 

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.
 
- Protected Attributes inherited from olb::LoadBalancer< T >
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
 

Detailed Description

template<typename T, unsigned D>
class olb::RefinedLoadBalancer< T, D >

Load balancer for refined lattice hierarchies.

Ensures that fine cuboids are assigned to the same rank and platform as their corresponding coarse parents.

Coarse parent load balancer must be aware of additional weight due to refinement for a good balancing.

Definition at line 41 of file loadBalancer.h.

Constructor & Destructor Documentation

◆ RefinedLoadBalancer()

template<typename T , unsigned D>
olb::RefinedLoadBalancer< T, D >::RefinedLoadBalancer ( CuboidDecomposition< T, D > & coarseGeometry,
LoadBalancer< T > & coarseBalancer,
CuboidDecomposition< T, D > & fineGeometry )
inline

Definition at line 46 of file loadBalancer.h.

50 {
51 OstreamManager clout(std::cout, "RefinedLoadBalancer");
52 clout.setMultiOutput(true);
53 std::vector<int> rankBuffer(fineGeometry.size(), 0);
54 std::vector<int> locBuffer(fineGeometry.size(), 0);
55 std::map<int,int> nLoc;
56 for (unsigned iC=0; iC < fineGeometry.size(); ++iC) {
57 const auto& fineCuboid = fineGeometry.get(iC);
58 if (auto latticeR = coarseGeometry.getLatticeR(fineCuboid.getOrigin())) {
59 const int coarseC = (*latticeR)[0];
60 if (coarseBalancer.isLocal(coarseC)) {
61 rankBuffer[iC] = coarseBalancer.rank(coarseC);
62 locBuffer[iC] = nLoc[rankBuffer[iC]]++;
63 this->_platform[iC] = coarseBalancer.platform(coarseBalancer.loc(coarseC));
64 clout << "Matching fineC=" << iC << " to coarseC=" << coarseC << " on rank=" << rankBuffer[iC] << std::endl;
65 _coarseLoc[locBuffer[iC]] = coarseBalancer.loc(coarseC);
66 }
67 }
68 }
69
70 #ifdef PARALLEL_MODE_MPI
71 std::vector<int> globalRankBuffer(fineGeometry.size(), 0);
72 std::vector<int> globalLocBuffer(fineGeometry.size(), 0);
73 // Broadcast assignments to all processes
74 singleton::mpi().allreduce(rankBuffer.data(), globalRankBuffer.data(), rankBuffer.size(), MPI_SUM);
75 singleton::mpi().allreduce(locBuffer.data(), globalLocBuffer.data(), locBuffer.size(), MPI_SUM);
76 #else
77 auto& globalRankBuffer = rankBuffer;
78 auto& globalLocBuffer = locBuffer;
79 #endif
80
81 // Update internal LoadBalancer structure to match given assignment
82 for (unsigned iC=0; iC < fineGeometry.size(); ++iC) {
83 this->_rank[iC] = globalRankBuffer[iC];
84 this->_loc[iC] = globalLocBuffer[iC];
85 if (globalRankBuffer[iC] == singleton::mpi().getRank()) {
86 this->_glob.resize(std::max(static_cast<int>(this->_glob.size()), this->_loc[iC]+1));
87 this->_glob[this->_loc[iC]] = iC;
88 this->_size = this->_glob.size();
89 }
90 }
91 clout.setMultiOutput(false);
92 }
std::map< int, Platform > _platform
maps global cuboid number to local platform
std::vector< int > _glob
content is 0,1,2,...,_size
int _size
number of cuboids after shrink -1 in appropriate thread
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
LoadBalancer(int size=1)
Default empty constructor.
void allreduce(const T *in, T *out, int count, MPI_Op op, MPI_Comm comm=MPI_COMM_WORLD)
MpiManager & mpi()

References olb::LoadBalancer< T >::_glob, olb::LoadBalancer< T >::_loc, olb::LoadBalancer< T >::_platform, olb::LoadBalancer< T >::_rank, olb::LoadBalancer< T >::_size, olb::singleton::MpiManager::allreduce(), olb::CuboidDecomposition< T, D >::get(), olb::CuboidDecomposition< T, D >::getLatticeR(), olb::LoadBalancer< T >::isLocal(), olb::LoadBalancer< T >::loc(), olb::singleton::mpi(), olb::LoadBalancer< T >::platform(), olb::LoadBalancer< T >::rank(), olb::OstreamManager::setMultiOutput(), and olb::CuboidDecomposition< T, D >::size().

+ Here is the call graph for this function:

Member Function Documentation

◆ cloc()

template<typename T , unsigned D>
int olb::RefinedLoadBalancer< T, D >::cloc ( int fineLoc) const
inline

Returns coarse loc for given fine loc.

Definition at line 95 of file loadBalancer.h.

95 {
96 return _coarseLoc.at(fineLoc);
97 }

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