Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
s/surf_finalize/surf_exit/ for uniformity with other modules
[simgrid.git] / src / include / surf / surf.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef _SURF_SURF_H
9 #define _SURF_SURF_H
10
11 #include "xbt/swag.h"
12 #include "xbt/dynar.h"
13 #include "xbt/dict.h"
14
15 /* Actions and resources are higly connected structures... */
16 typedef struct surf_action *surf_action_t;
17 typedef struct surf_resource *surf_resource_t;
18
19 /*****************/
20 /* Action object */
21 /*****************/
22 typedef enum {
23   SURF_ACTION_READY = 0,        /* Ready        */
24   SURF_ACTION_RUNNING,          /* Running      */
25   SURF_ACTION_FAILED,           /* Task Failure */
26   SURF_ACTION_DONE,             /* Completed    */
27   SURF_ACTION_TO_FREE,          /* Action to free in next cleanup */
28   SURF_ACTION_NOT_IN_THE_SYSTEM /* Not in the system anymore. Why did you ask ? */
29 } e_surf_action_state_t;
30
31 typedef struct surf_action_state {
32   xbt_swag_t ready_action_set;
33   xbt_swag_t running_action_set;
34   xbt_swag_t failed_action_set;
35   xbt_swag_t done_action_set;
36 } s_surf_action_state_t, *surf_action_state_t;
37
38 /* Never create s_surf_action_t by yourself !!!! */
39 /* Use action_new from the corresponding resource */
40 typedef struct surf_action {
41   s_xbt_swag_hookup_t state_hookup;
42   xbt_swag_t state_set;
43   double cost;                  /* cost        */
44   double max_duration;          /* max_duration (may fluctuate until
45                                    the task is completed) */
46   double remains;               /* How much of that cost remains to
47                                  * be done in the currently running task */
48   double start;                 /* start time  */
49   double finish;                /* finish time : this is modified during the run
50                                  * and fluctuates until the task is completed */
51   void *data;                   /* for your convenience */
52   int using;
53   surf_resource_t resource_type;
54 } s_surf_action_t;
55
56 /***************************/
57 /* Generic resource object */
58 /***************************/
59
60 typedef struct surf_resource_private *surf_resource_private_t;
61 typedef struct surf_resource_public {
62   s_surf_action_state_t states; /* Any living action on this resource */
63   void *(*name_service) (const char *name);
64   const char *(*get_resource_name) (void *resource_id);
65
66    e_surf_action_state_t(*action_get_state) (surf_action_t action);
67   void (*action_use) (surf_action_t action);
68   int  (*action_free) (surf_action_t action);
69   void (*action_cancel) (surf_action_t action);
70   void (*action_recycle) (surf_action_t action);
71   void (*action_change_state) (surf_action_t action,
72                                e_surf_action_state_t state);
73   void (*action_set_data) (surf_action_t action, void *data);
74   void (*suspend) (surf_action_t action);
75   void (*resume) (surf_action_t action);
76   int (*is_suspended) (surf_action_t action);
77   void (*set_max_duration) (surf_action_t action, double duration);
78   const char *name;
79 } s_surf_resource_public_t, *surf_resource_public_t;
80
81 typedef struct surf_resource {
82   surf_resource_private_t common_private;
83   surf_resource_public_t common_public;
84 } s_surf_resource_t;
85
86 /**************************************/
87 /* Implementations of resource object */
88 /**************************************/
89 /* Timer resource */
90 typedef struct surf_timer_resource_extension_private
91 *surf_timer_resource_extension_private_t;
92 typedef struct surf_timer_resource_extension_public {
93   void (*set) (double date, void *function, void *arg);
94   int (*get)  (void **function, void **arg);
95 } s_surf_timer_resource_extension_public_t,
96   *surf_timer_resource_extension_public_t;
97
98 typedef struct surf_timer_resource {
99   surf_resource_private_t common_private;
100   surf_resource_public_t common_public;
101   surf_timer_resource_extension_public_t extension_public;
102 } s_surf_timer_resource_t, *surf_timer_resource_t;
103 extern surf_timer_resource_t surf_timer_resource;
104 void surf_timer_resource_init(const char *filename);
105
106 /* Cpu resource */
107 typedef enum {
108   SURF_CPU_ON = 1,              /* Ready        */
109   SURF_CPU_OFF = 0              /* Running      */
110 } e_surf_cpu_state_t;
111
112 typedef struct surf_cpu_resource_extension_private
113 *surf_cpu_resource_extension_private_t;
114 typedef struct surf_cpu_resource_extension_public {
115   surf_action_t(*execute) (void *cpu, double size);
116   surf_action_t(*sleep) (void *cpu, double duration);
117   e_surf_cpu_state_t(*get_state) (void *cpu);
118   double (*get_speed) (void *cpu, double load);
119 } s_surf_cpu_resource_extension_public_t,
120     *surf_cpu_resource_extension_public_t;
121
122 typedef struct surf_cpu_resource {
123   surf_resource_private_t common_private;
124   surf_resource_public_t common_public;
125   surf_cpu_resource_extension_public_t extension_public;
126 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
127 extern surf_cpu_resource_t surf_cpu_resource;
128 void surf_cpu_resource_init_Cas01(const char *filename);
129
130 /* Network resource */
131 typedef struct surf_network_resource_extension_private
132 *surf_network_resource_extension_private_t;
133 typedef struct surf_network_resource_extension_public {
134   surf_action_t(*communicate) (void *src, void *dst, double size,
135                                double max_rate);
136 } s_surf_network_resource_extension_public_t,
137     *surf_network_resource_extension_public_t;
138
139 typedef struct surf_network_resource {
140   surf_resource_private_t common_private;
141   surf_resource_public_t common_public;
142   surf_network_resource_extension_public_t extension_public;
143 } s_surf_network_resource_t, *surf_network_resource_t;
144
145 extern surf_network_resource_t surf_network_resource;
146 void surf_network_resource_init_CM02(const char *filename);
147
148 /* Workstation resource */
149 typedef struct surf_workstation_resource_extension_private
150 *surf_workstation_resource_extension_private_t;
151 typedef struct surf_workstation_resource_extension_public {
152   surf_action_t(*execute) (void *workstation, double size);
153   surf_action_t(*sleep) (void *workstation, double duration);
154   e_surf_cpu_state_t(*get_state) (void *workstation);
155   double (*get_speed) (void *workstation, double load);
156   surf_action_t(*communicate) (void *workstation_src,
157                                void *workstation_dst, double size,
158                                double max_rate);
159   surf_action_t(*execute_parallel_task) (int workstation_nb,
160                                          void **workstation_list,
161                                          double *computation_amount,
162                                          double *communication_amount,
163                                          double amount,
164                                          double rate);
165 } s_surf_workstation_resource_extension_public_t,
166     *surf_workstation_resource_extension_public_t;
167
168 typedef struct surf_workstation_resource {
169   surf_resource_private_t common_private;
170   surf_resource_public_t common_public;
171   surf_workstation_resource_extension_public_t extension_public;
172 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
173
174 extern surf_workstation_resource_t surf_workstation_resource;
175 void surf_workstation_resource_init_CLM03(const char *filename);
176 void surf_workstation_resource_init_KCCFLN05(const char *filename);
177 extern xbt_dict_t workstation_set;
178
179 /*******************************************/
180 /*** SURF Globals **************************/
181 /*******************************************/
182
183 void surf_init(int *argc, char **argv); /* initialize common structures */
184
185 extern xbt_dynar_t resource_list;       /* list of initialized resources */
186
187 double surf_solve(void);        /*  update all states and returns
188                                    the time elapsed since last
189                                    event */
190 double surf_get_clock(void);
191 void surf_exit(void);   /* clean everything */
192
193 #endif                          /* _SURF_SURF_H */