* Implement MPI_Waitany and MPI_Waitall
SURF:
- * Factorize model_init/exit between models
* Declare common_public as an embeeded struct to reduce redirections
and mallocs
+ * Factorize model_init/exit between models
+ * Factorize the set of resources within common_public;
+ + change model->common_model->resource_name()
+ into surf_model_resource_by_name(model)
+ (less redirections, less function to write when defining a model)
XBT:
* Add xbt_set_get_by_name_or_null() [Silas De Munck]
typedef struct surf_model_public {
s_surf_action_state_t states;
/**< Any living action on this model */
- void *(*name_service) (const char *name);
- /**< Return a model given its name */
const char *(*get_resource_name) (void *resource_id);
/**< Return the name of a resource */
/**< Return the properties dictionary */
const char *name;
/**< Name of this model */
+ xbt_dict_t resource_set;
} s_surf_model_public_t, *surf_model_public_t;
/** \brief Private data available on all models
} s_surf_model_t;
void surf_model_init(surf_model_t model);
+ void* surf_model_resource_by_name(void* model, const char *name);
+#define surf_model_resource_set(model) (model)->common_public.resource_set
void surf_model_exit(surf_model_t model);
*
* \see link_set
*/
-XBT_PUBLIC_DATA(xbt_dict_t) workstation_set;
-XBT_PUBLIC_DATA(xbt_dict_t) cpu_set;
+/*XBT_PUBLIC_DATA(xbt_dict_t) workstation_set; //KILLME
+XBT_PUBLIC_DATA(xbt_dict_t) cpu_set; //KILLME*/
/** \brief List of initialized models
* \ingroup SURF_models
*/
parse_platform_file(platform_file);
/* now let's create the SD wrappers for workstations and links */
- xbt_dict_foreach(workstation_set, cursor, name, surf_workstation) {
+ xbt_dict_foreach(surf_model_resource_set(surf_workstation_model), cursor, name, surf_workstation) {
__SD_workstation_create(surf_workstation, NULL);
}
end = xbt_os_time();
DEBUG1("PARSE TIME: %lg", (end - start));
- xbt_dict_foreach(workstation_set, cursor, name, workstation) {
+ xbt_dict_foreach(surf_model_resource_set(surf_workstation_model), cursor, name, workstation) {
__SIMIX_host_create(name, workstation, NULL);
}
surf_cpu_model_t surf_cpu_model = NULL;
lmm_system_t cpu_maxmin_system = NULL;
-xbt_dict_t cpu_set = NULL;
+
static xbt_swag_t running_action_set_that_does_not_need_being_checked = NULL;
static void cpu_free(void *cpu)
xbt_dict_t cpu_properties)
{
cpu_Cas01_t cpu = xbt_new0(s_cpu_Cas01_t, 1);
- xbt_assert1(!xbt_dict_get_or_null(cpu_set, name),
+ xbt_assert1(!surf_model_resource_by_name(surf_cpu_model, name),
"Host '%s' declared several times in the platform file", name);
cpu->model = (surf_model_t) surf_cpu_model;
cpu->name = name;
current_property_set = cpu_properties;
- xbt_dict_set(cpu_set, name, cpu, cpu_free);
+ xbt_dict_set(surf_model_resource_set(surf_cpu_model), name, cpu, cpu_free);
return cpu;
}
/* connect all traces relative to hosts */
xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- cpu_Cas01_t host = xbt_dict_get_or_null(cpu_set, elm);
+ cpu_Cas01_t host = surf_model_resource_by_name((surf_model_t)surf_cpu_model, elm);
xbt_assert1(host, "Host %s undefined", elm);
xbt_assert1(trace, "Trace %s undefined", trace_name);
xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- cpu_Cas01_t host = xbt_dict_get_or_null(cpu_set, elm);
+ cpu_Cas01_t host = surf_model_resource_by_name((surf_model_t)surf_cpu_model, elm);
xbt_assert1(host, "Host %s undefined", elm);
xbt_assert1(trace, "Trace %s undefined", trace_name);
surfxml_add_callback(STag_surfxml_host_cb_list, parse_cpu_init);
}
-static void *name_service(const char *name)
-{
- return xbt_dict_get_or_null(cpu_set, name);
-}
-
static const char *get_resource_name(void *resource_id)
{
return ((cpu_Cas01_t) resource_id)->name;
static void finalize(void)
{
- xbt_dict_free(&cpu_set);
lmm_system_free(cpu_maxmin_system);
cpu_maxmin_system = NULL;
running_action_set_that_does_not_need_being_checked =
xbt_swag_new(xbt_swag_offset(action, state_hookup));
- surf_cpu_model->common_public.name_service = name_service;
surf_cpu_model->common_public.get_resource_name = get_resource_name;
surf_cpu_model->common_public.action_get_state = surf_action_get_state;
surf_cpu_model->common_public.action_get_start_time =
/*manage the properties of the cpu */
surf_cpu_model->common_public.get_properties = get_properties;
- if (!cpu_set)
- cpu_set = xbt_dict_new();
if (!cpu_maxmin_system)
cpu_maxmin_system = lmm_system_new();
}
xbt_dict_t properties;
} s_cpu_Cas01_t, *cpu_Cas01_t;
-extern xbt_dict_t cpu_set;
-
#endif /* _SURF_CPU_PRIVATE_H */
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "surf_private.h"
+#include "xbt/dict.h"
static void void_die_impossible_paction(surf_action_t action) {
DIE_IMPOSSIBLE;
xbt_swag_new(xbt_swag_offset(action, state_hookup));
model->common_public.states.done_action_set =
xbt_swag_new(xbt_swag_offset(action, state_hookup));
+ model->common_public.resource_set = xbt_dict_new();
model->common_public.action_free = int_die_impossible_paction;
model->common_public.action_cancel = void_die_impossible_paction;
}
+void* surf_model_resource_by_name(void* model, const char *name) {
+ return xbt_dict_get_or_null(((surf_model_t)model)->common_public.resource_set,name);
+}
+
/** @brief finalize common datastructures to all models */
void surf_model_exit(surf_model_t model) {
xbt_swag_free(model->common_public.states.running_action_set);
xbt_swag_free(model->common_public.states.failed_action_set);
xbt_swag_free(model->common_public.states.done_action_set);
+ xbt_dict_free(&model->common_public.resource_set);
free(model->common_private);
}
static lmm_system_t network_maxmin_system = NULL;
static void (*network_solve) (lmm_system_t) = NULL;
xbt_dict_t link_set = NULL;
-xbt_dict_t network_card_set = NULL;
double latency_factor = 1.0; /* default value */
double bandwidth_factor = 1.0; /* default value */
static int network_card_new(const char *card_name)
{
network_card_CM02_t card =
- xbt_dict_get_or_null(network_card_set, card_name);
+ surf_model_resource_by_name(surf_network_model,card_name);
if (!card) {
card = xbt_new0(s_network_card_CM02_t, 1);
card->name = xbt_strdup(card_name);
card->id = host_number++;
- xbt_dict_set(network_card_set, card_name, card, network_card_free);
+ xbt_dict_set(surf_model_resource_set(surf_network_model), card_name, card, network_card_free);
}
return card->id;
}
surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
}
-static void *name_service(const char *name)
-{
- network_card_CM02_t card = xbt_dict_get_or_null(network_card_set, name);
- return card;
-}
-
static const char *get_resource_name(void *resource_id)
{
return ((network_card_CM02_t) resource_id)->name;
{
int i, j;
- xbt_dict_free(&network_card_set);
xbt_dict_free(&link_set);
surf_model_exit((surf_model_t)surf_network_model);
surf_network_model->extension_public =
xbt_new0(s_surf_network_model_extension_public_t, 1);
- surf_network_model->common_public.name_service = name_service;
surf_network_model->common_public.get_resource_name = get_resource_name;
surf_network_model->common_public.action_get_state = surf_action_get_state;
surf_network_model->common_public.action_get_start_time =
surf_network_model->common_public.get_properties = get_properties;
link_set = xbt_dict_new();
- network_card_set = xbt_dict_new();
if (!network_maxmin_system)
network_maxmin_system = lmm_system_new();
#ifndef _SURF_NETWORK_COMMON_H
#define _SURF_NETWORK_COMMON_H
-#include "xbt/dict.h"
-
-extern xbt_dict_t network_card_set;
#endif /* _SURF_NETWORK_COMMON_H */
static int network_card_new(const char *card_name)
{
network_card_Constant_t card =
- xbt_dict_get_or_null(network_card_set, card_name);
+ surf_model_resource_by_name(surf_network_model,card_name);
if (!card) {
card = xbt_new0(s_network_card_Constant_t, 1);
card->name = xbt_strdup(card_name);
card->id = card_number++;
- xbt_dict_set(network_card_set, card_name, card, network_card_free);
+ xbt_dict_set(surf_model_resource_set(surf_network_model), card_name, card, network_card_free);
}
return card->id;
}
surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
}
-static void *name_service(const char *name)
-{
- network_card_Constant_t card = xbt_dict_get_or_null(network_card_set, name);
- return card;
-}
-
static const char *get_resource_name(void *resource_id)
{
return ((network_card_Constant_t) resource_id)->name;
static void finalize(void)
{
- xbt_dict_free(&network_card_set);
-
surf_model_exit((surf_model_t)surf_network_model);
free(surf_network_model->extension_public);
surf_network_model->extension_public =
xbt_new0(s_surf_network_model_extension_public_t, 1);
- surf_network_model->common_public.name_service = name_service;
surf_network_model->common_public.get_resource_name = get_resource_name;
surf_network_model->common_public.action_get_state = surf_action_get_state;
surf_network_model->common_public.action_get_start_time =
surf_network_model->common_public.get_properties = get_properties;
- network_card_set = xbt_dict_new();
-
if (!random_latency)
random_latency = random_new(RAND, 100, 0.0, 1.0, .125, .034);
}
XBT_IN1("(%s)", name);
/* KF: Check that we haven't seen the network card before */
- network_card_GTNETS_t card = xbt_dict_get_or_null(network_card_set, name);
+ network_card_GTNETS_t card = surf_model_resource_by_name(surf_network_model, name);
if (!card) {
/* KF: Increment the card counter for GTNetS */
card = xbt_new0(s_network_card_GTNETS_t, 1);
card->name = xbt_strdup(name);
card->id = card_count;
- xbt_dict_set(network_card_set, name, card, network_card_free);
+ xbt_dict_set(surf_model_resource_set(surf_network_model), name, card, network_card_free);
}
LOG1(xbt_log_priority_trace, " return %d", card->id);
surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
}
-static void *name_service(const char *name)
-{
- return xbt_dict_get_or_null(network_card_set, name);
-}
-
static const char *get_resource_name(void *resource_id)
{
return ((network_card_GTNETS_t) resource_id)->name;
static void finalize(void)
{
- xbt_dict_free(&network_card_set);
xbt_dict_free(&link_set);
surf_model_exit((surf_model_t)surf_network_model);
surf_network_model->common_public.get_properties = get_properties;
link_set = xbt_dict_new();
- network_card_set = xbt_dict_new();
/* KF: Added the initialization for GTNetS interface */
if (gtnets_initialize()) {
network_card_GTNETS_t dst;
} s_surf_action_network_GTNETS_t, *surf_action_network_GTNETS_t;
-extern xbt_dict_t network_card_set;
+//extern xbt_dict_t network_card_set;
#endif /* _SURF_NETWORK_PRIVATE_H */
{
}
-static void *name_service(const char *name)
-{
- DIE_IMPOSSIBLE;
- return NULL;
-}
-
static const char *get_resource_name(void *resource_id)
{
DIE_IMPOSSIBLE;
surf_timer_model->extension_public =
xbt_new0(s_surf_timer_model_extension_public_t, 1);
- surf_timer_model->common_public.name_service = name_service;
surf_timer_model->common_public.get_resource_name = get_resource_name;
surf_timer_model->common_public.action_get_state = surf_action_get_state;
surf_timer_model->common_public.action_change_state = action_change_state;
if (!route_multi_elements)
return;
- set = cpu_set;
- DEBUG1("%d", xbt_dict_length(workstation_set));
- if (workstation_set != NULL && xbt_dict_length(workstation_set) > 0)
- set = workstation_set;
+ if (surf_cpu_model)
+ set = surf_model_resource_set(surf_cpu_model);
+ if (surf_workstation_model != NULL &&
+ surf_model_resource_set(surf_workstation_model) != NULL &&
+ xbt_dict_length(surf_model_resource_set(surf_workstation_model)) > 0)
+ set = surf_model_resource_set(surf_workstation_model);
push_surfxml_bufferstack(0);
"Logging specific to the SURF workstation module");
surf_workstation_model_t surf_workstation_model = NULL;
-xbt_dict_t workstation_set = NULL;
+
+static void workstation_free(void *workstation)
+{
+ free(((workstation_CLM03_t) workstation)->name);
+ free(workstation);
+}
static workstation_CLM03_t workstation_new(const char *name,
void *cpu, void *card)
workstation->cpu = cpu;
workstation->network_card = card;
- return workstation;
-}
+ xbt_dict_set(surf_model_resource_set(surf_workstation_model),name,workstation,workstation_free);
-static void workstation_free(void *workstation)
-{
- free(((workstation_CLM03_t) workstation)->name);
- free(workstation);
+ return workstation;
}
void create_workstations(void)
void *cpu = NULL;
void *nw_card = NULL;
- xbt_dict_foreach(cpu_set, cursor, name, cpu) {
- nw_card = xbt_dict_get_or_null(network_card_set, name);
+ xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, name, cpu) {
+ nw_card = surf_model_resource_by_name(surf_network_model, name);
xbt_assert1(nw_card, "No corresponding card found for %s", name);
- xbt_dict_set(workstation_set, name,
- workstation_new(name, cpu, nw_card), workstation_free);
+ workstation_new(name,cpu,nw_card);
}
}
-static void *name_service(const char *name)
-{
- return xbt_dict_get_or_null(workstation_set, name);
-}
-
static const char *get_resource_name(void *resource_id)
{
return ((workstation_CLM03_t) resource_id)->name;
static void finalize(void)
{
- xbt_dict_free(&workstation_set);
-
surf_model_exit((surf_model_t)surf_workstation_model);
free(surf_workstation_model->extension_public);
surf_workstation_model->extension_public =
xbt_new0(s_surf_workstation_model_extension_public_t, 1);
- surf_workstation_model->common_public.name_service = name_service;
surf_workstation_model->common_public.get_resource_name =
get_resource_name;
surf_workstation_model->common_public.action_get_state =
surf_workstation_model->extension_public->get_link_latency =
get_link_latency;
surf_workstation_model->extension_public->link_shared = link_shared;
-
- workstation_set = xbt_dict_new();
}
/********************************************************************/
#include "xbt/str.h"
#include "xbt/dict.h"
#include "surf_private.h"
-/* extern lmm_system_t maxmin_system; */
typedef enum {
SURF_WORKSTATION_RESOURCE_CPU,
/******* Resource Public **********/
/**************************************/
-static void *name_service(const char *name)
-{
- return xbt_dict_get_or_null(workstation_set, name);
-}
-
static const char *get_resource_name(void *resource_id)
{
/* We can freely cast as a cpu_L07_t because it has the same
int i, j;
xbt_dict_free(&link_set);
- xbt_dict_free(&workstation_set);
if (parallel_task_link_set != NULL) {
xbt_dict_free(¶llel_task_link_set);
}
tmgr_trace_t state_trace, xbt_dict_t cpu_properties)
{
cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
- xbt_assert1(!xbt_dict_get_or_null(workstation_set, name),
+ xbt_assert1(!surf_model_resource_by_name(surf_workstation_model, name),
"Host '%s' declared several times in the platform file.", name);
cpu->model = (surf_model_t) surf_workstation_model;
/*add the property set */
cpu->properties = current_property_set;
- xbt_dict_set(workstation_set, name, cpu, cpu_free);
+ xbt_dict_set(surf_model_resource_set(surf_workstation_model), name, cpu, cpu_free);
return cpu;
}
{
cpu_L07_t cpu_tmp = NULL;
- cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_src);
+ cpu_tmp = (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model, A_surfxml_route_src);
xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src);
if (cpu_tmp != NULL)
src_id = cpu_tmp->id;
- cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_dst);
+ cpu_tmp = (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model, A_surfxml_route_dst);
xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_dst);
if (cpu_tmp != NULL)
dst_id = cpu_tmp->id;
/* Connect traces relative to cpu */
xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- cpu_L07_t host = xbt_dict_get_or_null(workstation_set, elm);
+ cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
xbt_assert1(host, "Host %s undefined", elm);
xbt_assert1(trace, "Trace %s undefined", trace_name);
xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- cpu_L07_t host = xbt_dict_get_or_null(workstation_set, elm);
+ cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
xbt_assert1(host, "Host %s undefined", elm);
xbt_assert1(trace, "Trace %s undefined", trace_name);
link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
}
-/*
-
- xbt_dynar_foreach (traces_connect_list, cpt, value) {
- trace_connect = xbt_str_split_str(value, "#");
- trace_id = xbt_dynar_get_as(trace_connect, 0, char*);
- connect_element = atoi(xbt_dynar_get_as(trace_connect, 1, char*));
- connect_kind = atoi(xbt_dynar_get_as(trace_connect, 2, char*));
- connector_id = xbt_dynar_get_as(trace_connect, 3, char*);
-
- xbt_assert1((trace = xbt_dict_get_or_null(traces_set_list, trace_id)), "Trace %s undefined", trace_id);
-
- if (connect_element == A_surfxml_trace_c_connect_element_HOST) {
- xbt_assert1((host = xbt_dict_get_or_null(workstation_set, connector_id)), "Host %s undefined", connector_id);
- switch (connect_kind) {
- case A_surfxml_trace_c_connect_kind_AVAILABILITY: host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); break;
- case A_surfxml_trace_c_connect_kind_POWER: host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); break;
- }
- }
- else {
- xbt_assert1((link = xbt_dict_get_or_null(link_set, connector_id)), "Link %s undefined", connector_id);
- switch (connect_kind) {
- case A_surfxml_trace_c_connect_kind_AVAILABILITY: link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
- case A_surfxml_trace_c_connect_kind_BANDWIDTH: link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
- case A_surfxml_trace_c_connect_kind_LATENCY: link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
- }
- }
- }
-*/
}
static void define_callbacks(const char *file)
surf_workstation_model->extension_public =
xbt_new0(s_surf_workstation_model_extension_public_t, 1);
- surf_workstation_model->common_public.name_service = name_service;
surf_workstation_model->common_public.get_resource_name =
get_resource_name;
surf_workstation_model->common_public.action_get_state =
surf_workstation_model->common_public.get_properties = get_properties;
- workstation_set = xbt_dict_new();
link_set = xbt_dict_new();
if (!ptask_maxmin_system)