Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
766fe1e3df35eb1b9fa4de7d43c95da080bf04c5
[simgrid.git] / include / simgrid / simdag.h
1 /* Copyright (c) 2006-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 SIMGRID_SIMDAG_H
7 #define SIMGRID_SIMDAG_H
8
9 #include <simgrid/host.h>
10 #include <simgrid/link.h>
11 #include <xbt/log.h>
12 #include <xbt/sysdep.h>
13
14 #ifdef __cplusplus
15 #include <set>
16 #endif
17
18 #ifdef MIN
19 #undef MIN
20 #endif
21 #define MIN(a, b) ((a) < (b) ? (a) : (b))
22
23 #ifdef MAX
24 #undef MAX
25 #endif
26 #define MAX(a, b) ((a) > (b) ? (a) : (b))
27
28 SG_BEGIN_DECL()
29
30 /** @brief Link opaque datatype
31     @ingroup SD_link_api
32
33     A link is a network node represented as a <em>name</em>, a <em>bandwidth</em> and a <em>latency</em>.
34     A route is a list of links between two hosts.
35  */
36 typedef sg_link_t SD_link_t;
37
38 /** @brief Task opaque datatype
39     @ingroup SD_task_api
40
41     A task is some <em>computing amount</em> that can be executed in parallel on several hosts.
42     A task may depend on other tasks, which means that the task cannot start until the other tasks are done.
43     Each task has a <em>\ref e_SD_task_state_t "state"</em> indicating whether the task is scheduled, running, done, ...
44
45     */
46 typedef struct s_SD_task_t* SD_task_t;
47
48 /** @brief Task states
49     @ingroup SD_task_api */
50 typedef enum {
51   SD_NOT_SCHEDULED = 0x0001,      /**< @brief Initial state (not valid for SD_watch and SD_unwatch). */
52   SD_SCHEDULABLE = 0x0002,   /**< @brief A task becomes SD_SCHEDULABLE as soon as its dependencies are satisfied */
53   SD_SCHEDULED = 0x0004,     /**< @brief A task becomes SD_SCHEDULED when you call function
54                                   SD_task_schedule. SD_simulate will execute it when it becomes SD_RUNNABLE. */
55   SD_RUNNABLE = 0x0008,      /**< @brief A scheduled task becomes runnable is SD_simulate as soon as its dependencies are satisfied. */
56   SD_RUNNING = 0x0010,       /**< @brief An SD_RUNNABLE task becomes SD_RUNNING when it is launched. */
57   SD_DONE = 0x0020,          /**< @brief The task is successfully finished. */
58   SD_FAILED = 0x0040         /**< @brief A problem occurred during the execution of the task. */
59 } e_SD_task_state_t;
60
61 /** @brief Task kinds
62     @ingroup SD_task_api */
63 typedef enum {
64   SD_TASK_NOT_TYPED = 0,      /**< @brief no specified type */
65   SD_TASK_COMM_E2E = 1,       /**< @brief end to end communication */
66   SD_TASK_COMP_SEQ = 2,        /**< @brief sequential computation */
67   SD_TASK_COMP_PAR_AMDAHL = 3, /**< @brief parallel computation (Amdahl's law) */
68   SD_TASK_COMM_PAR_MXN_1D_BLOCK = 4 /**< @brief MxN data redistribution (1D Block distribution) */
69 } e_SD_task_kind_t;
70
71 /************************** Task handling ************************************/
72 /** @defgroup SD_task_api Tasks
73  *  @brief Functions for managing the tasks
74  *
75  *  This section describes the functions for managing the tasks.
76  *
77  *  A task is some <em>working amount</em> that can be executed in parallel on several hosts.
78  *  A task may depend on other tasks, which means that the task cannot start until the other tasks are done.
79  *  Each task has a <em>\ref e_SD_task_state_t "state"</em> indicating whether the task is scheduled, running, done, ...
80  *
81  *  @see SD_task_t, @see SD_task_dependency_api
82  *  @{
83  */
84 XBT_PUBLIC SD_task_t SD_task_create(const char* name, void* data, double amount);
85 XBT_PUBLIC void* SD_task_get_data(SD_task_t task);
86 XBT_PUBLIC void SD_task_set_data(SD_task_t task, void* data);
87 XBT_PUBLIC e_SD_task_state_t SD_task_get_state(SD_task_t task);
88 XBT_PUBLIC const char* SD_task_get_name(SD_task_t task);
89 XBT_PUBLIC void SD_task_set_name(SD_task_t task, const char* name);
90 XBT_PUBLIC void SD_task_set_rate(SD_task_t task, double rate);
91
92 XBT_PUBLIC void SD_task_watch(SD_task_t task, e_SD_task_state_t state);
93 XBT_PUBLIC void SD_task_unwatch(SD_task_t task, e_SD_task_state_t state);
94 XBT_PUBLIC double SD_task_get_amount(SD_task_t task);
95 XBT_PUBLIC void SD_task_set_amount(SD_task_t task, double amount);
96 XBT_PUBLIC double SD_task_get_alpha(SD_task_t task);
97 XBT_PUBLIC double SD_task_get_remaining_amount(SD_task_t task);
98 XBT_PUBLIC double SD_task_get_execution_time(SD_task_t task, int host_count, const sg_host_t* host_list,
99                                              const double* flops_amount, const double* bytes_amount);
100 XBT_PUBLIC e_SD_task_kind_t SD_task_get_kind(SD_task_t task);
101 XBT_PUBLIC void SD_task_schedule(SD_task_t task, int host_count, const sg_host_t* host_list, const double* flops_amount,
102                                  const double* bytes_amount, double rate);
103 XBT_PUBLIC void SD_task_unschedule(SD_task_t task);
104 XBT_PUBLIC double SD_task_get_start_time(SD_task_t task);
105 XBT_PUBLIC double SD_task_get_finish_time(SD_task_t task);
106 XBT_PUBLIC xbt_dynar_t SD_task_get_parents(SD_task_t task);
107 XBT_PUBLIC xbt_dynar_t SD_task_get_children(SD_task_t task);
108 XBT_PUBLIC int SD_task_get_workstation_count(SD_task_t task);
109 XBT_PUBLIC sg_host_t* SD_task_get_workstation_list(SD_task_t task);
110 XBT_PUBLIC void SD_task_destroy(SD_task_t task);
111 XBT_PUBLIC void SD_task_dump(SD_task_t task);
112 XBT_PUBLIC void SD_task_dotty(SD_task_t task, void* out_FILE);
113
114 XBT_PUBLIC SD_task_t SD_task_create_comp_seq(const char* name, void* data, double amount);
115 XBT_PUBLIC SD_task_t SD_task_create_comp_par_amdahl(const char* name, void* data, double amount, double alpha);
116 XBT_PUBLIC SD_task_t SD_task_create_comm_e2e(const char* name, void* data, double amount);
117 XBT_PUBLIC SD_task_t SD_task_create_comm_par_mxn_1d_block(const char* name, void* data, double amount);
118
119 XBT_PUBLIC void SD_task_distribute_comp_amdahl(SD_task_t task, int ws_count);
120 XBT_PUBLIC void SD_task_build_MxN_1D_block_matrix(SD_task_t task, int src_nb, int dst_nb);
121 XBT_PUBLIC void SD_task_schedulev(SD_task_t task, int count, const sg_host_t* list);
122 XBT_PUBLIC void SD_task_schedulel(SD_task_t task, int count, ...);
123
124 /** @brief A constant to use in SD_task_schedule to mean that there is no cost.
125  *
126  *  For example, create a pure computation task (i.e., with no communication) like this:
127  *
128  *  SD_task_schedule(task, my_host_count, my_host_list, my_flops_amount, SD_SCHED_NO_COST, my_rate);
129  */
130 #define SD_SCHED_NO_COST NULL
131
132 /** @} */
133
134 /** @addtogroup SD_task_dependency_api
135  *
136  *  This section describes the functions for managing the dependencies between the tasks.
137  *
138  *  @see SD_task_api
139  *  @{
140  */
141 XBT_PUBLIC void SD_task_dependency_add(SD_task_t src, SD_task_t dst);
142 XBT_PUBLIC void SD_task_dependency_remove(SD_task_t src, SD_task_t dst);
143 XBT_PUBLIC int SD_task_dependency_exists(SD_task_t src, SD_task_t dst);
144 /** @} */
145
146 /************************** Global *******************************************/
147 /** @addtogroup SD_simulation Simulation
148  *
149  *  This section describes the functions for initializing SimDag, launching the simulation and exiting SimDag.
150  *
151  *  @{
152  */
153
154 #define SD_init(argc, argv)                                                                                            \
155   do {                                                                                                                 \
156     sg_version_check(SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);                             \
157     SD_init_nocheck(argc, argv);                                                                                       \
158   } while (0)
159
160 XBT_PUBLIC void SD_init_nocheck(int* argc, char** argv);
161 XBT_PUBLIC void SD_config(const char* key, const char* value);
162 XBT_PUBLIC void SD_create_environment(const char* platform_file);
163 XBT_PUBLIC void SD_simulate(double how_long);
164 XBT_PUBLIC void SD_simulate_with_update(double how_long, xbt_dynar_t changed_tasks_dynar);
165 XBT_PUBLIC double SD_get_clock();
166 XBT_PUBLIC void SD_exit();
167 XBT_PUBLIC xbt_dynar_t SD_daxload(const char* filename);
168 XBT_PUBLIC xbt_dynar_t SD_dotload(const char* filename);
169 XBT_PUBLIC xbt_dynar_t SD_dotload_with_sched(const char* filename);
170 XBT_PUBLIC xbt_dynar_t SD_PTG_dotload(const char* filename);
171 /** @} */
172
173 /* Support some backward compatibility */
174 #define SD_workstation_t sg_host_t
175
176 #define SD_link_get_name sg_link_name
177 #define SD_link_get_current_latency sg_link_latency
178 #define SD_link_get_current_bandwidth sg_link_bandwidth
179
180 #define SD_route_get_current_latency SD_route_get_latency
181 #define SD_route_get_current_bandwidth SD_route_get_bandwidth
182
183 #define SD_workstation_get_list sg_host_list
184 #define SD_workstation_get_number sg_host_count
185
186 #define SD_workstation_get_name sg_host_get_name
187 #define SD_workstation_get_by_name sg_host_by_name
188 #define SD_workstation_dump sg_host_dump
189 #define SD_workstation_get_data sg_host_user
190 #define SD_workstation_set_data sg_host_user_set
191 #define SD_workstation_get_properties sg_host_get_properties
192 #define SD_workstation_get_property_value sg_host_get_property_value
193 #define SD_workstation_get_power sg_host_speed
194 #define SD_workstation_get_available_power sg_host_get_available_speed
195 #define SD_route_get_latency sg_host_route_latency
196 #define SD_route_get_bandwidth sg_host_route_bandwidth
197
198 #define SD_workstation_get_mounted_storage_list sg_host_get_mounted_storage_list
199 // Lost functions
200 //SD_workstation_get_access_mode
201 //SD_workstation_set_access_mode
202 //SD_workstation_get_current_task
203 //SD_route_get_communication_time => SG_route_get_latency() + amount / SD_route_get_bandwidth()
204 //SD_workstation_get_computation_time => amount / sg_host_speed()
205 //SD_route_get_size
206 //SD_route_get_list
207 //TRACE_sd_set_task_category
208 SG_END_DECL()
209
210 #ifdef __cplusplus
211 namespace simgrid {
212 namespace sd {
213 XBT_PUBLIC std::set<SD_task_t>* simulate(double how_long);
214 }
215 }
216 #endif
217
218 #endif