Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add an entry on dynamic resources
[simgrid.git] / doc / FAQ.doc
1 /*! \page faq Frequently Asked Questions
2
3 \section faq_installation Installing the SimGrid library
4
5 Many people have been asking me questions on how to use SimGrid. Quite
6 often, the questions were not really about SimGrid but on the
7 installation process. This section is intended to help people that are
8 not familiar with compiling C files under UNIX. If you follow these
9 instructions and still have some troubles, drop an e-mail to
10 <simgrid-user@lists.gforge.inria.fr>.
11
12 \subsection faq_compiling Compiling SimGrid
13
14 Suppose you have uncompressed SimGrid in some temporary location of
15 your home directory (say <tt>/home/joe/tmp/simgrid-2.18.2 </tt>). The
16 simplest way to use SimGrid is to install it in your home
17 directory. Change your directory to
18 <tt>/home/joe/tmp/simgrid-2.18.2</tt> and type
19
20 \verbatim./configure --prefix=$HOME
21 make
22 make install
23 \endverbatim
24
25 If at some point, something fails, you can report me this problem but,
26 please, avoid sending a laconic mail like "There is a problem. Is it
27 normal ?". Send me the config.log file which is automatically
28 generated by configure. Try to capture both the standard output and
29 the error output of the <tt>make</tt> command. There is no way for me
30 to help you if you do not give me a little bit of information.
31
32 Now, the following directory should have been created : 
33
34       \li <tt>/home/joe/doc/simgrid/html/</tt>
35       \li <tt>/home/joe/lib/</tt>
36       \li <tt>/home/joe/include/</tt>
37
38 SimGrid is not a binary, it is a library. Both a static and a dynamic
39 version are available. Here is what you can find if you try a <tt>ls
40 /home/joe/lib</tt>:
41
42 \verbatim libsimgrid.a  libsimgrid.la  libsimgrid.so  libsimgrid.so.0 libsimgrid.so.0.0.1
43 \endverbatim
44
45 Thus, there is two ways to link your program with SimGrid:
46       \li Either you use the static version, e.g 
47 \verbatim gcc libsimgrid.a -o MainProgram MainProgram.c
48 \endverbatim
49           In this case, all the SimGrid functions are directly
50           included in <tt>MainProgram</tt> (hence a bigger binary).
51       \li Either you use the dynamic version (the preferred method)
52 \verbatim gcc -lsimgrid -o MainProgram MainProgram.c
53 \endverbatim
54           In this case, the SimGrid functions are not included in
55           <tt>MainProgram</tt> and you need to set your environment
56           variable in such a way that <tt>libsimgrid.so</tt> will be
57           found at runtime. This can be done by adding the following
58           line in your .bashrc (if you use bash and if you have
59           installed the SimGrid libraries in your home directory):
60 \verbatim export LD_LIBRARY_PATH=$HOME/lib/:$LD_LIBRARY_PATH
61 \endverbatim
62
63 \subsection faq_setting Setting up your own code
64
65 Do not build your simulator by modifying the SimGrid examples.  Go
66 outside the SimGrid source tree and create your own working directory
67 (say <tt>/home/joe/SimGrid/MyFirstScheduler/</tt>).
68
69 Suppose your simulation has the following structure (remember it is
70 just an example to illustrate a possible way to compile everything;
71 feel free to organize it as you want).
72
73       \li <tt>sched.h</tt>: a description of the core of the
74           scheduler (i.e. which functions are can be used by the
75           agents). For example we could find the following functions
76           (master, forwarder, slave).
77
78       \li <tt>sched.c</tt>: a C file including <tt>sched.h</tt> and
79           implementing the core of the scheduler. Most of these
80           functions use the MSG functions defined in section \ref
81           msg_gos_functions.
82
83       \li <tt>masterslave.c</tt>: a C file with the main function, i.e.
84           the MSG initialization (MSG_global_init()), the platform
85           creation (e.g. with MSG_create_environment()), the
86           deployment phase (e.g. with MSG_function_register() and
87           MSG_launch_application()) and the call to
88           MSG_main()).
89
90 To compile such a program, I suggest to use the following Makefile. It
91 is a generic Makefile that I generally use with my students when I
92 teach the C language.
93
94 \verbatim
95 all: masterslave 
96 masterslave: masterslave.o sched.o
97
98 INSTALL_PATH = $$HOME
99 CC = gcc
100 PEDANTIC_PARANOID_FREAK =       -O0 -Wshadow -Wcast-align \
101                                 -Waggregate-return -Wmissing-prototypes -Wmissing-declarations \
102                                 -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
103                                 -Wmissing-noreturn -Wredundant-decls -Wnested-externs \
104                                 -Wpointer-arith -Wwrite-strings -finline-functions
105 REASONABLY_CAREFUL_DUDE =       -Wall
106 NO_PRAYER_FOR_THE_WICKED =      -w -O2 
107 WARNINGS =                      $(REASONABLY_CAREFUL_DUDE)
108 CFLAGS = -g $(WARNINGS)
109
110 INCLUDES = -I$(INSTALL_PATH)/include
111 DEFS = -L$(INSTALL_PATH)/lib/
112 LDADD = -lm -lsimgrid 
113 LIBS = 
114
115 %: %.o
116         $(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ 
117
118 %.o: %.c
119         $(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<
120
121 clean:
122         rm -f $(BIN_FILES) *.o *~
123 .SUFFIXES:
124 .PHONY : clean
125
126 \endverbatim
127
128 The first two lines indicates what should be build when typing make
129 (<tt>masterslave</tt>) and of which files it is to be made of
130 (<tt>masterslave.o</tt> and <tt>sched.o</tt>). This makefile assumes
131 that you have set up correctly your <tt>LD_LIBRARY_PATH</tt> variable
132 (look, there is a <tt>LDADD = -lm -lsimgrid</tt>). If you prefer using
133 the static version, remove the <tt>-lsimgrid</tt> and add a
134 <tt>$(INSTALL_PATH)/lib/libsimgrid.a</tt> on the next line, right
135 after the <tt>LIBS = </tt>.
136
137 More generally, if you have never written a Makefile by yourself, type
138 in a terminal : <tt>info make</tt> and read the introduction. The
139 previous example should be enough for a first try but you may want to
140 perform some more complex compilations...
141
142 \section faq_simgrid I'm new to SimGrid. I have some questions. Where should I start ?
143
144 You are at the right place... Having a look to these
145 <a href="http://graal.ens-lyon.fr/~alegrand/articles/Simgrid-Introduction.pdf">slides</a>
146 may give you some insights on what SimGrid can help you to do and what
147 are its limitations. Then you definitely should read the \ref
148 MSG_examples. There is also a mailing list: <simgrid-user@lists.gforge.inria.fr>.
149
150 \subsection faq_generic Building a generic simulator
151
152 Please read carefully the \ref MSG_examples. You'll find in \ref
153 MSG_ex_master_slave a very simple consisting of a master (that owns a bunch of
154 tasks and distributes them) , some slaves (that process tasks whenever
155 they receive one) and some forwarder agents (that simply pass the
156 tasks they receive to some slaves).
157
158 \subsection faq_examples I want some more complex examples !
159
160 Many people have come to ask me a more complex example and each time,
161 they have realized afterward that the basics were in the previous three
162 examples. 
163
164 Of course they have often been needing more complex functions like
165 MSG_process_suspend(), MSG_process_resume() and
166 MSG_process_isSuspended() (to perform synchronization), or
167 MSG_task_Iprobe() and MSG_process_sleep() (to avoid blocking
168 receptions), or even MSG_process_create() (to design asynchronous
169 communications or computations). But the examples are sufficient to
170 start.
171
172 I know I should add some more examples, but not some more complex
173 ones... I should add some examples that illustrate some other
174 functionalities (like how to simply encode asynchronous
175 communications, RPC, process migrations, thread synchronization, ...)
176 and I will do it when I will have a little bit more time. I have tried
177 to document the examples so that they are understandable. I know it is
178 not really satisfying but it is the best I have managed to do yet.
179
180 \subsection faq_platform Building a realistic platform
181
182 I can speak more than an hour on this subject and I still do not have
183 the right answer, just some ideas. You can read the following
184 <a href="http://graal.ens-lyon.fr/~alegrand/articles/Simgrid-Introduction.pdf">slides</a>.
185 It may give you some hints. You can also have a look at the
186 <tt>tools/platform_generation/</tt> directory. There is a perl-script
187 I use to annotate a Tiers generated platform (may not be up-to-date
188 though).
189
190 \subsection faq_visualization Visualizing the schedule
191
192 It is sometime convenient to "see" how the agents are behaving. If you
193 like colors, you can use <tt>tools/MSG_visualization/colorize.pl </tt>
194 as a filter to your MSG outputs. It works directly with INFO. Beware,
195 INFO() prints on stderr. Do not forget to redirect if you want to
196 filter (e.g. with bash): 
197 \verbatim 
198 ./msg_test small_platform.xml small_deployment.xml 2>&1 | ../../tools/MSG_visualization/colorize.pl
199 \endverbatim
200
201 We also have a more graphical output. Have a look at MSG_paje_output(). It 
202 generates an input to <a href="http://www-id.imag.fr/Logiciels/paje/">Paje</a>.
203 <center>
204 \htmlonly
205  <a href="Paje_MSG_screenshot.jpg"><img src="Paje_MSG_screenshot_thn.jpg"></a>
206 \endhtmlonly
207 </center>
208
209 \subsection faq_context I have tons of process and it is limiting my simulation.
210
211 MSG can use either pthreads or the GNU context library. On most
212 systems, the number of pthreads is limited (especially with the
213 current linux pthreads) and then your simulation may be limited for a
214 stupid reason. If you enable the context option
215 (<tt>--enable-context</tt> in the <tt>./configure</tt> phase), you
216 will not use the pthread anymore and the context switching will be
217 done manually, which enables us to have as much agents as your memory
218 can hold and should be much faster... So think about it if your
219 simulation is getting really big.
220
221 Nevertheless, be aware that this code does not work on some system. It
222 is not very clean. As usual, as soon as I will have a little bit more
223 time, I will recode it in a cleaner way.
224
225 \section faq_SG Where has SG disappeared ?!?
226
227 OK, it's time to explain what's happening to the SimGrid project. Let's
228 start with a little bit of history.
229
230 * Historically, SimGrid was a low-level toolkit for scheduling with
231 classical models such as DAGs. That was SimGrid v.1.* aka SG, written by
232 Henri Casanova. I had been using it in its earliest versions during an
233 internship at UCSD.
234
235 Then we have realized that encoding distributed algorithm in SG was a
236 real pain.
237
238 * So we have built MSG on top of SG and have released SimGrid v.2.*. MSG
239 offered a very basic API to encode a distributed application easily.
240 However encoding MSG on top of SG was not really convenient and did not
241 use the DAG part since the control of the task synchronization was done
242 on top of MSG and no more in SG. We have been playing a little bit with
243 MSG. We have realized that:
244
245    \li 1) the platform modeling was quite flexible and could be "almost"
246        automated (e.g. using random generator and post-annotations);
247
248    \li 2) SG was the bottleneck because of the way we were using
249        it. We needed to simulate concurrent transfers, complex load
250        sharing mechanisms. Many optimizations (e.g. trace integration)
251        were totally inefficient when combined with MSG and made extending SG
252        to implement new sharing policies, parallel tasks models, or failures
253        (many people were asking for these kind of features) a real pain;
254
255    \li 3) the application modeling was not really easy. Even though the
256        application modeling depends on people's applications, we thought
257        we could improve things here. One of our target here was realistic
258 distributed applications ranging from computer sensor networks like
259 the NWS to peer-to-peer applications;
260
261 * So we have been planning mainly two things for SimGrid 3:
262
263    \li 1) I have proposed to get rid of SG and to re-implement a new kernel
264        that would be faster and more flexible. That is what I did in the
265 end of 2004: SURF. SURF is based on a fast max-min linear solver
266 using O(1) data-structures. I have quickly replaced SG by SURF in
267 MSG and the result has been that on the MSG example, the new
268 version was more than 10 times faster while we had gain a lot of
269 flexibility. I think I could still easily make MSG faster but I
270 have to work on MSG now (e.g. using some of the O(1)
271 data-structures I've been using to build SURF) since it has become
272 the bottleneck. Some MSG functions have been removed from the API
273 but they were mainly intended to build the platform by hand (they
274 had appeared in the earliest versions of MSG) and were therefore
275 not useful anymore since we are providing a complete mechanism to
276 automatically build the platform and deploy the agents on it.;
277
278    \li 2) GRAS is a new project Martin and I have come up with. The idea is
279 to have a programming environment that let you program real
280 distributed applications while letting you the ability to run it in
281 the simulator without having to change the slightest line of your
282 code. From the simulation point of view, GRAS performs the
283 application modeling automatically... Up until now, GRAS works on
284 top MSG for historical reasons but I'm going to make it work
285 directly on top of SURF so that it can use all the flex and the
286 speed provided by SURF.
287
288 Those two things are working, but we want to make everything as clean as
289 possible before releasing SimGrid v.3.
290
291 So what about those nice DAGs we used to have in SimGrid v.1. ? They're not
292 anymore in SimGrid v.3. Let me recall you the way SimGrid 3 is organized:
293
294 \verbatim
295 ________________
296 |   User code  |
297 |______________|
298 | | MSG | GRAS |
299 | -------------|
300 | |   SURF     |
301 | -------------|
302 |     XBT      |
303 ----------------
304 \endverbatim
305
306 XBT is our tool box and now, you should have an idea of what the other ones
307 are. As you can see, the primitive SG is not here anymore. However it could
308 still be brought back if people really need it. Here is how it would fit.
309
310 \verbatim
311 ______________________
312 |    User code       |
313 |____________________|
314 | | MSG | GRAS | SG  |
315 | -------------------|
316 | |      SURF        |
317 | -------------------|
318 |        XBT         |
319 ----------------------
320 \endverbatim
321
322 Re-implementing SG on top of SURF is really straightforward (it only
323 requires a little bit of time that I really don't have right now)
324 since the only thing that lacks to SURF is the DAG part. But adding it
325 to SURF would slow it down and therefore slow MSG and GRAS which is
326 not a good thing.  However it is really not on the top of our TODO
327 list because we have to work on GRAS, and its MPI counterpart, and a
328 parallel task model, and ... Anyway, we finally have migrated our CVS
329 to gforge so people that are interested by helping on this part will
330 have the possibility to do it.
331
332 \subsection faq_SG_DAG But I wanted to implement a distributed dynamic scheduler of DAGs... How can I do that it SG is not available anymore in the next versions ?
333
334 Distributed is somehow "contagious". If you start making distributed
335 decisions, there is no way to handle DAGs directly anymore (unless I am
336 missing something). You have to encode your DAGs in term of communicating
337 process to make the whole scheduling process distributed. Believe me, it is
338 worth the effort since you'll then be able to try your algorithms in a very
339 wide variety of conditions.
340
341 If you decide that the distributed part is not that much important and that
342 DAG is really the level of abstraction you want to work with (but it
343 prevents you from having "realistic" platform modeling), then you should
344 keep using the 2.18.5 versions until somebody has ported SG on top of SURF.
345 Note however that SURF will be slower than the old SG to handle traces with
346 a lots of variations (there is no trace integration anymore).
347
348
349 \subsection faq_SURF_dynami How can I have variable resource availability?
350
351 A nice feature of SimGrid is that it enables you to seamlessly have
352 resources whose availability change over time. When you build a
353 platform, you generally declare CPUs like that:
354
355 \verbatim
356   <cpu name="Cpu A" power="100.00"/>
357 \endverbatim 
358
359 If you want the availability of "CPU A" to change over time, the only
360 thing you have to do is change this definition like that:
361
362 \verbatim
363   <cpu name="Cpu A" power="100.00" availability_file="trace_A.txt" state_file="trace_A_failure.txt"/>
364 \endverbatim
365
366 For CPUs, availability files are expressed in fraction of available
367 power. Let's have a look at what "trace_A.txt" may look like:
368
369 \verbatim
370 PERIODICITY 1.0
371 0.0 1.0
372 11.0 0.5
373 20.0 0.9
374 \endverbatim
375
376 At time 0, our CPU will deliver 100 Mflop/s. At time 11.0, it will
377 deliver only 50 Mflop/s until time 20.0 where it will will start
378 delivering 90 Mflop/s. Last at time 21.0 (20.0 plus the periodicity
379 1.0), we'll be back to the beginning and it will deliver 100Mflop/s.
380
381 Now let's look at the state file:
382 \verbatim
383 PERIODICITY 10.0
384 1.0 -1.0
385 2.0 1.0
386 \endverbatim
387
388 A negative value means "off" while a positive one means "on". At time
389 1.0, the CPU is on. At time 1.0, it is turned off and at time 2.0, it
390 is turned on again until time 12 (2.0 plus the periodicity 10.0). It
391 will be turned on again at time 13.0 until time 23.0, and so on.
392
393 Now, let's look how the same kind of thing can be done for network
394 links. A usual declaration looks like:
395
396 \verbatim
397   <network_link name="LinkA" bandwidth="10.0" latency="0.2"/>
398 \endverbatim
399
400 You have at your disposal the following options: bandwidth_file,
401 latency_file and state_file. The only difference with CPUs is that
402 bandwidth_file and latency_file do not express fraction of available
403 power but are expressed directly in Mb/s and seconds.
404
405 \section faq_flexml_bypassing How could I have some C functions do what the platform and deployment files do?
406
407 So you want to bypass the XML files parser, uh? Maybe doin some parameter
408 sweep experiments on your simulations or so? This is possible, but it's not
409 really easy. Here is how it goes.
410
411 For this, you have to first remember that the XML parsing in SimGrid is done
412 using a tool called FleXML. Given a DTD, this gives a flex-based parser. If
413 you want to bypass the parser, you need to provide some code mimicking what
414 it does and replacing it in its interactions with the SURF code. So, let's
415 have a look at these interactions.
416
417 FleXML parser are close to classical SAX parsers. It means that a
418 well-formed SimGrid platform XML file might result in the following
419 "events":
420
421   - start "platform_description"
422   - start "cpu" with attributes name="host1" power="1.0"
423   - end "cpu"
424   - start "cpu" with attributes name="host2" power="2.0"
425   - end "cpu"
426   - start "network_link" with ...
427   - end "network_link"
428   - start "route" with ...
429   - end "route"
430   - start "route" with ...
431   - end "route"
432   - end "platform_description"
433
434 The communication from the parser to the SURF code uses two means:
435 Attributes get copied into some global variables, and a surf-provided
436 function gets called by the parser for each event. For example, the event
437   - start "cpu" with attributes name="host1" power="1.0"
438
439 let the parser do the equivalent of:
440 \verbatim
441   strcpy("host1",A_cpu_name);
442   A_cpu_power = 1.0;
443   (*STag_cpu_fun)();
444 \endverbatim
445
446 In SURF, we attach callbacks to the different events by initializing the
447 pointer functions to some the right surf functions. Example in
448 workstation_KCCFLN05.c (surf_parse_open() ends up calling surf_parse()):
449 \verbatim
450   // Building the routes
451   surf_parse_reset_parser();
452   STag_route_fun=parse_route_set_endpoints;
453   ETag_route_element_fun=parse_route_elem;
454   ETag_route_fun=parse_route_set_route;
455   surf_parse_open(file);
456   xbt_assert1((!surf_parse()),"Parse error in %s",file);
457   surf_parse_close();
458 \endverbatim
459     
460 So, to bypass the FleXML parser, you need to write your own version of the
461 surf_parse function, which should do the following:
462    - Call the corresponding STag_<tag>_fun function to simulate tag start
463    - Fill the A_<tag>_<attribute> variables with the wanted values
464    - Call the corresponding ETag_<tag>_fun function to simulate tag end
465    - (do the same for the next set of values, and loop)
466
467 Then, tell SimGrid that you want to use your own "parser" instead of the stock one:
468 \verbatim
469   surf_parse = surf_parse_bypass;
470   MSG_create_environment(NULL);
471 \endverbatim
472
473 An example of this trick is distributed in the file examples/msg/msg_test_surfxml_bypassed.c
474
475 \section faq_flexml_limit I get the message "surf_parse_lex: Assertion `next<limit' failed."
476
477 This is because your platform file is too big for the parser. 
478
479 Actually, the message comes directly from FleXML, the technology on top of
480 which the parser is built. FleXML has the bad idea of fetching the whole
481 document in memory before parsing it. And moreover, the memory buffer size
482 must be determinded at compilation time.
483
484 We use a value which seems big enough for our need withour bloating the
485 simulators footprints. But of course your mileage may vary. In this case,
486 just edit src/surf/surfxml.l modify the definition of
487 FLEXML_BUFFERSTACKSIZE. E.g.
488
489 \verbatim
490 #define FLEXML_BUFFERSTACKSIZE 1000000000
491 \endverbatim
492
493 Then recompile and everything should be fine, provided that your version of
494 Flex is recent enough (>= 2.5.31). If not the compilation process should
495 warn you.
496
497 A while ago, we worked on FleXML to reduce a bit its memory consumtion, but
498 these issues remain. There is two things we should do:
499
500   - use a dynamic buffer instead of a static one so that the only limit
501     becomes your memory, not a stupid constant fixed at compilation time
502     (maybe not so difficult).
503   - change the parser so that it does not need to get the whole file in
504     memory before parsing
505     (seems quite difficult, but I'm a complete newbe wrt flex stuff).
506
507 These are changes to FleXML itself, not SimGrid. But since we kinda hijacked
508 the development of FleXML, I can grant you that any patches would be really
509 welcome and quickly integrated.
510
511 \section faq_host_load Where is the get_host_load function hidden in MSG?
512
513 There is no such thing because its semantic wouldn't be really clear. Of
514 course, it is something about the amount of host throughput, but there is as
515 many definition of "host load" as people asking for this function.
516
517 It may be instantaneous value or an average one. Moreover it may be only the
518 power of the computer, or may take the background load into account, or may
519 even take the currently running tasks into account. In some SURF models,
520 communications have an influence on computational power. Should it be taken
521 into account too?
522
523 So, we decided not to include such a function into MSG and let people do it
524 thereselves so that they get the value matching exactly what they mean. One
525 possibility is to run active measurement as in next code snippet. It is very
526 close from what you would have to do out of the simulator, and thus gives
527 you information that you could also get in real settings to not hinder the
528 realism of your simulation. 
529
530 \verbatim
531 double get_host_load() {
532    m_task_t task = MSG_task_create("test", 0.001, 0, NULL);
533    double date = MSG_get_clock();
534
535    MSG_task_execute(task);
536    date = MSG_get_clock() - date;
537    MSG_task_destroy(task);
538    return (0.001/date);
539 }
540 \endverbatim
541
542 Of course, it may not match your personal definition of "host load". In this
543 case, please detail what you mean on the mailing list, and we will extend
544 this FAQ section to fit your taste if possible.
545
546
547 \author Arnaud Legrand (arnaud.legran::imag.fr)
548 \author Martin Quinson (martin.quinson::loria.fr)
549
550
551 */
552