Chombo + EB + MF  3.2
LoadBalance.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 // Purpose:
12 // LoadBalance() is a global function to compute an assignment
13 // of boxes to processors for an AMR mesh hierarchy. The assignment
14 // is made so as to balance the computation and communication
15 // workload on each processor (i.e. make it as even as possible).
16 //
17 // ********************************************************
18 // CAVEAT: this version ignores the communication workload.
19 // It balances ONLY the compute workload.
20 // ********************************************************
21 //
22 // Usage:
23 // The meshes in the AMR hierarchy are represented using
24 // a Vector of Vectors of Boxes.
25 //
26 // The computational workload is a real number for each box in the
27 // hierarchy, also represented as a Vector of Vectors.
28 //
29 // The communication workload is a real number for each connection
30 // between pairs of boxes, which specifies the cost of communication
31 // between the two boxes if they are on different processors. No
32 // allowance is made for varying the communication cost depending on the
33 // distance between processors (ie. all processors are equally far apart)
34 // and it assumes that the effective cost of communicating between two
35 // boxes on the same processor is zero. The communication workload is
36 // represented as a graph.
37 //
38 // ********************************************************
39 // CAVEAT: the communication workload argument is not
40 // present in this version of the function.
41 // ********************************************************
42 //
43 // The resulting assignment is an integer for each box in the hierarchy,
44 // which gives the processor number (starting at zero) on which each box
45 // should reside. Again, represented as a Vector of Vectors.
46 //
47 // The other output argument is the efficiency ratio, which is a measure
48 // of how close to perfect the final load balance is. The \var{effRatio}
49 // output variable is defined as the smallest load on any processor divided
50 // by the largest load. A perfect load balance has efficiency == 1.
51 //
52 // ********************************************************
53 // CAVEAT: in this version, each level in the AMR hierarchy
54 // is balanced independently, so the efficiency ratio
55 // that is returned is the worst over all levels.
56 // ********************************************************
57 //
58 // It is important to note that it is the sum of the computation cost
59 // and communication cost that is balanced, so the values in the two
60 // variables must be in the same units. It doesn't matter what the
61 // units are.
62 //
63 // ********************************************************
64 // CAVEAT: the communication workload argument is not
65 // present in this version of the function.
66 // ********************************************************
67 //
68 // Interface Specification:
69 // int LoadBalance() arguments are:
70 // Vector<Vector<int>>& procAssignments //output: processor number
71 // // for each box
72 // Real& effRatio //output: efficiency ratio
73 // const Vector<Vector<Box>>& Grids //input: meshes to balance
74 // const Vector<Vector<long>>&ComputeLoads //input: computational cost
75 // // of each box
76 //###not used###
77 //### const [...something...]&CommunicateLoads //input: communication cost
78 // // between each pair of
79 // // neighboring boxes
80 // const Vector<int>& RefRatios //input: refinement ratio
81 // // for each level
82 //
83 // Returns: integer status_code
84 // =0 means succesful completion
85 // exceptions: (output variables are not defined)
86 // -1011 input vectors (\var{Grids} and \var{ComputeLoads}) are not
87 // the same size
88 // -1012 one of the vector elements of the input vectors (\var{Grids}
89 // and \var{ComputeLoads}) are not the same size
90 // -1013 input vectors (\var{Grids} and \var{RefRatios}) are not
91 // the same size
92 //
93 // Modification History
94 // 19Nov99 <dbs> initial design and coding
95 //
96 
97 #ifndef _LOADBALANCE_H_
98 #define _LOADBALANCE_H_
99 
100 #include "SPACE.H"
101 #include "REAL.H"
102 #include "Box.H"
103 #include "Vector.H"
104 #include "BoxLayout.H"
105 #include "SPMD.H"
106 #include "NamespaceHeader.H"
107 
108 ///
109 /**
110  procAssignments output: processor number for each box
111  effRatio output: ratio of min load to max load
112  Grids input: meshes to balance
113  ComputeLoads input: computational cost of each box
114  RefRatios input: refinement ratio for each level
115 */
116 int
117 LoadBalance( Vector<Vector<int> >& a_procAssignments
118  ,Real& a_effRatio
119  ,const Vector<Vector<Box> >& a_Grids
120  ,const Vector<Vector<long> >& a_ComputeLoads
121  ,const Vector<int>& a_RefRatios
122  ,int a_nProc = numProc()
123  ) ;
124 
125 ///
126 /**
127 
128 Grids in-out: input grids to balance and output proc. numbers
129 effRatio output: ratio of min load to max load
130 ComputeLoads input: computational cost of each box
131 RefRatios input: refinement ratio for each level
132 */
133 int
135  ,Real& effRatio
136  ,const Vector<Vector<long> >& ComputeLoads
137  ,const Vector<int>& RefRatios
138  ,int nProc = numProc()
139  ) ;
140 
141 ///
142 /** convenience function to load balance a Vector of Boxes based
143  on load=box.numPts() */
144 int LoadBalance(Vector<int>& a_procAssignments, const Vector<Box>& a_boxes,
145  const int a_LBnumProc = numProc());
146 
147 ///
148 /** convenience function to load balance a Vector of Loads based
149  on load. boxes also passed in for possible use with box-swapping code */
150 int LoadBalance(Vector<int>& a_procAssignments,
151  const Vector<long long>& a_computeLoads,
152  const Vector<Box>& a_boxes,
153  const int a_LBnumProc = numProc());
154 
155 ///
156 /** Accepts "long int" computeLoads and then just calls the "long long" version. */
157 int LoadBalance(Vector<int>& a_procAssignments,
158  const Vector<long int>& a_computeLoads,
159  const Vector<Box>& a_boxes,
160  const int a_LBnumProc = numProc());
161 
162 //
163 /*
164  This is experimental and to keep me from doing long long <-> long conversions. (dtg)
165  I think we can remove this as it simply calls the above LoadBalance() (ndk 8.4.2008)
166  */
167 int UnLongLongLoadBalance(Vector<int>& a_procAssignments,
168  const Vector<unsigned long long>& a_computeLoads,
169  const Vector<Box>& a_boxes,
170  const int a_numProc = numProc());
171 
172 ///
173 /* Even simpler load balance scheme that just dices vector to give as close to the same number
174 of boxes to each rank.
175 */
176 int basicLoadBalance(Vector<int>& a_procAssignments, int numBoxes, int a_numProc = numProc());
177 
178 ///
179 int
180 LoadBalance(Vector<int>& procAssignments
181  ,Real& effRatio
182  ,const Vector<Box>& Grids
183  ,const Vector<long>& ComputeLoads);
184 
185 /// convenience function to gather a distributed set of Boxes with their corresponding processor assignment
186 /** Assumption is that each processor has at most one valid box. This is useful when interacting with other distributed codes which might not have the entire set of distributed boxes on all processors.
187  */
188 int LoadBalance(Vector<int>& a_procAssignments,
189  Vector<Box>& a_boxes,
190  const Box& a_localGridBox,
191  const int a_numProc = numProc());
192 
193 #include "NamespaceFooter.H"
194 #endif
one dimensional dynamic array
Definition: Vector.H:53
int basicLoadBalance(Vector< int > &a_procAssignments, int numBoxes, int a_numProc=numProc())
int LoadBalance(Vector< Vector< int > > &a_procAssignments, Real &a_effRatio, const Vector< Vector< Box > > &a_Grids, const Vector< Vector< long > > &a_ComputeLoads, const Vector< int > &a_RefRatios, int a_nProc=numProc())
unsigned int numProc()
number of parallel processes
double Real
Definition: REAL.H:33
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
int UnLongLongLoadBalance(Vector< int > &a_procAssignments, const Vector< unsigned long long > &a_computeLoads, const Vector< Box > &a_boxes, const int a_numProc=numProc())