From: Martin Quinson Date: Mon, 14 Nov 2011 16:40:03 +0000 (+0100) Subject: pre-parse the vivaldi coordinates X-Git-Tag: exp_20120216~285 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/fa8dc48a0d60d1d31c89c0d2add46680119444d9 pre-parse the vivaldi coordinates --- diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index ed2c35db27..443c40121c 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -105,11 +105,21 @@ static void parse_S_host(sg_platf_host_cbarg_t host) info->rc_type = SURF_NETWORK_ELEMENT_HOST; xbt_lib_set(host_lib, host->id, ROUTING_HOST_LEVEL, (void *) info); if (host->coord && strcmp(host->coord, "")) { + unsigned int cursor; + char*str; + if (!COORD_HOST_LEVEL) - xbt_die - ("To use host coordinates, please add --cfg=coordinates:yes to your command line"); - xbt_dynar_t ctn = xbt_str_split_str(host->coord, " "); + xbt_die ("To use host coordinates, please add --cfg=coordinates:yes to your command line"); + + /* Pre-parse the host coordinates -- FIXME factorize with routers by overloading the routing->parse_PU function*/ + xbt_dynar_t ctn_str = xbt_str_split_str(host->coord, " "); + xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL); + xbt_dynar_foreach(ctn_str,cursor, str) { + double val = atof(str); + xbt_dynar_push(ctn,&val); + } xbt_dynar_shrink(ctn, 0); + xbt_dynar_free(&ctn_str); xbt_lib_set(host_lib, host->id, COORD_HOST_LEVEL, (void *) ctn); } } @@ -133,11 +143,21 @@ static void parse_S_router(sg_platf_router_cbarg_t router) xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) info); if (strcmp(router->coord, "")) { + unsigned int cursor; + char*str; + if (!COORD_ASR_LEVEL) - xbt_die - ("To use coordinates, you must set configuration 'coordinates' to 'yes'"); - xbt_dynar_t ctn = xbt_str_split_str(router->coord, " "); + xbt_die ("To use host coordinates, please add --cfg=coordinates:yes to your command line"); + + /* Pre-parse the host coordinates */ + xbt_dynar_t ctn_str = xbt_str_split_str(router->coord, " "); + xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL); + xbt_dynar_foreach(ctn_str,cursor, str) { + double val = atof(str); + xbt_dynar_push(ctn,&val); + } xbt_dynar_shrink(ctn, 0); + xbt_dynar_free(&ctn_str); xbt_lib_set(as_router_lib, router->id, COORD_ASR_LEVEL, (void *) ctn); } } @@ -947,6 +967,7 @@ static void routing_parse_peer(sg_platf_peer_cbarg_t peer) host.power_trace = peer->availability_trace; host.state_trace = peer->state_trace; host.core_amount = 1; + host.coord = peer->coord; sg_platf_new_host(&host); @@ -1113,7 +1134,7 @@ static void routing_parse_Srandom(void) } break; default: - XBT_INFO("Malformed radical"); + XBT_CRITICAL("Malformed radical"); break; } res = random_generate(random); diff --git a/src/surf/surf_routing_vivaldi.c b/src/surf/surf_routing_vivaldi.c index fe92bb4961..9e7ddfeede 100644 --- a/src/surf/surf_routing_vivaldi.c +++ b/src/surf/surf_routing_vivaldi.c @@ -22,13 +22,12 @@ static route_t vivaldi_get_route(AS_t rc, const char *src, const char *dst) return new_e_route; } -static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst) +static XBT_INLINE double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst) { double src_coord, dst_coord; - // FIXME converting from string to float each time we need a coordinate is ... suboptimal - src_coord = atof(xbt_dynar_get_as(src, index, char *)); - dst_coord = atof(xbt_dynar_get_as(dst, index, char *)); + src_coord = xbt_dynar_get_as(src, index, double); + dst_coord = xbt_dynar_get_as(dst, index, double); return (src_coord-dst_coord)*(src_coord-dst_coord); @@ -47,7 +46,7 @@ static double base_vivaldi_get_latency (const char *src, const char *dst) xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn); euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn)) - + fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *))); + + fabs(xbt_dynar_get_as(src_ctn, 2, double))+fabs(xbt_dynar_get_as(dst_ctn, 2, double)); //From .ms to .s return euclidean_dist / 1000;