-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteLB.tex
64 lines (55 loc) · 2.01 KB
/
writeLB.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
\begin{frame}[fragile]
\frametitle{How to write your own Load Balancer}
\begin{itemize}
\item Statistics collected by Charm
\begin{lstlisting}[basicstyle=\tiny]
struct LDStats { // load balancing database
ProcStats *procs; //statistics of PEs
int count;
int n_objs;
int n_migrateobjs;
LDObjData* objData; //info regarding chares
int n_comm;
LDCommData* commData; //communication information
int *from_proc, *to_proc; //residence of
chares
}
\end{lstlisting}
\item Use LDStats, ProcArray and ObjGraph for processor load and communication
statistics
\item \emph{work} is the function invoked by Charm RTS to perform load balancing
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Example Strategy - BFS}
\begin{lstlisting}[basicstyle=\tiny]
void GraphBFTLB::work(LDStats *stats) {
ProcArray *parr = new ProcArray(stats); // Processor Array
ObjGraph *ogr = new ObjGraph(stats); // Object Graph
double avgLoad = parr->getAverageLoad();
parr->resetTotalLoad();
int numPes = parr->procs.size(), start = 0, nextPe = 0, i, nbr;
std::queue<int> vertexq;
vertexq.push(start);
ogr->vertices[start].setNewPe(nextPe);
parr->procs[nextPe].totalLoad() += ogr->vertices[start].getVertexLoad();
while(!vertexq.empty()) {
start = vertexq.front(); vertexq.pop();
for(i = 0; i < ogr->vertices[start].sendToList.size(); i++) {
// look at all neighbors of a node in the queue and map them
nbr = ogr->vertices[start].sendToList[i].getNeighborId();
if(ogr->vertices[nbr].getNewPe() == -1) {
vertexq.push(nbr);
if(parr->procs[nextPe].getTotalLoad() + ogr->vertices[nbr].getVertexLoad() > avgLoad) {
nextPe++;
avgLoad += (avgLoad - parr->procs[nextPe].getTotalLoad())/(numPes-nextPe);
}
ogr->vertices[nbr].setNewPe(nextPe);
parr->procs[nextPe].totalLoad() += ogr->vertices[nbr].getVertexLoad();
}
}
}
ogr->convertDecisions(stats); // Send decisions back to LDStats
}
\end{lstlisting}
\end{frame}