Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Document that amok BW module is done
[simgrid.git] / doc / FAQ.doc
1 /*! \page faq Frequently Asked Questions
2
3 \htmlinclude .FAQ.doc.toc
4
5 \section faq_installation Installing the SimGrid library
6
7 Many people have been asking me questions on how to use SimGrid. Quite
8 often, the questions were not really about SimGrid but on the
9 installation process. This section is intended to help people that are
10 not familiar with compiling C files under UNIX. If you follow these
11 instructions and still have some troubles, drop an e-mail to
12 <simgrid-user@lists.gforge.inria.fr>.
13
14 \subsection faq_compiling Compiling SimGrid
15
16 Suppose you have uncompressed SimGrid in some temporary location of
17 your home directory (say <tt>/home/joe/tmp/simgrid-3.0.1 </tt>). The
18 simplest way to use SimGrid is to install it in your home
19 directory. Change your directory to
20 <tt>/home/joe/tmp/simgrid-3.0.1</tt> and type
21
22 \verbatim./configure --prefix=$HOME
23 make
24 make install
25 \endverbatim
26
27 If at some point, something fails, check the section "\ref
28 faq_compil_trouble". If it does not help, you can report this problem to the
29 list but, please, avoid sending a laconic mail like "There is a problem. Is it
30 okay?". Send the config.log file which is automatically generated by
31 configure. Try to capture both the standard output and the error output of the
32 <tt>make</tt> command with <tt>script</tt>. There is no way for us to help you
33 without the relevant bits of information.
34
35 Now, the following directory should have been created : 
36
37       \li <tt>/home/joe/doc/simgrid/html/</tt>
38       \li <tt>/home/joe/lib/</tt>
39       \li <tt>/home/joe/include/</tt>
40
41 SimGrid is not a binary, it is a library. Both a static and a dynamic
42 version are available. Here is what you can find if you try a <tt>ls
43 /home/joe/lib</tt>:
44
45 \verbatim libsimgrid.a libsimgrid.la libsimgrid.so libsimgrid.so.0 libsimgrid.so.0.0.1
46 \endverbatim
47
48 Thus, there is two ways to link your program with SimGrid:
49       \li Either you use the static version, e.g 
50 \verbatim gcc libsimgrid.a -o MainProgram MainProgram.c
51 \endverbatim
52           In this case, all the SimGrid functions are directly
53           included in <tt>MainProgram</tt> (hence a bigger binary).
54       \li Either you use the dynamic version (the preferred method)
55 \verbatim gcc -lsimgrid -o MainProgram MainProgram.c
56 \endverbatim
57           In this case, the SimGrid functions are not included in
58           <tt>MainProgram</tt> and you need to set your environment
59           variable in such a way that <tt>libsimgrid.so</tt> will be
60           found at runtime. This can be done by adding the following
61           line in your .bashrc (if you use bash and if you have
62           installed the SimGrid libraries in your home directory):
63 \verbatim export LD_LIBRARY_PATH=$HOME/lib/:$LD_LIBRARY_PATH
64 \endverbatim
65
66 \subsection faq_setting Setting up your own code
67
68 Do not build your simulator by modifying the SimGrid examples.  Go
69 outside the SimGrid source tree and create your own working directory
70 (say <tt>/home/joe/SimGrid/MyFirstScheduler/</tt>).
71
72 Suppose your simulation has the following structure (remember it is
73 just an example to illustrate a possible way to compile everything;
74 feel free to organize it as you want).
75
76       \li <tt>sched.h</tt>: a description of the core of the
77           scheduler (i.e. which functions are can be used by the
78           agents). For example we could find the following functions
79           (master, forwarder, slave).
80
81       \li <tt>sched.c</tt>: a C file including <tt>sched.h</tt> and
82           implementing the core of the scheduler. Most of these
83           functions use the MSG functions defined in section \ref
84           msg_gos_functions.
85
86       \li <tt>masterslave.c</tt>: a C file with the main function, i.e.
87           the MSG initialization (MSG_global_init()), the platform
88           creation (e.g. with MSG_create_environment()), the
89           deployment phase (e.g. with MSG_function_register() and
90           MSG_launch_application()) and the call to
91           MSG_main()).
92
93 To compile such a program, we suggest to use the following
94 Makefile. It is a generic Makefile that we have used many times with
95 our students when we teach the C language.
96
97 \verbatim
98 all: masterslave 
99 masterslave: masterslave.o sched.o
100
101 INSTALL_PATH = $$HOME
102 CC = gcc
103 PEDANTIC_PARANOID_FREAK =       -O0 -Wshadow -Wcast-align \
104                                 -Waggregate-return -Wmissing-prototypes -Wmissing-declarations \
105                                 -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
106                                 -Wmissing-noreturn -Wredundant-decls -Wnested-externs \
107                                 -Wpointer-arith -Wwrite-strings -finline-functions
108 REASONABLY_CAREFUL_DUDE =       -Wall
109 NO_PRAYER_FOR_THE_WICKED =      -w -O2 
110 WARNINGS =                      $(REASONABLY_CAREFUL_DUDE)
111 CFLAGS = -g $(WARNINGS)
112
113 INCLUDES = -I$(INSTALL_PATH)/include
114 DEFS = -L$(INSTALL_PATH)/lib/
115 LDADD = -lm -lsimgrid 
116 LIBS = 
117
118 %: %.o
119         $(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ 
120
121 %.o: %.c
122         $(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<
123
124 clean:
125         rm -f $(BIN_FILES) *.o *~
126 .SUFFIXES:
127 .PHONY : clean
128
129 \endverbatim
130
131 The first two lines indicates what should be build when typing make
132 (<tt>masterslave</tt>) and of which files it is to be made of
133 (<tt>masterslave.o</tt> and <tt>sched.o</tt>). This makefile assumes
134 that you have set up correctly your <tt>LD_LIBRARY_PATH</tt> variable
135 (look, there is a <tt>LDADD = -lm -lsimgrid</tt>). If you prefer using
136 the static version, remove the <tt>-lsimgrid</tt> and add a
137 <tt>$(INSTALL_PATH)/lib/libsimgrid.a</tt> on the next line, right
138 after the <tt>LIBS = </tt>.
139
140 More generally, if you have never written a Makefile by yourself, type
141 in a terminal : <tt>info make</tt> and read the introduction. The
142 previous example should be enough for a first try but you may want to
143 perform some more complex compilations...
144
145 \section faq_simgrid I'm new to SimGrid. I have some questions. Where should I start?
146
147 You are at the right place... Having a look to these
148 <a href="http://graal.ens-lyon.fr/~alegrand/articles/Simgrid-Introduction.pdf">slides</a>
149 may give you some insights on what SimGrid can help you to do and what
150 are its limitations. Then you definitely should read the \ref
151 MSG_examples. There is also a mailing list: <simgrid-user@lists.gforge.inria.fr>.
152
153 \subsection faq_generic Building a generic simulator
154
155 Please read carefully the \ref MSG_examples. You'll find in \ref
156 MSG_ex_master_slave a very simple consisting of a master (that owns a bunch of
157 tasks and distributes them) , some slaves (that process tasks whenever
158 they receive one) and some forwarder agents (that simply pass the
159 tasks they receive to some slaves).
160
161 \subsection faq_visualization Visualizing the schedule
162
163 It is sometime convenient to "see" how the agents are behaving. If you
164 like colors, you can use <tt>tools/MSG_visualization/colorize.pl </tt>
165 as a filter to your MSG outputs. It works directly with INFO. Beware,
166 INFO() prints on stderr. Do not forget to redirect if you want to
167 filter (e.g. with bash): 
168 \verbatim 
169 ./msg_test small_platform.xml small_deployment.xml 2>&1 | ../../tools/MSG_visualization/colorize.pl
170 \endverbatim
171
172 We also have a more graphical output. Have a look at MSG_paje_output(). It 
173 generates an input to <a href="http://www-id.imag.fr/Logiciels/paje/">Paje</a>.
174 <center>
175 \htmlonly
176  <a href="Paje_MSG_screenshot.jpg"><img src="Paje_MSG_screenshot_thn.jpg"></a>
177 \endhtmlonly
178 </center>
179
180 \subsection faq_postmortem_analysis Online/postmortem analysis
181
182 Vizualization with Paje can be seen as a kind of postmortem
183 analysis. However, as soon as you start playing with big simulations,
184 you'll realize that processing such output is kind of tricky. There is
185 so much generic informations that it is hard to find the information
186 you are looking for.
187
188 As a matter of fact, loging really depends on simulations (e.g. what
189 kind of events is important...). That is why we do not propose a big
190 dump of your whole simulation (it would slow everything down) but give
191 you neat tools to structure you logs. Have a look at \ref XBT_log. In
192 fact, rather than a post-mortem analysis, you may want to do it on the
193 fly. The process you are running can do whatever you want. Have you
194 thought about adding a global structure where you directly compute the
195 informations that are really important rather than writing everything
196 down and then processing huge files ?
197
198 \subsection faq_C Argh! Do I really have to code in C ?
199
200 Up until now, there is no binding for other languages. If you use C++,
201 you should be able to use the SimGrid library as a standard C library
202 and everything should work fine (simply <i>link</i> against this
203 library; recompiling SimGrid with a C++ compiler won't work and it
204 wouldn't help if you could).
205
206 In fact, the bindings needed to allow one to use SimGrid from Perl,
207 Python, Java, etc. are double-layered.  The first layer would allow
208 you to call for example the MSG_task_get_name(task) function while
209 what you really want is a proper object wrapping allowing you to call
210 task->name(). That's the purpose of the second layer.  The first one
211 is granted with C++ but can be done with tools like 
212 <a href="www.swig.org/">swig</a> for other languages like Perl, Ruby,
213 Python, CAML. None of us really need the second one (which is a bit
214 more demanding and cannot be automatically generated) yet and there is
215 no real point in doing the first one without the second. :)
216
217 As usual, you're welcome to participate.
218
219 \section faq_MIA How to ....? Is there a function in the API to simply ....?
220
221 Here is the deal. The whole SimGrid project (MSG, SURF, GRAS, ...) is
222 meant to be kept as simple and generic as possible. We cannot add
223 functions for everybody's need when these functions can easily be
224 built from the ones already in the API. Most of the time, it is
225 possible and when it was not possible we always have upgraded the API
226 accordingly. When somebody asks us a question like "How to do that ?
227 Is there a function in the API to simply do this ?", we're always glad
228 to answer and help. However if we don't need this code for our own
229 need, there is no chance we're going to write it... it's your job! :)
230 The counterpart to our answers is that once you come up with a neat
231 implementation of this feature (task duplication, RPC, thread
232 synchronization, ...), you should send it to us and we will be glad to
233 add it to the distribution. Thus, other people will take advantage of
234 it (and we don't have to answer this question again and again ;).
235
236 You'll find in this section a few "Missing In Action" features. Many
237 people have asked about it and we have given hints on how to simply do
238 it with MSG. Feel free to contribute...
239
240 \subsection faq_MIA_examples I want some more complex examples!
241
242 Many people have come to ask me a more complex example and each time,
243 they have realized afterward that the basics were in the previous three
244 examples. 
245
246 Of course they have often been needing more complex functions like
247 MSG_process_suspend(), MSG_process_resume() and
248 MSG_process_isSuspended() (to perform synchronization), or
249 MSG_task_Iprobe() and MSG_process_sleep() (to avoid blocking
250 receptions), or even MSG_process_create() (to design asynchronous
251 communications or computations). But the examples are sufficient to
252 start.
253
254 We know. We should add some more examples, but not really some more
255 complex ones... We should add some examples that illustrate some other
256 functionalities (like how to simply encode asynchronous
257 communications, RPC, process migrations, thread synchronization, ...)
258 and we will do it when we will have a little bit more time. We have
259 tried to document the examples so that they are understandable. Tell
260 us if something is not clear and once again feel free to participate!
261 :)
262
263 \subsection faq_MIA_taskdup Missing in action: Task duplication/replication
264
265 There is no task duplication in MSG. When you create a task, you can
266 process it or send it somewhere else. As soon as a process has sent
267 this task, he doesn't have this task anymore. It's gone. The receiver
268 process has got the task. However, you could decide upon receiving to
269 create a "copy" of a task but you have to handle by yourself the
270 semantic associated to this "duplication".
271
272 As we already told, we prefer keeping the API as simple as
273 possible. This kind of feature is rather easy to implement by users
274 and the semantic you associate really depends on people. Having a
275 *generic* task duplication mechanism is not that trivial (in
276 particular because of the data field). That is why I would recommand
277 that you write it by yourself even if I can give you advice on how to
278 do it.
279
280 You have the following functions to get informations about a task:
281 MSG_task_get_name(), MSG_task_get_compute_duration(),
282 MSG_task_get_remaining_computation(), MSG_task_get_data_size(),
283 and MSG_task_get_data().
284
285 You could use a dictionnary (#xbt_dict_t) of dynars (#xbt_dict_t). If
286 you still don't see how to do it, please come back to us...
287
288 \subsection faq_MIA_asynchronous I want to do asynchronous communications.
289
290 Up until now, there is no asynchronous communications in MSG. However,
291 you can create as many process as you want so you should be able to do
292 whatever you want... I've written a queue module to help implementing
293 some asynchronous communications at low cost (creating thousands of
294 process only to handle communications may be problematic in term of
295 performance at some point). I'll add it in the distribution asap.
296
297 \subsection faq_MIA_thread_synchronization I need to synchronize my processes
298
299 You obviously cannot use pthread_mutexes of pthread_conds. The best
300 thing would be to propose similar structures. Unfortunately, we
301 haven't found time to do it yet. However you can try to play with
302 MSG_process_suspend() and MSG_process_resume(). You can even do some
303 synchronization with fake communications (using MSG_task_get(),
304 MSG_task_put() and MSG_task_Iprobe()).
305
306 \subsection faq_MIA_host_load Where is the get_host_load function hidden in MSG?
307
308 There is no such thing because its semantic wouldn't be really
309 clear. Of course, it is something about the amount of host throughput,
310 but there is as many definition of "host load" as people asking for
311 this function. First, you have to remember that resource availability
312 may vary over time, which make any load notion harder to define.
313
314 It may be instantaneous value or an average one. Moreover it may be only the
315 power of the computer, or may take the background load into account, or may
316 even take the currently running tasks into account. In some SURF models,
317 communications have an influence on computational power. Should it be taken
318 into account too?
319
320 So, we decided not to include such a function into MSG and let people do it
321 thereselves so that they get the value matching exactly what they mean. One
322 possibility is to run active measurement as in next code snippet. It is very
323 close from what you would have to do out of the simulator, and thus gives
324 you information that you could also get in real settings to not hinder the
325 realism of your simulation. 
326
327 \verbatim
328 double get_host_load() {
329    m_task_t task = MSG_task_create("test", 0.001, 0, NULL);
330    double date = MSG_get_clock();
331
332    MSG_task_execute(task);
333    date = MSG_get_clock() - date;
334    MSG_task_destroy(task);
335    return (0.001/date);
336 }
337 \endverbatim
338
339 Of course, it may not match your personal definition of "host load". In this
340 case, please detail what you mean on the mailing list, and we will extend
341 this FAQ section to fit your taste if possible.
342
343 \subsection faq_MIA_batch_scheduler Is there a native support for batch schedulers in SimGrid ?
344
345 No, there is no native support for batch schedulers and none is
346 planned because this is a very specific need (and doing it in a
347 generic way is thus very hard). However some people have implemented
348 their own batch schedulers. Vincent Garonne wrote one during his PhD
349 and put his code in the contrib directory of our CVS so that other can
350 keep working on it. You may find inspinring ideas in it.
351
352 \subsection faq_MIA_checkpointing I need a checkpointing thing
353
354 Actually, it depends on whether you want to checkpoint the simulation, or to
355 simulate checkpoints. 
356
357 The first one could help if your simulation is a long standing process you
358 want to keep running even on hardware issues. It could also help to
359 <i>rewind</i> the simulation by jumping sometimes on an old checkpoint to
360 cancel recent calculations.\n 
361 Unfortunately, such thing will probably never exist in SG. One would have to
362 duplicate all data structures because doing a rewind at the simulator level
363 is very very hard (not talking about the malloc free operations that might
364 have been done in between). Instead, you may be interested in the Libckpt
365 library (http://www.cs.utk.edu/~plank/plank/www/libckpt.html). This is the
366 checkpointing solution used in the condor project, for example. It makes it
367 easy to create checkpoints (at the OS level, creating something like core
368 files), and rerunning them on need.
369
370 If you want to simulate checkpoints instead, it means that you want the
371 state of an executing task (in particular, the progress made towards
372 completion) to be saved somewhere.  So if a host (and the task executing on
373 it) fails (cf. #MSG_HOST_FAILURE), then the task can be restarted
374 from the last checkpoint.\n
375
376 Actually, such a thing does not exists in SimGrid either, but it's just
377 because we don't think it is fundamental and it may be done in the user code
378 at relatively low cost. You could for example use a watcher that
379 periodically get the remaining amount of things to do (using
380 MSG_task_get_remaining_computation()), or fragment the task in smaller
381 subtasks.
382
383 \section faq_SG Where has SG disappeared?!?
384
385 OK, it's time to explain what's happening to the SimGrid project. Let's
386 start with a little bit of history.
387
388 * Historically, SimGrid was a low-level toolkit for scheduling with
389 classical models such as DAGs. That was SimGrid v.1.* aka SG, written
390 by Henri Casanova. I (Arnaud) had been using it in its earliest
391 versions during an internship at UCSD.
392
393 Then we have realized that encoding distributed algorithm in SG was a
394 real pain.
395
396 * So we have built MSG on top of SG and have released SimGrid v.2.*. MSG
397 offered a very basic API to encode a distributed application easily.
398 However encoding MSG on top of SG was not really convenient and did not
399 use the DAG part since the control of the task synchronization was done
400 on top of MSG and no more in SG. We have been playing a little bit with
401 MSG. We have realized that:
402
403    \li 1) the platform modeling was quite flexible and could be "almost"
404        automated (e.g. using random generator and post-annotations);
405
406    \li 2) SG was the bottleneck because of the way we were using
407        it. We needed to simulate concurrent transfers, complex load
408        sharing mechanisms. Many optimizations (e.g. trace integration)
409        were totally inefficient when combined with MSG and made extending SG
410        to implement new sharing policies, parallel tasks models, or failures
411        (many people were asking for these kind of features) a real pain;
412
413    \li 3) the application modeling was not really easy. Even though the
414        application modeling depends on people's applications, we thought
415        we could improve things here. One of our target here was realistic
416 distributed applications ranging from computer sensor networks like
417 the NWS to peer-to-peer applications;
418
419 * So we have been planning mainly two things for SimGrid 3:
420
421    \li 1) I have proposed to get rid of SG and to re-implement a new kernel
422        that would be faster and more flexible. That is what I did in the
423 end of 2004: SURF. SURF is based on a fast max-min linear solver
424 using O(1) data-structures. I have quickly replaced SG by SURF in
425 MSG and the result has been that on the MSG example, the new
426 version was more than 10 times faster while we had gain a lot of
427 flexibility. I think I could still easily make MSG faster but I
428 have to work on MSG now (e.g. using some of the O(1)
429 data-structures I've been using to build SURF) since it has become
430 the bottleneck. Some MSG functions have been removed from the API
431 but they were mainly intended to build the platform by hand (they
432 had appeared in the earliest versions of MSG) and were therefore
433 not useful anymore since we are providing a complete mechanism to
434 automatically build the platform and deploy the agents on it.;
435
436    \li 2) GRAS is a new project Martin and I have come up with. The idea is
437 to have a programming environment that let you program real
438 distributed applications while letting you the ability to run it in
439 the simulator without having to change the slightest line of your
440 code. From the simulation point of view, GRAS performs the
441 application modeling automatically... Up until now, GRAS works on
442 top MSG for historical reasons but I'm going to make it work
443 directly on top of SURF so that it can use all the flex and the
444 speed provided by SURF.
445
446 Those two things are working, but we want to make everything as clean as
447 possible before releasing SimGrid v.3.
448
449 So what about those nice DAGs we used to have in SimGrid v.1.? They're not
450 anymore in SimGrid v.3. Let me recall you the way SimGrid 3 is organized:
451
452 \verbatim
453 ________________
454 |   User code  |
455 |______________|
456 | | MSG | GRAS |
457 | -------------|
458 | |   SURF     |
459 | -------------|
460 |     XBT      |
461 ----------------
462 \endverbatim
463
464 XBT is our tool box and now, you should have an idea of what the other ones
465 are. As you can see, the primitive SG is not here anymore. However it could
466 still be brought back if people really need it. Here is how it would fit.
467
468 \verbatim
469 ______________________
470 |    User code       |
471 |____________________|
472 | | MSG | GRAS | SG  |
473 | -------------------|
474 | |      SURF        |
475 | -------------------|
476 |        XBT         |
477 ----------------------
478 \endverbatim
479
480 Re-implementing SG on top of SURF is really straightforward (it only
481 requires a little bit of time that I really don't have right now)
482 since the only thing that lacks to SURF is the DAG part. But adding it
483 to SURF would slow it down and therefore slow MSG and GRAS which is
484 not a good thing.  However it is really not on the top of our TODO
485 list because we have to work on GRAS, and its MPI counterpart, and a
486 parallel task model, and ... Anyway, we finally have migrated our CVS
487 to gforge so people that are interested by helping on this part will
488 have the possibility to do it.
489
490 \subsection faq_SG_DAG How to implement a distributed dynamic scheduler of DAGs.
491
492 Distributed is somehow "contagious". If you start making distributed
493 decisions, there is no way to handle DAGs directly anymore (unless I am
494 missing something). You have to encode your DAGs in term of communicating
495 process to make the whole scheduling process distributed. Believe me, it is
496 worth the effort since you'll then be able to try your algorithms in a very
497 wide variety of conditions. Here is an example of how you could do that.
498 Assume T1 has to be done before T2.
499
500 \verbatim
501  int your_agent(int argc, char *argv[] {
502    ...
503    T1 = MSG_task_create(...);
504    T2 = MSG_task_create(...);
505    ...
506    while(1) {
507      ...
508      if(cond) MSG_task_execute(T1);
509      ...
510      if((MSG_task_get_remaining_computation(T1)=0.0) && (you_re_in_a_good_mood))
511         MSG_task_execute(T2)
512      else {
513         /* do something else */
514      }
515    }
516  }
517 \endverbatim
518  
519 If you decide that the distributed part is not that much important and that
520 DAG is really the level of abstraction you want to work with (but it
521 prevents you from having "realistic" platform modeling), then you should
522 keep using the 2.18.5 versions until somebody has ported SG on top of SURF.
523 Note however that SURF will be slower than the old SG to handle traces with
524 a lots of variations (there is no trace integration anymore).
525
526 \subsection faq_SG_future Will SG come back in the maintained branch one day?
527
528 Sure. In fact, we already have thought about a new and cleaner API:
529 \verbatim
530 void*       SG_link_get_data(SG_link_t link);
531 void        SG_link_set_data(SG_link_t link, void *data);
532 const char* SG_link_get_name(SG_link_t link);
533 double      SG_link_get_capacity(SG_link_t link);
534 double      SG_link_get_current_bandwidth(SG_link_t link);
535 double      SG_link_get_current_latency(SG_link_t link);
536
537 SG_workstation_t  SG_workstation_get_by_name(const char *name);
538 SG_workstation_t* SG_workstation_get_list(void);
539 int               SG_workstation_get_number(void);
540 void              SG_workstation_set_data(SG_workstation_t workstation, void *data);
541 void *            SG_workstation_get_data(SG_workstation_t workstation);
542 const char*       SG_workstation_get_name(SG_workstation_t workstation);
543 SG_link_t*        SG_workstation_route_get_list(SG_workstation_t src, SG_workstation_t dst);
544 int               SG_workstation_route_get_size(SG_workstation_t src, SG_workstation_t dst);
545 double            SG_workstation_get_power(SG_workstation_t workstation);
546 double            SG_workstation_get_available_power(SG_workstation_t workstation);
547
548 SG_task_t         SG_task_create(const char *name, void *data, double amount);
549 int               SG_task_schedule(SG_task_t task, int workstation_nb,
550                                     SG_workstation_t **workstation_list, double *computation_amount,
551                                     double *communication_amount, double rate);
552
553 void*             SG_task_get_data(SG_task_t task);
554 void              SG_task_set_data(SG_task_t task, void *data);
555 const char*       SG_task_get_name(SG_task_t task);
556 double            SG_task_get_amount(SG_task_t task);
557 double            SG_task_get_remaining_amount(SG_task_t task);
558 void              SG_task_dependency_add(const char *name, void *data, SG_task_t src, SG_task_t dst);
559 void              SG_task_dependency_remove(SG_task_t src, SG_task_t dst); 
560 e_SG_task_state_t SG_task_state_get(SG_task_t task); /* e_SG_task_state_t can be either SG_SCHEDULED, SG_RUNNING, SG_DONE, or SG_FAILED */
561 void              SG_task_watch(SG_task_t task, e_SG_task_state_t state); /* SG_simulate will stop as soon as the state of this task is the one given in argument. 
562                                                                              Watch-point is then automatically removed */
563 void              SG_task_unwatch(SG_task_t task, e_SG_task_state_t state);
564
565 void              SG_task_unschedule(SG_task_t task); /* change state and rerun.. */
566
567 SG_task_t        *SG_simulate(double how_long); /* returns a NULL-terminated array of SG_task_t whose state has changed */
568 \endverbatim
569
570 We're just looking for somebody to implement it... :)
571
572 \section faq_dynamic Dynamic resources and platform building
573
574 \subsection faq_platform Building a realistic platform
575
576 We can speak more than an hour on this subject and we still do not have
577 the right answer, just some ideas. You can read the following
578 <a href="http://graal.ens-lyon.fr/~alegrand/articles/Simgrid-Introduction.pdf">slides</a>.
579 It may give you some hints. You can also have a look at the
580 <tt>tools/platform_generation/</tt> directory. There is a perl-script
581 we use to annotate a Tiers generated platform.
582
583 \subsection faq_SURF_dynamic How can I have variable resource availability?
584
585 A nice feature of SimGrid is that it enables you to seamlessly have
586 resources whose availability change over time. When you build a
587 platform, you generally declare CPUs like that:
588
589 \verbatim
590   <cpu name="Cpu A" power="100.00"/>
591 \endverbatim 
592
593 If you want the availability of "CPU A" to change over time, the only
594 thing you have to do is change this definition like that:
595
596 \verbatim
597   <cpu name="Cpu A" power="100.00" availability_file="trace_A.txt" state_file="trace_A_failure.txt"/>
598 \endverbatim
599
600 For CPUs, availability files are expressed in fraction of available
601 power. Let's have a look at what "trace_A.txt" may look like:
602
603 \verbatim
604 PERIODICITY 1.0
605 0.0 1.0
606 11.0 0.5
607 20.0 0.9
608 \endverbatim
609
610 At time 0, our CPU will deliver 100 Mflop/s. At time 11.0, it will
611 deliver only 50 Mflop/s until time 20.0 where it will will start
612 delivering 90 Mflop/s. Last at time 21.0 (20.0 plus the periodicity
613 1.0), we'll be back to the beginning and it will deliver 100Mflop/s.
614
615 Now let's look at the state file:
616 \verbatim
617 PERIODICITY 10.0
618 1.0 -1.0
619 2.0 1.0
620 \endverbatim
621
622 A negative value means "off" while a positive one means "on". At time
623 1.0, the CPU is on. At time 1.0, it is turned off and at time 2.0, it
624 is turned on again until time 12 (2.0 plus the periodicity 10.0). It
625 will be turned on again at time 13.0 until time 23.0, and so on.
626
627 Now, let's look how the same kind of thing can be done for network
628 links. A usual declaration looks like:
629
630 \verbatim
631   <network_link name="LinkA" bandwidth="10.0" latency="0.2"/>
632 \endverbatim
633
634 You have at your disposal the following options: bandwidth_file,
635 latency_file and state_file. The only difference with CPUs is that
636 bandwidth_file and latency_file do not express fraction of available
637 power but are expressed directly in Mb/s and seconds.
638
639 \subsection faq_flexml_bypassing How can I have some C functions do what the platform file does?
640
641 So you want to bypass the XML files parser, uh? Maybe doin some parameter
642 sweep experiments on your simulations or so? This is possible, but it's not
643 really easy. Here is how it goes.
644
645 For this, you have to first remember that the XML parsing in SimGrid is done
646 using a tool called FleXML. Given a DTD, this gives a flex-based parser. If
647 you want to bypass the parser, you need to provide some code mimicking what
648 it does and replacing it in its interactions with the SURF code. So, let's
649 have a look at these interactions.
650
651 FleXML parser are close to classical SAX parsers. It means that a
652 well-formed SimGrid platform XML file might result in the following
653 "events":
654
655   - start "platform_description"
656   - start "cpu" with attributes name="host1" power="1.0"
657   - end "cpu"
658   - start "cpu" with attributes name="host2" power="2.0"
659   - end "cpu"
660   - start "network_link" with ...
661   - end "network_link"
662   - start "route" with ...
663   - end "route"
664   - start "route" with ...
665   - end "route"
666   - end "platform_description"
667
668 The communication from the parser to the SURF code uses two means:
669 Attributes get copied into some global variables, and a surf-provided
670 function gets called by the parser for each event. For example, the event
671   - start "cpu" with attributes name="host1" power="1.0"
672
673 let the parser do the equivalent of:
674 \verbatim
675   strcpy("host1",A_cpu_name);
676   A_cpu_power = 1.0;
677   (*STag_cpu_fun)();
678 \endverbatim
679
680 In SURF, we attach callbacks to the different events by initializing the
681 pointer functions to some the right surf functions. Example in
682 workstation_KCCFLN05.c (surf_parse_open() ends up calling surf_parse()):
683 \verbatim
684   // Building the routes
685   surf_parse_reset_parser();
686   STag_route_fun=parse_route_set_endpoints;
687   ETag_route_element_fun=parse_route_elem;
688   ETag_route_fun=parse_route_set_route;
689   surf_parse_open(file);
690   xbt_assert1((!surf_parse()),"Parse error in %s",file);
691   surf_parse_close();
692 \endverbatim
693     
694 So, to bypass the FleXML parser, you need to write your own version of the
695 surf_parse function, which should do the following:
696    - Call the corresponding STag_<tag>_fun function to simulate tag start
697    - Fill the A_<tag>_<attribute> variables with the wanted values
698    - Call the corresponding ETag_<tag>_fun function to simulate tag end
699    - (do the same for the next set of values, and loop)
700
701 Then, tell SimGrid that you want to use your own "parser" instead of the stock one:
702 \verbatim
703   surf_parse = surf_parse_bypass;
704   MSG_create_environment(NULL);
705 \endverbatim
706
707 An example of this trick is distributed in the file examples/msg/msg_test_surfxml_bypassed.c
708
709 \section faq_troubleshooting Troubleshooting
710
711 \subsection faq_compil_trouble ./configure fails!
712
713 We now only one reason for the configure to fail:
714
715  - <b>You are using a borken build environment</b>\n
716    If symptom is that configure complains about gcc not being able to build
717    executables, you are probably missing the libc6-dev package. Damn Ubuntu.
718
719 If you experience other kind of issue, please get in touch with us. We are
720 always interested in improving our portability to new systems.
721
722 \subsection faq_distcheck_fails Dude! "make check" fails on my machine!
723
724 Don't assume we never run this target, because we do. Really. Promise!
725
726 There is several reasons which may cause the make check to fail on your
727 machine:
728
729  - <b>You are using a borken compiler</b>.\n
730    The symptom may be that the "make check" fails within testsuite/gras
731    directory.\n
732    For example, the breezy release of Ubuntu comes with a prerelease of the
733    4.0 gcc compiler. This version happens to be completely unusable, and you
734    should install a gcc-3.4 compiler and change the /usr/bin/gcc link to let
735    it point on /usr/bin/gcc-3.4.
736  - <b>You are using a borken libc (probably concerning the contextes)</b>.\n
737    The symptom is that the "make check" fails within the examples/msg directory.\n
738    By default, SimGrid uses something called ucontexts. This is part of the
739    libc, but it's quite undertested. For example, some (old) versions of the
740    glibc on alpha do not implement these functions, but provide the stubs
741    (which return ENOSYS: not implemented). It fools our detection mecanism
742    and leads to segfaults.\n
743    On some x86_64, the pointer to function is stored into a integer, but int
744    are 32bits only on this arch while pointers are 64bits. Our detection
745    mecanism also fails to detect the problem, which leads to segfaults.\n
746    In both cases, there is not much we can do to fix the bug. We are working
747    on a workaround for x86_64 machines, but in the meanwhile, you can
748    compile with --with-context=pthread to avoid ucontext completely. You'll
749    be a bit more limitated in the number of simulated processes you can start
750    concurently, but 5000 processes is still enough for most purposes, isn't
751    it?\n
752    This limitation is the reason why we insist on using this piece of ...
753    software even if it's so troublesome.
754  - <b>There is a bug in SimGrid we aren't aware of</b>.\n
755    If none of the above apply, please drop us a mail on the mailing list so
756    that we can check it out.
757
758 \subsection faq_context_1000 I want thousands of simulated processes
759
760 SimGrid can use either pthreads library or the UNIX98 contextes. On most
761 systems, the number of pthreads is limited and then your simulation may be
762 limited for a stupid reason. This is especially true with the current linux
763 pthreads, and I cannot get more than 2000 simulated processes with pthreads
764 on my box. The UNIX98 contexts allow me to raise the limit to 25,000
765 simulated processes on my laptop.
766
767 The <tt>--with-context</tt> option of the <tt>./configure</tt> script allows
768 you to choose between UNIX98 contextes (<tt>--with-context=ucontext</tt>)
769 and the pthread version ( (<tt>--with-context=pthread</tt>). The default
770 value is ucontext when the script detect a working UNIX98 context
771 implementation. On Windows boxes, the provided value is discarded and an
772 adapted version is picked up.
773
774 We experienced some issues with contextes on some rare systems (solaris 8
775 and lower or old alpha linuxes comes to mind). The main problem is that the
776 configure script detect the contextes as being functional when it's not
777 true. If you happen to use such a system, switch manually to the pthread
778 version, and provide us with a good patch for the configure script so that
779 it is done automatically ;)
780
781 \subsection faq_context_10000 I want hundred thousands of simulated processes
782
783 As explained above, SimGrid can use UNIX98 contextes to represent and handle
784 the simulated processes. Thanks to this, the main limitation to the number
785 of simulated processes becomes the available memory. 
786
787 Here are some tricks I had to use in order to run a token ring between
788 25,000 processes on my laptop (1Gb memory, 1.5Gb swap).
789
790  - First of all, make sure your code runs for a few hundreds processes
791    before trying to push the limit. Make sure it's valgrind-clean, ie that
792    valgrind does not report neither memory error nor memory leaks. Indeed,
793    numerous simulated processes result in *fat* simulation hindering debugging.
794
795  - It was really boring to write 25,000 entries in the deployment file, so I wrote 
796    a little script <tt>examples/gras/tokenS/make_deployment.pl</tt>, which you may
797    want to adapt to your case.
798
799  - The deployment file became quite big, so I had to do what is in the FAQ
800    entry \ref faq_flexml_limit
801
802  - Each UNIX98 context has its own stack entry. As debugging this is quite 
803    hairly, the default value is a bit overestimated so that user don't get 
804    into trouble about this. You want to tune this size to increse the number 
805    of processes. This is the <tt>STACK_SIZE</tt> define in 
806    <tt>src/xbt/context_private.h</tt>, which is 128kb by default.
807    Reduce this as much as you can, but be warned that if this value is too 
808    low, you'll get a segfault. The token ring example, which is quite simple, 
809    runs with 40kb stacks.
810
811 \subsection faq_longjmp longjmp madness
812
813 This is when valgrind starts complaining about longjmp things, just like:
814
815 \verbatim ==21434== Conditional jump or move depends on uninitialised value(s)
816 ==21434==    at 0x420DBE5: longjmp (longjmp.c:33)
817 ==21434==
818 ==21434== Use of uninitialised value of size 4
819 ==21434==    at 0x420DC3A: __longjmp (__longjmp.S:48)
820 \endverbatim
821
822 or even when it reports scary things like:
823
824 \verbatim ==24023== Warning: client switching stacks?  SP change: 0xBE3FF618 --> 0xBE7FF710
825 x86->IR: unhandled instruction bytes: 0xF4 0xC7 0x83 0xD0
826 ==24023==          to suppress, use: --max-stackframe=4194552 or greater
827 ==24023== Your program just tried to execute an instruction that Valgrind
828 ==24023== did not recognise.  There are two possible reasons for this.
829 ==24023== 1. Your program has a bug and erroneously jumped to a non-code
830 ==24023==    location.  If you are running Memcheck and you just saw a
831 ==24023==    warning about a bad jump, it's probably your program's fault.
832 ==24023== 2. The instruction is legitimate but Valgrind doesn't handle it,
833 ==24023==    i.e. it's Valgrind's fault.  If you think this is the case or
834 ==24023==    you are not sure, please let us know.
835 ==24023== Either way, Valgrind will now raise a SIGILL signal which will
836 ==24023== probably kill your program.
837 ==24023==
838 ==24023== Process terminating with default action of signal 4 (SIGILL)
839 ==24023==  Illegal opcode at address 0x420D234
840 ==24023==    at 0x420D234: abort (abort.c:124)
841 \endverbatim
842
843 This is the sign that you didn't used the exception mecanism well. Most
844 probably, you have a <tt>return;</tt> somewhere within a <tt>TRY{}</tt>
845 block. This is <b>evil</b>, and you must not do this. Did you read the section
846 about \ref XBT_ex??
847
848 \subsection faq_flexml_limit I get the message "surf_parse_lex: Assertion `next&lt;limit' failed."
849
850 This is because your platform file is too big for the parser. 
851
852 Actually, the message comes directly from FleXML, the technology on top of
853 which the parser is built. FleXML has the bad idea of fetching the whole
854 document in memory before parsing it. And moreover, the memory buffer size
855 must be determinded at compilation time.
856
857 We use a value which seems big enough for our need without bloating the
858 simulators footprints. But of course your mileage may vary. In this case,
859 just edit src/surf/surfxml.l modify the definition of
860 FLEXML_BUFFERSTACKSIZE. E.g.
861
862 \verbatim
863 #define FLEXML_BUFFERSTACKSIZE 1000000000
864 \endverbatim
865
866 Then recompile and everything should be fine, provided that your version of
867 Flex is recent enough (>= 2.5.31). If not the compilation process should
868 warn you.
869
870 A while ago, we worked on FleXML to reduce a bit its memory consumtion, but
871 these issues remain. There is two things we should do:
872
873   - use a dynamic buffer instead of a static one so that the only limit
874     becomes your memory, not a stupid constant fixed at compilation time
875     (maybe not so difficult).
876   - change the parser so that it does not need to get the whole file in
877     memory before parsing
878     (seems quite difficult, but I'm a complete newbe wrt flex stuff).
879
880 These are changes to FleXML itself, not SimGrid. But since we kinda hijacked
881 the development of FleXML, I can grant you that any patches would be really
882 welcome and quickly integrated.
883
884 \subsection faq_deadlock There is a deadlock !!!
885
886 Unfortunately, we cannot debug every code written in SimGrid.  We
887 furthermore believe that the framework provides ways enough
888 information to debug such informations yourself. If the textual output
889 is not enough, Make sure to check the \ref faq_visualization FAQ entry to see
890 how to get a graphical one.
891
892 Now, if you come up with a really simple example that deadlocks and
893 you're absolutely convinced that it should not, you can ask on the
894 list. Just be aware that you'll be severely punished if the mistake is
895 on your side... We have plenty of FAQ entries to redact and new
896 features to implement for the impenitents! ;)
897
898 \author Arnaud Legrand (arnaud.legrand::imag.fr)
899 \author Martin Quinson (martin.quinson::loria.fr)
900
901
902 */
903