Logo AND Algorithmique Numérique Distribuée

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