OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::RandomLoadBalancer< T > Struct Template Referencefinal

Basic Random Load Balancer. More...

#include <randomLoadBalancer.h>

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

Public Member Functions

 RandomLoadBalancer (int nCuboid, int nRank, int iRank)
 
 RandomLoadBalancer (CuboidGeometry< T, 3 > &cGeometry)
 
- 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)
 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 ()
 

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
 
- 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>
struct olb::RandomLoadBalancer< T >

Basic Random Load Balancer.

Randomly assigns cuboids to ranks while approximately preserving equal number of blocks (not cells) per rank.

Definition at line 40 of file randomLoadBalancer.h.

Constructor & Destructor Documentation

◆ RandomLoadBalancer() [1/2]

template<typename T >
olb::RandomLoadBalancer< T >::RandomLoadBalancer ( int nCuboid,
int nRank,
int iRank )
inline

Definition at line 41 of file randomLoadBalancer.h.

41 :
42 LoadBalancer<T>(0)
43 {
44 std::vector<int> rankBuffer(nCuboid, 0);
45 std::vector<int> locBuffer(nCuboid, 0);
46
47 // Randomly distribute cuboids to ranks on rank 0
48 if (iRank == 0) {
49 std::vector<int> cuboids(nCuboid, 0);
50 std::iota(cuboids.begin(),
51 cuboids.end(),
52 0);
53 std::random_device randomDevice;
54 std::default_random_engine randomEngine(randomDevice());
55 std::shuffle(cuboids.begin(), cuboids.end(), randomEngine);
56
57 std::map<int,int> nLoc;
58 int jRank = 0;
59 for (int iCuboid : cuboids) {
60 if (jRank >= nRank) {
61 jRank -= nRank;
62 }
63 rankBuffer[iCuboid] = jRank;
64 locBuffer[iCuboid] = nLoc[jRank]++;
65 jRank += 1;
66 }
67 }
68
69 #ifdef PARALLEL_MODE_MPI
70 // Broadcast assignments to all processes
71 singleton::mpi().bCast(rankBuffer.data(), rankBuffer.size());
72 singleton::mpi().bCast(locBuffer.data(), locBuffer.size());
73 #endif
74
75 // Update internal LoadBalancer structure to match given assignment
76 for (int iCuboid=0; iCuboid < nCuboid; ++iCuboid) {
77 this->_rank[iCuboid] = rankBuffer[iCuboid];
78 this->_loc[iCuboid] = locBuffer[iCuboid];
79 if (rankBuffer[iCuboid] == singleton::mpi().getRank()) {
80 this->_glob.resize(std::max(int{this->_glob.size()}, this->_loc[iCuboid]+1));
81 this->_glob[this->_loc[iCuboid]] = iCuboid;
82 this->_size = this->_glob.size();
83 }
84 }
85 }
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
void bCast(T *sendBuf, int sendCount, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Broadcast data from one processor to multiple processors.
MpiManager & mpi()

References olb::LoadBalancer< T >::_glob, olb::LoadBalancer< T >::_loc, olb::LoadBalancer< T >::_rank, olb::LoadBalancer< T >::_size, olb::singleton::MpiManager::bCast(), and olb::singleton::mpi().

+ Here is the call graph for this function:

◆ RandomLoadBalancer() [2/2]

template<typename T >
olb::RandomLoadBalancer< T >::RandomLoadBalancer ( CuboidGeometry< T, 3 > & cGeometry)
inline

Definition at line 87 of file randomLoadBalancer.h.

87 :
88 RandomLoadBalancer(cGeometry.getNc(),
91 { }
int getSize() const
Returns the number of processes.
int getRank() const
Returns the process ID.
RandomLoadBalancer(int nCuboid, int nRank, int iRank)

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