From: thiery Date: Mon, 19 Jun 2006 13:02:30 +0000 (+0000) Subject: Implement link names in SimDag. X-Git-Tag: v3.3~2965 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/702d6d0fe6771c35145c22266e0271c0c7daf0b7 Implement link names in SimDag. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2393 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/simdag/private.h b/src/simdag/private.h index c3d0f13338..7884ad004c 100644 --- a/src/simdag/private.h +++ b/src/simdag/private.h @@ -12,26 +12,27 @@ typedef struct SD_global { xbt_dict_t workstations; /* workstation list */ int workstation_count; /* number of workstations */ + xbt_dict_t links; /* link list */ } s_SD_global_t, *SD_global_t; extern SD_global_t sd_global; /* Link private data */ typedef struct SD_link_data { - void* surf_link; /* surf object */ - + void *surf_link; /* surf object */ + char *name; } s_SD_link_data_t; /* Workstation private data */ typedef struct SD_workstation_data { - void* surf_workstation; /* surf object */ + void *surf_workstation; /* surf object */ /* TODO: route */ } s_SD_workstation_data_t; /* Private functions */ -SD_link_t __SD_link_create(const char *name, void *surf_link, void *data); -void __SD_link_destroy(SD_link_t link); +SD_link_t __SD_link_create(void *surf_link, char *name, void *data); +void __SD_link_destroy(void *link); SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data); void __SD_workstation_destroy(void *workstation); diff --git a/src/simdag/sd_global.c b/src/simdag/sd_global.c index 8ce1104122..bf190c0449 100644 --- a/src/simdag/sd_global.c +++ b/src/simdag/sd_global.c @@ -14,25 +14,43 @@ void SD_init(int *argc, char **argv) { sd_global = xbt_new0(s_SD_global_t, 1); sd_global->workstations = xbt_dict_new(); sd_global->workstation_count = 0; + /*sd_global->links = xbt_dynar_new(sizeof(s_SD_link_t), __SD_link_destroy);*/ + sd_global->links = xbt_dict_new(); surf_init(argc, argv); } -/* Creates the environnement described in a xml file of a platform descriptions. +/* Creates the environnement described in a xml file of a platform description. */ void SD_create_environment(const char *platform_file) { xbt_dict_cursor_t cursor = NULL; char *name = NULL; void *surf_workstation = NULL; + void *surf_link = NULL; CHECK_INIT_DONE(); - surf_timer_resource_init(platform_file); - surf_workstation_resource_init_KCCFLN05(platform_file); /* tell Surf to create the environnement */ - /* now let's create the SD wrappers */ + surf_timer_resource_init(platform_file); /* tell Surf to create the environnement */ + + + /*printf("surf_workstation_resource = %p, workstation_set = %p\n", surf_workstation_resource, workstation_set); + printf("surf_network_resource = %p, network_link_set = %p\n", surf_network_resource, network_link_set);*/ + + surf_workstation_resource_init_KCCFLN05(platform_file); + /* surf_workstation_resource_init_CLM03(platform_file);*/ + + /*printf("surf_workstation_resource = %p, workstation_set = %p\n", surf_workstation_resource, workstation_set); + printf("surf_network_resource = %p, network_link_set = %p\n", surf_network_resource, network_link_set);*/ + + + /* now let's create the SD wrappers for workstations and links */ xbt_dict_foreach(workstation_set, cursor, name, surf_workstation) { __SD_workstation_create(surf_workstation, NULL); } + + xbt_dict_foreach(network_link_set, cursor, name, surf_link) { + __SD_link_create(surf_link, name, NULL); + } } /* Launches the simulation. Returns a NULL-terminated array of SD_task_t whose state has changed. @@ -41,11 +59,12 @@ SD_task_t* SD_simulate(double how_long) { /* TODO */ - /* temporary test to explore the workstations */ + /* temporary test to explore the workstations and the links */ xbt_dict_cursor_t cursor = NULL; char *name = NULL; SD_workstation_t workstation = NULL; double power, available_power; + SD_link_t link = NULL; surf_solve(); @@ -54,7 +73,10 @@ SD_task_t* SD_simulate(double how_long) available_power = SD_workstation_get_available_power(workstation); printf("Workstation name: %s, power: %f Mflop/s, available power: %f%%\n", name, power, (available_power*100)); } - /* TODO: remove name from SD workstation structure */ + + xbt_dict_foreach(sd_global->links, cursor, name, link) { + printf("Link name: %s\n", name); + } return NULL; } @@ -64,8 +86,9 @@ SD_task_t* SD_simulate(double how_long) void SD_clean() { if (sd_global != NULL) { xbt_dict_free(&sd_global->workstations); + xbt_dict_free(&sd_global->links); xbt_free(sd_global); surf_exit(); - /* TODO: destroy the workstations, the links and the tasks */ + /* TODO: destroy the tasks */ } } diff --git a/src/simdag/sd_link.c b/src/simdag/sd_link.c index 424ebc3488..3a4257445b 100644 --- a/src/simdag/sd_link.c +++ b/src/simdag/sd_link.c @@ -1,45 +1,57 @@ #include "private.h" #include "simdag/simdag.h" +#include "surf/surf.h" #include "xbt/sysdep.h" /* xbt_new0 */ /* Creates a link. */ -SD_link_t __SD_link_create(const char *name, void *surf_link, void *data) { +SD_link_t __SD_link_create(void *surf_link, char *name, void *data) { + CHECK_INIT_DONE(); xbt_assert0(surf_link != NULL, "surf_link is NULL !"); + xbt_assert0(name != NULL, "name is NULL !"); + SD_link_data_t sd_data = xbt_new0(s_SD_link_data_t, 1); /* link private data */ sd_data->surf_link = surf_link; + sd_data->name = xbt_strdup(name); SD_link_t link = xbt_new0(s_SD_link_t, 1); - link->name = xbt_strdup(name); - link->data = data; - link->sd_data = sd_data; + link->sd_data = sd_data; /* private data */ + link->data = data; /* user data */ /*link->capacity = capacity;*/ /* link->current_bandwidth = bandwidth; link->current_latency = latency;*/ + /*xbt_dynar_push(sd_global->links, link);*/ + xbt_dict_set(sd_global->links, name, link, __SD_link_destroy); /* add the workstation to the dictionary */ + return link; } /* Returns the user data of a link. The user data can be NULL. */ void* SD_link_get_data(SD_link_t link) { - xbt_assert0(link, "Invalid parameter"); + CHECK_INIT_DONE(); + xbt_assert0(link != NULL, "Invalid parameter"); return link->data; } /* Sets the user data of a link. The new data can be NULL. The old data should have been freed first if it was not NULL. */ void SD_link_set_data(SD_link_t link, void *data) { - xbt_assert0(link, "Invalid parameter"); + CHECK_INIT_DONE(); + xbt_assert0(link != NULL, "Invalid parameter"); link->data = data; } /* Returns the name of a link. The name can be NULL. */ const char* SD_link_get_name(SD_link_t link) { - xbt_assert0(link, "Invalid parameter"); - return link->name; + CHECK_INIT_DONE(); + xbt_assert0(link != NULL, "Invalid parameter"); + return link->sd_data->name; + + /* return surf_network_resource->common_public->get_resource_name(link->sd_data->surf_link);*/ } /* Returns the capacity of a link. @@ -53,7 +65,8 @@ double SD_link_get_capacity(SD_link_t link) { /* Return the current bandwidth of a link. */ double SD_link_get_current_bandwidth(SD_link_t link) { - xbt_assert0(link, "Invalid parameter"); + CHECK_INIT_DONE(); + xbt_assert0(link != NULL, "Invalid parameter"); /* TODO */ return 0; @@ -63,7 +76,8 @@ double SD_link_get_current_bandwidth(SD_link_t link) { /* Return the current latency of a link. */ double SD_link_get_current_latency(SD_link_t link) { - xbt_assert0(link, "Invalid parameter"); + CHECK_INIT_DONE(); + xbt_assert0(link != NULL, "Invalid parameter"); /* TODO */ return 0; @@ -72,14 +86,15 @@ double SD_link_get_current_latency(SD_link_t link) { /* Destroys a link. The user data (if any) should have been destroyed first. */ -void __SD_link_destroy(SD_link_t link) { - xbt_assert0(link, "Invalid parameter"); +void __SD_link_destroy(void *link) { + CHECK_INIT_DONE(); + xbt_assert0(link != NULL, "Invalid parameter"); - if (link->sd_data != NULL) - xbt_free(link->sd_data); - - if (link->name != NULL) - xbt_free(link->name); + if (((SD_link_t) link)->sd_data != NULL) + xbt_free(((SD_link_t) link)->sd_data); + /* TODO: name */ + xbt_free(link); } + diff --git a/src/simdag/sd_workstation.c b/src/simdag/sd_workstation.c index 4ae419a10e..5c25338872 100644 --- a/src/simdag/sd_workstation.c +++ b/src/simdag/sd_workstation.c @@ -8,6 +8,7 @@ */ SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data) { CHECK_INIT_DONE(); + xbt_assert0(surf_workstation != NULL, "surf_workstation is NULL !"); SD_workstation_data_t sd_data = xbt_new0(s_SD_workstation_data_t, 1); /* workstation private data */ sd_data->surf_workstation = surf_workstation;