chombo-discharge
CD_LoadBalancing.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2021 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_LoadBalancing_H
13 #define CD_LoadBalancing_H
14 
15 // Our includes
17 #include <CD_BoxSorting.H>
18 #include <CD_Loads.H>
19 #include <CD_NamespaceHeader.H>
20 
25 {
26 public:
34  template <class T>
35  static void
36  makeBalance(Vector<int>& a_ranks, const Vector<T>& a_loads, const Vector<Box>& a_boxes);
37 
47  template <class T>
48  static void
49  makeBalance(Vector<int>& a_ranks, Loads& a_rankLoads, const Vector<T>& a_boxLoads, const Vector<Box>& a_boxes);
50 
58  template <typename T>
59  static void
60  sort(Vector<Vector<Box>>& a_boxes, Vector<Vector<T>>& a_loads, const BoxSorting a_whichSorting);
61 
69  template <typename T>
70  static void
71  sort(Vector<Box>& a_boxes, Vector<T>& a_loads, const BoxSorting a_which);
72 
77  static void
78  sort(Vector<Box>& a_boxes, const BoxSorting a_which);
79 
85  static void
86  gatherBoxes(Vector<Box>& a_boxes);
87 
93  static void
94  gatherLoads(Vector<Real>& a_loads);
95 
101  static void
102  gatherLoads(Vector<int>& a_loads);
103 
109  static void
110  gatherLoads(Vector<long>& a_loads);
111 
118  static void
119  gatherBoxesAndLoads(Vector<Box>& a_boxes, Vector<int>& a_loads);
120 
121 protected:
127  template <class T>
128  static std::vector<std::pair<Box, T>>
129  packPairs(const Vector<Box>& a_boxes, const Vector<T>& a_loads);
130 
137  template <class T>
138  static void
139  unpackPairs(Vector<Box>& a_boxes, Vector<T>& a_loads, const std::vector<std::pair<Box, T>>& a_pairs);
140 
147  template <class T>
148  static void
149  standardSort(Vector<Box>& a_boxes, Vector<T>& a_loads);
150 
157  template <class T>
158  static void
159  shuffleSort(Vector<Box>& a_boxes, Vector<T>& a_loads);
160 
167  template <class T>
168  static void
169  mortonSort(Vector<Box>& a_boxes, Vector<T>& a_loads);
170 
178  template <class T>
179  static bool
180  mortonComparator(const int a_maxBits, const std::pair<Box, T>& a_lhs, const std::pair<Box, T>& a_rhs);
181 
187  static int
188  maxBits(std::vector<Box>::iterator a_first, std::vector<Box>::iterator a_last);
189 };
190 
191 #include <CD_NamespaceFooter.H>
192 
193 #include <CD_LoadBalancingImplem.H>
194 
195 #endif
Declaration of an enum for identifying various ways of sorting grid patches.
BoxSorting
Enum for sorting boxes.
Definition: CD_BoxSorting.H:21
Declaration of a simple class for holding computational loads.
Multi-fluid index space.
Static class which contains various load balancing routines.
Definition: CD_LoadBalancing.H:25
static int maxBits(std::vector< Box >::iterator a_first, std::vector< Box >::iterator a_last)
Utility function for Morton sorting which needs the maximum bits.
Definition: CD_LoadBalancing.cpp:279
static void gatherLoads(Vector< Real > &a_loads)
Gather computational loads.
Definition: CD_LoadBalancing.cpp:109
static void gatherBoxes(Vector< Box > &a_boxes)
Gather boxes.
Definition: CD_LoadBalancing.cpp:31
static void gatherBoxesAndLoads(Vector< Box > &a_boxes, Vector< int > &a_loads)
Gather boxes and loads.
Definition: CD_LoadBalancing.cpp:269
static void makeBalance(Vector< int > &a_ranks, const Vector< T > &a_loads, const Vector< Box > &a_boxes)
Load balancing, assigning ranks to boxes.
Definition: CD_LoadBalancingImplem.H:31
static void sort(Vector< Vector< Box >> &a_boxes, Vector< Vector< T >> &a_loads, const BoxSorting a_whichSorting)
Sorts boxes and loads over a hierarchy according to some sorting criterion.
Definition: CD_LoadBalancingImplem.H:221
static void standardSort(Vector< Box > &a_boxes, Vector< T > &a_loads)
Standard box sorting, calls C++ std::sort.
Definition: CD_LoadBalancingImplem.H:265
static void mortonSort(Vector< Box > &a_boxes, Vector< T > &a_loads)
Sort boxes using Morton code.
Definition: CD_LoadBalancingImplem.H:304
static bool mortonComparator(const int a_maxBits, const std::pair< Box, T > &a_lhs, const std::pair< Box, T > &a_rhs)
Morton comparator.
Definition: CD_LoadBalancingImplem.H:325
static std::vector< std::pair< Box, T > > packPairs(const Vector< Box > &a_boxes, const Vector< T > &a_loads)
Utility function which packs boxes and loads into a vector of pairs.
Definition: CD_LoadBalancingImplem.H:191
static void unpackPairs(Vector< Box > &a_boxes, Vector< T > &a_loads, const std::vector< std::pair< Box, T >> &a_pairs)
Splits vector pair into separate boxes and loads.
Definition: CD_LoadBalancingImplem.H:205
static void shuffleSort(Vector< Box > &a_boxes, Vector< T > &a_loads)
Randomly shuffles boxes and loads.
Definition: CD_LoadBalancingImplem.H:281
Class for holding computational loads.
Definition: CD_Loads.H:30