Logo AND Algorithmique Numérique Distribuée

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