Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use simgrid::Host instead of xbt_dictelt_t for root main object
[simgrid.git] / include / simgrid / simdag.h
1 /* Copyright (c) 2006-2010, 2012-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMDAG_SIMDAG_H
8 #define SIMDAG_SIMDAG_H
9
10 #include "xbt/misc.h"
11 #include "xbt/dynar.h"
12 #include "xbt/dict.h"
13
14 #include "simgrid/link.h"
15
16 SG_BEGIN_DECL()
17 /** @brief Workstation datatype
18     @ingroup SD_datatypes_management
19
20     A workstation is a place where a task can be executed.
21     A workstation is represented as a <em>physical
22     resource with computing capabilities</em> and has a <em>name</em>.
23
24     @see SD_workstation_management */
25 typedef sg_host_t SD_workstation_t;
26
27 /** @brief Workstation access mode
28     @ingroup SD_datatypes_management
29
30     By default, a workstation resource is shared, i.e. several tasks
31     can be executed at the same time on a workstation. The CPU power of
32     the workstation is shared between the running tasks on the workstation.
33     In sequential mode, only one task can use the workstation, and the other
34     tasks wait in a FIFO.
35
36     @see SD_workstation_get_access_mode(), SD_workstation_set_access_mode() */
37 typedef enum {
38   SD_WORKSTATION_SHARED_ACCESS,     /**< @brief Several tasks can be executed at the same time */
39   SD_WORKSTATION_SEQUENTIAL_ACCESS  /**< @brief Only one task can be executed, the others wait in a FIFO. */
40 } e_SD_workstation_access_mode_t;
41
42 /** @brief Link datatype
43     @ingroup SD_datatypes_management
44
45     A link is a network node represented as a <em>name</em>, a <em>current
46     bandwidth</em> and a <em>current latency</em>. A route is a list of
47     links between two workstations.
48
49     @see SD_link_management */
50 typedef Link *SD_link_t;
51
52 /** @brief Task datatype
53     @ingroup SD_datatypes_management
54
55     A task is some <em>computing amount</em> that can be executed
56     in parallel on several workstations. A task may depend on other
57     tasks, this means that the task cannot start until the other tasks are done.
58     Each task has a <em>\ref e_SD_task_state_t "state"</em> indicating whether
59     the task is scheduled, running, done, etc.
60
61     @see SD_task_management */
62 typedef struct SD_task *SD_task_t;
63
64 /** @brief Task states
65     @ingroup SD_datatypes_management
66
67     @see SD_task_management */
68 typedef enum {
69   SD_NOT_SCHEDULED = 0,      /**< @brief Initial state (not valid for SD_watch and SD_unwatch). */
70   SD_SCHEDULABLE = 0x0001,               /**< @brief A task becomes SD_SCHEDULABLE as soon as its dependencies are satisfied */
71   SD_SCHEDULED = 0x0002,     /**< @brief A task becomes SD_SCHEDULED when you call function
72                                   SD_task_schedule. SD_simulate will execute it when it becomes SD_RUNNABLE. */
73   SD_RUNNABLE = 0x0004,      /**< @brief A scheduled task becomes runnable is SD_simulate as soon as its dependencies are satisfied. */
74   SD_IN_FIFO = 0x0008,       /**< @brief A runnable task can have to wait in a workstation fifo if the workstation is sequential */
75   SD_RUNNING = 0x0010,       /**< @brief An SD_RUNNABLE or SD_IN_FIFO becomes SD_RUNNING when it is launched. */
76   SD_DONE = 0x0020,          /**< @brief The task is successfully finished. */
77   SD_FAILED = 0x0040         /**< @brief A problem occurred during the execution of the task. */
78 } e_SD_task_state_t;
79
80 /** @brief Task kinds
81     @ingroup SD_datatypes_management
82
83     @see SD_task_management */
84 typedef enum {
85   SD_TASK_NOT_TYPED = 0,      /**< @brief no specified type */
86   SD_TASK_COMM_E2E = 1,       /**< @brief end to end communication */
87   SD_TASK_COMP_SEQ = 2,        /**< @brief sequential computation */
88   SD_TASK_COMP_PAR_AMDAHL = 3, /**< @brief parallel computation (Amdahl's law) */
89   SD_TASK_COMM_PAR_MXN_1D_BLOCK = 4 /**< @brief MxN data redistribution (1D Block distribution) */
90 } e_SD_task_kind_t;
91
92
93 /** @brief Storage datatype
94     @ingroup SD_datatypes_management
95
96  TODO PV: comment it !
97
98     @see SD_storage_management */
99 typedef xbt_dictelm_t SD_storage_t;
100
101 /************************** AS handling *************************************/
102 XBT_PUBLIC(xbt_dict_t) SD_as_router_get_properties(const char *as);
103 XBT_PUBLIC(const char*) SD_as_router_get_property_value(const char * as,
104                                                   const char *name);
105
106 /************************** Link handling ***********************************/
107 /** @defgroup SD_link_management Links
108  *  @brief Functions for managing the network links
109  *
110  *  This section describes the functions for managing the network links.
111  *
112  *  A link is a network node represented as a <em>name</em>, a <em>current
113  *  bandwidth</em> and a <em>current latency</em>. The links are created
114  *  when you call the function SD_create_environment.
115  *
116  *  @see SD_link_t
117  *  @{
118  */
119 XBT_PUBLIC(const SD_link_t *) SD_link_get_list(void);
120 /** @brief Returns the number of links in the whole platform */
121 static inline int SD_link_get_number(void) {
122   return sg_link_amount();
123 }
124
125 /** @brief Returns the user data of a link */
126 static inline void *SD_link_get_data(SD_link_t link) {
127   return sg_link_data(link);
128 }
129
130 /** @brief Sets the user data of a link
131  *
132  * The new data can be \c NULL. The old data should have been freed first
133  * if it was not \c NULL.
134  */
135 static inline void SD_link_set_data(SD_link_t link, void *data) {
136         sg_link_data_set(link, data);
137 }
138 /** @brief Returns the name of a link  */
139 static inline const char *SD_link_get_name(SD_link_t link) {
140   return sg_link_name(link);
141 }
142 /** @brief Returns the current bandwidth of a link (in bytes per second) */
143 static inline double SD_link_get_current_bandwidth(SD_link_t link) {
144   return sg_link_bandwidth(link);
145 }
146 /** @brief Returns the current latency of a link (in seconds) */
147 static inline double SD_link_get_current_latency(SD_link_t link){
148   return sg_link_latency(link);
149 }
150 /** @brief Returns the sharing policy of this workstation.
151  *  @return true if the link is shared, and false if it's a fatpipe
152  */
153 static inline int SD_link_is_shared(SD_link_t link) {
154   return sg_link_is_shared(link);
155 }
156 /** @} */
157
158 /************************** Workstation handling ****************************/
159
160 /** @defgroup SD_workstation_management Workstations
161  *  @brief Functions for managing the workstations
162  *
163  *  This section describes the functions for managing the workstations.
164  *
165  *  A workstation is a place where a task can be executed.
166  *  A workstation is represented as a <em>physical
167  *  resource with computing capabilities</em> and has a <em>name</em>.
168  *
169  *  The workstations are created when you call the function SD_create_environment.
170  *
171  *  @see SD_workstation_t
172  *  @{
173  */
174 XBT_PUBLIC(SD_workstation_t) SD_workstation_get_by_name(const char *name);
175 XBT_PUBLIC(const SD_workstation_t *) SD_workstation_get_list(void);
176 XBT_PUBLIC(int) SD_workstation_get_number(void);
177 XBT_PUBLIC(void) SD_workstation_set_data(SD_workstation_t workstation,
178                                          void *data);
179 XBT_PUBLIC(void *) SD_workstation_get_data(SD_workstation_t workstation);
180 XBT_PUBLIC(const char *) SD_workstation_get_name(SD_workstation_t
181                                                  workstation);
182 /*property handling functions*/
183 XBT_PUBLIC(xbt_dict_t) SD_workstation_get_properties(SD_workstation_t
184                                                      workstation);
185 XBT_PUBLIC(const char *) SD_workstation_get_property_value(SD_workstation_t
186                                                            workstation,
187                                                            const char
188                                                            *name);
189 XBT_PUBLIC(void) SD_workstation_dump(SD_workstation_t ws);
190 XBT_PUBLIC(const SD_link_t *) SD_route_get_list(SD_workstation_t src,
191                                                 SD_workstation_t dst);
192 XBT_PUBLIC(int) SD_route_get_size(SD_workstation_t src,
193                                   SD_workstation_t dst);
194 XBT_PUBLIC(double) SD_workstation_get_power(SD_workstation_t workstation);
195 XBT_PUBLIC(double) SD_workstation_get_available_power(SD_workstation_t
196                                                       workstation);
197 XBT_PUBLIC(int) SD_workstation_get_cores(SD_workstation_t workstation);
198 XBT_PUBLIC(e_SD_workstation_access_mode_t)
199     SD_workstation_get_access_mode(SD_workstation_t workstation);
200 XBT_PUBLIC(void) SD_workstation_set_access_mode(SD_workstation_t
201                                                 workstation,
202                                                 e_SD_workstation_access_mode_t
203                                                 access_mode);
204
205 XBT_PUBLIC(double) SD_workstation_get_computation_time(SD_workstation_t workstation,
206                                                        double flops_amount);
207 XBT_PUBLIC(double) SD_route_get_current_latency(SD_workstation_t src,
208                                                 SD_workstation_t dst);
209 XBT_PUBLIC(double) SD_route_get_current_bandwidth(SD_workstation_t src,
210                                                   SD_workstation_t dst);
211 XBT_PUBLIC(double) SD_route_get_communication_time(SD_workstation_t src,
212                                                    SD_workstation_t dst,
213                                                    double bytes_amount);
214
215 XBT_PUBLIC(SD_task_t) SD_workstation_get_current_task(SD_workstation_t workstation);
216 XBT_PUBLIC(xbt_dict_t)
217     SD_workstation_get_mounted_storage_list(SD_workstation_t workstation);
218 XBT_PUBLIC(xbt_dynar_t)
219     SD_workstation_get_attached_storage_list(SD_workstation_t workstation);
220 XBT_PUBLIC(const char*) SD_storage_get_host(SD_storage_t storage);
221 /** @} */
222
223 /************************** Task handling ************************************/
224
225 /** @defgroup SD_task_management Tasks
226  *  @brief Functions for managing the tasks
227  *
228  *  This section describes the functions for managing the tasks.
229  *
230  *  A task is some <em>working amount</em> that can be executed
231  *  in parallel on several workstations. A task may depend on other
232  *  tasks, this means that the task cannot start until the other tasks are done.
233  *  Each task has a <em>\ref e_SD_task_state_t "state"</em> indicating whether
234  *  the task is scheduled, running, done, etc.
235  *
236  *  @see SD_task_t, SD_task_dependency_management
237  *  @{
238  */
239 XBT_PUBLIC(SD_task_t) SD_task_create(const char *name, void *data,
240                                      double amount);
241 XBT_PUBLIC(void *) SD_task_get_data(SD_task_t task);
242 XBT_PUBLIC(void) SD_task_set_data(SD_task_t task, void *data);
243 XBT_PUBLIC(e_SD_task_state_t) SD_task_get_state(SD_task_t task);
244 XBT_PUBLIC(const char *) SD_task_get_name(SD_task_t task);
245 XBT_PUBLIC(void) SD_task_set_name(SD_task_t task, const char *name);
246 XBT_PUBLIC(void) SD_task_set_rate(SD_task_t task, double rate);
247
248 XBT_PUBLIC(void) SD_task_watch(SD_task_t task, e_SD_task_state_t state);
249 XBT_PUBLIC(void) SD_task_unwatch(SD_task_t task, e_SD_task_state_t state);
250 XBT_PUBLIC(double) SD_task_get_amount(SD_task_t task);
251 XBT_PUBLIC(void) SD_task_set_amount(SD_task_t task, double amount);
252 XBT_PUBLIC(double) SD_task_get_alpha(SD_task_t task);
253 XBT_PUBLIC(double) SD_task_get_remaining_amount(SD_task_t task);
254 XBT_PUBLIC(double) SD_task_get_execution_time(SD_task_t task,
255                                               int workstation_nb,
256                                               const SD_workstation_t *
257                                               workstation_list,
258                                               const double *flops_amount,
259                                                                                           const double *bytes_amount);
260 XBT_PUBLIC(int) SD_task_get_kind(SD_task_t task);
261 XBT_PUBLIC(void) SD_task_schedule(SD_task_t task, int workstation_nb,
262                                   const SD_workstation_t *
263                                   workstation_list,
264                                   const double *flops_amount,
265                                   const double *bytes_amount,
266                                   double rate);
267 XBT_PUBLIC(void) SD_task_unschedule(SD_task_t task);
268 XBT_PUBLIC(double) SD_task_get_start_time(SD_task_t task);
269 XBT_PUBLIC(double) SD_task_get_finish_time(SD_task_t task);
270 XBT_PUBLIC(xbt_dynar_t) SD_task_get_parents(SD_task_t task);
271 XBT_PUBLIC(xbt_dynar_t) SD_task_get_children(SD_task_t task);
272 XBT_PUBLIC(int) SD_task_get_workstation_count(SD_task_t task);
273 XBT_PUBLIC(SD_workstation_t *) SD_task_get_workstation_list(SD_task_t
274                                                             task);
275 XBT_PUBLIC(void) SD_task_destroy(SD_task_t task);
276 XBT_PUBLIC(void) SD_task_dump(SD_task_t task);
277 XBT_PUBLIC(void) SD_task_dotty(SD_task_t task, void *out_FILE);
278
279 XBT_PUBLIC(SD_task_t) SD_task_create_comp_seq(const char *name, void *data,
280                                               double amount);
281 XBT_PUBLIC(SD_task_t) SD_task_create_comp_par_amdahl(const char *name,
282                                                      void *data,
283                                                      double amount,
284                                                      double alpha);
285 XBT_PUBLIC(SD_task_t) SD_task_create_comm_e2e(const char *name, void *data,
286                                               double amount);
287 XBT_PUBLIC(SD_task_t) SD_task_create_comm_par_mxn_1d_block(const char *name,
288                                                            void *data,
289                                                            double amount);
290
291 XBT_PUBLIC(void) SD_task_distribute_comp_amdahl(SD_task_t task, int ws_count);
292 XBT_PUBLIC(void) SD_task_schedulev(SD_task_t task, int count,
293                                    const SD_workstation_t * list);
294 XBT_PUBLIC(void) SD_task_schedulel(SD_task_t task, int count, ...);
295
296
297 /** @brief A constant to use in SD_task_schedule to mean that there is no cost.
298  *
299  *  For example, create a pure computation task (no comm) like this:
300  *
301  *  SD_task_schedule(task, my_workstation_nb,
302  *                   my_workstation_list,
303  *                   my_flops_amount,
304  *                   SD_TASK_SCHED_NO_COST,
305  *                   my_rate);
306  */
307 #define SD_SCHED_NO_COST NULL
308
309 /** @} */
310
311
312 /** @defgroup SD_task_dependency_management Tasks dependencies
313  *  @brief Functions for managing the task dependencies
314  *
315  *  This section describes the functions for managing the dependencies between the tasks.
316  *
317  *  @see SD_task_management
318  *  @{
319  */
320 XBT_PUBLIC(void) SD_task_dependency_add(const char *name, void *data,
321                                         SD_task_t src, SD_task_t dst);
322 XBT_PUBLIC(void) SD_task_dependency_remove(SD_task_t src, SD_task_t dst);
323 XBT_PUBLIC(const char *) SD_task_dependency_get_name(SD_task_t src,
324                                                      SD_task_t dst);
325 XBT_PUBLIC(void *) SD_task_dependency_get_data(SD_task_t src,
326                                                SD_task_t dst);
327 XBT_PUBLIC(int) SD_task_dependency_exists(SD_task_t src, SD_task_t dst);
328 /** @} */
329
330 /************************** Global *******************************************/
331
332 /** @defgroup SD_simulation Simulation
333  *  @brief Functions for creating the environment and launching the simulation
334  *
335  *  This section describes the functions for initialising SimDag, launching
336  *  the simulation and exiting SimDag.
337  *
338  *  @{
339  */
340 XBT_PUBLIC(void) SD_init(int *argc, char **argv);
341 XBT_PUBLIC(void) SD_config(const char *key, const char *value);
342 XBT_PUBLIC(void) SD_application_reinit(void);
343 XBT_PUBLIC(void) SD_create_environment(const char *platform_file);
344 XBT_PUBLIC(xbt_dynar_t) SD_simulate(double how_long);
345 XBT_PUBLIC(double) SD_get_clock(void);
346 XBT_PUBLIC(void) SD_exit(void);
347 XBT_PUBLIC(xbt_dynar_t) SD_daxload(const char *filename);
348 XBT_PUBLIC(xbt_dynar_t) SD_dotload(const char *filename);
349 XBT_PUBLIC(xbt_dynar_t) SD_PTG_dotload(const char *filename);
350 XBT_PUBLIC(xbt_dynar_t) SD_dotload_with_sched(const char *filename);
351 XBT_PUBLIC(void) uniq_transfer_task_name(SD_task_t task);
352
353 /** @} */
354
355 #include "simgrid/instr.h"
356
357 SG_END_DECL()
358 #endif