Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
de27e4f5e17f10b9abbdb92e5967827bbed3dc4f
[simgrid.git] / src / simdag / simdag_private.h
1 /* Copyright (c) 2006-2015. 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/base.h"
11 #include "xbt/dict.h"
12 #include "xbt/dynar.h"
13 #include "simgrid/simdag.h"
14 #include "surf/surf.h"
15 #include "xbt/mallocator.h"
16 #include <stdbool.h>
17
18 SG_BEGIN_DECL()
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 */
26   SD_link_t *recyclable_route;  /* array returned by SD_route_get_list
27                                    and mallocated only once */
28
29   xbt_mallocator_t task_mallocator; /* to not remalloc new tasks */
30
31   int watch_point_reached;      /* has a task just reached a watch point? */
32
33   xbt_dynar_t initial_task_set;
34   xbt_dynar_t executable_task_set;
35   xbt_dynar_t completed_task_set;
36
37   xbt_dynar_t return_set;
38   int task_number;
39
40 } s_SD_global_t, *SD_global_t;
41
42 extern XBT_PRIVATE SD_global_t sd_global;
43
44 /* Workstation */
45 typedef s_xbt_dictelm_t s_SD_workstation_t;
46
47 /* Storage */
48 typedef s_xbt_dictelm_t s_SD_storage_t;
49 typedef struct SD_storage {
50   void *data;                   /* user data */
51   const char *host;
52 } s_SD_storage_priv_t, *SD_storage_priv_t;
53
54 static inline SD_storage_priv_t SD_storage_priv(SD_storage_t storage){
55   return (SD_storage_priv_t)xbt_lib_get_level(storage, SD_STORAGE_LEVEL);
56 }
57
58 /* Task */
59 typedef struct SD_task {
60   e_SD_task_state_t state;
61   void *data;                   /* user data */
62   char *name;
63   e_SD_task_kind_t kind;
64   double amount;
65   double alpha;          /* used by typed parallel tasks */
66   double remains;
67   double start_time;
68   double finish_time;
69   surf_action_t surf_action;
70   unsigned short watch_points;  /* bit field xor()ed with masks */
71
72   int marked;                   /* used to check if the task DAG has some cycle*/
73
74   /* dependencies */
75   xbt_dynar_t tasks_before;
76   xbt_dynar_t tasks_after;
77   int unsatisfied_dependencies;
78   unsigned int is_not_ready;
79
80   /* scheduling parameters (only exist in state SD_SCHEDULED) */
81   int workstation_nb;
82   SD_workstation_t *workstation_list;   /* surf workstations */
83   double *flops_amount;
84   double *bytes_amount;
85   double rate;
86
87   long long int counter;        /* task unique identifier for instrumentation */
88   char *category;               /* sd task category for instrumentation */
89 } s_SD_task_t;
90
91 /* Task dependencies */
92 typedef struct SD_dependency {
93   char *name;
94   void *data;
95   SD_task_t src;
96   SD_task_t dst;
97   /* src must be finished before dst can start */
98 } s_SD_dependency_t, *SD_dependency_t;
99
100 /* SimDag private functions */
101 XBT_PRIVATE void SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
102 XBT_PRIVATE void SD_task_run(SD_task_t task);
103 XBT_PRIVATE bool acyclic_graph_detail(xbt_dynar_t dag);
104 XBT_PRIVATE void uniq_transfer_task_name(SD_task_t task);
105
106 /* Task mallocator functions */
107 XBT_PRIVATE void* SD_task_new_f(void);
108 XBT_PRIVATE void SD_task_recycle_f(void *t);
109 XBT_PRIVATE void SD_task_free_f(void *t);
110
111 /* Functions to test if the task is in a given state. */
112
113 /* Returns whether the given task is scheduled or runnable. */
114 static XBT_INLINE int __SD_task_is_scheduled_or_runnable(SD_task_t task)
115 {
116   return task->state == SD_SCHEDULED || task->state == SD_RUNNABLE;
117 }
118
119 /********** Storage **********/
120 XBT_PRIVATE SD_storage_t __SD_storage_create(void *surf_storage, void *data);
121 XBT_PRIVATE void __SD_storage_destroy(void *storage);
122
123 /********** Tracing **********/
124 /* declaration of instrumentation functions from sd_task_instr.c */
125 XBT_PRIVATE void TRACE_sd_task_create(SD_task_t task);
126 XBT_PRIVATE void TRACE_sd_task_execute_start(SD_task_t task);
127 XBT_PRIVATE void TRACE_sd_task_execute_end(SD_task_t task);
128 XBT_PRIVATE void TRACE_sd_task_destroy(SD_task_t task);
129
130 SG_END_DECL()
131
132 #endif