Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more comments to explain the structure
[simgrid.git] / src / simdag / private.h
1 /* Copyright (c) 2007-2009 Da SimGrid Team.  All rights reserved.           */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMDAG_PRIVATE_H
7 #define SIMDAG_PRIVATE_H
8
9 #include "xbt/dict.h"
10 #include "xbt/dynar.h"
11 #include "xbt/fifo.h"
12 #include "simdag/simdag.h"
13 #include "simdag/datatypes.h"
14 #include "surf/surf.h"
15
16 #define SD_INITIALISED() (sd_global != NULL)
17 #define SD_CHECK_INIT_DONE() xbt_assert0(SD_INITIALISED(), "Call SD_init() first");
18
19 /* Global variables */
20
21 typedef struct SD_global {
22   xbt_dict_t workstations;      /* workstation dictionary */
23   int workstation_count;        /* number of workstations */
24   SD_workstation_t *workstation_list;   /* array of workstations, created only if
25                                            necessary in SD_workstation_get_list */
26
27   xbt_dict_t links;             /* links */
28   int link_count;               /* number of links */
29   SD_link_t *link_list;         /* array of links, created only if
30                                    necessary in SD_link_get_list */
31   SD_link_t *recyclable_route;  /* array returned by SD_route_get_list
32                                    and mallocated only once */
33
34   int watch_point_reached;      /* has a task just reached a watch point? */
35
36   /* task state sets */
37   xbt_swag_t not_scheduled_task_set;
38   xbt_swag_t scheduled_task_set;
39   xbt_swag_t ready_task_set;
40   xbt_swag_t in_fifo_task_set;
41   xbt_swag_t running_task_set;
42   xbt_swag_t done_task_set;
43   xbt_swag_t failed_task_set;
44
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 struct SD_workstation {
60   void *surf_workstation;       /* surf object */
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_t;
67
68 /* Task */
69 typedef struct SD_task {
70   s_xbt_swag_hookup_t state_hookup;
71   xbt_swag_t state_set;
72   e_SD_task_state_t state;
73   void *data;                   /* user data */
74   char *name;
75   double amount;
76   double remains;
77   double start_time;
78   double finish_time;
79   surf_action_t surf_action;
80   unsigned short watch_points; /* bit field xor()ed with masks */
81
82   int fifo_checked;             /* used by SD_task_just_done to make sure we evaluate
83                                    the task only once */
84
85   /* dependencies */
86   xbt_dynar_t tasks_before;
87   xbt_dynar_t tasks_after;
88
89   /* scheduling parameters (only exist in state SD_SCHEDULED) */
90   int workstation_nb;
91   SD_workstation_t *workstation_list;   /* surf workstations */
92   double *computation_amount;
93   double *communication_amount;
94   double rate;
95 } s_SD_task_t;
96
97 /* Task dependencies */
98 typedef struct SD_dependency {
99   char *name;
100   void *data;
101   SD_task_t src;
102   SD_task_t dst;
103   /* src must be finished before dst can start */
104 } s_SD_dependency_t, *SD_dependency_t;
105
106 /* SimDag private functions */
107
108 SD_link_t __SD_link_create(void *surf_link, void *data);
109 void __SD_link_destroy(void *link);
110
111 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data);
112 void __SD_workstation_destroy(void *workstation);
113 int __SD_workstation_is_busy(SD_workstation_t workstation);
114
115 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
116 void __SD_task_really_run(SD_task_t task);
117 int __SD_task_try_to_run(SD_task_t task);
118 void __SD_task_just_done(SD_task_t task);
119
120 /* Functions to test if the task is in a given state. */
121
122 /* Returns whether the given task is scheduled or ready. */
123 static XBT_INLINE int __SD_task_is_scheduled_or_ready(SD_task_t task)
124 {
125   return task->state_set == sd_global->scheduled_task_set ||
126     task->state_set == sd_global->ready_task_set;
127 }
128
129 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
130 static XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task)
131 {
132   return task->state_set == sd_global->not_scheduled_task_set;
133 }
134
135 /* Returns whether the state of the given task is SD_SCHEDULED. */
136 static XBT_INLINE int __SD_task_is_scheduled(SD_task_t task)
137 {
138   return task->state_set == sd_global->scheduled_task_set;
139 }
140
141 /* Returns whether the state of the given task is SD_READY. */
142 static XBT_INLINE int __SD_task_is_ready(SD_task_t task)
143 {
144   return task->state_set == sd_global->ready_task_set;
145 }
146
147 /* Returns whether the state of the given task is SD_IN_FIFO. */
148 static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task)
149 {
150   return task->state_set == sd_global->in_fifo_task_set;
151 }
152
153 /* Returns whether the state of the given task is SD_READY or SD_IN_FIFO. */
154 static XBT_INLINE int __SD_task_is_ready_or_in_fifo(SD_task_t task)
155 {
156   return task->state_set == sd_global->ready_task_set ||
157     task->state_set == sd_global->in_fifo_task_set;
158 }
159
160 /* Returns whether the state of the given task is SD_RUNNING. */
161 static XBT_INLINE int __SD_task_is_running(SD_task_t task)
162 {
163   return task->state_set == sd_global->running_task_set;
164 }
165
166 #endif