void xbt_heap_free(xbt_heap_t H);
int xbt_heap_size(xbt_heap_t H);
-void xbt_heap_push(xbt_heap_t H, void *content, xbt_heap_float_t key);
+void xbt_heap_push(xbt_heap_t H, void *content, double key);
void *xbt_heap_pop(xbt_heap_t H);
-xbt_heap_float_t xbt_heap_maxkey(xbt_heap_t H);
+double xbt_heap_maxkey(xbt_heap_t H);
void *xbt_heap_maxcontent(xbt_heap_t H);
#endif /* _XBT_HEAP_H */
typedef void (void_f_ppvoid_t)(void**);
typedef void (void_f_pvoid_t) (void*);
-/* The following two definitions concern the type of the keys used for
- the heaps. That should be handled via configure (FIXME). */
-typedef long double xbt_heap_float_t;
-#define XBT_HEAP_FLOAT_T "%Lg" /* for printing purposes */
-
-typedef long double xbt_maxmin_float_t;
-#define XBT_MAXMIN_FLOAT_T "%Lg" /* for printing purposes */
-
-
END_DECL
#endif /* XBT_MISC_H */
void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var);
lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id,
- xbt_maxmin_float_t bound_value);
+ double bound_value);
void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst);
lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
- xbt_maxmin_float_t weight_value,
- xbt_maxmin_float_t bound,
- int number_of_constraints);
+ double weight_value,
+ double bound, int number_of_constraints);
void lmm_variable_free(lmm_system_t sys, lmm_variable_t var);
-xbt_maxmin_float_t lmm_variable_getvalue(lmm_variable_t var);
+double lmm_variable_getvalue(lmm_variable_t var);
void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst,
- lmm_variable_t var, xbt_maxmin_float_t value);
+ lmm_variable_t var, double value);
-lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, lmm_variable_t var, int num);
+lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys,
+ lmm_variable_t var, int num);
int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var);
-lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys, lmm_constraint_t cnst,
- lmm_variable_t *var);
+lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys,
+ lmm_constraint_t cnst,
+ lmm_variable_t * var);
void *lmm_constraint_id(lmm_constraint_t cnst);
void *lmm_variable_id(lmm_variable_t var);
void lmm_update(lmm_system_t sys, lmm_constraint_t cnst,
- lmm_variable_t var, xbt_maxmin_float_t value);
+ lmm_variable_t var, double value);
void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var,
- xbt_maxmin_float_t bound);
+ double bound);
void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var,
- xbt_maxmin_float_t weight);
+ double weight);
void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst,
- xbt_maxmin_float_t bound);
+ double bound);
int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst);
typedef struct surf_action {
s_xbt_swag_hookup_t state_hookup;
xbt_swag_t state_set;
- xbt_maxmin_float_t cost; /* cost */
- xbt_maxmin_float_t max_duration; /* max_duration (may fluctuate until
- the task is completed) */
- xbt_maxmin_float_t remains; /* How much of that cost remains to
+ double cost; /* cost */
+ double max_duration; /* max_duration (may fluctuate until
+ the task is completed) */
+ double remains; /* How much of that cost remains to
* be done in the currently running task */
- xbt_heap_float_t start; /* start time */
- xbt_heap_float_t finish; /* finish time : this is modified during the run
+ double start; /* start time */
+ double finish; /* finish time : this is modified during the run
* and fluctuates until the task is completed */
void *callback; /* for your convenience */
surf_resource_t resource_type;
typedef struct surf_cpu_resource_extension_private
*surf_cpu_resource_extension_private_t;
typedef struct surf_cpu_resource_extension_public {
- surf_action_t(*execute) (void *cpu, xbt_maxmin_float_t size);
- surf_action_t(*sleep) (void *cpu, xbt_maxmin_float_t duration);
+ surf_action_t(*execute) (void *cpu, double size);
+ surf_action_t(*sleep) (void *cpu, double duration);
void (*suspend) (surf_action_t action);
void (*resume) (surf_action_t action);
e_surf_cpu_state_t(*get_state) (void *cpu);
typedef struct surf_network_resource_extension_private
*surf_network_resource_extension_private_t;
typedef struct surf_network_resource_extension_public {
- surf_action_t(*communicate) (void *src, void *dst,
- xbt_maxmin_float_t size);
+ surf_action_t(*communicate) (void *src, void *dst, double size);
} s_surf_network_resource_extension_public_t,
*surf_network_resource_extension_public_t;
typedef struct surf_workstation_resource_extension_private
*surf_workstation_resource_extension_private_t;
typedef struct surf_workstation_resource_extension_public {
- surf_action_t(*execute) (void *workstation, xbt_maxmin_float_t size);
- surf_action_t(*sleep) (void *workstation, xbt_maxmin_float_t duration);
+ surf_action_t(*execute) (void *workstation, double size);
+ surf_action_t(*sleep) (void *workstation, double duration);
void (*suspend) (surf_action_t action);
void (*resume) (surf_action_t action);
e_surf_cpu_state_t(*get_state) (void *workstation);
surf_action_t(*communicate) (void *workstation_src,
- void *workstation_dst,
- xbt_maxmin_float_t size);
+ void *workstation_dst, double size);
} s_surf_workstation_resource_extension_public_t,
*surf_workstation_resource_extension_public_t;
extern xbt_dynar_t resource_list; /* list of initialized resources */
-xbt_heap_float_t surf_solve(void); /* update all states and returns
- the time elapsed since last
- event */
-xbt_heap_float_t surf_get_clock(void);
+double surf_solve(void); /* update all states and returns
+ the time elapsed since last
+ event */
+double surf_get_clock(void);
void surf_finalize(void); /* clean everything */
#endif /* _SURF_SURF_H */
extern int tok_num;
e_surf_token_t surf_parse(void);
-void find_section(const char* file, const char* section_name);
-void close_section(const char* section_name);
-void surf_parse_float(xbt_maxmin_float_t *value);
-void surf_parse_trace(tmgr_trace_t *trace);
+void find_section(const char *file, const char *section_name);
+void close_section(const char *section_name);
+void surf_parse_double(double *value);
+void surf_parse_trace(tmgr_trace_t * trace);
/* Should not be called if you use the previous "section" functions */
-void surf_parse_open(const char *file);
-void surf_parse_close(void);
+void surf_parse_open(const char *file);
+void surf_parse_close(void);
/* Prototypes of the functions offered by flex */
int surf_parse_lex(void);
-int surf_parse_get_lineno (void);
-FILE *surf_parse_get_in (void);
-FILE *surf_parse_get_out (void);
-int surf_parse_get_leng (void);
-char *surf_parse_get_text (void);
-void surf_parse_set_lineno (int line_number );
-void surf_parse_set_in (FILE * in_str );
-void surf_parse_set_out (FILE * out_str );
-int surf_parse_get_debug (void);
-void surf_parse_set_debug (int bdebug );
-int surf_parse_lex_destroy (void);
+int surf_parse_get_lineno(void);
+FILE *surf_parse_get_in(void);
+FILE *surf_parse_get_out(void);
+int surf_parse_get_leng(void);
+char *surf_parse_get_text(void);
+void surf_parse_set_lineno(int line_number);
+void surf_parse_set_in(FILE * in_str);
+void surf_parse_set_out(FILE * out_str);
+int surf_parse_get_debug(void);
+void surf_parse_set_debug(int bdebug);
+int surf_parse_lex_destroy(void);
#endif
tmgr_trace_t tmgr_trace_new(const char *filename);
void tmgr_trace_free(tmgr_trace_t trace);
-tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t history, tmgr_trace_t trace,
- xbt_heap_float_t start_time, int offset,
+tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t history,
+ tmgr_trace_t trace,
+ double start_time, int offset,
void *resource);
/* Access functions */
-xbt_heap_float_t tmgr_history_next_date(tmgr_history_t history);
+double tmgr_history_next_date(tmgr_history_t history);
tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t history,
- xbt_heap_float_t date,
- xbt_maxmin_float_t * value,
- void **resource);
+ double date,
+ double *value,
+ void **resource);
void tmgr_finalize(void);
state_trace values mean SURF_CPU_ON if >0 and SURF_CPU_OFF
otherwise.
*/
-static cpu_t cpu_new(const char *name, xbt_maxmin_float_t power_scale,
- xbt_maxmin_float_t power_initial,
+static cpu_t cpu_new(const char *name, double power_scale,
+ double power_initial,
tmgr_trace_t power_trace,
e_surf_cpu_state_t state_initial,
tmgr_trace_t state_trace)
power trace state trace
Token: TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD
- Type: string float float string ON/OFF string
+ Type: string double double string ON/OFF string
*/
static void parse_cpu(void)
{
e_surf_token_t token;
char *name = NULL;
- xbt_maxmin_float_t power_scale = 0.0;
- xbt_maxmin_float_t power_initial = 0.0;
+ double power_scale = 0.0;
+ double power_initial = 0.0;
tmgr_trace_t power_trace = NULL;;
e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
tmgr_trace_t state_trace = NULL;
name = xbt_strdup(surf_parse_text);
- surf_parse_float(&power_scale);
- surf_parse_float(&power_initial);
+ surf_parse_double(&power_scale);
+ surf_parse_double(&power_initial);
surf_parse_trace(&power_trace);
token = surf_parse(); /* state_initial */
return;
}
-static xbt_heap_float_t share_resources(xbt_heap_float_t now)
+static double share_resources(double now)
{
s_surf_action_cpu_t action;
return generic_maxmin_share_resources(surf_cpu_resource->common_public->
xbt_swag_offset(action, variable));
}
-static void update_actions_state(xbt_heap_float_t now,
- xbt_heap_float_t delta)
+static void update_actions_state(double now, double delta)
{
surf_action_cpu_t action = NULL;
surf_action_cpu_t next_action = NULL;
static void update_resource_state(void *id,
tmgr_trace_event_t event_type,
- xbt_maxmin_float_t value)
+ double value)
{
cpu_t cpu = id;
-/* printf("[" XBT_HEAP_FLOAT_T "] Asking to update CPU \"%s\" with value " */
-/* XBT_MAXMIN_FLOAT_T " for event %p\n", surf_get_clock(), cpu->name, */
+/* printf("[" "%lg" "] Asking to update CPU \"%s\" with value " */
+/* "%lg" " for event %p\n", surf_get_clock(), cpu->name, */
/* value, event_type); */
if (event_type == cpu->power_event) {
return;
}
-static surf_action_t execute(void *cpu, xbt_maxmin_float_t size)
+static surf_action_t execute(void *cpu, double size)
{
surf_action_cpu_t action = NULL;
cpu_t CPU = cpu;
return (surf_action_t) action;
}
-static surf_action_t action_sleep(void *cpu, xbt_maxmin_float_t duration)
+static surf_action_t action_sleep(void *cpu, double duration)
{
surf_action_cpu_t action = NULL;
surf_resource_t resource; /* Any such object, added in a trace
should start by this field!!! */
const char *name;
- xbt_maxmin_float_t power_scale;
- xbt_maxmin_float_t power_current;
+ double power_scale;
+ double power_current;
tmgr_trace_event_t power_event;
e_surf_cpu_state_t state_current;
tmgr_trace_event_t state_event;
}
lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id,
- xbt_maxmin_float_t bound_value)
+ double bound_value)
{
lmm_constraint_t cnst = NULL;
s_lmm_element_t elem;
}
lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
- xbt_maxmin_float_t weight,
- xbt_maxmin_float_t bound,
- int number_of_constraints)
+ double weight,
+ double bound, int number_of_constraints)
{
lmm_variable_t var = NULL;
lmm_var_free(sys, var);
}
-xbt_maxmin_float_t lmm_variable_getvalue(lmm_variable_t var)
+double lmm_variable_getvalue(lmm_variable_t var)
{
return (var->value);
}
void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst,
- lmm_variable_t var, xbt_maxmin_float_t value)
+ lmm_variable_t var, double value)
{
lmm_element_t elem = NULL;
make_constraint_active(sys, cnst);
}
-lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, lmm_variable_t var, int num)
+lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys,
+ lmm_variable_t var, int num)
{
- if(num<var->cnsts_number) return(var->cnsts[num].constraint);
- else return NULL;
+ if (num < var->cnsts_number)
+ return (var->cnsts[num].constraint);
+ else
+ return NULL;
}
int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var)
{
- return(var->cnsts_number);
+ return (var->cnsts_number);
}
-lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys, lmm_constraint_t cnst,
- lmm_variable_t *var)
+lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys,
+ lmm_constraint_t cnst,
+ lmm_variable_t * var)
{
- if(!(*var)) xbt_swag_getFirst(&(cnst->element_set));
- else *var=xbt_swag_getNext(*var,cnst->element_set.offset);
+ if (!(*var))
+ xbt_swag_getFirst(&(cnst->element_set));
+ else
+ *var = xbt_swag_getNext(*var, cnst->element_set.offset);
return *var;
}
}
static void saturated_constraint_set_update(lmm_system_t sys,
- lmm_constraint_t cnst,
- xbt_maxmin_float_t * min_usage)
+ lmm_constraint_t cnst,
+ double *min_usage)
{
lmm_constraint_t useless_cnst = NULL;
- if(cnst->usage <=0) return;
- if (cnst->remaining <= 0) return;
+ if (cnst->usage <= 0)
+ return;
+ if (cnst->remaining <= 0)
+ return;
if ((*min_usage < 0) || (*min_usage > cnst->remaining / cnst->usage)) {
*min_usage = cnst->remaining / cnst->usage;
- while ((useless_cnst = xbt_swag_getFirst(&(sys->saturated_constraint_set))))
+ while ((useless_cnst =
+ xbt_swag_getFirst(&(sys->saturated_constraint_set))))
xbt_swag_remove(useless_cnst, &(sys->saturated_constraint_set));
xbt_swag_insert(cnst, &(sys->saturated_constraint_set));
while ((cnst = xbt_swag_getFirst(cnst_list))) {
elem_list = &(cnst->active_element_set);
xbt_swag_foreach(elem, elem_list)
- if((elem->value>0) && (elem->variable->weight>0))
- xbt_swag_insert(elem->variable, &(sys->saturated_variable_set));
+ if ((elem->value > 0) && (elem->variable->weight > 0))
+ xbt_swag_insert(elem->variable, &(sys->saturated_variable_set));
xbt_swag_remove(cnst, cnst_list);
}
xbt_swag_t cnst_list = NULL;
xbt_swag_t var_list = NULL;
xbt_swag_t elem_list = NULL;
- xbt_maxmin_float_t min_usage = -1;
+ double min_usage = -1;
- if(!(sys->modified)) return;
+ if (!(sys->modified))
+ return;
/* Init */
var_list = &(sys->variable_set);
cnst->remaining = cnst->bound;
cnst->usage = 0;
xbt_swag_foreach(elem, elem_list) {
- if((elem->value>0) && (elem->variable->weight>0)) {
+ if ((elem->value > 0) && (elem->variable->weight > 0)) {
cnst->usage += elem->value / elem->variable->weight;
insert_active_elem_in_constraint(elem);
}
/* Not a O(1) function */
void lmm_update(lmm_system_t sys, lmm_constraint_t cnst,
- lmm_variable_t var, xbt_maxmin_float_t value)
+ lmm_variable_t var, double value)
{
int i;
}
void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var,
- xbt_maxmin_float_t bound)
+ double bound)
{
sys->modified = 1;
var->bound = bound;
}
void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var,
- xbt_maxmin_float_t weight)
+ double weight)
{
sys->modified = 1;
var->weight = weight;
}
void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst,
- xbt_maxmin_float_t bound)
+ double bound)
{
sys->modified = 1;
cnst->bound = bound;
int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst)
{
- return xbt_swag_belongs(cnst,&(sys->active_constraint_set));
+ return xbt_swag_belongs(cnst, &(sys->active_constraint_set));
}
lmm_constraint_t constraint;
lmm_variable_t variable;
- xbt_maxmin_float_t value;
+ double value;
} s_lmm_element_t, *lmm_element_t;
#define insert_elem_in_constraint(elem) xbt_swag_insert(elem,&(elem->constraint->element_set))
#define insert_active_elem_in_constraint(elem) xbt_swag_insert(elem,&(elem->constraint->active_element_set))
s_xbt_swag_t element_set; /* a list of lmm_mat_element_t */
s_xbt_swag_t active_element_set; /* a list of lmm_mat_element_t */
- xbt_maxmin_float_t bound;
- xbt_maxmin_float_t remaining;
- xbt_maxmin_float_t usage;
+ double bound;
+ double remaining;
+ double usage;
void *id;
} s_lmm_constraint_t;
s_lmm_element_t *cnsts;
int cnsts_size;
int cnsts_number;
- xbt_maxmin_float_t weight;
- xbt_maxmin_float_t bound;
- xbt_maxmin_float_t value;
+ double weight;
+ double bound;
+ double value;
void *id;
} s_lmm_variable_t;
}
static network_link_t network_link_new(const char *name,
- xbt_maxmin_float_t bw_initial,
+ double bw_initial,
tmgr_trace_t bw_trace,
- xbt_maxmin_float_t lat_initial,
+ double lat_initial,
tmgr_trace_t lat_trace,
e_surf_network_link_state_t
state_initial,
bandwidth trace latency trace state trace
Token: TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD
- Type: string float string float string ON/OFF string
+ Type: string double string double string ON/OFF string
*/
static void parse_network_link(void)
{
e_surf_token_t token;
char *name;
- xbt_maxmin_float_t bw_initial;
+ double bw_initial;
tmgr_trace_t bw_trace;
- xbt_maxmin_float_t lat_initial;
+ double lat_initial;
tmgr_trace_t lat_trace;
e_surf_network_link_state_t state_initial;
tmgr_trace_t state_trace;
name = xbt_strdup(surf_parse_text);
- surf_parse_float(&bw_initial);
+ surf_parse_double(&bw_initial);
surf_parse_trace(&bw_trace);
- surf_parse_float(&lat_initial);
+ surf_parse_double(&lat_initial);
surf_parse_trace(&lat_trace);
token = surf_parse(); /* state_initial */
return;
}
-static xbt_heap_float_t share_resources(xbt_heap_float_t now)
+static double share_resources(double now)
{
s_surf_action_network_t action;
return generic_maxmin_share_resources(surf_network_resource->
}
-static void update_actions_state(xbt_heap_float_t now,
- xbt_heap_float_t delta)
+static void update_actions_state(double now, double delta)
{
- xbt_heap_float_t deltap = 0.0;
+ double deltap = 0.0;
surf_action_network_t action = NULL;
surf_action_network_t next_action = NULL;
xbt_swag_t running_actions =
static void update_resource_state(void *id,
tmgr_trace_event_t event_type,
- xbt_maxmin_float_t value)
+ double value)
{
network_link_t nw_link = id;
-/* printf("[" XBT_HEAP_FLOAT_T "] Asking to update network card \"%s\" with value " */
-/* XBT_MAXMIN_FLOAT_T " for event %p\n", surf_get_clock(), nw_link->name, */
+/* printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
+/* "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
/* value, event_type); */
if (event_type == nw_link->bw_event) {
lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
nw_link->bw_current);
} else if (event_type == nw_link->lat_event) {
- xbt_maxmin_float_t delta = value - nw_link->lat_current;
+ double delta = value - nw_link->lat_current;
lmm_variable_t var = NULL;
surf_action_network_t action = NULL;
return;
}
-static surf_action_t communicate(void *src, void *dst,
- xbt_maxmin_float_t size)
+static surf_action_t communicate(void *src, void *dst, double size)
{
surf_action_network_t action = NULL;
network_card_t card_src = src;
#include "xbt/dict.h"
typedef enum {
- SURF_NETWORK_LINK_ON = 1, /* Ready */
- SURF_NETWORK_LINK_OFF = 0 /* Running */
+ SURF_NETWORK_LINK_ON = 1, /* Ready */
+ SURF_NETWORK_LINK_OFF = 0 /* Running */
} e_surf_network_link_state_t;
typedef struct network_link {
- surf_resource_t resource; /* Any such object, added in a trace
- should start by this field!!! */
- /* Using this object with the public part of
- resource does not make sense */
+ surf_resource_t resource; /* Any such object, added in a trace
+ should start by this field!!! */
+ /* Using this object with the public part of
+ resource does not make sense */
const char *name;
- xbt_maxmin_float_t bw_current;
+ double bw_current;
tmgr_trace_event_t bw_event;
- xbt_maxmin_float_t lat_current;
+ double lat_current;
tmgr_trace_event_t lat_event;
e_surf_network_link_state_t state_current;
tmgr_trace_event_t state_event;
typedef struct surf_action_network {
s_surf_action_t generic_action;
- xbt_heap_float_t latency;
- xbt_heap_float_t lat_current;
+ double latency;
+ double lat_current;
lmm_variable_t variable;
network_card_t src;
network_card_t dst;
#include "surf_private.h"
#include "xbt/module.h"
-static xbt_heap_float_t NOW=0;
+static double NOW = 0;
xbt_dynar_t resource_list = NULL;
tmgr_history_t history = NULL;
lmm_system_t maxmin_system = NULL;
-xbt_heap_float_t generic_maxmin_share_resources(xbt_swag_t running_actions,
- size_t offset)
+double generic_maxmin_share_resources(xbt_swag_t running_actions,
+ size_t offset)
{
surf_action_t action = NULL;
- xbt_maxmin_float_t min = -1;
- xbt_maxmin_float_t value = -1;
+ double min = -1;
+ double value = -1;
#define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + (offset))))
- lmm_solve(maxmin_system);
+ lmm_solve(maxmin_system);
xbt_swag_foreach(action, running_actions) {
value = lmm_variable_getvalue(VARIABLE(action));
- if((value>0) || (action->max_duration>=0)) break;
+ if ((value > 0) || (action->max_duration >= 0))
+ break;
}
-
+
if (!action)
return -1.0;
- if(value>0) {
+ if (value > 0) {
min = value = action->remains / value;
- if((action->max_duration>=0) &&
- (action->max_duration<min))
+ if ((action->max_duration >= 0) && (action->max_duration < min))
min = action->max_duration;
- } else min = action->max_duration;
+ } else
+ min = action->max_duration;
+
-
- for(action=xbt_swag_getNext(action,running_actions->offset);
- action;
- action=xbt_swag_getNext(action,running_actions->offset)) {
+ for (action = xbt_swag_getNext(action, running_actions->offset);
+ action;
+ action = xbt_swag_getNext(action, running_actions->offset)) {
value = lmm_variable_getvalue(VARIABLE(action));
- if(value>0) {
+ if (value > 0) {
value = action->remains / value;
- if (value < min) min = value;
+ if (value < min)
+ min = value;
}
- if((action->max_duration>=0) &&
- (action->max_duration<min))
+ if ((action->max_duration >= 0) && (action->max_duration < min))
min = action->max_duration;
}
#undef VARIABLE
e_surf_action_state_t surf_action_get_state(surf_action_t action)
{
- surf_action_state_t action_state = &(action->resource_type->common_public->states);
-
- if(action->state_set == action_state->ready_action_set)
+ surf_action_state_t action_state =
+ &(action->resource_type->common_public->states);
+
+ if (action->state_set == action_state->ready_action_set)
return SURF_ACTION_READY;
- if(action->state_set == action_state->running_action_set)
+ if (action->state_set == action_state->running_action_set)
return SURF_ACTION_RUNNING;
- if(action->state_set == action_state->failed_action_set)
+ if (action->state_set == action_state->failed_action_set)
return SURF_ACTION_FAILED;
- if(action->state_set == action_state->done_action_set)
+ if (action->state_set == action_state->done_action_set)
return SURF_ACTION_DONE;
return SURF_ACTION_NOT_IN_THE_SYSTEM;
}
{
(*action)->resource_type->common_public->action_cancel(*action);
xbt_free(*action);
- *action=NULL;
+ *action = NULL;
}
-void surf_action_change_state(surf_action_t action, e_surf_action_state_t state)
+void surf_action_change_state(surf_action_t action,
+ e_surf_action_state_t state)
{
- surf_action_state_t action_state = &(action->resource_type->common_public->states);
+ surf_action_state_t action_state =
+ &(action->resource_type->common_public->states);
xbt_swag_remove(action, action->state_set);
- if(state == SURF_ACTION_READY)
+ if (state == SURF_ACTION_READY)
action->state_set = action_state->ready_action_set;
- else if(state == SURF_ACTION_RUNNING)
+ else if (state == SURF_ACTION_RUNNING)
action->state_set = action_state->running_action_set;
- else if(state == SURF_ACTION_FAILED)
+ else if (state == SURF_ACTION_FAILED)
action->state_set = action_state->failed_action_set;
- else if(state == SURF_ACTION_DONE)
+ else if (state == SURF_ACTION_DONE)
action->state_set = action_state->done_action_set;
- else action->state_set = NULL;
+ else
+ action->state_set = NULL;
- if(action->state_set) xbt_swag_insert(action, action->state_set);
+ if (action->state_set)
+ xbt_swag_insert(action, action->state_set);
}
void surf_init(int *argc, char **argv)
{
xbt_init(argc, argv);
- if(!resource_list) resource_list = xbt_dynar_new(sizeof(surf_resource_private_t), NULL);
- if(!history) history = tmgr_history_new();
- if(!maxmin_system) maxmin_system = lmm_system_new();
+ if (!resource_list)
+ resource_list = xbt_dynar_new(sizeof(surf_resource_private_t), NULL);
+ if (!history)
+ history = tmgr_history_new();
+ if (!maxmin_system)
+ maxmin_system = lmm_system_new();
}
void surf_finalize(void)
-{
+{
int i;
surf_resource_t resource = NULL;
- xbt_dynar_foreach (resource_list,i,resource) {
+ xbt_dynar_foreach(resource_list, i, resource) {
resource->common_private->finalize();
}
- if(maxmin_system) {
+ if (maxmin_system) {
lmm_system_free(maxmin_system);
maxmin_system = NULL;
}
- if(history) {
+ if (history) {
tmgr_history_free(history);
history = NULL;
}
- if(resource_list) xbt_dynar_free(&resource_list);
+ if (resource_list)
+ xbt_dynar_free(&resource_list);
tmgr_finalize();
}
-xbt_heap_float_t surf_solve(void)
+double surf_solve(void)
{
static int first_run = 1;
- xbt_heap_float_t min = -1.0;
- xbt_heap_float_t next_event_date = -1.0;
- xbt_heap_float_t resource_next_action_end = -1.0;
- xbt_maxmin_float_t value = -1.0;
+ double min = -1.0;
+ double next_event_date = -1.0;
+ double resource_next_action_end = -1.0;
+ double value = -1.0;
surf_resource_object_t resource_obj = NULL;
surf_resource_t resource = NULL;
tmgr_trace_event_t event = NULL;
int i;
- if(first_run) {
+ if (first_run) {
while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
- if(next_event_date > NOW) break;
- while ((event = tmgr_history_get_next_event_leq(history, next_event_date,
- &value, (void **) &resource_obj))) {
- resource_obj->resource->common_private->update_resource_state(resource_obj,
- event, value);
+ if (next_event_date > NOW)
+ break;
+ while ((event =
+ tmgr_history_get_next_event_leq(history, next_event_date,
+ &value,
+ (void **) &resource_obj))) {
+ resource_obj->resource->common_private->
+ update_resource_state(resource_obj, event, value);
}
}
- xbt_dynar_foreach (resource_list,i,resource) {
+ xbt_dynar_foreach(resource_list, i, resource) {
resource->common_private->update_actions_state(NOW, 0.0);
}
first_run = 0;
min = -1.0;
- xbt_dynar_foreach (resource_list,i,resource) {
- resource_next_action_end = resource->common_private->share_resources(NOW);
- if(((min<0.0) || (resource_next_action_end<min)) && (resource_next_action_end>=0.0))
+ xbt_dynar_foreach(resource_list, i, resource) {
+ resource_next_action_end =
+ resource->common_private->share_resources(NOW);
+ if (((min < 0.0) || (resource_next_action_end < min))
+ && (resource_next_action_end >= 0.0))
min = resource_next_action_end;
}
- if(min<0.0) return 0.0;
+ if (min < 0.0)
+ return 0.0;
while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
- if(next_event_date > NOW+min) break;
- while ((event=tmgr_history_get_next_event_leq(history, next_event_date,
- &value, (void **) &resource_obj))) {
- if(resource_obj->resource->common_private->resource_used(resource_obj)) {
- min = next_event_date-NOW;
+ if (next_event_date > NOW + min)
+ break;
+ while ((event =
+ tmgr_history_get_next_event_leq(history, next_event_date,
+ &value,
+ (void **) &resource_obj))) {
+ if (resource_obj->resource->common_private->
+ resource_used(resource_obj)) {
+ min = next_event_date - NOW;
}
/* update state of resource_obj according to new value. Does not touch lmm.
It will be modified if needed when updating actions */
- resource_obj->resource->common_private->update_resource_state(resource_obj,
- event, value);
+ resource_obj->resource->common_private->
+ update_resource_state(resource_obj, event, value);
}
}
- xbt_dynar_foreach (resource_list,i,resource) {
+ xbt_dynar_foreach(resource_list, i, resource) {
resource->common_private->update_actions_state(NOW, min);
}
- NOW=NOW+min;
+ NOW = NOW + min;
return min;
}
-xbt_heap_float_t surf_get_clock(void)
+double surf_get_clock(void)
{
return NOW;
}
void surf_parse_open(const char *file) {
file_to_parse = fopen(file,"r");
- xbt_assert1((file_to_parse), "Unable to open \"%s\"\n",file)
+ xbt_assert1((file_to_parse), "Unable to open \"%s\"\n",file);
input_buffer = surf_parse__create_buffer( file_to_parse, 10 );
surf_parse__switch_to_buffer(input_buffer);
tok_num = 0;
}
-void surf_parse_float(xbt_maxmin_float_t *value)
+void surf_parse_double(double *value)
{
e_surf_token_t token;
int ret = 0;
token = surf_parse(); /* power_scale */
xbt_assert1((token == TOKEN_WORD), "Parse error line %d", line_pos);
- ret = sscanf(surf_parse_text, XBT_MAXMIN_FLOAT_T, value);
+ ret = sscanf(surf_parse_text, "%lg", value);
xbt_assert2((ret==1), "Parse error line %d : %s not a number", line_pos,
surf_parse_text);
}
#define NO_MAX_DURATION -1.0
typedef struct surf_resource_private {
- int (*resource_used)(void *resource_id);
+ int (*resource_used) (void *resource_id);
/* Share the resources to the actions and return in hom much time
- the next action may terminate */
- xbt_heap_float_t(*share_resources) (xbt_heap_float_t now);
+ the next action may terminate */
+ double (*share_resources) (double now);
/* Update the actions' state */
- void (*update_actions_state) (xbt_heap_float_t now, xbt_heap_float_t delta);
- void (*update_resource_state) (void *id,tmgr_trace_event_t event_type, xbt_maxmin_float_t value);
- void (*finalize)(void);
+ void (*update_actions_state) (double now, double delta);
+ void (*update_resource_state) (void *id, tmgr_trace_event_t event_type,
+ double value);
+ void (*finalize) (void);
} s_surf_resource_private_t;
/* #define pub2priv(r) ((surf_resource_private_t) ((char *)(r) -(sizeof(struct surf_resource_private_part)))) */
/* #define priv2pub(r) ((void *) ((char *)(r) +(sizeof(struct surf_resource_private_part)))) */
-xbt_heap_float_t generic_maxmin_share_resources(xbt_swag_t running_actions,
- size_t offset);
+double generic_maxmin_share_resources(xbt_swag_t running_actions,
+ size_t offset);
/* Generic functions common to all ressources */
e_surf_action_state_t surf_action_get_state(surf_action_t action);
void surf_action_free(surf_action_t * action);
-void surf_action_change_state(surf_action_t action, e_surf_action_state_t state);
+void surf_action_change_state(surf_action_t action,
+ e_surf_action_state_t state);
extern lmm_system_t maxmin_system;
extern tmgr_history_t history;
FILE *f = NULL;
int linecount = 0;
char line[256];
- xbt_heap_float_t periodicity = -1.0; /* No periodicity by default */
+ double periodicity = -1.0; /* No periodicity by default */
s_tmgr_event_t event;
tmgr_event_t last_event = NULL;
}
if ((f = fopen(filename, "r")) == NULL) {
- xbt_assert1(0,"Cannot open file '%s'", filename);
+ xbt_assert1(0, "Cannot open file '%s'", filename);
}
trace = xbt_new0(s_tmgr_trace_t, 1);
if ((line[0] == '#') || (line[0] == '\n') || (line[0] == '%'))
continue;
- if (sscanf(line, "PERIODICITY " XBT_HEAP_FLOAT_T "\n", &(periodicity))
+ if (sscanf(line, "PERIODICITY " "%lg" "\n", &(periodicity))
== 1) {
if (periodicity <= 0) {
- xbt_assert2(0,"%s,%d: Syntax error. Periodicity has to be positive",
+ xbt_assert2(0,
+ "%s,%d: Syntax error. Periodicity has to be positive",
filename, linecount);
}
continue;
}
if (sscanf
- (line, XBT_HEAP_FLOAT_T " " XBT_MAXMIN_FLOAT_T "\n", &event.delta,
- &event.value) != 2) {
- xbt_assert2(0,"%s,%d: Syntax error", filename, linecount);
+ (line, "%lg" " " "%lg" "\n", &event.delta, &event.value) != 2) {
+ xbt_assert2(0, "%s,%d: Syntax error", filename, linecount);
}
if (last_event) {
if ((last_event->delta = event.delta - last_event->delta) <= 0) {
- xbt_assert2(0,"%s,%d: Invalid trace value, events have to be sorted",
+ xbt_assert2(0,
+ "%s,%d: Invalid trace value, events have to be sorted",
filename, linecount);
}
}
xbt_free(trace);
}
-tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t history, tmgr_trace_t trace,
- xbt_heap_float_t start_time, int offset,
+tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t history,
+ tmgr_trace_t trace,
+ double start_time, int offset,
void *resource)
{
tmgr_trace_event_t trace_event = NULL;
return trace_event;
}
-xbt_heap_float_t tmgr_history_next_date(tmgr_history_t history)
+double tmgr_history_next_date(tmgr_history_t history)
{
if (xbt_heap_size(history->heap))
return (xbt_heap_maxkey(history->heap));
}
tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t history,
- xbt_heap_float_t date,
- xbt_maxmin_float_t * value,
+ double date,
+ double *value,
void **resource)
{
- xbt_heap_float_t event_date = xbt_heap_maxkey(history->heap);
+ double event_date = xbt_heap_maxkey(history->heap);
tmgr_trace_event_t trace_event = NULL;
tmgr_event_t event = NULL;
tmgr_trace_t trace = NULL;
#include "surf/trace_mgr.h"
typedef struct tmgr_event {
- xbt_heap_float_t delta;
- xbt_maxmin_float_t value;
+ double delta;
+ double value;
} s_tmgr_event_t, *tmgr_event_t;
typedef struct tmgr_trace {
return;
}
-static xbt_heap_float_t share_resources(xbt_heap_float_t now)
+static double share_resources(double now)
{
return -1.0;
}
-static void update_actions_state(xbt_heap_float_t now,
- xbt_heap_float_t delta)
+static void update_actions_state(double now, double delta)
{
return;
}
static void update_resource_state(void *id,
tmgr_trace_event_t event_type,
- xbt_maxmin_float_t value)
+ double value)
{
return;
}
-static surf_action_t execute(void *workstation, xbt_maxmin_float_t size)
+static surf_action_t execute(void *workstation, double size)
{
return surf_cpu_resource->extension_public->
execute(((workstation_t) workstation)->cpu, size);
}
-static surf_action_t action_sleep(void *workstation,
- xbt_maxmin_float_t duration)
+static surf_action_t action_sleep(void *workstation, double duration)
{
return surf_cpu_resource->extension_public->
sleep(((workstation_t) workstation)->cpu, duration);
}
static surf_action_t communicate(void *workstation_src,
- void *workstation_dst,
- xbt_maxmin_float_t size)
+ void *workstation_dst, double size)
{
return surf_network_resource->extension_public->
communicate(((workstation_t) workstation_src)->network_card,
#include "xbt/sysdep.h"
#include "xbt/error.h"
#include "heap_private.h"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(heap,xbt,"Heap");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(heap, xbt, "Heap");
/**
* xbt_heap_new:
* Add an element int the heap. The element with the smallest key is
* automatically moved at the top of the heap.
*/
-void xbt_heap_push(xbt_heap_t H, void *content, xbt_heap_float_t key)
+void xbt_heap_push(xbt_heap_t H, void *content, double key)
{
int count = ++(H->count);
int size = H->size;
*/
void *xbt_heap_pop(xbt_heap_t H)
{
- void *max ;
+ void *max;
- if(H->count==0) return NULL;
+ if (H->count == 0)
+ return NULL;
max = CONTENT(H, 0);
*
* Returns the smallest key in the heap without modifying the heap.
*/
-xbt_heap_float_t xbt_heap_maxkey(xbt_heap_t H)
+double xbt_heap_maxkey(xbt_heap_t H)
{
- if(H->count==0) abort();
+ if (H->count == 0)
+ abort();
return KEY(H, 0);
}
*/
void *xbt_heap_maxcontent(xbt_heap_t H)
{
- if(H->count==0) abort();
+ if (H->count == 0)
+ abort();
return CONTENT(H, 0);
}
typedef struct xbt_heapItem {
void *content;
- xbt_heap_float_t key;
+ double key;
} s_xbt_heapItem_t, *xbt_heapItem_t;
typedef struct xbt_heap {
#include <stdlib.h>
#include <stdio.h>
#include "surf/maxmin.h"
-#include "gras/virtu.h" /* time manipulation for benchmarking */
+#include "gras/virtu.h" /* time manipulation for benchmarking */
double date;
-xbt_maxmin_float_t float_random(xbt_maxmin_float_t max);
-xbt_maxmin_float_t float_random(xbt_maxmin_float_t max)
+double float_random(double max);
+double float_random(double max)
{
return ((max * rand()) / (RAND_MAX + 1.0));
}
+/* $Id$ */
<CPU>
"Cpu A" 100.00 1.0 trace_A.txt ON trace_A_failure.txt
e_surf_action_state_t stateActionA;
e_surf_action_state_t stateActionB;
e_surf_action_state_t stateActionC;
- xbt_maxmin_float_t now = -1.0;
+ double now = -1.0;
- surf_cpu_resource_init("platform.txt"); /* Now it is possible to use CPUs */
- surf_network_resource_init("platform.txt"); /* Now it is possible to use eth0 */
+ surf_cpu_resource_init("platform.txt"); /* Now it is possible to use CPUs */
+ surf_network_resource_init("platform.txt"); /* Now it is possible to use eth0 */
/*********************** CPU ***********************************/
printf("%p \n", surf_cpu_resource);
cpuB = surf_cpu_resource->common_public->name_service("Cpu B");
/* Let's check that those two processors exist */
- printf("%s : %p\n", surf_cpu_resource->common_public->get_resource_name(cpuA), cpuA);
- printf("%s : %p\n", surf_cpu_resource->common_public->get_resource_name(cpuB), cpuB);
+ printf("%s : %p\n",
+ surf_cpu_resource->common_public->get_resource_name(cpuA), cpuA);
+ printf("%s : %p\n",
+ surf_cpu_resource->common_public->get_resource_name(cpuB), cpuB);
/* Let's do something on it */
actionA = surf_cpu_resource->extension_public->execute(cpuA, 1000.0);
cardB = surf_network_resource->common_public->name_service("Cpu B");
/* Let's check that those two processors exist */
- printf("%s : %p\n", surf_network_resource->common_public->get_resource_name(cardA), cardA);
- printf("%s : %p\n", surf_network_resource->common_public->get_resource_name(cardB), cardB);
+ printf("%s : %p\n",
+ surf_network_resource->common_public->get_resource_name(cardA),
+ cardA);
+ printf("%s : %p\n",
+ surf_network_resource->common_public->get_resource_name(cardB),
+ cardB);
/* Let's do something on it */
- commAB = surf_network_resource->extension_public->communicate(cardA, cardB, 150.0);
+ commAB =
+ surf_network_resource->extension_public->communicate(cardA, cardB,
+ 150.0);
- surf_solve(); /* Takes traces into account. Returns 0.0 */
+ surf_solve(); /* Takes traces into account. Returns 0.0 */
do {
- surf_action_t action = NULL;
+ surf_action_t action = NULL;
now = surf_get_clock();
- printf("Next Event : " XBT_HEAP_FLOAT_T "\n", now);
+ printf("Next Event : " "%lg" "\n", now);
printf("\t CPU actions\n");
- while((action=xbt_swag_extract(surf_cpu_resource->common_public->states.failed_action_set))) {
+ while ((action =
+ xbt_swag_extract(surf_cpu_resource->common_public->states.
+ failed_action_set))) {
printf("\t * Failed : %p\n", action);
action->resource_type->common_public->action_free(action);
}
- while((action=xbt_swag_extract(surf_cpu_resource->common_public->states.done_action_set))) {
+ while ((action =
+ xbt_swag_extract(surf_cpu_resource->common_public->states.
+ done_action_set))) {
printf("\t * Done : %p\n", action);
action->resource_type->common_public->action_free(action);
}
printf("\t Network actions\n");
- while((action=xbt_swag_extract(surf_network_resource->common_public->states.failed_action_set))) {
+ while ((action =
+ xbt_swag_extract(surf_network_resource->common_public->states.
+ failed_action_set))) {
printf("\t * Failed : %p\n", action);
action->resource_type->common_public->action_free(action);
}
- while((action=xbt_swag_extract(surf_network_resource->common_public->states.done_action_set))) {
+ while ((action =
+ xbt_swag_extract(surf_network_resource->common_public->states.
+ done_action_set))) {
printf("\t * Done : %p\n", action);
action->resource_type->common_public->action_free(action);
}
- } while(surf_solve());
+ } while (surf_solve());
printf("Simulation Terminated\n");
int main(int argc, char **argv)
{
- surf_init(&argc, argv); /* Initialize some common structures */
+ surf_init(&argc, argv); /* Initialize some common structures */
test();
return 0;
}
e_surf_action_state_t stateActionA;
e_surf_action_state_t stateActionB;
e_surf_action_state_t stateActionC;
- xbt_maxmin_float_t now = -1.0;
+ double now = -1.0;
surf_workstation_resource_init("platform.txt");
surf_resource_t resource = NULL;
now = surf_get_clock();
- printf("Next Event : " XBT_HEAP_FLOAT_T "\n", now);
-
- xbt_dynar_foreach (resource_list,i,resource) {
+ printf("Next Event : " "%lg" "\n", now);
+
+ xbt_dynar_foreach(resource_list, i, resource) {
printf("\t %s actions\n", resource->common_public->name);
while (action =
xbt_swag_extract(resource->common_public->states.
tmgr_history_t history = tmgr_history_new();
tmgr_trace_t trace_A = tmgr_trace_new("trace_A.txt");
tmgr_trace_t trace_B = tmgr_trace_new("trace_B.txt");
- xbt_heap_float_t next_event_date = -1.0;
- xbt_maxmin_float_t value = -1.0;
+ double next_event_date = -1.0;
+ double value = -1.0;
char *resource = NULL;
char *host_A = strdup("Host A");
char *host_B = strdup("Host B");
tmgr_history_add_trace(history, trace_B, 0.0, 0, host_B);
while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
- printf(XBT_HEAP_FLOAT_T " : \n", next_event_date);
+ printf("%lg" " : \n", next_event_date);
while (tmgr_history_get_next_event_leq(history, next_event_date,
&value, (void **) &resource)) {
- printf("\t %s : " XBT_MAXMIN_FLOAT_T "\n", resource, value);
+ printf("\t %s : " "%lg" "\n", resource, value);
}
if (next_event_date > 1000)
break;
#include <stdio.h>
#include "xbt/heap.h"
-#include "gras/virtu.h" /* time manipulation in bench */
+#include "gras/virtu.h" /* time manipulation in bench */
#define MAX_TEST 1000000
-int compare_xbt_heap_float_t(const void *a, const void *b);
+int compare_double(const void *a, const void *b);
void test_heap_validity(int size);
void test_heap_mean_operation(int size);
-int compare_xbt_heap_float_t(const void *a, const void *b)
+int compare_double(const void *a, const void *b)
{
- xbt_heap_float_t pa, pb;
+ double pa, pb;
- pa = *((xbt_heap_float_t *) a);
- pb = *((xbt_heap_float_t *) b);
+ pa = *((double *) a);
+ pb = *((double *) b);
if (pa > pb)
return 1;
void test_heap_validity(int size)
{
xbt_heap_t heap = xbt_heap_new(size, NULL);
- xbt_heap_float_t *tab = calloc(size, sizeof(xbt_heap_float_t));
+ double *tab = calloc(size, sizeof(double));
int i;
for (i = 0; i < size; i++) {
xbt_heap_push(heap, NULL, tab[i]);
}
- qsort(tab, size, sizeof(xbt_heap_float_t), compare_xbt_heap_float_t);
+ qsort(tab, size, sizeof(double), compare_double);
for (i = 0; i < size; i++) {
- /* printf(XBT_HEAP_FLOAT_T " ", xbt_heap_maxkey(heap)); */
+ /* printf("%lg" " ", xbt_heap_maxkey(heap)); */
if (xbt_heap_maxkey(heap) != tab[i]) {
fprintf(stderr, "Problem !\n");
exit(1);
void test_heap_mean_operation(int size)
{
xbt_heap_t heap = xbt_heap_new(size, NULL);
- xbt_heap_float_t val;
+ double val;
double date = 0;
int i, j;