Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a sequential mode to the workstations. In this mode, only one task can be execute...
[simgrid.git] / src / simdag / private.h
1 #ifndef SIMDAG_PRIVATE_H
2 #define SIMDAG_PRIVATE_H
3
4 #include "xbt/dict.h"
5 #include "xbt/dynar.h"
6 #include "xbt/fifo.h"
7 #include "simdag/simdag.h"
8 #include "simdag/datatypes.h"
9 #include "surf/surf.h"
10
11 #define SD_INITIALISED() (sd_global != NULL)
12 #define SD_CHECK_INIT_DONE() xbt_assert0(SD_INITIALISED(), "Call SD_init() first");
13
14 /* Global variables */
15
16 typedef struct SD_global {
17   xbt_dict_t workstations; /* workstation dictionary */
18   int workstation_count; /* number of workstations */
19   SD_workstation_t *workstation_list; /* array of workstations, created only if
20                                          necessary in SD_workstation_get_list */
21
22   xbt_dict_t links; /* links */
23   int link_count; /* number of links */
24   SD_link_t *link_list; /* array of links, created only if
25                            necessary in SD_link_get_list */
26
27   int watch_point_reached; /* has a task just reached a watch point? */
28   
29   /* task state sets */
30   xbt_swag_t not_scheduled_task_set;
31   xbt_swag_t scheduled_task_set;
32   xbt_swag_t ready_task_set;
33   xbt_swag_t in_fifo_task_set;
34   xbt_swag_t running_task_set;
35   xbt_swag_t done_task_set;
36   xbt_swag_t failed_task_set;
37
38 } s_SD_global_t, *SD_global_t;
39
40 extern SD_global_t sd_global;
41
42 /* Link */
43 typedef struct SD_link {
44   void *surf_link; /* surf object */
45   void *data; /* user data */
46 } s_SD_link_t;
47
48 /* Workstation */
49 typedef struct SD_workstation {
50   void *surf_workstation; /* surf object */
51   void *data; /* user data */
52   e_SD_workstation_access_mode_t access_mode;
53
54   xbt_fifo_t task_fifo; /* only used in sequential mode */
55   SD_task_t current_task; /* only used in sequential mode */
56 } s_SD_workstation_t;
57
58 /* Task */
59 typedef struct SD_task {
60   s_xbt_swag_hookup_t state_hookup;
61   xbt_swag_t state_set;
62   void *data; /* user data */
63   char *name;
64   double amount;
65   double remains;
66   double start_time;
67   double finish_time;
68   surf_action_t surf_action;
69   unsigned short watch_points;
70
71   int state_changed; /* used only by SD_simulate, to make sure we put
72                         the task only once in the returning array */
73   int fifo_checked; /* used by SD_task_just_done to make sure we evaluate
74                        the task only once */
75
76   /* dependencies */
77   xbt_dynar_t tasks_before;
78   xbt_dynar_t tasks_after;
79
80   /* scheduling parameters (only exist in state SD_SCHEDULED) */
81   int workstation_nb;
82   SD_workstation_t *workstation_list; /* surf workstations */
83   double *computation_amount;
84   double *communication_amount;
85   double rate;
86 } s_SD_task_t;
87
88 /* Task dependencies */
89 typedef struct SD_dependency {
90   char *name;
91   void *data;
92   SD_task_t src;
93   SD_task_t dst;
94   /* src must be finished before dst can start */
95 } s_SD_dependency_t, *SD_dependency_t;
96
97 /* SimDag private functions */
98
99 SD_link_t __SD_link_create(void *surf_link, void *data);
100 void __SD_link_destroy(void *link);
101
102 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data);
103 void __SD_workstation_destroy(void *workstation);
104 int __SD_workstation_is_busy(SD_workstation_t workstation);
105
106 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
107 void __SD_task_really_run(SD_task_t task);
108 int __SD_task_try_to_run(SD_task_t task);
109 void __SD_task_just_done(SD_task_t task);
110
111 /* Functions to test if the task is in a given state.
112    These functions are faster than using SD_task_get_state() */
113
114 /* Returns whether the given task is scheduled or ready. */
115 static _XBT_INLINE int __SD_task_is_scheduled_or_ready(SD_task_t task) {
116   return task->state_set == sd_global->scheduled_task_set ||
117     task->state_set == sd_global->ready_task_set;
118 }
119
120 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
121 static _XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task) {
122   return task->state_set == sd_global->not_scheduled_task_set;
123 }
124
125 /* Returns whether the state of the given task is SD_SCHEDULED. */
126 static _XBT_INLINE int __SD_task_is_scheduled(SD_task_t task) {
127   return task->state_set == sd_global->scheduled_task_set;
128 }
129
130 /* Returns whether the state of the given task is SD_READY. */
131 static _XBT_INLINE int __SD_task_is_ready(SD_task_t task) {
132   return task->state_set == sd_global->ready_task_set;
133 }
134
135 /* Returns whether the state of the given task is SD_IN_FIFO. */
136 static _XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task) {
137   return task->state_set == sd_global->in_fifo_task_set;
138 }
139
140 /* Returns whether the state of the given task is SD_READY or SD_IN_FIFO. */
141 static _XBT_INLINE int __SD_task_is_ready_or_in_fifo(SD_task_t task) {
142   return task->state_set == sd_global->ready_task_set ||
143     task->state_set == sd_global->in_fifo_task_set;
144 }
145
146 /* Returns whether the state of the given task is SD_RUNNING. */
147 static _XBT_INLINE int __SD_task_is_running(SD_task_t task) {
148   return task->state_set == sd_global->running_task_set;
149 }
150
151 #endif