Logo AND Algorithmique Numérique Distribuée

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