Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8d7635434662397b922ff8650a9478589d06e6e5
[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   SD_link_t *recyclable_route; /* array returned by SD_route_get_list
27                                   and mallocated only once */
28
29   int watch_point_reached; /* has a task just reached a watch point? */
30   
31   /* task state sets */
32   xbt_swag_t not_scheduled_task_set;
33   xbt_swag_t scheduled_task_set;
34   xbt_swag_t ready_task_set;
35   xbt_swag_t in_fifo_task_set;
36   xbt_swag_t running_task_set;
37   xbt_swag_t done_task_set;
38   xbt_swag_t failed_task_set;
39
40 } s_SD_global_t, *SD_global_t;
41
42 extern SD_global_t sd_global;
43
44 /* Link */
45 typedef struct SD_link {
46   void *surf_link; /* surf object */
47   void *data; /* user data */
48 } s_SD_link_t;
49
50 /* Workstation */
51 typedef struct SD_workstation {
52   void *surf_workstation; /* surf object */
53   void *data; /* user data */
54   e_SD_workstation_access_mode_t access_mode;
55
56   xbt_fifo_t task_fifo; /* only used in sequential mode */
57   SD_task_t current_task; /* only used in sequential mode */
58 } s_SD_workstation_t;
59
60 /* Task */
61 typedef struct SD_task {
62   s_xbt_swag_hookup_t state_hookup;
63   xbt_swag_t state_set;
64   void *data; /* user data */
65   char *name;
66   double amount;
67   double remains;
68   double start_time;
69   double finish_time;
70   surf_action_t surf_action;
71   unsigned short watch_points;
72
73   int state_changed; /* used only by SD_simulate, to make sure we put
74                         the task only once in the returning array */
75   int fifo_checked; /* used by SD_task_just_done to make sure we evaluate
76                        the task only once */
77
78   /* dependencies */
79   xbt_dynar_t tasks_before;
80   xbt_dynar_t tasks_after;
81
82   /* scheduling parameters (only exist in state SD_SCHEDULED) */
83   int workstation_nb;
84   SD_workstation_t *workstation_list; /* surf workstations */
85   double *computation_amount;
86   double *communication_amount;
87   double rate;
88 } s_SD_task_t;
89
90 /* Task dependencies */
91 typedef struct SD_dependency {
92   char *name;
93   void *data;
94   SD_task_t src;
95   SD_task_t dst;
96   /* src must be finished before dst can start */
97 } s_SD_dependency_t, *SD_dependency_t;
98
99 /* SimDag private functions */
100
101 SD_link_t __SD_link_create(void *surf_link, void *data);
102 void __SD_link_destroy(void *link);
103
104 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data);
105 void __SD_workstation_destroy(void *workstation);
106 int __SD_workstation_is_busy(SD_workstation_t workstation);
107
108 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
109 void __SD_task_really_run(SD_task_t task);
110 int __SD_task_try_to_run(SD_task_t task);
111 void __SD_task_just_done(SD_task_t task);
112
113 /* Functions to test if the task is in a given state.
114    These functions are faster than using SD_task_get_state() */
115
116 /* Returns whether the given task is scheduled or ready. */
117 static _XBT_INLINE int __SD_task_is_scheduled_or_ready(SD_task_t task) {
118   return task->state_set == sd_global->scheduled_task_set ||
119     task->state_set == sd_global->ready_task_set;
120 }
121
122 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
123 static _XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task) {
124   return task->state_set == sd_global->not_scheduled_task_set;
125 }
126
127 /* Returns whether the state of the given task is SD_SCHEDULED. */
128 static _XBT_INLINE int __SD_task_is_scheduled(SD_task_t task) {
129   return task->state_set == sd_global->scheduled_task_set;
130 }
131
132 /* Returns whether the state of the given task is SD_READY. */
133 static _XBT_INLINE int __SD_task_is_ready(SD_task_t task) {
134   return task->state_set == sd_global->ready_task_set;
135 }
136
137 /* Returns whether the state of the given task is SD_IN_FIFO. */
138 static _XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task) {
139   return task->state_set == sd_global->in_fifo_task_set;
140 }
141
142 /* Returns whether the state of the given task is SD_READY or SD_IN_FIFO. */
143 static _XBT_INLINE int __SD_task_is_ready_or_in_fifo(SD_task_t task) {
144   return task->state_set == sd_global->ready_task_set ||
145     task->state_set == sd_global->in_fifo_task_set;
146 }
147
148 /* Returns whether the state of the given task is SD_RUNNING. */
149 static _XBT_INLINE int __SD_task_is_running(SD_task_t task) {
150   return task->state_set == sd_global->running_task_set;
151 }
152
153 #endif