Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Modify SD_task structures so that get_start_time, get_finish_time and get_remaining_a...
[simgrid.git] / README.coding
1 **
2 ** Source tree organization
3 **
4 ******************************************************
5
6 There is at least 5 sub-projects in the tree:
7
8  - XBT: eXtended Bundle of Tools (low-level toolbox: logging, datatypes).
9  - SURF: a SimUlation aRtiFact. This is the simulation kernel.
10  - MSG:  originally MetaSimGrid, MSG is a simple distributed application
11          simulator.
12  - GRAS: Grid Reality And Simulation (message passing API with two
13          implementations allowing to compile programs on top of the
14          simulator or for the real life without code modification)
15  - AMOK: Advanced Metacomputing Overlay Kit (high level toolbox; Grid
16          application elements such as distributed database, topology
17          discovery service, and so on)
18
19 They are all in the same tree because they are complementary tools and
20 having all of them in the same package makes the installation easier
21 for end-users. Moreover, it enables to share the compilation chain and
22 eases the development.
23
24 The tree is not splited on projects, but on file finality:
25  include/            -> all *public* headers
26  include/xbt/*.h     -> one file per module
27  include/gras.h      -> file including all modules headers
28   (same for xbt instead of gros)
29   
30  src/Makefile.am     -> main makefile. All projects should fit in only one
31                         library (I mean 2, RL+SG), which is compiled here.
32                         
33                         Since all object.o files are placed here, you should
34                         choose the name of c files carfully to avoid
35                         conflict. 
36                         
37  src/gras/DataDesc                      -> typical project module
38  src/gras/DataDesc/datadesc_interface.h -> visible to any GRAS modules;
39                                            masked to the user and GROS/AMOK/SURF
40  src/gras/DataDesc/datadesc_private.h   -> visible only from this module                                           
41   
42    So, the modules have 3 levels of publicity for their interface. 
43    Private, internal to GRAS, public. Of course, I try to keep as much stuff
44    private as possible.
45
46  src/include -> another location for protected headers. Used by SURF, and
47                 other should be converted, since this is the Right Thing.
48
49  testsuite/ -> The more test the better. 
50                Same organization than src/ and include/
51                Tests are allowed to load some headers of the module they test.
52                All tests should be listed in run_test.in so that they get
53                   run on 'make check'. 
54                They are not listed directly in the check_PROGRAMS part of
55                   the makefile because run_test knows about the gras logging
56                   features and relaunch with full details the failed tests.
57                   
58  examples/ -> Supposed to be copy/pastable by the user, so keep it clear and
59                 avoid any kind of trick. In particular, do only include the
60                 public headers here.
61 **
62 ** Indentation standard
63 **
64 *****************************************************
65
66 Most files use the Kernighan & Ritchie coding style with 2 spaces of
67 indentation. The indent program can help you to stick to it. :)
68
69 **
70 ** Type naming standard
71 **
72 *****************************************************
73
74 It may sound strange, but the type naming convention was source of intense
75 discution between da GRAS posse members. The convention we came to may not
76 be the best solution, but it has the merit to exist and leave everyone work.
77 So please stick to it.
78
79   - ???_t is a valid type (builded with typedef)
80   - s_toto_t is a structure (access to fields with .)
81   - s_toto   is a structure needing 'struct' keyword to be used
82   - e_toto_t is an enum
83   - u_toto_t is an union
84   - u_toto   is an union needing 'union' keyword to be used
85   -   toto_t is an 'object' (struct*)
86   
87 Please to not call toto_t something else than an 'object' (ie, something you
88 have to call _new and _free on it).
89
90 Exemple:
91   typedef struct s_toto {} s_toto_t, *toto_t;
92   typedef enum {} e_toto_t;
93   
94 Moreover, only toto_t (and e_toto_t) are public. The rest (mainly s_toto_t)
95 is private.
96
97 If you see any part of the code not following this convention, this is a
98 bug. Please report it (or fix it yourself if you can).
99
100 **
101 ** Random bits about coding standards and portability
102 **
103 *****************************************************
104
105 MALLOC:
106  Don't use it, or you'll have to check the result (and do some dirty stuff
107  on AIX). Use xbt_malloc (or even better, xbt_new) instead.
108
109 SIZE_T
110  If possible, avoid size_t and use unsigned long instead. If not,
111  #include <sys/types.h> in all files manipulating size_t
112  do cast it to unsigned long before printing (and use %lu)
113  
114 PRINTF pointer difference
115  printf ("diff = %ld\n", (long) (pointer2 - pointer1));
116   
117
118 **              
119 ** Commenting the source: doxygen
120 **
121 ****************************************************
122
123 The global structure of the documentation is in doc/modules.doc 
124
125 The structure of each module (xbt, gras, etc) is in doc/module-<module>.doc
126
127 The structure of a module is in its public header. This way, you're sure to
128 see all the public interface (and only it). The different parts of the
129 interface are grouped using the @name construct, even if it's buggy. Since
130 parts often get reordered, it's better to add numbers to the parts (so that
131 users can see the intended order).
132
133 The documentation of each type and macro are also in the public header since
134 this is were they live.
135
136 The documentation of each function must be in the C file were it lives. 
137
138 Any public element (function, type and macro) must have a @brief part.
139
140
141 **              
142 ** Using the logs
143 **
144 ****************************************************
145
146 Dans gras, tu ne te contente pas d'écrire des choses à l'écran, mais tu
147 écris sur un sujet particulier (notion de canal) des choses d'une gravité
148 particulière. Il y a 7 niveaux de gravité.
149  trace: tracer les entrées dans une fonction, retour de fonction
150         (famille de macros XBT_IN/XBT_OUT)
151  debug: pour t'aider à mettre au point le module, potentiellement tres bavard
152  verbose: quelques infos succintes sur les internals du module
153  info: niveau normal, ton de la conversation
154  warning: problème potentiel, mais auquel on a su faire face
155  error: problème qui t'as empêché de faire ton job
156  critical: juste avant de mourir
157
158 Quand on compile avec -DNDEBUG (par défaut dans le paquet Debian), tout ce
159 qui est '>= verbose' est supprimé au moment de la compilation. Retiré du
160 binaire, killé.
161
162 Ensuite, tu écris dans un canal particulier. Tous les canaux sont rangés en
163 arbre. Il faudrait faire un ptit script qui fouille les sources à la
164 recherche des macros XBT_LOG_NEW_* utilisées pour créer des canaux. Le
165 dernier argument de ces macros est ignoré dans le source. Il est destiné à
166 être la documentation de la chose en une ligne. En gros, ca fait:
167 root
168  +--xbt
169  |   +--config
170  |   +--dict
171  |   |   +--dict_cursor
172  |   |   +--dict_elm
173  |   |   ...
174  |   +--dynar
175  |   +--set
176  |   +--log
177  |   +--module
178  +--gras
179      +--datadesc
180      |   +--ddt_cbps
181      |   +--ddt_convert
182      |   +--ddt_exchange
183      |   +--ddt_parse
184      |       +--lexer
185      +--msg
186      +--transport
187          +--raw_trp (Je devrais tuer ce module, un jour)
188          +--trp_buf
189          +--trp_sg
190          +--trp_file
191          +--trp_tcp
192          
193 Et ensuite les utilisateurs peuvent choisir le niveau de gravité qui les
194 interresse sur tel ou tel sujet.
195
196 Toute la mécanique de logging repose sur des variables statiques dont le nom
197 dépend du nom du canal.
198  => attention aux conflits de nom de canal
199  => il faut une macro XBT_LOG dans chaque fichier où tu fais des logs.
200  
201 XBT_LOG_NEW_CATEGORY: nouveau canal sous "root". Rare, donc.
202 XBT_LOG_NEW_SUBCATEGORY: nouveau canal dont on précise le père.
203 XBT_LOG_DEFAULT_CATEGORY: indique quel est le canal par défaut dans ce fichier
204 XBT_LOG_NEW_DEFAULT_CATEGORY: Crèe un canal et l'utilise par défaut
205 XBT_LOG_NEW_DEFAULT_SUBCATEGORY: devine
206 XBT_LOG_EXTERNAL_CATEGORY: quand tu veux utiliser par défaut un canal créé
207                            dans un autre fichier.
208                            
209 Une fois que ton canal est créé, tu l'utilise avec les macros LOG, DEBUG,
210 VERB, WARN, ERROR et CRITICAL. Il faut que tu donne le nombre d'arguments
211 après le nom de macro. Exemple: LOG2("My name is %s %s","Martin","Quinson")
212 Si tu veux préciser explicitement le canal où écrire, ajoute un C devant le
213 nom de la macro. Exemple: CCRITICAL0(module, "Cannot initialize GRAS")
214
215 Toutes ces macros (enfin, ce en quoi elles se réécrivent) vérifient leurs
216 arguments comme printf le fait lorsqu'on compile avec gcc. 
217 LOG1("name: %d","toto"); donne un warning, et donc une erreur en mode
218 mainteneur.
219
220 Enfin, tu peux tester si un canal est ouvert à une priorité donnée (pour
221 préparer plus de débug, par exemple. Dans le parseur, je fais du pretty
222 printing sur ce qu'il faut parser dans ce cas).
223 XBT_LOG_ISENABLED(catName, priority) Le second argument doit être une valeur
224 de e_xbt_log_priority_t (log.h). Par exemple: xbt_log_priority_verbose
225
226 Voila sur comment mettre des logs dans ton code. N'hesite pas à faire pleins
227 de canaux différents pour des aspects différents de ton code. En
228 particulier, dans les dict, j'ai un canal pour l'ajout, le retrait, le
229 netoyage du code après suppression et ainsi de suite. De cette façon, je
230 peux choisir qui m'interresse.
231
232
233 Pour utiliser les logs, tu déjà faire, non ? Tu colle sur la ligne de
234 commande un ou plusieurs arguments de la forme
235   --gras-log="<réglage> [<reglage>+]" (ou sans " si t'as pas d'espace)
236 chaque réglage étant de la forme:
237   <canal>.thres=<priorité>
238 Les différents réglages sont lus de gauche à droite.
239 "root.thres=debug root.thres=critical" ferme tout, normalement.