Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Log priorities were renamed a long time ago.
[simgrid.git] / README.coding
1 **
2 ** Source tree organization
3 **
4 ******************************************************
5
6 There is at least 4 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  - SMPI: Simulated MPI, to run MPI application using emulation technics.
13
14 They are all in the same tree because they are complementary tools and
15 having all of them in the same package makes the installation easier
16 for end-users. Moreover, it enables to share the compilation chain and
17 eases the development.
18
19 The tree is not splited on projects, but on file finality:
20  include/            -> all *public* headers
21  include/xbt/*.h     -> one file per module
22
23  src/include -> another location for protected headers. Used by SURF, and
24                 other should be converted, since this is the Right Thing.
25
26  testsuite/ -> The more test the better. 
27                Same organization than src/ and include/
28                Tests are allowed to load some headers of the module they test.
29                All tests should be listed in run_test.in so that they get
30                run on 'make check'. 
31                   
32  examples/ -> Supposed to be copy/pastable by the user, so keep it clear and
33                 avoid any kind of trick. In particular, do only include the
34                 public headers here.
35 **
36 ** Indentation standard
37 **
38 *****************************************************
39
40 Most files use the Kernighan & Ritchie coding style with 2 spaces of
41 indentation. The indent program can help you to stick to it:
42
43 indent -kr -l80 -nut -i2 -lps -npcs -br -brs -ce -cdw -bbo -npsl <myfile>
44
45 The script ./tools/indent runs indent with the appropriate options.
46
47 FIXME: this list of arguments is still to be discussed, maybe
48
49 **
50 ** Type naming standard
51 **
52 *****************************************************
53
54 It may sound strange, but the type naming convention was source of intense
55 discution between da SimGrid posse members. The convention we came to may not
56 be the best solution, but it has the merit to exist and leave everyone work.
57 So please stick to it.
58
59   - ???_t is a valid type (builded with typedef)
60   - s_toto_t is a structure (access to fields with .)
61   - s_toto   is a structure needing 'struct' keyword to be used
62   - e_toto_t is an enum
63   - u_toto_t is an union
64   - u_toto   is an union needing 'union' keyword to be used
65   -   toto_t is an 'object' (struct*)
66   
67 Please to not call toto_t something else than an 'object' (ie, something you
68 have to call _new and _free on it).
69
70 Exemple:
71   typedef struct s_toto {} s_toto_t, *toto_t;
72   typedef enum {} e_toto_t;
73   
74 Moreover, only toto_t (and e_toto_t) are public. The rest (mainly s_toto_t)
75 is private.
76
77 If you see any part of the code not following this convention, this is a
78 bug. Please report it (or fix it yourself if you can).
79
80 **
81 ** Random bits about coding standards and portability
82 **
83 *****************************************************
84
85 MALLOC:
86  Don't use it, or you'll have to check the result (and do some dirty stuff
87  on AIX). Use xbt_malloc (or even better, xbt_new) instead.
88
89 SIZE_T
90  If possible, avoid size_t and use unsigned long instead. If not,
91  #include <sys/types.h> in all files manipulating size_t
92  do cast it to unsigned long before printing (and use %lu)
93  
94 PRINTF pointer difference
95  printf ("diff = %ld\n", (long) (pointer2 - pointer1));
96   
97
98 **              
99 ** Commenting the source: doxygen
100 **
101 ****************************************************
102
103 The global structure of the documentation is in doc/modules.doc 
104
105 The structure of each module (xbt, msg, etc) is in doc/module-<module>.doc
106
107 The structure of a module is in its public header. This way, you're sure to
108 see all the public interface (and only it). The different parts of the
109 interface are grouped using the @name construct, even if it's buggy. Since
110 parts often get reordered, it's better to add numbers to the parts (so that
111 users can see the intended order).
112
113 The documentation of each type and macro are also in the public header since
114 this is were they live.
115
116 The documentation of each function must be in the C file were it lives. 
117
118 Any public element (function, type and macro) must have a @brief part.
119
120 **
121 ** XBT virtualization mecanism (FIXME:this section is deprecated)
122 **
123 ****************************************************
124
125 There is some functionnalities that we want to virtualize in XBT. We
126 want xbt_time to give the simulated clock when running on top of the
127 simulator, and the host clock when running on a real system. This
128 could be placed in GRAS (and was, historically), but there is some
129 reason to lower it down to XBT. 
130
131 Here is the used naming scheme:
132
133   - xbt_<module>_<func>(): functions working both in SG and RL  
134   - xbt_os_<module>_<func>(): RL functions usable even in simulator
135     
136     That way, in libsimgrid, we still can use native functions if we
137     want to. It may for example be useful to get the real time when
138     implementing the simulator. Think of the SIGINT handler, which
139     wants to see if the user pressed the key twice in a 5 seconds
140     interval. This is of little use to check the simulated time here.
141
142 Here is the file layout:
143
144   - xbt_rl_<module>.c: native implementation (xbt_<module>_<func>()).
145     Simply call the corresponding xbt_os_<module>_<func>.     
146     Part only of libgras.so
147     
148   - xbt_sg_<module>.c: SIMIX implementation xbt_<module>_<func>()).
149     Simply call the corresponding SIMIX implementation. 
150     Part only of libsimgrid.so
151     
152   - xbt_os_<module>.c: body of the functions implementing natively the
153     stuff (xbt_os_<module>_<func>()).
154     Part of both libgras.so and libsimgrid.so
155     
156 Since there is almost nothing in xbt_rl_module.c and xbt_sg_module.c,
157 it'd be better to use symbol aliasing here (to declare in the object
158 code that the same function have two names), but I'm still
159 investigating the portability of the thing to windows.
160
161
162 *
163 * SimGrid Hacker Survival Guide (FIXME: should be betterly placed)
164 ********************************
165
166 * If you break the logs (for example while hacking in the dynars), you
167   want to define XBT_LOG_MAYDAY at the beginning of log.h. It will
168   desactivate the whole logging mecanism, switching to printfs
169   instead. SimGrid becomes incredibly verbose when doing so, but it
170   you let you fixing the dynars.