Logo AND Algorithmique Numérique Distribuée

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