Logo AND Algorithmique Numérique Distribuée

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