1 /* Copyright (c) 2006-2010, 2012-2016. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef SIMDAG_SIMDAG_H
8 #define SIMDAG_SIMDAG_H
11 #include "xbt/dynar.h"
13 #include "xbt/asserts.h"
15 #include "simgrid/link.h"
16 #include "simgrid/host.h"
20 /** @brief Link datatype
21 @ingroup SD_datatypes_management
23 A link is a network node represented as a <em>name</em>, a <em>bandwidth</em> and a <em>latency</em>.
24 A route is a list of links between two workstations.
26 @see SD_link_management */
27 typedef Link *SD_link_t;
29 /** @brief Task datatype
30 @ingroup SD_datatypes_management
32 A task is some <em>computing amount</em> that can be executed in parallel on several hosts.
33 A task may depend on other tasks, which means that the task cannot start until the other tasks are done.
34 Each task has a <em>\ref e_SD_task_state_t "state"</em> indicating whether the task is scheduled, running, done, ...
36 @see SD_task_management */
37 typedef struct SD_task *SD_task_t;
39 /** @brief Task states
40 @ingroup SD_datatypes_management
42 @see SD_task_management */
44 SD_NOT_SCHEDULED = 0, /**< @brief Initial state (not valid for SD_watch and SD_unwatch). */
45 SD_SCHEDULABLE = 0x0001, /**< @brief A task becomes SD_SCHEDULABLE as soon as its dependencies are satisfied */
46 SD_SCHEDULED = 0x0002, /**< @brief A task becomes SD_SCHEDULED when you call function
47 SD_task_schedule. SD_simulate will execute it when it becomes SD_RUNNABLE. */
48 SD_RUNNABLE = 0x0004, /**< @brief A scheduled task becomes runnable is SD_simulate as soon as its dependencies are satisfied. */
49 SD_RUNNING = 0x0008, /**< @brief An SD_RUNNABLE task becomes SD_RUNNING when it is launched. */
50 SD_DONE = 0x0010, /**< @brief The task is successfully finished. */
51 SD_FAILED = 0x0020 /**< @brief A problem occurred during the execution of the task. */
55 @ingroup SD_datatypes_management
57 @see SD_task_management */
59 SD_TASK_NOT_TYPED = 0, /**< @brief no specified type */
60 SD_TASK_COMM_E2E = 1, /**< @brief end to end communication */
61 SD_TASK_COMP_SEQ = 2, /**< @brief sequential computation */
62 SD_TASK_COMP_PAR_AMDAHL = 3, /**< @brief parallel computation (Amdahl's law) */
63 SD_TASK_COMM_PAR_MXN_1D_BLOCK = 4 /**< @brief MxN data redistribution (1D Block distribution) */
66 /** @brief Storage datatype
67 @ingroup SD_datatypes_management
69 @see SD_storage_management */
70 typedef xbt_dictelm_t SD_storage_t;
72 /************************** Workstation handling ****************************/
73 /** @defgroup sg_host_management Hosts
74 * @brief Functions for managing the Hosts
76 * This section describes the functions for managing the hosts.
78 * A host is a place where a task can be executed.
79 * A host is represented as a <em>physical resource with computing capabilities</em> and has a <em>name</em>.
81 * The hosts are created when you call the function SD_create_environment.
86 XBT_PUBLIC(SD_link_t *) SD_route_get_list(sg_host_t src, sg_host_t dst);
87 XBT_PUBLIC(int) SD_route_get_size(sg_host_t src, sg_host_t dst);
89 XBT_PUBLIC(double) SD_route_get_latency(sg_host_t src, sg_host_t dst);
90 XBT_PUBLIC(double) SD_route_get_bandwidth(sg_host_t src, sg_host_t dst);
92 XBT_PUBLIC(const char*) SD_storage_get_host(SD_storage_t storage);
95 /************************** Task handling ************************************/
96 /** @defgroup SD_task_management Tasks
97 * @brief Functions for managing the tasks
99 * This section describes the functions for managing the tasks.
101 * A task is some <em>working amount</em> that can be executed in parallel on several hosts.
102 * A task may depend on other tasks, which means that the task cannot start until the other tasks are done.
103 * Each task has a <em>\ref e_SD_task_state_t "state"</em> indicating whether the task is scheduled, running, done, ...
105 * @see SD_task_t, SD_task_dependency_management
108 XBT_PUBLIC(SD_task_t) SD_task_create(const char *name, void *data, double amount);
109 XBT_PUBLIC(void *) SD_task_get_data(SD_task_t task);
110 XBT_PUBLIC(void) SD_task_set_data(SD_task_t task, void *data);
111 XBT_PUBLIC(e_SD_task_state_t) SD_task_get_state(SD_task_t task);
112 XBT_PUBLIC(const char *) SD_task_get_name(SD_task_t task);
113 XBT_PUBLIC(void) SD_task_set_name(SD_task_t task, const char *name);
114 XBT_PUBLIC(void) SD_task_set_rate(SD_task_t task, double rate);
116 XBT_PUBLIC(void) SD_task_watch(SD_task_t task, e_SD_task_state_t state);
117 XBT_PUBLIC(void) SD_task_unwatch(SD_task_t task, e_SD_task_state_t state);
118 XBT_PUBLIC(double) SD_task_get_amount(SD_task_t task);
119 XBT_PUBLIC(void) SD_task_set_amount(SD_task_t task, double amount);
120 XBT_PUBLIC(double) SD_task_get_alpha(SD_task_t task);
121 XBT_PUBLIC(double) SD_task_get_remaining_amount(SD_task_t task);
122 XBT_PUBLIC(double) SD_task_get_execution_time(SD_task_t task, int workstation_nb, const sg_host_t *workstation_list,
123 const double *flops_amount, const double *bytes_amount);
124 XBT_PUBLIC(e_SD_task_kind_t) SD_task_get_kind(SD_task_t task);
125 XBT_PUBLIC(void) SD_task_schedule(SD_task_t task, int workstation_nb, const sg_host_t *workstation_list,
126 const double *flops_amount, const double *bytes_amount, double rate);
127 XBT_PUBLIC(void) SD_task_unschedule(SD_task_t task);
128 XBT_PUBLIC(double) SD_task_get_start_time(SD_task_t task);
129 XBT_PUBLIC(double) SD_task_get_finish_time(SD_task_t task);
130 XBT_PUBLIC(xbt_dynar_t) SD_task_get_parents(SD_task_t task);
131 XBT_PUBLIC(xbt_dynar_t) SD_task_get_children(SD_task_t task);
132 XBT_PUBLIC(int) SD_task_get_workstation_count(SD_task_t task);
133 XBT_PUBLIC(sg_host_t *) SD_task_get_workstation_list(SD_task_t task);
134 XBT_PUBLIC(void) SD_task_destroy(SD_task_t task);
135 XBT_PUBLIC(void) SD_task_dump(SD_task_t task);
136 XBT_PUBLIC(void) SD_task_dotty(SD_task_t task, void *out_FILE);
138 XBT_PUBLIC(SD_task_t) SD_task_create_comp_seq(const char *name, void *data, double amount);
139 XBT_PUBLIC(SD_task_t) SD_task_create_comp_par_amdahl(const char *name, void *data, double amount, double alpha);
140 XBT_PUBLIC(SD_task_t) SD_task_create_comm_e2e(const char *name, void *data, double amount);
141 XBT_PUBLIC(SD_task_t) SD_task_create_comm_par_mxn_1d_block(const char *name, void *data, double amount);
143 XBT_PUBLIC(void) SD_task_distribute_comp_amdahl(SD_task_t task, int ws_count);
144 XBT_PUBLIC(void) SD_task_schedulev(SD_task_t task, int count, const sg_host_t * list);
145 XBT_PUBLIC(void) SD_task_schedulel(SD_task_t task, int count, ...);
148 /** @brief A constant to use in SD_task_schedule to mean that there is no cost.
150 * For example, create a pure computation task (no comm) like this:
152 * SD_task_schedule(task, my_host_count, my_host_list, my_flops_amount, SD_TASK_SCHED_NO_COST, my_rate);
154 #define SD_SCHED_NO_COST NULL
158 /** @defgroup SD_task_dependency_management Tasks dependencies
159 * @brief Functions for managing the task dependencies
161 * This section describes the functions for managing the dependencies between the tasks.
163 * @see SD_task_management
166 XBT_PUBLIC(void) SD_task_dependency_add(const char *name, void *data, SD_task_t src, SD_task_t dst);
167 XBT_PUBLIC(void) SD_task_dependency_remove(SD_task_t src, SD_task_t dst);
168 XBT_PUBLIC(const char *) SD_task_dependency_get_name(SD_task_t src, SD_task_t dst);
169 XBT_PUBLIC(void *) SD_task_dependency_get_data(SD_task_t src, SD_task_t dst);
170 XBT_PUBLIC(int) SD_task_dependency_exists(SD_task_t src, SD_task_t dst);
173 /************************** Global *******************************************/
174 /** @defgroup SD_simulation Simulation
175 * @brief Functions for creating the environment and launching the simulation
177 * This section describes the functions for initializing SimDag, launching the simulation and exiting SimDag.
181 XBT_PUBLIC(void) SD_init(int *argc, char **argv);
182 XBT_PUBLIC(void) SD_config(const char *key, const char *value);
183 XBT_PUBLIC(void) SD_create_environment(const char *platform_file);
184 XBT_PUBLIC(xbt_dynar_t) SD_simulate(double how_long);
185 XBT_PUBLIC(double) SD_get_clock(void);
186 XBT_PUBLIC(void) SD_exit(void);
187 XBT_PUBLIC(xbt_dynar_t) SD_daxload(const char *filename);
188 XBT_PUBLIC(xbt_dynar_t) SD_dotload(const char *filename);
189 XBT_PUBLIC(xbt_dynar_t) SD_dotload_with_sched(const char *filename);
190 XBT_PUBLIC(xbt_dynar_t) SD_PTG_dotload(const char *filename);
194 /* Support some backward compatibility */
195 #define SD_workstation_t sg_host_t
197 #define SD_link_get_name sg_link_name
198 #define SD_link_get_current_latency sg_link_latency
199 #define SD_link_get_current_bandwidth sg_link_bandwidth
201 #define SD_route_get_current_latency SD_route_get_latency
202 #define SD_route_get_current_bandwidth SD_route_get_bandwidth
204 #define SD_workstation_get_list sg_host_list
205 #define SD_workstation_get_number sg_host_count
207 #define SD_workstation_get_name sg_host_get_name
208 #define SD_workstation_get_by_name sg_host_by_name
209 #define SD_workstation_dump sg_host_dump
210 #define SD_workstation_get_data sg_host_user
211 #define SD_workstation_set_data sg_host_user_set
212 #define SD_workstation_get_properties sg_host_get_properties
213 #define SD_workstation_get_property_value sg_host_get_property_value
214 #define SD_workstation_get_power sg_host_speed
215 #define SD_workstation_get_available_power sg_host_get_available_speed
217 #define SD_workstation_get_mounted_storage_list sg_host_get_mounted_storage_list
219 //SD_workstation_get_access_mode
220 //SD_workstation_set_access_mode
221 //SD_workstation_get_current_task
222 //SD_route_get_communication_time => SG_route_get_latency() + amount / SD_route_get_bandwidth()
223 //SD_workstation_get_computation_time => amount / sg_host_speed()
224 //TRACE_sd_set_task_category