Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0432d414e3ce082258f6776819bbf291d0b49a81
[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 ## Tutorials
98
99 A lot of information on how to install and use Simgrid are
100 provided by the [online documentation][fn:4] and by several tutorials:
101
102 - http://simgrid.gforge.inria.fr/tutorials/simgrid-use-101.pdf
103 - http://simgrid.gforge.inria.fr/tutorials/simgrid-tracing-101.pdf
104 - http://simgrid.gforge.inria.fr/tutorials/simgrid-platf-101.pdf
105
106 ## Installing SimGrid
107
108 Please see our Section on \ref install "installing SimGrid". 
109
110 \note
111    Please note that your distribution may ship with an old version of
112    SimGrid; you may want to use [a newer release](https://gforge.inria.fr/frs/?group_id=12)
113    or even [clone our git repository](https://gforge.inria.fr/frs/?group_id=12)
114    (a [GitHub mirror](https://github.com/mquinson/simgrid) is also available).
115
116 # Recommended Steps
117
118 ## Installing Viva
119
120 This [software][fn:1] will be useful to make fancy graph or treemap
121 visualizations and get a better understanding of simulations. You
122 will first need to install pajeng:
123
124 ~~~~{.sh}
125 sudo apt-get install git cmake build-essential libqt4-dev  libboost-dev freeglut3-dev ;
126 git clone https://github.com/schnorr/pajeng.git
127 cd pajeng && mkdir -p build &&  cd build && cmake ../ -DCMAKE_INSTALL_PREFIX=$HOME &&  make -j install
128 cd ../../
129 ~~~~
130
131 Then you can install viva.
132
133 ~~~~{.sh}
134 sudo apt-get install libboost-dev libconfig++-dev libconfig8-dev libgtk2.0-dev freeglut3-dev
135 git clone https://github.com/schnorr/viva.git
136 cd viva && mkdir -p build_graph &&  cd build_graph && cmake ../ -DTUPI_LIBRARY=ON -DVIVA=ON -DCMAKE_INSTALL_PREFIX=$HOME &&  make -j install
137 cd ../../
138 ~~~~
139
140 ## Installing Paje
141
142 This [software][fn:5] provides a Gantt-chart visualization.
143
144 ~~~~{.sh}
145 sudo apt-get install paje.app
146 ~~~~
147
148 ## Installing Vite
149
150 This software provides a [Gantt-chart visualization][fn:6].
151
152 ~~~~{.sh}
153 sudo apt-get install vite
154 ~~~~
155
156 # Let's get Started
157
158 \anchor intro_setup
159 ## Setting up and Compiling
160
161 The corresponding archive with all source files and platform files
162 can be obtained [here](http://simgrid.gforge.inria.fr/tutorials/msg-tuto/msg-tuto.tgz).
163
164 ~~~~{.sh}
165 tar zxf msg-tuto.tgz
166 cd msg-tuto/src
167 make
168 ~~~~
169
170 %As you can see, there is already a nice Makefile that compiles
171 everything for you. Now the tiny example has been compiled and it
172 can be easily run as follows:
173
174 ~~~~{.sh}
175 ./masterworker0 platforms/platform.xml deployment0.xml 2>&1
176 ~~~~
177
178 If you create a single self-content C-file named foo.c, the
179 corresponding program will be simply compiled and linked with
180 SimGrid by typing:
181
182 ~~~~{.sh}
183 make foo
184 ~~~~
185
186 For a more "fancy" output, you can try:
187
188 ~~~~{.sh}
189 ./masterworker0 platforms/platform.xml deployment0.xml 2>&1 | simgrid-colorizer
190 ~~~~
191
192 For a really fancy output, you should use [viva/triva][fn:1]:
193
194 ~~~~{.sh}
195 ./masterworker0 platforms/platform.xml deployment0.xml --cfg=tracing:yes \
196     --cfg=tracing/uncategorized:yes --cfg=viva/uncategorized:uncat.plist
197 LANG=C ; viva simgrid.trace uncat.plist
198 ~~~~
199
200 For a more classical Gantt-Chart visualization, you can produce a
201 [Paje][fn:5] trace:
202
203 ~~~~{.sh}
204 ./masterworker0 platforms/platform.xml deployment0.xml --cfg=tracing:yes \
205     --cfg=tracing/msg/process:yes
206 LANG=C ; Paje simgrid.trace
207 ~~~~
208
209 Alternatively, you can use [vite][fn:6].
210
211 ~~~~{.sh}
212 ./masterworker0 platforms/platform.xml deployment0.xml --cfg=tracing:yes \
213     --cfg=tracing/msg/process:yes --cfg=tracing/basic:yes
214 vite simgrid.trace
215 ~~~~
216
217 ## Getting Rid of Workers in the Deployment File
218
219 In the previous example, the deployment file `deployment0.xml`
220 is tightly connected to the platform file `platform.xml` and a
221 worker process is launched on each host:
222
223 ~~~~{.xml}
224 <?xml version='1.0'?>
225 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
226 <platform version="3">
227   <!-- The master process (with some arguments) -->
228   <process host="Tremblay" function="master">
229      <argument value="20"/>       <!-- Number of tasks -->
230      <argument value="50000000"/>  <!-- Computation size of tasks -->
231      <argument value="1000000"/>   <!-- Communication size of tasks -->
232      <argument value="Jupiter"/>  <!-- First worker -->
233      <argument value="Fafard"/>   <!-- Second worker -->
234      <argument value="Ginette"/>  <!-- Third worker -->
235      <argument value="Bourassa"/> <!-- Last worker -->
236      <argument value="Tremblay"/> <!-- Me! I can work too! -->
237   </process>
238   <!-- The worker process (with no argument) -->
239   <process host="Tremblay" function="worker" on_failure="RESTART"/>
240   <process host="Jupiter" function="worker" on_failure="RESTART"/>
241   <process host="Fafard" function="worker" on_failure="RESTART"/>
242   <process host="Ginette" function="worker" on_failure="RESTART"/>
243   <process host="Bourassa" function="worker" on_failure="RESTART"/>
244 </platform>
245 ~~~~
246
247 This is ok as the platform is rather small but will be painful when
248 using larger platforms. Instead, modify the simulator
249 `masterworker0.c` into `masterworker1.c` so that the master
250 launches a worker process on all the other machines at startup. The
251 new deployment file `deployment1.xml` should thus now simply be:
252
253 ~~~~{.xml}
254 <?xml version='1.0'?>
255 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
256 <platform version="3">
257   <!-- The master process (with some arguments) -->
258   <process host="Tremblay" function="master">
259      <argument value="20"/>       <!-- Number of tasks -->
260      <argument value="50000000"/>  <!-- Computation size of tasks -->
261      <argument value="1000000"/>   <!-- Communication size of tasks -->
262   </process>
263 </platform>
264 ~~~~
265
266 To this end you may need the following MSG functions (click on the links
267 to see their descriptions):
268
269 ~~~~{.c}
270 int MSG_get_host_number(void);
271 xbt_dynar_t MSG_hosts_as_dynar(void);
272 void * xbt_dynar_to_array (xbt_dynar_t dynar);
273 msg_process_t MSG_process_create(const char *name, xbt_main_func_t code,
274                                  void *data, msg_host_t host);
275 ~~~~
276
277 \note
278     It may avoid bugs later to avoid launching a worker on
279     the master host so you probably want to remove it from the host
280     list.
281
282 The `data` field of the @ref MSG_process_create can be used to pass
283 a channel name that will be private between master
284 and workers (e.g., `master_name:worker_name`). Adding the
285 `master_name` in the channel name will allow to easily have several
286 masters and a worker per master on each machine. To this end, you
287 may need to use the following functions:
288
289 ~~~~{.c}
290 msg_host_t MSG_host_self(void);
291 const char * MSG_host_get_name(msg_host_t host);
292 msg_process_t MSG_process_self(void);
293 void * MSG_process_get_data(msg_process_t process);
294 ~~~~
295
296 If you are not too familiar with string
297 manipulation in C, you may want to use the following functions
298 (see the C reference for details):
299
300 ~~~~{.c}
301 char *strcpy(char *dest, const char *src);
302 char *strcat(char *dest, const char *src);
303 ~~~~
304
305 ## Setting up a Time Limit Mechanism
306
307 In the current version, the number of tasks is defined through the
308 worker arguments. Hence, tasks are created at the very beginning of
309 the simulation. Instead, create tasks as needed and provide a time
310 limit indicating when it stops sending tasks. To this end, you will
311 obviously need to know what time it is:
312
313 ~~~~{.c}
314 double MSG_get_clock(void);
315 ~~~~
316
317 Otherwise, a quite effective way of terminating the simulation
318 would be to use some of the following functions:
319
320 ~~~~{.c}
321 void MSG_process_kill(msg_process_t process);
322 int MSG_process_killall(int reset_PIDs);
323 ~~~~
324
325 Anyway, the new deployment `deployment2.xml` file should thus look
326 like this:
327
328 ~~~~{.xml}
329 <?xml version='1.0'?>
330 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
331 <platform version="3">
332   <process host="Tremblay" function="master">
333      <argument value="3600"/>      <!-- Simulation timeout -->
334      <argument value="50000000"/>  <!-- Computation size of tasks -->
335      <argument value="1000000"/>   <!-- Communication size of tasks -->
336   </process>
337 </platform>
338 ~~~~
339
340 It may also be a good idea to transform most of the `XBT_INFO` into
341 `XBT_DEBUG` (e.g., keep the information on the total number of
342 tasks processed). These debug messages can be activated as follows:
343
344 ~~~~{.sh}
345 ./masterworker2 platforms/platform.xml deployment2.xml --log=msg_test.thres:debug
346 ~~~~
347
348 ## Using the Tracing Mechanism
349
350 SimGrid can trace all resource consumption and the outcome can be
351 displayed with viva as illustrated in the section \ref intro_setup. However, when several
352 masters are deployed, it is hard to understand what happens.
353
354 ~~~~{.xml}
355 <?xml version='1.0'?>
356 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
357 <platform version="3">
358   <process host="Tremblay" function="master">
359      <argument value="3600"/>      <!-- Simulation timeout -->
360      <argument value="50000000"/>  <!-- Computation size of tasks -->
361      <argument value="10"/>   <!-- Communication size of tasks -->
362   </process>
363   <process host="Fafard" function="master">
364      <argument value="3600"/>      <!-- Simulation timeout -->
365      <argument value="50000000"/>  <!-- Computation size of tasks -->
366      <argument value="10"/>   <!-- Communication size of tasks -->
367   </process>
368   <process host="Jupiter" function="master">
369      <argument value="3600"/>      <!-- Simulation timeout -->
370      <argument value="50000000"/>  <!-- Computation size of tasks -->
371      <argument value="10"/>   <!-- Communication size of tasks -->
372   </process>
373 </platform>
374 ~~~~
375
376 So let's use categories to track more precisely who does what and when:
377
378 ~~~~{.c}
379 void TRACE_category(const char *category);
380 void MSG_task_set_category (msg_task_t task, const char *category);
381 ~~~~
382
383 The outcome can then be visualized as follows:
384
385 ~~~~{.sh}
386 ./masterworker3 platforms/platform.xml deployment3.xml --cfg=tracing:yes\
387     --cfg=tracing/categorized:yes --cfg=viva/categorized:viva_cat.plist
388 LANG=C; viva simgrid.trace viva_cat.plist
389 ~~~~
390
391 Right now, you should realize that nothing is behaving like you
392 expect. Most workers are idle even though input data are ridiculous
393 and there are several masters deployed on the platform. Using a
394 Gantt-chart visualization may help:
395
396 ~~~~{.sh}
397 ./masterworker3 platforms/platform.xml deployment3.xml --cfg=tracing:yes \
398     --cfg=tracing/msg/process:yes
399 LANG=C; Paje simgrid.trace
400 ~~~~
401
402 OK, so it should now be obvious that round robin is actually
403 very bad.
404
405 ## Improving the Scheduling
406
407 Instead of a round-robin scheduling, let's implement a first-come
408 first-served mechanism. To this end, workers need to send a tiny
409 request first. A possible way to implement such a request with MSG
410 is to send on a specific channel (e.g., the name of the master
411 name) a task with payload 0 and whose attached data is the worker
412 name. This way, the master can keep track of which workers are idle
413 and willing to work.
414
415 To know whether it has pending requests, the master can use the
416 following [function][fn:7]:
417
418 ~~~~{.c}
419 int MSG_task_listen(const char *alias);
420 ~~~~
421
422 If so, it should get the request and push the corresponding host
423 into a dynar so that they can later be retrieved when sending a
424 real [task][fn:7].
425
426 ~~~~{.c}
427 xbt_dynar_t xbt_dynar_new(const unsigned long elm_size,
428                           void_f_pvoid_t const free_f);
429 void xbt_dynar_push(xbt_dynar_t const dynar, const void *src);
430 void xbt_dynar_shift(xbt_dynar_t const dynar, void *const dst);
431 unsigned long xbt_dynar_length(const xbt_dynar_t dynar);
432 ~~~~
433
434 %As you will soon realize, with such simple mechanisms, simple
435 deadlocks will soon appear. They can easily be removed with a
436 simple polling mechanism, hence the need for the following
437 [function][fn:7]:
438
439 ~~~~{.c}
440 msg_error_t MSG_process_sleep(double nb_sec);
441 ~~~~
442
443 %As you should quickly realize, on the simple previous example, it
444 will double the throughput of the platform but will be quite
445 ineffective when input size of the tasks is not negligible anymore.
446
447 From this, many things can easily be added. For example, you could:
448 - add a performance measurement mechanism;
449 - enable the master to make smart scheduling choices using
450   measurement information;
451 - allow workers to have several pending requests so as to overlap
452   communication and computations as much as possible;
453 - ...
454
455 ## Using More Elaborate Platforms
456
457 SimGrid offers a rather powerful platform modeling mechanism. The
458 `src/examples/platforms/` repository comprises a variety of platforms ranging
459 from simple to elaborate. Associated to a good
460 visualization tool to ensure your simulation is meaningful, they
461 can allow you to study to which extent your algorithm scales...
462
463 What is the largest number of tasks requiring 50e6 flops and 1e5
464 bytes that you manage to distribute and process in one hour on
465 `g5k.xml` (you should use `deployment_general.xml`)?
466
467 # TODO: Points to improve for the next time
468
469 - Propose equivalent exercises and skeleton in java.
470 - Propose a virtualbox image with everything (simgrid, paje, viva,
471   ...) already set up.
472 - Ease the installation on mac OS X (binary installer) and
473   windows.
474 - Explain that programming in C or java and having a working
475   development environment is a prerequisite.
476
477 [fn:1]: http://triva.gforge.inria.fr/index.html
478 [fn:2]: http://hal.inria.fr/inria-00529569
479 [fn:3]: http://hal.inria.fr/hal-00738321
480 [fn:4]: http://simgrid.gforge.inria.fr/documentation.html
481 [fn:5]: http://paje.sourceforge.net/
482 [fn:6]: http://vite.gforge.inria.fr/
483
484
485
486
487
488 */