Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
File surf.hpp is C++ only. Remove SG_BEGIN/END_DECL.
[simgrid.git] / src / include / surf / surf.hpp
1 /* Copyright (c) 2004-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SURF_SURF_H
7 #define SURF_SURF_H
8
9 #include "simgrid/forward.h"
10 #include "src/internal_config.h"
11 #include "xbt/config.h"
12 #include "xbt/dict.h"
13 #include "xbt/dynar.h"
14 #include "xbt/graph.h"
15 #include "xbt/misc.h"
16
17 #ifndef __cplusplus
18 #error This is a C++ only file, now
19 #endif
20
21 namespace simgrid {
22 namespace surf {
23 class CpuModel;
24 class HostModel;
25 class NetworkModel;
26 class StorageModel;
27 class NetworkCm02Link;
28 }
29 }
30
31 /** @ingroup SURF_c_bindings
32  *  \brief Model datatype
33  *
34  *  Generic data structure for a model. The hosts,
35  *  the CPUs and the network links are examples of models.
36  */
37 typedef simgrid::surf::CpuModel* surf_cpu_model_t;
38 typedef simgrid::surf::HostModel* surf_host_model_t;
39 typedef simgrid::surf::NetworkModel* surf_network_model_t;
40 typedef simgrid::surf::StorageModel* surf_storage_model_t;
41
42 /* Actions and models are highly connected structures... */
43
44 /* user-visible parameters */
45 extern XBT_PRIVATE double sg_tcp_gamma;
46 extern XBT_PRIVATE double sg_latency_factor;
47 extern XBT_PRIVATE double sg_bandwidth_factor;
48 extern XBT_PRIVATE double sg_weight_S_parameter;
49 extern XBT_PRIVATE int sg_network_crosstraffic;
50
51 /** \brief Resource model description
52  */
53 struct surf_model_description {
54   const char* name;
55   const char* description;
56   void_f_void_t model_init_preparse;
57 };
58 typedef struct surf_model_description s_surf_model_description_t;
59
60 XBT_PUBLIC int find_model_description(s_surf_model_description_t* table, std::string name);
61 XBT_PUBLIC void model_help(const char* category, s_surf_model_description_t* table);
62
63 /***************************/
64 /* Generic model object */
65 /***************************/
66
67 /** @{ @ingroup SURF_c_bindings */
68
69 /**
70  * @brief Pop an action from the done actions set
71  *
72  * @param model The model from which the action is extracted
73  * @return An action in done state
74  */
75 XBT_PUBLIC simgrid::kernel::resource::Action*
76 surf_model_extract_done_action_set(simgrid::kernel::resource::Model* model);
77
78 /**
79  * @brief Pop an action from the failed actions set
80  *
81  * @param model The model from which the action is extracted
82  * @return An action in failed state
83  */
84 XBT_PUBLIC simgrid::kernel::resource::Action*
85 surf_model_extract_failed_action_set(simgrid::kernel::resource::Model* model);
86
87 /**
88  * @brief Get the size of the running action set of a model
89  *
90  * @param model The model
91  * @return The size of the running action set
92  */
93 XBT_PUBLIC int surf_model_running_action_set_size(simgrid::kernel::resource::Model* model);
94
95 /**
96  * @brief [brief description]
97  * @details [long description]
98  *
99  * @param action The surf cpu action
100  * @param bound [description]
101  */
102 XBT_PUBLIC void surf_cpu_action_set_bound(simgrid::kernel::resource::Action* action, double bound);
103
104 /** @} */
105
106 /**************************************/
107 /* Implementations of model object */
108 /**************************************/
109
110 /** \ingroup SURF_models
111  *  \brief The CPU model object for the physical machine layer
112  */
113 XBT_PUBLIC_DATA surf_cpu_model_t surf_cpu_model_pm;
114
115 /** \ingroup SURF_models
116  *  \brief The CPU model object for the virtual machine layer
117  */
118 XBT_PUBLIC_DATA surf_cpu_model_t surf_cpu_model_vm;
119
120 /** \ingroup SURF_models
121  *  \brief Initializes the CPU model with the model Cas01
122  *
123  *  By default, this model uses the lazy optimization mechanism that relies on partial invalidation in LMM and a heap
124  *  for lazy action update.
125  *  You can change this behavior by setting the cpu/optim configuration variable to a different value.
126  *
127  *  You shouldn't have to call it by yourself.
128  */
129 XBT_PUBLIC void surf_cpu_model_init_Cas01();
130
131 /** \ingroup SURF_models
132  *  \brief Initializes the CPU model with trace integration [Deprecated]
133  *
134  *  You shouldn't have to call it by yourself.
135  */
136 XBT_PUBLIC void surf_cpu_model_init_ti();
137
138 /** \ingroup SURF_models
139  *  \brief The list of all available optimization modes (both for cpu and networks).
140  *  These optimization modes can be set using --cfg=cpu/optim:... and --cfg=network/optim:...
141  */
142 XBT_PUBLIC_DATA s_surf_model_description_t surf_optimization_mode_description[];
143
144 /** \ingroup SURF_plugins
145  *  \brief The list of all available surf plugins
146  */
147 XBT_PUBLIC_DATA s_surf_model_description_t surf_plugin_description[];
148
149 /** \ingroup SURF_models
150  *  \brief The list of all available cpu model models
151  */
152 XBT_PUBLIC_DATA s_surf_model_description_t surf_cpu_model_description[];
153
154 /** \ingroup SURF_models
155  *  \brief The network model
156  *
157  *  When creating a new API on top on SURF, you shouldn't use the network model unless you know what you are doing.
158  *  Only the host model should be accessed because depending on the platform model, the network model can be NULL.
159  */
160 XBT_PUBLIC_DATA surf_network_model_t surf_network_model;
161
162 /** \ingroup SURF_models
163  *  \brief Same as network model 'LagrangeVelho', only with different correction factors.
164  *
165  * This model is proposed by Pierre-Nicolas Clauss and Martin Quinson and Stéphane Génaud based on the model 'LV08' and
166  * different correction factors depending on the communication size (< 1KiB, < 64KiB, >= 64KiB).
167  * See comments in the code for more information.
168  *
169  *  \see surf_host_model_init_SMPI()
170  */
171 XBT_PUBLIC void surf_network_model_init_SMPI();
172
173 /** \ingroup SURF_models
174  *  \brief Same as network model 'LagrangeVelho', only with different correction factors.
175  *
176  * This model impelments a variant of the contention model on Infinband networks based on
177  * the works of Jérôme Vienne : http://mescal.imag.fr/membres/jean-marc.vincent/index.html/PhD/Vienne.pdf
178  *
179  *  \see surf_host_model_init_IB()
180  */
181 XBT_PUBLIC void surf_network_model_init_IB();
182
183 /** \ingroup SURF_models
184  *  \brief Initializes the platform with the network model 'LegrandVelho'
185  *
186  * This model is proposed by Arnaud Legrand and Pedro Velho based on the results obtained with the GTNets simulator for
187  * onelink and dogbone sharing scenarios. See comments in the code for more information.
188  *
189  *  \see surf_host_model_init_LegrandVelho()
190  */
191 XBT_PUBLIC void surf_network_model_init_LegrandVelho();
192
193 /** \ingroup SURF_models
194  *  \brief Initializes the platform with the network model 'Constant'
195  *
196  *  In this model, the communication time between two network cards is constant, hence no need for a routing table.
197  *  This is particularly useful when simulating huge distributed algorithms where scalability is really an issue. This
198  *  function is called in conjunction with surf_host_model_init_compound.
199  *
200  *  \see surf_host_model_init_compound()
201  */
202 XBT_PUBLIC void surf_network_model_init_Constant();
203
204 /** \ingroup SURF_models
205  *  \brief Initializes the platform with the network model CM02
206  *
207  *  You sould call this function by yourself only if you plan using surf_host_model_init_compound.
208  *  See comments in the code for more information.
209  */
210 XBT_PUBLIC void surf_network_model_init_CM02();
211
212 /** \ingroup SURF_models
213  *  \brief Initializes the platform with the network model NS3
214  *
215  *  This function is called by surf_host_model_init_NS3 or by yourself only if you plan using
216  *  surf_host_model_init_compound
217  *
218  *  \see surf_host_model_init_NS3()
219  */
220 XBT_PUBLIC void surf_network_model_init_NS3();
221
222 /** \ingroup SURF_models
223  *  \brief Initializes the platform with the network model Reno
224  *
225  *  The problem is related to max( sum( arctan(C * Df * xi) ) ).
226  *
227  *  Reference:
228  *  [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
229  *  IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
230  *
231  *  Call this function only if you plan using surf_host_model_init_compound.
232  */
233 XBT_PUBLIC void surf_network_model_init_Reno();
234
235 /** \ingroup SURF_models
236  *  \brief Initializes the platform with the network model Reno2
237  *
238  *  The problem is related to max( sum( arctan(C * Df * xi) ) ).
239  *
240  *  Reference:
241  *  [LOW01] S. H. Low. A duality model of TCP and queue management algorithms.
242  *  IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
243  *
244  *  Call this function only if you plan using surf_host_model_init_compound.
245  */
246 XBT_PUBLIC void surf_network_model_init_Reno2();
247
248 /** \ingroup SURF_models
249  *  \brief Initializes the platform with the network model Vegas
250  *
251  *  This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent  to the proportional fairness.
252  *
253  *  Reference:
254  *  [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
255  *  IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
256  *
257  *  Call this function only if you plan using surf_host_model_init_compound.
258  */
259 XBT_PUBLIC void surf_network_model_init_Vegas();
260
261 /** \ingroup SURF_models
262  *  \brief The list of all available network model models
263  */
264 XBT_PUBLIC_DATA s_surf_model_description_t surf_network_model_description[];
265
266 /** \ingroup SURF_models
267  *  \brief The storage model
268  */
269 XBT_PUBLIC void surf_storage_model_init_default();
270
271 /** \ingroup SURF_models
272  *  \brief The list of all available storage modes.
273  *  This storage mode can be set using --cfg=storage/model:...
274  */
275 XBT_PUBLIC_DATA s_surf_model_description_t surf_storage_model_description[];
276
277 XBT_PUBLIC_DATA surf_storage_model_t surf_storage_model;
278
279 /** \ingroup SURF_models
280  *  \brief The host model
281  *
282  *  Note that when you create an API on top of SURF, the host model should be the only one you use
283  *  because depending on the platform model, the network model and the CPU model may not exist.
284  */
285 XBT_PUBLIC_DATA surf_host_model_t surf_host_model;
286
287 /** \ingroup SURF_models
288  *  \brief Initializes the platform with a compound host model
289  *
290  *  This function should be called after a cpu_model and a network_model have been set up.
291  */
292 XBT_PUBLIC void surf_host_model_init_compound();
293
294 /** \ingroup SURF_models
295  *  \brief Initializes the platform with the current best network and cpu models at hand
296  *
297  *  This platform model separates the host model and the network model.
298  *  The host model will be initialized with the model compound, the network model with the model LV08 (with cross
299  *  traffic support) and the CPU model with the model Cas01.
300  *  Such model is subject to modification with warning in the ChangeLog so monitor it!
301  */
302 XBT_PUBLIC void surf_host_model_init_current_default();
303
304 /** \ingroup SURF_models
305  *  \brief Initializes the platform with the model L07
306  *
307  *  With this model, only parallel tasks can be used. Resource sharing is done by identifying bottlenecks and giving an
308  *  equal share of the model to each action.
309  */
310 XBT_PUBLIC void surf_host_model_init_ptask_L07();
311
312 /** \ingroup SURF_models
313  *  \brief The list of all available host model models
314  */
315 XBT_PUBLIC_DATA s_surf_model_description_t surf_host_model_description[];
316
317 /** \ingroup SURF_models
318  *  \brief Initializes the platform with the current best network and cpu models at hand
319  *
320  *  This platform model seperates the host model and the network model.
321  *  The host model will be initialized with the model compound, the network model with the model LV08 (with cross
322  *  traffic support) and the CPU model with the model Cas01.
323  *  Such model is subject to modification with warning in the ChangeLog so monitor it!
324  */
325 XBT_PUBLIC void surf_vm_model_init_HL13();
326
327 /*** SURF Globals **************************/
328
329 /** \ingroup SURF_simulation
330  *  \brief Initialize SURF
331  *  \param argc argument number
332  *  \param argv arguments
333  *
334  *  This function has to be called to initialize the common structures. Then you will have to create the environment by
335  *  calling  e.g. surf_host_model_init_CM02()
336  *
337  *  \see surf_host_model_init_CM02(), surf_host_model_init_compound(), surf_exit()
338  */
339 XBT_PUBLIC void surf_init(int* argc, char** argv); /* initialize common structures */
340
341 /** \ingroup SURF_simulation
342  *  \brief Finish simulation initialization
343  *
344  *  This function must be called before the first call to surf_solve()
345  */
346 XBT_PUBLIC void surf_presolve();
347
348 /** \ingroup SURF_simulation
349  *  \brief Performs a part of the simulation
350  *  \param max_date Maximum date to update the simulation to, or -1
351  *  \return the elapsed time, or -1.0 if no event could be executed
352  *
353  *  This function execute all possible events, update the action states  and returns the time elapsed.
354  *  When you call execute or communicate on a model, the corresponding actions are not executed immediately but only
355  *  when you call surf_solve.
356  *  Note that the returned elapsed time can be zero.
357  */
358 XBT_PUBLIC double surf_solve(double max_date);
359
360 /** \ingroup SURF_simulation
361  *  \brief Return the current time
362  *
363  *  Return the current time in millisecond.
364  */
365 XBT_PUBLIC double surf_get_clock();
366
367 /** \ingroup SURF_simulation
368  *  \brief Exit SURF
369  *
370  *  Clean everything.
371  *
372  *  \see surf_init()
373  */
374 XBT_PUBLIC void surf_exit();
375
376 /* surf parse file related (public because called from a test suite) */
377 XBT_PUBLIC void parse_platform_file(const char* file);
378
379 /********** Tracing **********/
380
381 /* instr_routing.c */
382 void instr_routing_define_callbacks();
383 xbt_graph_t instr_routing_platform_graph();
384 void instr_routing_platform_graph_export_graphviz(xbt_graph_t g, const char* filename);
385
386 #endif