Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
new tracing mask TRACE_VOLUME to trace the msg tasks communication size and group...
[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   int kind;
76   double amount;
77   double remains;
78   double start_time;
79   double finish_time;
80   surf_action_t surf_action;
81   unsigned short watch_points; /* bit field xor()ed with masks */
82
83   int fifo_checked;             /* used by SD_task_just_done to make sure we evaluate
84                                    the task only once */
85
86   /* dependencies */
87   xbt_dynar_t tasks_before;
88   xbt_dynar_t tasks_after;
89
90   /* scheduling parameters (only exist in state SD_SCHEDULED) */
91   int workstation_nb;
92   SD_workstation_t *workstation_list;   /* surf workstations */
93   double *computation_amount;
94   double *communication_amount;
95   double rate;
96 } s_SD_task_t;
97
98 /* Task dependencies */
99 typedef struct SD_dependency {
100   char *name;
101   void *data;
102   SD_task_t src;
103   SD_task_t dst;
104   /* src must be finished before dst can start */
105 } s_SD_dependency_t, *SD_dependency_t;
106
107 /* SimDag private functions */
108
109 SD_link_t __SD_link_create(void *surf_link, void *data);
110 void __SD_link_destroy(void *link);
111
112 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data);
113 void __SD_workstation_destroy(void *workstation);
114 int __SD_workstation_is_busy(SD_workstation_t workstation);
115
116 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
117 void __SD_task_really_run(SD_task_t task);
118 int __SD_task_try_to_run(SD_task_t task);
119 void __SD_task_just_done(SD_task_t task);
120
121 /* Functions to test if the task is in a given state. */
122
123 /* Returns whether the given task is scheduled or ready. */
124 static XBT_INLINE int __SD_task_is_scheduled_or_ready(SD_task_t task)
125 {
126   return task->state_set == sd_global->scheduled_task_set ||
127     task->state_set == sd_global->ready_task_set;
128 }
129
130 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
131 static XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task)
132 {
133   return task->state_set == sd_global->not_scheduled_task_set;
134 }
135
136 /* Returns whether the state of the given task is SD_SCHEDULED. */
137 static XBT_INLINE int __SD_task_is_scheduled(SD_task_t task)
138 {
139   return task->state_set == sd_global->scheduled_task_set;
140 }
141
142 /* Returns whether the state of the given task is SD_READY. */
143 static XBT_INLINE int __SD_task_is_ready(SD_task_t task)
144 {
145   return task->state_set == sd_global->ready_task_set;
146 }
147
148 /* Returns whether the state of the given task is SD_IN_FIFO. */
149 static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task)
150 {
151   return task->state_set == sd_global->in_fifo_task_set;
152 }
153
154 /* Returns whether the state of the given task is SD_READY or SD_IN_FIFO. */
155 static XBT_INLINE int __SD_task_is_ready_or_in_fifo(SD_task_t task)
156 {
157   return task->state_set == sd_global->ready_task_set ||
158     task->state_set == sd_global->in_fifo_task_set;
159 }
160
161 /* Returns whether the state of the given task is SD_RUNNING. */
162 static XBT_INLINE int __SD_task_is_running(SD_task_t task)
163 {
164   return task->state_set == sd_global->running_task_set;
165 }
166
167 #endif