From: Martin Quinson Date: Tue, 9 Feb 2016 15:20:03 +0000 (+0100) Subject: cosmetics: inline a parsing function to unclutter the routing code X-Git-Tag: v3_13~901 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5e9ecc268a45db21daf49b37edb7df76987f798b?hp=67e88ab9635136f62aab0b9e68f05d16fab123f5 cosmetics: inline a parsing function to unclutter the routing code --- diff --git a/ChangeLog b/ChangeLog index 657c184331..53528c6b44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,7 @@ SimGrid (3.13) UNRELEASED; urgency=low - In , attribute kind="POWER" is now kind="SPEED". - The DOCTYPE points to the right URL (this file): http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd + (the file at this address now documents the changelog since its v1) - A warning is emitted for unit-less values (they are still accepted). - speed. Default: 'f' or 'flops'. Also defined: 'Yf', 'Zf', 'Ef', 'Pf', 'Tf', 'Gf', 'Mf', 'kf' diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 0b98b0679c..166ce02768 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -1005,7 +1005,6 @@ void instr_routing_platform_graph_export_graphviz (xbt_graph_t g, const char *fi /********** Routing **********/ void routing_AS_begin(sg_platf_AS_cbarg_t AS); void routing_AS_end(void); -surf_NetCard* routing_add_host(surf_As* as, sg_platf_host_cbarg_t host); void routing_cluster_add_backbone(void* bb); surf_As* routing_get_current(); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 62c611547b..0c7df96202 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -51,27 +51,56 @@ void sg_platf_exit(void) { surf_parse_models_setup_already_called = 0; } +/** @brief Add an "host" to the current AS */ void sg_platf_new_host(sg_platf_host_cbarg_t host) { xbt_assert(! sg_host_by_name(host->id), - "Refusing to create a second host named '%s'.", host->id); + "Refusing to create a second host named '%s'.", host->id); - simgrid::surf::NetCard *net = NULL; simgrid::surf::As* current_routing = routing_get_current(); - if (current_routing) - net = routing_add_host(current_routing, host); + if (current_routing->p_hierarchy == SURF_ROUTING_NULL) + current_routing->p_hierarchy = SURF_ROUTING_BASE; + + simgrid::surf::NetCard *netcard = + new simgrid::surf::NetCardImpl(xbt_strdup(host->id), -1, SURF_NETWORK_ELEMENT_HOST, current_routing); + netcard->setId(current_routing->parsePU(netcard)); sg_host_t h = simgrid::s4u::Host::by_name_or_create(host->id); - simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( - h, - host->speed_peak, - host->pstate, - host->speed_scale, - host->speed_trace, - host->core_amount, - host->initiallyOn, - host->state_trace); - surf_host_model->createHost(host->id, net, cpu, host->properties)->attach(h); + h->pimpl_netcard = netcard; + simgrid::surf::netcardCreatedCallbacks(netcard); + + if(mount_list){ + xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void *) mount_list); + mount_list = NULL; + } + + if (host->coord && strcmp(host->coord, "")) { + unsigned int cursor; + char*str; + + if (!COORD_HOST_LEVEL) + xbt_die ("To use host coordinates, please add --cfg=network/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 = xbt_str_parse_double(str, "Invalid coordinate: %s"); + xbt_dynar_push(ctn,&val); + } + xbt_dynar_shrink(ctn, 0); + xbt_dynar_free(&ctn_str); + h->extension_set(COORD_HOST_LEVEL, (void *) ctn); + XBT_DEBUG("Having set host coordinates for '%s'",host->id); + } + + + simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( h, + host->speed_peak, + host->pstate, + host->speed_scale, host->speed_trace, + host->core_amount, + host->initiallyOn, host->state_trace); + surf_host_model->createHost(host->id, netcard, cpu, host->properties)->attach(h); simgrid::s4u::Host::onCreation(*h); if (TRACE_is_enabled() && TRACE_needs_platform()) @@ -336,11 +365,11 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) SIMIX_process_create_from_wrapper((smx_process_arg_t) arg); }, arg); } else { // start_time <= SIMIX_get_clock() - XBT_DEBUG("Starting Process %s(%s) right now", process->argv[0], sg_host_get_name(host)); + XBT_DEBUG("Starting Process %s(%s) right now", arg->name, sg_host_get_name(host)); if (simix_global->create_process_function) process_created = simix_global->create_process_function( - (char*)(process->argv)[0], + arg->name, parse_code, NULL, sg_host_get_name(host), @@ -350,7 +379,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) current_property_set, auto_restart, NULL); else - process_created = simcall_process_create((char*)(process->argv)[0], parse_code, NULL, sg_host_get_name(host), kill_time, process->argc, + process_created = simcall_process_create(arg->name, parse_code, NULL, sg_host_get_name(host), kill_time, process->argc, (char**)process->argv, current_property_set,auto_restart); /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */ diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index 96ec550920..5e3b5ed8ae 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -151,55 +151,6 @@ void sg_platf_new_netcard(sg_platf_host_link_cbarg_t netcard) xbt_dynar_set_as(current_routing->p_linkUpDownList, info->getId(), s_surf_parsing_link_up_down_t, link_up_down); } -/** - * \brief Add a "host" to the network element list - */ -simgrid::surf::NetCard *routing_add_host( - simgrid::surf::As* current_routing, sg_platf_host_cbarg_t host) -{ - if (current_routing->p_hierarchy == SURF_ROUTING_NULL) - current_routing->p_hierarchy = SURF_ROUTING_BASE; - xbt_assert(!sg_host_by_name(host->id), - "Reading a host, processing unit \"%s\" already exists", host->id); - - simgrid::surf::NetCard *netcard = - new simgrid::surf::NetCardImpl(xbt_strdup(host->id), - -1, - SURF_NETWORK_ELEMENT_HOST, - current_routing); - netcard->setId(current_routing->parsePU(netcard)); - sg_host_t h = sg_host_by_name_or_create(host->id); - h->pimpl_netcard = netcard; - XBT_DEBUG("Having set name '%s' id '%d'", host->id, netcard->getId()); - simgrid::surf::netcardCreatedCallbacks(netcard); - - if(mount_list){ - xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void *) mount_list); - mount_list = NULL; - } - - if (host->coord && strcmp(host->coord, "")) { - unsigned int cursor; - char*str; - - if (!COORD_HOST_LEVEL) - xbt_die ("To use host coordinates, please add --cfg=network/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 = xbt_str_parse_double(str, "Invalid coordinate: %s"); - xbt_dynar_push(ctn,&val); - } - xbt_dynar_shrink(ctn, 0); - xbt_dynar_free(&ctn_str); - h->extension_set(COORD_HOST_LEVEL, (void *) ctn); - XBT_DEBUG("Having set host coordinates for '%s'",host->id); - } - - return netcard; -} - void sg_platf_new_trace(sg_platf_trace_cbarg_t trace) { tmgr_trace_t tmgr_trace;