Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
test of sd_test
[simgrid.git] / src / simdag / private.h
1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef SIMDAG_PRIVATE_H
8 #define SIMDAG_PRIVATE_H
9
10 #include "xbt/dict.h"
11 #include "xbt/dynar.h"
12 #include "xbt/fifo.h"
13 #include "simdag/simdag.h"
14 #include "simdag/datatypes.h"
15 #include "surf/surf.h"
16
17 #define SD_INITIALISED() (sd_global != NULL)
18 #define SD_CHECK_INIT_DONE() xbt_assert0(SD_INITIALISED(), "Call SD_init() first");
19
20 /* Global variables */
21
22 typedef struct SD_global {
23   xbt_dict_t workstations;      /* workstation dictionary */
24   int workstation_count;        /* number of workstations */
25   SD_workstation_t *workstation_list;   /* array of workstations, created only if
26                                            necessary in SD_workstation_get_list */
27
28   xbt_dict_t links;             /* links */
29   int link_count;               /* number of links */
30   SD_link_t *link_list;         /* array of links, created only if
31                                    necessary in SD_link_get_list */
32   SD_link_t *recyclable_route;  /* array returned by SD_route_get_list
33                                    and mallocated only once */
34
35   int watch_point_reached;      /* has a task just reached a watch point? */
36
37   /* task state sets */
38   xbt_swag_t not_scheduled_task_set;
39   xbt_swag_t schedulable_task_set;
40   xbt_swag_t scheduled_task_set;
41   xbt_swag_t runnable_task_set;
42   xbt_swag_t in_fifo_task_set;
43   xbt_swag_t running_task_set;
44   xbt_swag_t done_task_set;
45   xbt_swag_t failed_task_set;
46
47   int task_number;
48
49 } s_SD_global_t, *SD_global_t;
50
51 extern SD_global_t sd_global;
52
53 /* Link */
54 typedef struct SD_link {
55   void *surf_link;              /* surf object */
56   void *data;                   /* user data */
57   e_SD_link_sharing_policy_t sharing_policy;
58 } s_SD_link_t;
59
60 /* Workstation */
61 typedef struct SD_workstation {
62   void *surf_workstation;       /* surf object */
63   void *data;                   /* user data */
64   e_SD_workstation_access_mode_t access_mode;
65
66   xbt_fifo_t task_fifo;         /* only used in sequential mode */
67   SD_task_t current_task;       /* only used in sequential mode */
68 } s_SD_workstation_t;
69
70 /* Task */
71 typedef struct SD_task {
72   s_xbt_swag_hookup_t state_hookup;
73   xbt_swag_t state_set;
74   e_SD_task_state_t state;
75   void *data;                   /* user data */
76   char *name;
77   int kind;
78   double amount;
79   double remains;
80   double start_time;
81   double finish_time;
82   surf_action_t surf_action;
83   unsigned short watch_points; /* bit field xor()ed with masks */
84
85   int fifo_checked;             /* used by SD_task_just_done to make sure we evaluate
86                                    the task only once */
87
88   /* dependencies */
89   xbt_dynar_t tasks_before;
90   xbt_dynar_t tasks_after;
91   unsigned int unsatisfied_dependencies;
92   unsigned int is_not_ready;
93
94   /* scheduling parameters (only exist in state SD_SCHEDULED) */
95   int workstation_nb;
96   SD_workstation_t *workstation_list;   /* surf workstations */
97   double *computation_amount;
98   double *communication_amount;
99   double rate;
100 } s_SD_task_t;
101
102 /* Task dependencies */
103 typedef struct SD_dependency {
104   char *name;
105   void *data;
106   SD_task_t src;
107   SD_task_t dst;
108   /* src must be finished before dst can start */
109 } s_SD_dependency_t, *SD_dependency_t;
110
111 /* SimDag private functions */
112
113 SD_link_t __SD_link_create(void *surf_link, void *data);
114 void __SD_link_destroy(void *link);
115
116 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data);
117 void __SD_workstation_destroy(void *workstation);
118 int __SD_workstation_is_busy(SD_workstation_t workstation);
119
120 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
121 void __SD_task_really_run(SD_task_t task);
122 int __SD_task_try_to_run(SD_task_t task);
123 void __SD_task_just_done(SD_task_t task);
124
125 /* Functions to test if the task is in a given state. */
126
127 /* Returns whether the given task is scheduled or runnable. */
128 static XBT_INLINE int __SD_task_is_scheduled_or_runnable(SD_task_t task)
129 {
130   return task->state_set == sd_global->scheduled_task_set ||
131     task->state_set == sd_global->runnable_task_set;
132 }
133
134 /* Returns whether the given task is scheduled or runnable. */
135 static XBT_INLINE int __SD_task_is_schedulable_or_done(SD_task_t task)
136 {
137   return task->state_set == sd_global->schedulable_task_set ||
138     task->state_set == sd_global->done_task_set;
139 }
140
141 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
142 static XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task)
143 {
144   return task->state_set == sd_global->not_scheduled_task_set;
145 }
146
147 /* Returns whether the state of the given task is SD_SCHEDULED. */
148 static XBT_INLINE int __SD_task_is_schedulable(SD_task_t task)
149 {
150   return task->state_set == sd_global->schedulable_task_set;
151 }
152
153 /* Returns whether the state of the given task is SD_SCHEDULED. */
154 static XBT_INLINE int __SD_task_is_scheduled(SD_task_t task)
155 {
156   return task->state_set == sd_global->scheduled_task_set;
157 }
158
159 /* Returns whether the state of the given task is SD_RUNNABLE. */
160 static XBT_INLINE int __SD_task_is_runnable(SD_task_t task)
161 {
162   return task->state_set == sd_global->runnable_task_set;
163 }
164
165 /* Returns whether the state of the given task is SD_IN_FIFO. */
166 static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task)
167 {
168   return task->state_set == sd_global->in_fifo_task_set;
169 }
170
171 /* Returns whether the state of the given task is SD_RUNNABLE or SD_IN_FIFO. */
172 static XBT_INLINE int __SD_task_is_runnable_or_in_fifo(SD_task_t task)
173 {
174   return task->state_set == sd_global->runnable_task_set ||
175     task->state_set == sd_global->in_fifo_task_set;
176 }
177
178 /* Returns whether the state of the given task is SD_RUNNING. */
179 static XBT_INLINE int __SD_task_is_running(SD_task_t task)
180 {
181   return task->state_set == sd_global->running_task_set;
182 }
183
184 #endif