Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5abeb9a532239567c1891fd80ee023c76fae6b1f
[simgrid.git] / doc / doxygen / introduction.doc
1 /*! @page introduction Introduction to SimGrid
2
3 [SimGrid](http://simgrid.gforge.inria.fr/) is a toolkit
4 that provides core functionalities for the simulation of distributed
5 applications in heterogeneous distributed environments.
6
7 The specific goal of the project is to facilitate research in the area of
8 distributed and parallel application scheduling on distributed computing
9 platforms ranging from simple network of workstations to Computational
10 Grids.
11
12 # Scenario
13 The goal of this practical session is to illustrate various usage of
14 the MSG interface. To this end we will use the following simple setting:
15
16 > Assume we have a (possibly large) bunch of (possibly large) data to
17 > process and which originally reside on a server (a.k.a. master). For
18 > sake of simplicity, we assume all input file require the same amount
19 > of computation. We assume the server can be helped by a (possibly
20 > large) set of worker machines. What is the best way to organize the
21 > computations ?
22
23 Although this looks like a very simple setting it raises several
24 interesting questions:
25
26 - Which algorithm should the master use to send workload?
27
28     The most obvious algorithm would be to send tasks to workers in a
29     round-robin fashion. This is the initial code we provide you.
30
31     A less obvious but probably more efficient approach would be to set up
32     a request mechanism where a client first ask for tasks, which allows
33     the server to decide which request to answer and possibly to send
34     the tasks to the fastest machines. Maybe you can think of a
35     smarter mechanism...
36
37 - How many tasks should the client ask for?
38
39     Indeed, if we set up a request mechanism so that workers only
40     send request whenever they have no more task to process, they are
41     likely to be poorly exploited since they will have to wait for the
42     master to consider their request and for the input data to be
43     transferred. A client should thus probably request a pool of tasks
44     but if it requests too many tasks, it is likely to lead to a poor
45     load-balancing...
46
47 - How is the quality of such algorithm dependent on the platform
48     characteristics and on the task characteristics?
49
50     Whenever the input communication time is very small compared to
51     processing time and workers are homogeneous, it is likely that the
52     round-robin algorithm performs very well. Would it still hold true
53     when transfer time is not negligible and the platform is, say,
54     a volunteer computing system ?
55
56 - The network topology interconnecting the master and the workers
57   may be quite complicated. How does such a topology impact the
58   previous result?
59
60     When data transfers are the bottleneck, it is likely that a good
61     modeling of the platform becomes essential. In this case, you may
62     want to be able to account for complex platform topologies.
63
64 - Do the algorithms depend on a perfect knowledge of this
65   topology?
66
67     Should we still use a flat master worker deployment or should we
68     use a
69
70 - How is such an algorithm sensitive to external workload variation?
71
72     What if bandwidth, latency and power can vary with no warning?
73     Shouldn't you study whether your algorithm is sensitive to such
74     load variations?
75
76 - Although an algorithm may be more efficient than another, how
77   does it interfere with other applications?
78
79     %As you can see, this very simple setting may need to evolve way
80     beyond what you initially imagined.
81
82     <blockquote> Premature optimization is  the root of all evil. -- D.E.Knuth</blockquote>
83
84     Furthermore, writing your own simulator is much harder than you
85     may imagine. This is why you should rely on an established and flexible
86     one.
87
88 The following figure is a screenshot of [triva][fn:1] visualizing a [SimGrid
89 simulation][fn:2] of two master worker applications (one in light gray and
90 the other in dark gray) running in concurrence and showing resource
91 usage over a long period of time.
92
93 ![Test](./sc3-description.png)
94
95 # Prerequisites
96
97 Of course, you need to install SimGrid before taking this tutorial.
98 Please refer to the relevant Section: \ref install.
99
100 ## Tutorials
101
102 A lot of information on how to install and use Simgrid are
103 provided by the [online documentation][fn:4] and by several tutorials:
104
105 - http://simgrid.gforge.inria.fr/tutorials/simgrid-use-101.pdf
106 - http://simgrid.gforge.inria.fr/tutorials/simgrid-tracing-101.pdf
107 - http://simgrid.gforge.inria.fr/tutorials/simgrid-platf-101.pdf
108
109 # Recommended Steps
110
111 ## Installing Viva
112
113 This [software][fn:1] will be useful to make fancy graph or treemap
114 visualizations and get a better understanding of simulations. You
115 will first need to install pajeng:
116
117 ~~~~{.sh}
118 sudo apt-get install git cmake build-essential libqt4-dev  libboost-dev freeglut3-dev ;
119 git clone https://github.com/schnorr/pajeng.git
120 cd pajeng && mkdir -p build &&  cd build && cmake ../ -DCMAKE_INSTALL_PREFIX=$HOME &&  make -j install
121 cd ../../
122 ~~~~
123
124 Then you can install viva.
125
126 ~~~~{.sh}
127 sudo apt-get install libboost-dev libconfig++-dev libconfig8-dev libgtk2.0-dev freeglut3-dev
128 git clone https://github.com/schnorr/viva.git
129 cd viva && mkdir -p build_graph &&  cd build_graph && cmake ../ -DTUPI_LIBRARY=ON -DVIVA=ON -DCMAKE_INSTALL_PREFIX=$HOME &&  make -j install
130 cd ../../
131 ~~~~
132
133 ## Installing Paje
134
135 This [software][fn:5] provides a Gantt-chart visualization.
136
137 ~~~~{.sh}
138 sudo apt-get install paje.app
139 ~~~~
140
141 ## Installing Vite
142
143 This software provides a [Gantt-chart visualization][fn:6].
144
145 ~~~~{.sh}
146 sudo apt-get install vite
147 ~~~~
148
149 # Let's get Started
150
151 \anchor intro_setup
152 ## Setting up and Compiling
153
154 The corresponding archive with all source files and platform files
155 can be obtained [here](http://simgrid.gforge.inria.fr/tutorials/msg-tuto/msg-tuto.tgz).
156
157 ~~~~{.sh}
158 tar zxf msg-tuto.tgz
159 cd msg-tuto/src
160 make
161 ~~~~
162
163 %As you can see, there is already a nice Makefile that compiles
164 everything for you. Now the tiny example has been compiled and it
165 can be easily run as follows:
166
167 ~~~~{.sh}
168 ./masterworker0 platforms/platform.xml deployment0.xml 2>&1
169 ~~~~
170
171 If you create a single self-content C-file named foo.c, the
172 corresponding program will be simply compiled and linked with
173 SimGrid by typing:
174
175 ~~~~{.sh}
176 make foo
177 ~~~~
178
179 For a more "fancy" output, you can try:
180
181 ~~~~{.sh}
182 ./masterworker0 platforms/platform.xml deployment0.xml 2>&1 | simgrid-colorizer
183 ~~~~
184
185 For a really fancy output, you should use [viva/triva][fn:1]:
186
187 ~~~~{.sh}
188 ./masterworker0 platforms/platform.xml deployment0.xml --cfg=tracing:yes \
189     --cfg=tracing/uncategorized:yes --cfg=viva/uncategorized:uncat.plist
190 LANG=C ; viva simgrid.trace uncat.plist
191 ~~~~
192
193 For a more classical Gantt-Chart visualization, you can produce a
194 [Paje][fn:5] trace:
195
196 ~~~~{.sh}
197 ./masterworker0 platforms/platform.xml deployment0.xml --cfg=tracing:yes \
198     --cfg=tracing/msg/process:yes
199 LANG=C ; Paje simgrid.trace
200 ~~~~
201
202 Alternatively, you can use [vite][fn:6].
203
204 ~~~~{.sh}
205 ./masterworker0 platforms/platform.xml deployment0.xml --cfg=tracing:yes \
206     --cfg=tracing/msg/process:yes --cfg=tracing/basic:yes
207 vite simgrid.trace
208 ~~~~
209
210 ## Getting Rid of Workers in the Deployment File
211
212 In the previous example, the deployment file `deployment0.xml`
213 is tightly connected to the platform file `platform.xml` and a
214 worker process is launched on each host:
215
216 ~~~~{.xml}
217 <?xml version='1.0'?>
218 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
219 <platform version="3">
220   <!-- The master process (with some arguments) -->
221   <process host="Tremblay" function="master">
222      <argument value="20"/>       <!-- Number of tasks -->
223      <argument value="50000000"/>  <!-- Computation size of tasks -->
224      <argument value="1000000"/>   <!-- Communication size of tasks -->
225      <argument value="Jupiter"/>  <!-- First worker -->
226      <argument value="Fafard"/>   <!-- Second worker -->
227      <argument value="Ginette"/>  <!-- Third worker -->
228      <argument value="Bourassa"/> <!-- Last worker -->
229      <argument value="Tremblay"/> <!-- Me! I can work too! -->
230   </process>
231   <!-- The worker process (with no argument) -->
232   <process host="Tremblay" function="worker" on_failure="RESTART"/>
233   <process host="Jupiter" function="worker" on_failure="RESTART"/>
234   <process host="Fafard" function="worker" on_failure="RESTART"/>
235   <process host="Ginette" function="worker" on_failure="RESTART"/>
236   <process host="Bourassa" function="worker" on_failure="RESTART"/>
237 </platform>
238 ~~~~
239
240 This is ok as the platform is rather small but will be painful when
241 using larger platforms. Instead, modify the simulator
242 `masterworker0.c` into `masterworker1.c` so that the master
243 launches a worker process on all the other machines at startup. The
244 new deployment file `deployment1.xml` should thus now simply be:
245
246 ~~~~{.xml}
247 <?xml version='1.0'?>
248 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
249 <platform version="3">
250   <!-- The master process (with some arguments) -->
251   <process host="Tremblay" function="master">
252      <argument value="20"/>       <!-- Number of tasks -->
253      <argument value="50000000"/>  <!-- Computation size of tasks -->
254      <argument value="1000000"/>   <!-- Communication size of tasks -->
255   </process>
256 </platform>
257 ~~~~
258
259 To this end you may need the following MSG functions (click on the links
260 to see their descriptions):
261
262 ~~~~{.c}
263 int MSG_get_host_number(void);
264 xbt_dynar_t MSG_hosts_as_dynar(void);
265 void * xbt_dynar_to_array (xbt_dynar_t dynar);
266 msg_process_t MSG_process_create(const char *name, xbt_main_func_t code,
267                                  void *data, msg_host_t host);
268 ~~~~
269
270 \note
271     It may avoid bugs later to avoid launching a worker on
272     the master host so you probably want to remove it from the host
273     list.
274
275 The `data` field of the @ref MSG_process_create can be used to pass
276 a channel name that will be private between master
277 and workers (e.g., `master_name:worker_name`). Adding the
278 `master_name` in the channel name will allow to easily have several
279 masters and a worker per master on each machine. To this end, you
280 may need to use the following functions:
281
282 ~~~~{.c}
283 msg_host_t MSG_host_self(void);
284 const char * MSG_host_get_name(msg_host_t host);
285 msg_process_t MSG_process_self(void);
286 void * MSG_process_get_data(msg_process_t process);
287 ~~~~
288
289 If you are not too familiar with string
290 manipulation in C, you may want to use the following functions
291 (see the C reference for details):
292
293 ~~~~{.c}
294 char *strcpy(char *dest, const char *src);
295 char *strcat(char *dest, const char *src);
296 ~~~~
297
298 ## Setting up a Time Limit Mechanism
299
300 In the current version, the number of tasks is defined through the
301 worker arguments. Hence, tasks are created at the very beginning of
302 the simulation. Instead, create tasks as needed and provide a time
303 limit indicating when it stops sending tasks. To this end, you will
304 obviously need to know what time it is:
305
306 ~~~~{.c}
307 double MSG_get_clock(void);
308 ~~~~
309
310 Otherwise, a quite effective way of terminating the simulation
311 would be to use some of the following functions:
312
313 ~~~~{.c}
314 void MSG_process_kill(msg_process_t process);
315 int MSG_process_killall(int reset_PIDs);
316 ~~~~
317
318 Anyway, the new deployment `deployment2.xml` file should thus look
319 like this:
320
321 ~~~~{.xml}
322 <?xml version='1.0'?>
323 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
324 <platform version="3">
325   <process host="Tremblay" function="master">
326      <argument value="3600"/>      <!-- Simulation timeout -->
327      <argument value="50000000"/>  <!-- Computation size of tasks -->
328      <argument value="1000000"/>   <!-- Communication size of tasks -->
329   </process>
330 </platform>
331 ~~~~
332
333 It may also be a good idea to transform most of the `XBT_INFO` into
334 `XBT_DEBUG` (e.g., keep the information on the total number of
335 tasks processed). These debug messages can be activated as follows:
336
337 ~~~~{.sh}
338 ./masterworker2 platforms/platform.xml deployment2.xml --log=msg_test.thres:debug
339 ~~~~
340
341 ## Using the Tracing Mechanism
342
343 SimGrid can trace all resource consumption and the outcome can be
344 displayed with viva as illustrated in the section \ref intro_setup. However, when several
345 masters are deployed, it is hard to understand what happens.
346
347 ~~~~{.xml}
348 <?xml version='1.0'?>
349 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
350 <platform version="3">
351   <process host="Tremblay" function="master">
352      <argument value="3600"/>      <!-- Simulation timeout -->
353      <argument value="50000000"/>  <!-- Computation size of tasks -->
354      <argument value="10"/>   <!-- Communication size of tasks -->
355   </process>
356   <process host="Fafard" function="master">
357      <argument value="3600"/>      <!-- Simulation timeout -->
358      <argument value="50000000"/>  <!-- Computation size of tasks -->
359      <argument value="10"/>   <!-- Communication size of tasks -->
360   </process>
361   <process host="Jupiter" function="master">
362      <argument value="3600"/>      <!-- Simulation timeout -->
363      <argument value="50000000"/>  <!-- Computation size of tasks -->
364      <argument value="10"/>   <!-- Communication size of tasks -->
365   </process>
366 </platform>
367 ~~~~
368
369 So let's use categories to track more precisely who does what and when:
370
371 ~~~~{.c}
372 void TRACE_category(const char *category);
373 void MSG_task_set_category (msg_task_t task, const char *category);
374 ~~~~
375
376 The outcome can then be visualized as follows:
377
378 ~~~~{.sh}
379 ./masterworker3 platforms/platform.xml deployment3.xml --cfg=tracing:yes\
380     --cfg=tracing/categorized:yes --cfg=viva/categorized:viva_cat.plist
381 LANG=C; viva simgrid.trace viva_cat.plist
382 ~~~~
383
384 Right now, you should realize that nothing is behaving like you
385 expect. Most workers are idle even though input data are ridiculous
386 and there are several masters deployed on the platform. Using a
387 Gantt-chart visualization may help:
388
389 ~~~~{.sh}
390 ./masterworker3 platforms/platform.xml deployment3.xml --cfg=tracing:yes \
391     --cfg=tracing/msg/process:yes
392 LANG=C; Paje simgrid.trace
393 ~~~~
394
395 OK, so it should now be obvious that round robin is actually
396 very bad.
397
398 ## Improving the Scheduling
399
400 Instead of a round-robin scheduling, let's implement a first-come
401 first-served mechanism. To this end, workers need to send a tiny
402 request first. A possible way to implement such a request with MSG
403 is to send on a specific channel (e.g., the name of the master
404 name) a task with payload 0 and whose attached data is the worker
405 name. This way, the master can keep track of which workers are idle
406 and willing to work.
407
408 To know whether it has pending requests, the master can use the
409 following [function][fn:7]:
410
411 ~~~~{.c}
412 int MSG_task_listen(const char *alias);
413 ~~~~
414
415 If so, it should get the request and push the corresponding host
416 into a dynar so that they can later be retrieved when sending a
417 real [task][fn:7].
418
419 ~~~~{.c}
420 xbt_dynar_t xbt_dynar_new(const unsigned long elm_size,
421                           void_f_pvoid_t const free_f);
422 void xbt_dynar_push(xbt_dynar_t const dynar, const void *src);
423 void xbt_dynar_shift(xbt_dynar_t const dynar, void *const dst);
424 unsigned long xbt_dynar_length(const xbt_dynar_t dynar);
425 ~~~~
426
427 %As you will soon realize, with such simple mechanisms, simple
428 deadlocks will soon appear. They can easily be removed with a
429 simple polling mechanism, hence the need for the following
430 [function][fn:7]:
431
432 ~~~~{.c}
433 msg_error_t MSG_process_sleep(double nb_sec);
434 ~~~~
435
436 %As you should quickly realize, on the simple previous example, it
437 will double the throughput of the platform but will be quite
438 ineffective when input size of the tasks is not negligible anymore.
439
440 From this, many things can easily be added. For example, you could:
441 - add a performance measurement mechanism;
442 - enable the master to make smart scheduling choices using
443   measurement information;
444 - allow workers to have several pending requests so as to overlap
445   communication and computations as much as possible;
446 - ...
447
448 ## Using More Elaborate Platforms
449
450 SimGrid offers a rather powerful platform modeling mechanism. The
451 `src/examples/platforms/` repository comprises a variety of platforms ranging
452 from simple to elaborate. Associated to a good
453 visualization tool to ensure your simulation is meaningful, they
454 can allow you to study to which extent your algorithm scales...
455
456 What is the largest number of tasks requiring 50e6 flops and 1e5
457 bytes that you manage to distribute and process in one hour on
458 `g5k.xml` (you should use `deployment_general.xml`)?
459
460 # TODO: Points to improve for the next time
461
462 - Propose equivalent exercises and skeleton in java.
463 - Propose a virtualbox image with everything (simgrid, paje, viva,
464   ...) already set up.
465 - Ease the installation on mac OS X (binary installer) and
466   windows.
467 - Explain that programming in C or java and having a working
468   development environment is a prerequisite.
469
470 [fn:1]: http://triva.gforge.inria.fr/index.html
471 [fn:2]: http://hal.inria.fr/inria-00529569
472 [fn:3]: http://hal.inria.fr/hal-00738321
473 [fn:4]: http://simgrid.gforge.inria.fr/documentation.html
474 [fn:5]: http://paje.sourceforge.net/
475 [fn:6]: http://vite.gforge.inria.fr/
476
477
478
479
480
481 */