int main(int argc, char **argv) { xbt_dict_cursor_t cursor = NULL; char *key, *data; char noexist[] = "NoProp"; const char *value; char exist[] = "Hdd"; /* SD initialization */ SD_init(&argc, argv); xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s ../../platforms/prop.xml", argv[0], argv[0]); SD_create_environment(argv[1]); /* init of platform elements */ sg_host_t h1 = sg_host_by_name("host1"); sg_host_t h2 = sg_host_by_name("host2"); const char *name1 = sg_host_get_name(h1); const char *name2 = sg_host_get_name(h2); /* Get the property list of 'host1' */ XBT_INFO("Property list for host %s", name1); xbt_dict_t props = sg_host_get_properties(h1); /* Trying to set a new property */ xbt_dict_set(props, "NewProp", strdup("newValue"), NULL); /* Print the properties of 'host1' */ xbt_dict_foreach(props, cursor, key, data) { XBT_INFO("\tProperty: %s has value: %s", key, data); }
int main(int argc, char **argv) { double now = -1.0; int running; surf_init(&argc, argv); /* Initialize some common structures */ xbt_cfg_set_parse("network/model:CM02"); xbt_cfg_set_parse("cpu/model:Cas01"); xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]); parse_platform_file(argv[1]); /*********************** HOST ***********************************/ simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A"); simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B"); /* Let's do something on it */ hostA->pimpl_cpu->execution_start(1000.0); hostB->pimpl_cpu->execution_start(1000.0); hostB->pimpl_cpu->sleep(7.32); surf_network_model->communicate(hostA, hostB, 150.0, -1.0); surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */ do { surf_action_t action = nullptr; running = 0; now = surf_get_clock(); XBT_INFO("Next Event : %g", now); for (auto model: *all_existing_models) { if (surf_model_running_action_set_size(model)) { XBT_DEBUG("\t Running that model"); running = 1; } action = surf_model_extract_failed_action_set(model); while (action != nullptr) { XBT_INFO(" * Done Action"); XBT_DEBUG("\t * Failed Action: %p", action); action->unref(); action = surf_model_extract_failed_action_set(model); } action = surf_model_extract_done_action_set(model); while (action != nullptr){ XBT_INFO(" * Done Action"); XBT_DEBUG("\t * Done Action: %p", action); action->unref(); action = surf_model_extract_done_action_set(model); } } } while (running && surf_solve(-1.0) >= 0.0); XBT_INFO("Simulation Terminated"); return 0; }
LinkDynar getRoute(char *srcName, char *dstName) { RoutingEdge *src = sg_host_edge(sg_host_by_name(srcName)); RoutingEdge *dst = sg_host_edge(sg_host_by_name(dstName)); xbt_assert(src,"Cannot get the route from a NULL source"); xbt_assert(dst,"Cannot get the route to a NULL destination"); xbt_dynar_t route = xbt_dynar_new(sizeof(RoutingEdge*), NULL); routing_platf->getRouteAndLatency(src, dst, &route, NULL); return route; }
/** * \brief Add a "host_link" to the network element list */ static void parse_S_host_link(sg_platf_host_link_cbarg_t host) { RoutingEdge *info = sg_host_edge(sg_host_by_name(host->id)); xbt_assert(info, "Host '%s' not found!", host->id); xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER] || current_routing->p_modelDesc == &routing_models[SURF_MODEL_VIVALDI], "You have to be in model Cluster to use tag host_link!"); s_surf_parsing_link_up_down_t link_up_down; link_up_down.link_up = Link::byName(host->link_up); link_up_down.link_down = Link::byName(host->link_down); xbt_assert(link_up_down.link_up, "Link '%s' not found!",host->link_up); xbt_assert(link_up_down.link_down, "Link '%s' not found!",host->link_down); if(!current_routing->p_linkUpDownList) current_routing->p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL); // If dynar is is greater than edge id and if the host_link is already defined if((int)xbt_dynar_length(current_routing->p_linkUpDownList) > info->getId() && xbt_dynar_get_as(current_routing->p_linkUpDownList, info->getId(), void*)) surf_parse_error("Host_link for '%s' is already defined!",host->id); XBT_DEBUG("Push Host_link for host '%s' to position %d", info->getName(), info->getId()); xbt_dynar_set_as(current_routing->p_linkUpDownList, info->getId(), s_surf_parsing_link_up_down_t, link_up_down); }
/** @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); simgrid::surf::AsImpl* current_routing = routing_get_current(); if (current_routing->hierarchy_ == simgrid::surf::AsImpl::RoutingMode::unset) current_routing->hierarchy_ = simgrid::surf::AsImpl::RoutingMode::base; simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(host->id, SURF_NETWORK_ELEMENT_HOST, current_routing); netcard->setId(current_routing->addComponent(netcard)); sg_host_t h = simgrid::s4u::Host::by_name_or_create(host->id); 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); }
/** @brief Retrieve a routing edge from its name * * Routing edges are either host and routers, whatever */ RoutingEdge *sg_routing_edge_by_name_or_null(const char *name) { sg_host_t h = sg_host_by_name(name); RoutingEdge *net_elm = h==NULL?NULL: sg_host_edge(h); if (!net_elm) net_elm = (RoutingEdge*) xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL); return net_elm; }
int console_host_set_property(lua_State *L) { const char* name =""; const char* prop_id = ""; const char* prop_value = ""; lua_ensure(lua_istable(L, -1), "Bad Arguments to create link, Should be a table with named arguments"); // get Host id lua_pushstring(L, "host"); lua_gettable(L, -2); name = lua_tostring(L, -1); lua_pop(L, 1); // get prop Name lua_pushstring(L, "prop"); lua_gettable(L, -2); prop_id = lua_tostring(L, -1); lua_pop(L, 1); //get args lua_pushstring(L,"value"); lua_gettable(L, -2); prop_value = lua_tostring(L,-1); lua_pop(L, 1); sg_host_t host = sg_host_by_name(name); lua_ensure(host, "no host '%s' found",name); xbt_dict_t props = sg_host_get_properties(host); xbt_dict_set(props,prop_id,xbt_strdup(prop_value),nullptr); return 0; }
/** * \brief Add a "host" to the network element list */ static void parse_S_host(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); RoutingEdge *info = new RoutingEdgeImpl(xbt_strdup(host->id), -1, SURF_NETWORK_ELEMENT_HOST, current_routing); info->setId(current_routing->parsePU(info)); sg_host_edge_set(sg_host_by_name_or_create(host->id), info); XBT_DEBUG("Having set name '%s' id '%d'", host->id, info->getId()); 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 = atof(str); xbt_dynar_push(ctn,&val); }
/** @brief Retrieve a netcard from its name * * Netcards are the thing that connect host or routers to the network */ simgrid::routing::NetCard *sg_netcard_by_name_or_null(const char *name) { sg_host_t h = sg_host_by_name(name); simgrid::routing::NetCard *netcard = h==nullptr ? nullptr: h->pimpl_netcard; if (!netcard) netcard = (simgrid::routing::NetCard*) xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL); return netcard; }
int main(int argc, char* argv[]) { SIMIX_global_init(&argc, argv); xbt_assert(argc == 2, "Usage: %s platform.xml\n", argv[0]); simgrid_load_platform(argv[1]); simcall_process_create("master", example::master, NULL, sg_host_by_name("Tremblay"), NULL); SIMIX_run(); return 0; }
Host *HostCLM03Model::createHost(const char *name){ sg_host_t sg_host = sg_host_by_name(name); Host *host = new HostCLM03(surf_host_model, name, NULL, (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL), sg_host_edge(sg_host), sg_host_surfcpu(sg_host)); XBT_DEBUG("Create host %s with %ld mounted disks", name, xbt_dynar_length(host->p_storage)); xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, host); return host; }
/** * @brief Internal function to create a SIMIX host. * @param name name of the host to create * @param data some user data (may be nullptr) */ sg_host_t SIMIX_vm_create(const char *name, sg_host_t ind_phys_host) { /* Create surf associated resource */ surf_vm_model_create(name, ind_phys_host); sg_host_t host = sg_host_by_name(name); SIMIX_host_create(host); /* We will be able to register the VM to its physical host, so that we can promptly * retrieve the list VMs on the physical host. */ return host; }
/* Update the physical host of the given VM */ void VMHL13::migrate(sg_host_t host_dest) { HostImpl *surfHost_dst = host_dest->extension<HostImpl>(); const char *vm_name = getName(); const char *pm_name_src = hostPM_->name().c_str(); const char *pm_name_dst = surfHost_dst->getName(); /* update net_elm with that of the destination physical host */ sg_host_by_name(vm_name)->pimpl_netcard = sg_host_by_name(pm_name_dst)->pimpl_netcard; hostPM_ = host_dest; /* Update vcpu's action for the new pm */ { /* create a cpu action bound to the pm model at the destination. */ CpuAction *new_cpu_action = static_cast<CpuAction*>(host_dest->pimpl_cpu->execution_start(0)); Action::State state = action_->getState(); if (state != Action::State::done) XBT_CRITICAL("FIXME: may need a proper handling, %d", static_cast<int>(state)); if (action_->getRemainsNoUpdate() > 0) XBT_CRITICAL("FIXME: need copy the state(?), %f", action_->getRemainsNoUpdate()); /* keep the bound value of the cpu action of the VM. */ double old_bound = action_->getBound(); if (old_bound != 0) { XBT_DEBUG("migrate VM(%s): set bound (%f) at %s", vm_name, old_bound, pm_name_dst); new_cpu_action->setBound(old_bound); } XBT_ATTRIB_UNUSED int ret = action_->unref(); xbt_assert(ret == 1, "Bug: some resource still remains"); action_ = new_cpu_action; } XBT_DEBUG("migrate VM(%s): change PM (%s to %s)", vm_name, pm_name_src, pm_name_dst); }
/** * \brief Returns a host given its name. This is a lua function. * * \param L a Lua state * \return number of values returned to Lua * * - Argument 1 (string): name of a host * - Return value (host): the corresponding host will be pushed onto the stack */ static int l_host_get_by_name(lua_State * L) { const char *name = luaL_checkstring(L, 1); lua_remove(L, 1); /* remove the args from the stack */ sg_host_t host = sg_host_by_name(name); lua_ensure(host, "No host name '%s' found.", name); lua_newtable(L); /* table */ sg_host_t *lua_host = (sg_host_t *) lua_newuserdata(L, sizeof(sg_host_t)); /* table userdatum */ *lua_host = host; luaL_getmetatable(L, HOST_MODULE_NAME); /* table userdatum metatable */ lua_setmetatable(L, -2); /* table userdatum */ lua_setfield(L, -2, HOST_FIELDNAME); /* table -- put the userdata as field of the table */ return 1; }
/* Creates a workstation and registers it in SD. */ SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data) { SD_workstation_priv_t workstation; const char *name; workstation = xbt_new(s_SD_workstation_priv_t, 1); workstation->data = data; /* user data */ workstation->access_mode = SD_WORKSTATION_SHARED_ACCESS; /* default mode is shared */ workstation->task_fifo = NULL; workstation->current_task = NULL; name = surf_resource_name(surf_workstation); sg_host_t sg_host = sg_host_by_name(name); sg_host_sd_set(sg_host,workstation); return sg_host; }
int main(int argc, char **argv) { double now = -1.0; surf_init(&argc, argv); /* Initialize some common structures */ xbt_cfg_set_parse("cpu/model:Cas01"); xbt_cfg_set_parse("network/model:CM02"); xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]); parse_platform_file(argv[1]); XBT_DEBUG("CPU model: %p", surf_cpu_model_pm); XBT_DEBUG("Network model: %p", surf_network_model); simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A"); simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B"); /* Let's do something on it */ simgrid::surf::Action* actionA = hostA->pimpl_cpu->execution_start(1000.0); simgrid::surf::Action* actionB = hostB->pimpl_cpu->execution_start(1000.0); simgrid::surf::Action* actionC = hostB->pimpl_cpu->sleep(7.32); simgrid::surf::Action::State stateActionA = actionA->getState(); simgrid::surf::Action::State stateActionB = actionB->getState(); simgrid::surf::Action::State stateActionC = actionC->getState(); /* And just look at the state of these tasks */ XBT_INFO("actionA state: %s", string_action(stateActionA)); XBT_INFO("actionB state: %s", string_action(stateActionB)); XBT_INFO("actionC state: %s", string_action(stateActionC)); /* Let's do something on it */ surf_network_model->communicate(hostA, hostB, 150.0, -1.0); surf_solve(-1.0); do { simgrid::surf::ActionList *action_list = nullptr; now = surf_get_clock(); XBT_INFO("Next Event : %g", now); XBT_DEBUG("\t CPU actions"); action_list = surf_cpu_model_pm->getFailedActionSet(); for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ; it != itend ; it=itNext) { ++itNext; simgrid::surf::Action *action = static_cast<simgrid::surf::CpuAction*>(&*it); XBT_INFO(" CPU Failed action"); XBT_DEBUG("\t * Failed : %p", action); action->unref(); } action_list = surf_cpu_model_pm->getDoneActionSet(); for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ; it != itend ; it=itNext) { ++itNext; simgrid::surf::Action *action = static_cast<simgrid::surf::CpuAction*>(&*it); XBT_INFO(" CPU Done action"); XBT_DEBUG("\t * Done : %p", action); action->unref(); } action_list = surf_network_model->getFailedActionSet(); for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ; it != itend ; it=itNext) { ++itNext; simgrid::surf::Action *action = static_cast<simgrid::surf::NetworkAction*>(&*it); XBT_INFO(" Network Failed action"); XBT_DEBUG("\t * Failed : %p", action); action->unref(); } action_list = surf_network_model->getDoneActionSet(); for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ; it != itend ; it=itNext) { ++itNext; simgrid::surf::Action *action = static_cast<simgrid::surf::NetworkAction*>(&*it); XBT_INFO(" Network Done action"); XBT_DEBUG("\t * Done : %p", action); action->unref(); } } while ((surf_network_model->getRunningActionSet()->size() || surf_cpu_model_pm->getRunningActionSet()->size()) && surf_solve(-1.0) >= 0.0); XBT_DEBUG("Simulation Terminated"); return 0; }
/* This function acts as a main in the parsing area. */ void parse_platform_file(const char *file) { #if HAVE_LUA int is_lua = (file != NULL && strlen(file) > 3 && file[strlen(file)-3] == 'l' && file[strlen(file)-2] == 'u' && file[strlen(file)-1] == 'a'); #endif sg_platf_init(); #if HAVE_LUA /* Check if file extension is "lua". If so, we will use * the lua bindings to parse the platform file (since it is * written in lua). If not, we will use the (old?) XML parser */ if (is_lua) { lua_State* L = luaL_newstate(); luaL_openlibs(L); luaL_loadfile(L, file); // This loads the file without executing it. /* Run the script */ if (lua_pcall(L, 0, 0, 0)) { XBT_ERROR("FATAL ERROR:\n %s: %s\n\n", "Lua call failed. Errormessage:", lua_tostring(L, -1)); xbt_die("Lua call failed. See Log"); } } else #endif { // Use XML parser int parse_status; /* init the flex parser */ surfxml_buffer_stack_stack_ptr = 1; surfxml_buffer_stack_stack[0] = 0; after_config_done = 0; surf_parse_open(file); traces_set_list = xbt_dict_new_homogeneous(NULL); trace_connect_list_host_avail = xbt_dict_new_homogeneous(free); trace_connect_list_host_speed = xbt_dict_new_homogeneous(free); trace_connect_list_link_avail = xbt_dict_new_homogeneous(free); trace_connect_list_link_bw = xbt_dict_new_homogeneous(free); trace_connect_list_link_lat = xbt_dict_new_homogeneous(free); /* Init my data */ if (!surfxml_bufferstack_stack) surfxml_bufferstack_stack = xbt_dynar_new(sizeof(char *), NULL); /* Do the actual parsing */ parse_status = surf_parse(); /* connect all traces relative to hosts */ xbt_dict_cursor_t cursor = NULL; char *trace_name, *elm; xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) { tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); xbt_assert(trace, "Trace %s undefined", trace_name); simgrid::s4u::Host *host = sg_host_by_name(elm); xbt_assert(host, "Host %s undefined", elm); simgrid::surf::Cpu *cpu = host->pimpl_cpu; cpu->setStateTrace(trace); } xbt_dict_foreach(trace_connect_list_host_speed, cursor, trace_name, elm) { tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); xbt_assert(trace, "Trace %s undefined", trace_name); simgrid::s4u::Host *host = sg_host_by_name(elm); xbt_assert(host, "Host %s undefined", elm); simgrid::surf::Cpu *cpu = host->pimpl_cpu; cpu->setSpeedTrace(trace); }
int main(int argc, char **argv) { double computation_amount[1]; double communication_amount[2] = { 0 }; sg_host_t hosts[1]; /* initialization of SD */ SD_init(&argc, argv); /* creation of the environment */ SD_create_environment(argv[1]); /* creation of a single task that will poorly fail when the workstation will stop */ XBT_INFO("First test: COMP_SEQ task"); SD_task_t task = SD_task_create_comp_seq("Poor task", NULL, 2e10); SD_task_watch(task, SD_FAILED); SD_task_watch(task, SD_DONE); XBT_INFO("Schedule task '%s' on 'Faulty Host'", SD_task_get_name(task)); SD_task_schedulel(task, 1, sg_host_by_name("Faulty Host")); xbt_dynar_t tasks = SD_simulate(-1.0); xbt_dynar_free(&tasks); SD_task_dump(task); XBT_INFO("Task '%s' has failed. %.f flops remain to be done", SD_task_get_name(task), SD_task_get_remaining_amount(task)); XBT_INFO("let's unschedule task '%s' and reschedule it on the 'Safe Host'", SD_task_get_name(task)); SD_task_unschedule(task); SD_task_schedulel(task, 1, sg_host_by_name("Safe Host")); XBT_INFO("Run the simulation again"); tasks = SD_simulate(-1.0); xbt_dynar_free(&tasks); SD_task_dump(task); XBT_INFO("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task), SD_task_get_start_time(task), SD_task_get_finish_time(task)); SD_task_destroy(task); task=NULL; XBT_INFO("Second test: NON TYPED task"); task = SD_task_create("Poor parallel task", NULL, 2e10); SD_task_watch(task, SD_FAILED); SD_task_watch(task, SD_DONE); computation_amount[0] = 2e10; XBT_INFO("Schedule task '%s' on 'Faulty Host'", SD_task_get_name(task)); hosts[0] = sg_host_by_name("Faulty Host"); SD_task_schedule(task, 1, hosts, computation_amount, communication_amount,-1); tasks = SD_simulate(-1.0); xbt_dynar_free(&tasks); SD_task_dump(task); XBT_INFO("Task '%s' has failed. %.f flops remain to be done", SD_task_get_name(task), SD_task_get_remaining_amount(task)); XBT_INFO("let's unschedule task '%s' and reschedule it on the 'Safe Host'", SD_task_get_name(task)); SD_task_unschedule(task); hosts[0] = sg_host_by_name("Safe Host"); SD_task_schedule(task, 1, hosts, computation_amount, communication_amount,-1); XBT_INFO("Run the simulation again"); tasks = SD_simulate(-1.0); xbt_dynar_free(&tasks); SD_task_dump(task); XBT_INFO("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task), SD_task_get_start_time(task), SD_task_get_finish_time(task)); SD_task_destroy(task); SD_exit(); return 0; }
int main(int argc, char **argv) { sg_host_t hostA = NULL; sg_host_t hostB = NULL; double now = -1.0; int running; surf_init(&argc, argv); /* Initialize some common structures */ xbt_cfg_set_parse("network/model:CM02"); xbt_cfg_set_parse("cpu/model:Cas01"); xbt_assert(argc >1, "Usage : %s platform.txt\n", argv[0]); parse_platform_file(argv[1]); /*********************** HOST ***********************************/ hostA = sg_host_by_name("Cpu A"); hostB = sg_host_by_name("Cpu B"); /* Let's check that those two processors exist */ XBT_DEBUG("%s : %p", sg_host_get_name(hostA), hostA); XBT_DEBUG("%s : %p", sg_host_get_name(hostB), hostB); /* Let's do something on it */ hostA->pimpl_cpu->execution_start(1000.0); hostB->pimpl_cpu->execution_start(1000.0); surf_host_sleep(hostB, 7.32); surf_network_model_communicate(surf_network_model, hostA, hostB, 150.0, -1.0); surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */ do { surf_action_t action = NULL; unsigned int iter; surf_model_t model = NULL; running = 0; now = surf_get_clock(); XBT_INFO("Next Event : %g", now); xbt_dynar_foreach(all_existing_models, iter, model) { if (surf_model_running_action_set_size((surf_model_t)model)) { XBT_DEBUG("\t Running that model"); running = 1; } while ((action = surf_model_extract_failed_action_set((surf_model_t)model))) { XBT_INFO(" * Done Action"); XBT_DEBUG("\t * Failed Action: %p", action); action->unref(); } while ((action = surf_model_extract_done_action_set((surf_model_t)model))) { XBT_INFO(" * Done Action"); XBT_DEBUG("\t * Done Action: %p", action); action->unref(); } } } while (running && surf_solve(-1.0) >= 0.0); XBT_INFO("Simulation Terminated"); surf_exit(); return 0; }
void test(char *platform) { sg_host_t cpuA = NULL; sg_host_t cpuB = NULL; surf_action_t actionA = NULL; surf_action_t actionB = NULL; surf_action_t actionC = NULL; e_surf_action_state_t stateActionA; e_surf_action_state_t stateActionB; e_surf_action_state_t stateActionC; double now = -1.0; xbt_cfg_set_parse(_sg_cfg_set, "cpu/model:Cas01"); xbt_cfg_set_parse(_sg_cfg_set, "network/model:CM02"); parse_platform_file(platform); /*********************** CPU ***********************************/ XBT_DEBUG("%p", surf_cpu_model_pm); cpuA = sg_host_by_name("Cpu A"); cpuB = sg_host_by_name("Cpu B"); /* Let's check that those two processors exist */ XBT_DEBUG("%s : %p", surf_cpu_name(sg_host_surfcpu(cpuA)), cpuA); XBT_DEBUG("%s : %p", surf_cpu_name(sg_host_surfcpu(cpuB)), cpuB); /* Let's do something on it */ actionA = surf_cpu_execute(cpuA, 1000.0); actionB = surf_cpu_execute(cpuB, 1000.0); actionC = surf_cpu_sleep(cpuB, 7.32); /* Use whatever calling style you want... */ stateActionA = surf_action_get_state(actionA); /* When you know actionA model type */ stateActionB = surf_action_get_state(actionB); /* If you're unsure about it's model type */ stateActionC = surf_action_get_state(actionC); /* When you know actionA model type */ /* And just look at the state of these tasks */ XBT_DEBUG("actionA : %p (%s)", actionA, string_action(stateActionA)); XBT_DEBUG("actionB : %p (%s)", actionB, string_action(stateActionB)); XBT_DEBUG("actionC : %p (%s)", actionB, string_action(stateActionC)); /*********************** Network *******************************/ XBT_DEBUG("%p", surf_network_model); /* Let's do something on it */ surf_network_model_communicate(surf_network_model, cpuA, cpuB, 150.0, -1.0); surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */ do { surf_action_t action = NULL; now = surf_get_clock(); XBT_DEBUG("Next Event : %g", now); XBT_DEBUG("\t CPU actions"); while ((action = surf_model_extract_failed_action_set((surf_model_t)surf_cpu_model_pm))) { XBT_DEBUG("\t * Failed : %p", action); surf_action_unref(action); } while ((action = surf_model_extract_done_action_set((surf_model_t)surf_cpu_model_pm))) { XBT_DEBUG("\t * Done : %p", action); surf_action_unref(action); } XBT_DEBUG("\t Network actions"); while ((action = surf_model_extract_failed_action_set((surf_model_t)surf_network_model))) { XBT_DEBUG("\t * Failed : %p", action); surf_action_unref(action); } while ((action = surf_model_extract_done_action_set((surf_model_t)surf_network_model))) { XBT_DEBUG("\t * Done : %p", action); surf_action_unref(action); } } while ((surf_model_running_action_set_size((surf_model_t)surf_network_model) || surf_model_running_action_set_size((surf_model_t)surf_cpu_model_pm)) && surf_solve(-1.0) >= 0.0); XBT_DEBUG("Simulation Terminated"); }
void setCpu(char *name, Cpu *cpu) { sg_host_surfcpu_set(sg_host_by_name(name), cpu); }