Logo AND Algorithmique Numérique Distribuée

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