Skip to content

Commit aa74708

Browse files
Merge pull request #5 from charmplusplus/ExerciseUpdates
Exercise updates
2 parents 60690fe + 181690f commit aa74708

File tree

5 files changed

+98
-3
lines changed

5 files changed

+98
-3
lines changed

content/exercises.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h2>!! Under Construction, the following is currently being updated and will inc
4141
</ol>
4242
<li><h2>Load Balancing</h2></li>
4343
<ol>
44-
<li>Particle Exercise with multiple types of particles</li>
44+
<li><a href="loadbalancing">Particle Exercise with multiple types of particles</a></li>
4545
<ol>
4646
<li>Add load balancing</li>
4747
<li>Add projections and show impact of load balancing via time-profile and timeline</li>
34.8 KB
Loading
20 KB
Loading

content/exercises/loadbalancing.html

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
title: Load Balancing Particle Exercise (Extension)
3+
homec: home
4+
tutorialc: tutorial
5+
applicationsc: applications
6+
miniAppsc: miniApps
7+
downloadc: download
8+
toolsc: tools
9+
helpc: help
10+
---
11+
12+
<link rel="stylesheet" type="text/css" href="../../tutorial/TutorialStyle.css">
13+
14+
<h1>Load Balancing: Particle Exercise <em>(Extension)</em></h1>
15+
16+
<table class="StandardFigure" align="right" border="0">
17+
<tr><td align="center" valign="middle">
18+
<a href="../images/particlescode_lb.png">
19+
<img class="StandardFigure" src="../images/particlescode_lb.png" border="0" width="375">
20+
</a>
21+
</td></tr>
22+
<tr><td align="center" valign="middle"><b>Figure&nbsp;1</b></td></tr>
23+
</table>
24+
<h2>Part&nbsp;1 – Introducing Imbalance</h2>
25+
26+
<p>The very first task is to create measurable imbalance so that load balancers have something meaningful to fix.</p>
27+
28+
<ol>
29+
<li>
30+
Let <code>m&nbsp;×&nbsp;m</code> be the chare-array dimensions and <code>k</code> the baseline number of particles per chare. Update the number of particles per chare to be
31+
<span lang="latex">N_{x,y} = k + \frac{k(x + y)}{m}</span>.
32+
</li>
33+
34+
<li>
35+
Build with tracing enabled using the <code>-tracemode projections</code> flag.
36+
</li>
37+
<li>
38+
Install <a href="https://github.com/charmplusplus/projections">projections</a>, and focus on the time profile view to see how the imbalance affects performance and efficiency.
39+
</li>
40+
</ol>
41+
42+
<p><u>Variants</u>: Instructors may choose to use a different formula for introducing imbalance</p>
43+
44+
<!-- =================================================================== -->
45+
<h2>Part&nbsp;2 – Adding Migration Support &amp; Load-Balancing</h2>
46+
47+
<p>Now enable dynamic migration so Charm++ balancers can actually move work around.</p>
48+
49+
<ol>
50+
<li>
51+
Implement <code>PUP</code> serialization for your chare array as <a href="https://charm.readthedocs.io/en/latest/charm++/manual.html#arraymigratable">documented</a>.
52+
</li>
53+
<li>
54+
At appropriate intervals, call <code><a href="https://charm.readthedocs.io/en/latest/charm++/manual.html#load-balancing-chare-arrays">AtSync()</a></code> so the runtime knows the chare is ready for potential migration.
55+
</li>
56+
<li>
57+
Select a load-balancing strategy. For this exercise we will use
58+
<code>GreedyRefineLB</code> (use option <code>-balancer GreedyRefineLB</code>).
59+
</li>
60+
61+
<li>
62+
Re-run the application as in Part&nbsp;1 and compare how the program behaves differently.
63+
</li>
64+
</ol>
65+
66+
<h2>Part&nbsp;3 – Visualising with LiveViz</h2>
67+
68+
<p>Add colour to emphasise the skew and watch the balancer work.</p>
69+
70+
<ol>
71+
<li>
72+
Extend each chare to contain particles of three different colors. Each color should move at different speeds - green should move at the default speed, red should move twice as fast and green should move half as fast.
73+
</li>
74+
75+
<li>
76+
Distribute colours to reproduce the imbalance as shown in the figure: reds bunched in the centre, greens in the upper-left, blues in the lower-right.
77+
</li>
78+
79+
<li>
80+
Compile with <a href="https://github.com/UIUC-PPL/ccs_tools">LiveViz</a> using the <code>-module liveViz</code> flag.
81+
</li>
82+
83+
<li>
84+
Run your C++ code using <code>++server</code> and <code>++server-port 1234</code>, and then run the liveViz client using <code>liveVize localhost 1234</code>, and observe how the particles behave.
85+
</li>
86+
</ol>

content/exercises/particle.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,21 @@ <h2>Random Migrating Particles</h2>
5555
<li>The pseudocode for the overall algorithm is:</li>
5656
<code>for(iteration=0; iteration&lt;ITERATION; iteration++){</code>
5757
<ul>
58-
<li>For each of the particles that belong to my chare: change its <i>x</i> and <i>y</i> coordinate by a small random amount.</li>
59-
<li>Move all the particles that do not belong to a chare's bounding box to their correct homes. Since the movement is small, this will mean communication to the eight near neighbor chares. Some of these messages may contain no particles.</li>
58+
<li>For each of the particles that belong to my chare: change its <i>x</i> and <i>y</i> coordinate by a small random amount.
59+
If this change causes the particle to move to an invalid coordinate, keep the particle in its original position.</li>
60+
<li>Move all the particles that do not belong to a chare's bounding box to their correct homes.
61+
Since the movement is small, this will mean communication to the eight near neighbor chares. Some of these messages may contain no particles.
62+
For both efficiency and ease of implementation, all communication with neighbor chares should happen at the end of an iteration rather than after each particle.</li>
6063
<li><code>if(iteration%10 == 0)</code></li>
6164
<ul>
6265
<li>Do reductions to calculate average and max number of particles</li>
6366
</ul>
6467
</ul>
6568
<code>}</code>
69+
</ul>
70+
71+
<p><u>Instructor's Note</u>: This exercise can be implemented in several ways, feel free to choose from the variations below or create your own based on your learning objectives:</p>
72+
<ul>
73+
<li>Choose to move the particle along either the <i>x</i> <i>or</i> <i>y</i> axis using an additional random variable, which simplifies communication as there are now only four neighbor chares.</li>
74+
<li>If a movement causes a particle to move to an invalid coordinate, move in the opposite direction instead.</li>
6675
</ul>

0 commit comments

Comments
 (0)