Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
80b6b709e4c87808e9e1f29c4b9f72c1bbacd7ab
[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 scheduled_task_set;
40   xbt_swag_t runnable_task_set;
41   xbt_swag_t in_fifo_task_set;
42   xbt_swag_t running_task_set;
43   xbt_swag_t done_task_set;
44   xbt_swag_t failed_task_set;
45
46   int task_number;
47
48 } s_SD_global_t, *SD_global_t;
49
50 extern SD_global_t sd_global;
51
52 /* Link */
53 typedef struct SD_link {
54   void *surf_link;              /* surf object */
55   void *data;                   /* user data */
56   e_SD_link_sharing_policy_t sharing_policy;
57 } s_SD_link_t;
58
59 /* Workstation */
60 typedef struct SD_workstation {
61   void *surf_workstation;       /* surf object */
62   void *data;                   /* user data */
63   e_SD_workstation_access_mode_t access_mode;
64
65   xbt_fifo_t task_fifo;         /* only used in sequential mode */
66   SD_task_t current_task;       /* only used in sequential mode */
67 } s_SD_workstation_t;
68
69 /* Task */
70 typedef struct SD_task {
71   s_xbt_swag_hookup_t state_hookup;
72   xbt_swag_t state_set;
73   e_SD_task_state_t state;
74   void *data;                   /* user data */
75   char *name;
76   int kind;
77   double amount;
78   double remains;
79   double start_time;
80   double finish_time;
81   surf_action_t surf_action;
82   unsigned short watch_points; /* bit field xor()ed with masks */
83
84   int fifo_checked;             /* used by SD_task_just_done to make sure we evaluate
85                                    the task only once */
86
87   /* dependencies */
88   xbt_dynar_t tasks_before;
89   xbt_dynar_t tasks_after;
90   unsigned int unsatisfied_dependencies;
91
92   /* scheduling parameters (only exist in state SD_SCHEDULED) */
93   int workstation_nb;
94   SD_workstation_t *workstation_list;   /* surf workstations */
95   double *computation_amount;
96   double *communication_amount;
97   double rate;
98 } s_SD_task_t;
99
100 /* Task dependencies */
101 typedef struct SD_dependency {
102   char *name;
103   void *data;
104   SD_task_t src;
105   SD_task_t dst;
106   /* src must be finished before dst can start */
107 } s_SD_dependency_t, *SD_dependency_t;
108
109 /* SimDag private functions */
110
111 SD_link_t __SD_link_create(void *surf_link, void *data);
112 void __SD_link_destroy(void *link);
113
114 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data);
115 void __SD_workstation_destroy(void *workstation);
116 int __SD_workstation_is_busy(SD_workstation_t workstation);
117
118 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
119 void __SD_task_really_run(SD_task_t task);
120 int __SD_task_try_to_run(SD_task_t task);
121 void __SD_task_just_done(SD_task_t task);
122
123 /* Functions to test if the task is in a given state. */
124
125 /* Returns whether the given task is scheduled or runnable. */
126 static XBT_INLINE int __SD_task_is_scheduled_or_runnable(SD_task_t task)
127 {
128   return task->state_set == sd_global->scheduled_task_set ||
129     task->state_set == sd_global->runnable_task_set;
130 }
131
132 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
133 static XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task)
134 {
135   return task->state_set == sd_global->not_scheduled_task_set;
136 }
137
138 /* Returns whether the state of the given task is SD_SCHEDULED. */
139 static XBT_INLINE int __SD_task_is_scheduled(SD_task_t task)
140 {
141   return task->state_set == sd_global->scheduled_task_set;
142 }
143
144 /* Returns whether the state of the given task is SD_READY. */
145 static XBT_INLINE int __SD_task_is_runnable(SD_task_t task)
146 {
147   return task->state_set == sd_global->runnable_task_set;
148 }
149
150 /* Returns whether the state of the given task is SD_IN_FIFO. */
151 static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task)
152 {
153   return task->state_set == sd_global->in_fifo_task_set;
154 }
155
156 /* Returns whether the state of the given task is SD_READY or SD_IN_FIFO. */
157 static XBT_INLINE int __SD_task_is_runnable_or_in_fifo(SD_task_t task)
158 {
159   return task->state_set == sd_global->runnable_task_set ||
160     task->state_set == sd_global->in_fifo_task_set;
161 }
162
163 /* Returns whether the state of the given task is SD_RUNNING. */
164 static XBT_INLINE int __SD_task_is_running(SD_task_t task)
165 {
166   return task->state_set == sd_global->running_task_set;
167 }
168
169 #endif