X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1d18e615eaa617d3354bc22dfbe711d34be9f902..790548512bc97315d97b03d2d418b167d903e895:/src/surf/surfxml_parse.c diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index fb6e217633..02fd37b0ed 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -49,6 +49,7 @@ double surf_parse_get_double(const char *string) { int ret = sscanf(string, "%lg", &res); if (ret != 1) surf_parse_error("%s is not a double", string); + //printf("Parsed double [%lg] %s\n", res, string); return res; } @@ -60,6 +61,103 @@ int surf_parse_get_int(const char *string) { return res; } +double surf_parse_get_time(const char *string) { + char* ptr; + double res = strtod(string, &ptr); + if (ptr == string) + surf_parse_error("This is not a time: %s", string); + else if (strcmp(ptr, "ps") == 0) + res *= 1E-12; + else if (strcmp(ptr, "ns") == 0) + res *= 1E-9; + else if (strcmp(ptr, "us") == 0) + res *= 1E-6; + else if (strcmp(ptr, "ms") == 0) + res *= 1E-3; + else if (strcmp(ptr, "s") == 0) + res *= 1; + else if (strcmp(ptr, "m") == 0) + res *= 60; + else if (strcmp(ptr, "h") == 0) + res *= 3600; + else if (strcmp(ptr, "d") == 0) + res *= 86400; + else if (strcmp(ptr, "w") == 0) + res *= 604800; + return res; +} + +double surf_parse_get_bandwidth(const char *string) { + char* ptr; + double res = strtod(string, &ptr); + if (ptr == string) + surf_parse_error("This is not a bandwidth: %s", string); + else if (strcmp(ptr, "KBps") == 0) + res *= 1E3; + else if (strcmp(ptr, "MBps") == 0) + res *= 1E6; + else if (strcmp(ptr, "GBps") == 0) + res *= 1E9; + else if (strcmp(ptr, "TBps") == 0) + res *= 1E12; + else if (strcmp(ptr, "Bps") == 0) + res *= 1; + else if (strcmp(ptr, "kbps") == 0) + res *= 0.125 * 1E3; + else if (strcmp(ptr, "mbps") == 0) + res *= 0.125 * 1E6; + else if (strcmp(ptr, "gbps") == 0) + res *= 0.125 * 1E9; + else if (strcmp(ptr, "tbps") == 0) + res *= 0.125 * 1E12; + else if (strcmp(ptr, "bps") == 0) + res *= 0.125; + return res; +} + +double surf_parse_get_power(const char *string) { + char* ptr; + double res = strtod(string, &ptr); + if (ptr == string) + surf_parse_error("This is not a power: %s", string); + else if (strcmp(ptr, "kiloflops") == 0) + res *= 1E3; + else if (strcmp(ptr, "megaflops") == 0) + res *= 1E6; + else if (strcmp(ptr, "gigaflops") == 0) + res *= 1E9; + else if (strcmp(ptr, "teraflops") == 0) + res *= 1E12; + else if (strcmp(ptr, "petaflops") == 0) + res *= 1E15; + else if (strcmp(ptr, "exaflops") == 0) + res *= 1E18; + else if (strcmp(ptr, "zettaflops") == 0) + res *= 1E21; + else if (strcmp(ptr, "yottaflops") == 0) + res *= 1E24; + else if (strcmp(ptr, "flops") == 0) + res *= 1; + else if (strcmp(ptr, "kf") == 0) + res *= 1E3; + else if (strcmp(ptr, "mf") == 0) + res *= 1E6; + else if (strcmp(ptr, "gf") == 0) + res *= 1E9; + else if (strcmp(ptr, "tf") == 0) + res *= 1E12; + else if (strcmp(ptr, "pf") == 0) + res *= 1E15; + else if (strcmp(ptr, "ef") == 0) + res *= 1E18; + else if (strcmp(ptr, "zf") == 0) + res *= 1E21; + else if (strcmp(ptr, "yf") == 0) + res *= 1E24; + else if (strcmp(ptr, "f") == 0) + res *= 1; + return res; +} /* * All the callback lists that can be overridden anywhere. @@ -340,20 +438,20 @@ void STag_surfxml_cluster(void){ cluster.prefix = A_surfxml_cluster_prefix; cluster.suffix = A_surfxml_cluster_suffix; cluster.radical = A_surfxml_cluster_radical; - cluster.power= surf_parse_get_double(A_surfxml_cluster_power); + cluster.power = surf_parse_get_power(A_surfxml_cluster_power); cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core); - cluster.bw = surf_parse_get_double(A_surfxml_cluster_bw); - cluster.lat = surf_parse_get_double(A_surfxml_cluster_lat); + cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw); + cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat); if(strcmp(A_surfxml_cluster_bb___bw,"")) - cluster.bb_bw = surf_parse_get_double(A_surfxml_cluster_bb___bw); + cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw); if(strcmp(A_surfxml_cluster_bb___lat,"")) - cluster.bb_lat = surf_parse_get_double(A_surfxml_cluster_bb___lat); + cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat); if(strcmp(A_surfxml_cluster_limiter___link,"")) cluster.limiter_link = surf_parse_get_double(A_surfxml_cluster_limiter___link); if(strcmp(A_surfxml_cluster_loopback___bw,"")) - cluster.loopback_bw = surf_parse_get_double(A_surfxml_cluster_loopback___bw); + cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw); if(strcmp(A_surfxml_cluster_loopback___lat,"")) - cluster.loopback_lat = surf_parse_get_double(A_surfxml_cluster_loopback___lat); + cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat); cluster.router_id = A_surfxml_cluster_router___id; switch (AX_surfxml_cluster_sharing___policy) { @@ -395,9 +493,9 @@ void STag_surfxml_cabinet(void){ cabinet.id = A_surfxml_cabinet_id; cabinet.prefix = A_surfxml_cabinet_prefix; cabinet.suffix = A_surfxml_cabinet_suffix; - cabinet.power = surf_parse_get_double(A_surfxml_cabinet_power); - cabinet.bw = surf_parse_get_double(A_surfxml_cabinet_bw); - cabinet.lat = surf_parse_get_double(A_surfxml_cabinet_lat); + cabinet.power = surf_parse_get_power(A_surfxml_cabinet_power); + cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw); + cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat); cabinet.radical = A_surfxml_cabinet_radical; sg_platf_new_cabinet(&cabinet); @@ -407,10 +505,10 @@ void STag_surfxml_peer(void){ s_sg_platf_peer_cbarg_t peer; memset(&peer,0,sizeof(peer)); peer.id = A_surfxml_peer_id; - peer.power = surf_parse_get_double(A_surfxml_peer_power); - peer.bw_in = surf_parse_get_double(A_surfxml_peer_bw___in); - peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw___out); - peer.lat = surf_parse_get_double(A_surfxml_peer_lat); + peer.power = surf_parse_get_power(A_surfxml_peer_power); + peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in); + peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out); + peer.lat = surf_parse_get_time(A_surfxml_peer_lat); peer.coord = A_surfxml_peer_coordinates; peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability___file); peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state___file); @@ -430,9 +528,11 @@ void ETag_surfxml_link(void){ link.properties = current_property_set; link.id = A_surfxml_link_id; - link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth); + link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth); + //printf("Link bandwidth [%lg]\n", link.bandwidth); link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file); - link.latency = surf_parse_get_double(A_surfxml_link_latency); + link.latency = surf_parse_get_time(A_surfxml_link_latency); + //printf("Link latency [%lg]\n", link.latency); link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency___file); switch (A_surfxml_link_state) { @@ -496,8 +596,8 @@ void ETag_surfxml_backbone(void){ link.properties = NULL; link.id = A_surfxml_backbone_id; - link.bandwidth = surf_parse_get_double(A_surfxml_backbone_bandwidth); - link.latency = surf_parse_get_double(A_surfxml_backbone_latency); + link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth); + link.latency = surf_parse_get_time(A_surfxml_backbone_latency); link.state = SURF_RESOURCE_ON; link.policy = SURF_LINK_SHARED; @@ -890,7 +990,7 @@ double get_cpu_power(const char *power) power_scale = random_generate(random); } } else { - power_scale = surf_parse_get_double(power); + power_scale = surf_parse_get_power(power); } return power_scale; }