/* Business methods */ xbt_dynar_t AsFloyd::getOneLinkRoutes() { xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), xbt_free_f); sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1); route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); int src,dst; sg_routing_edge_t src_elm, dst_elm; int table_size = xbt_dynar_length(p_indexNetworkElm); for(src=0; src < table_size; src++) { for(dst=0; dst< table_size; dst++) { xbt_dynar_reset(route->link_list); src_elm = xbt_dynar_get_as(p_indexNetworkElm, src, RoutingEdgePtr); dst_elm = xbt_dynar_get_as(p_indexNetworkElm, dst, RoutingEdgePtr); this->getRouteAndLatency(src_elm, dst_elm, route, NULL); if (xbt_dynar_length(route->link_list) == 1) { void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0); OnelinkPtr onelink; if (p_hierarchy == SURF_ROUTING_BASE) onelink = new Onelink(link, src_elm, dst_elm); else if (p_hierarchy == SURF_ROUTING_RECURSIVE) onelink = new Onelink(link, route->gw_src, route->gw_dst); else onelink = new Onelink(link, NULL, NULL); xbt_dynar_push(ret, &onelink); } } } return ret; }
int MC_request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx) { smx_action_t act; switch (req->call) { case SIMCALL_COMM_WAIT: /* FIXME: check also that src and dst processes are not suspended */ act = simcall_comm_wait__get__comm(req); return (act->comm.src_proc && act->comm.dst_proc); break; case SIMCALL_COMM_WAITANY: act = xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), idx, smx_action_t); return (act->comm.src_proc && act->comm.dst_proc); break; case SIMCALL_COMM_TESTANY: act = xbt_dynar_get_as(simcall_comm_testany__get__comms(req), idx, smx_action_t); return (act->comm.src_proc && act->comm.dst_proc); break; default: return TRUE; } }
JNIEXPORT void JNICALL JNICALL Java_org_simgrid_msg_Msg_run(JNIEnv * env, jclass cls) { /* Run everything */ XBT_DEBUG("Ready to run MSG_MAIN"); msg_error_t rv = MSG_main(); XBT_DEBUG("Done running MSG_MAIN"); jxbt_check_res("MSG_main()", rv, MSG_OK, xbt_strdup("unexpected error : MSG_main() failed .. please report this bug ")); XBT_INFO("MSG_main finished; Cleaning up the simulation..."); /* Cleanup java hosts */ xbt_dynar_t hosts = MSG_hosts_as_dynar(); for (unsigned long index = 0; index < xbt_dynar_length(hosts) - 1; index++) { msg_host_t msg_host = xbt_dynar_get_as(hosts,index,msg_host_t); jobject jhost = (jobject) msg_host->extension(JAVA_HOST_LEVEL); if (jhost) jhost_unref(env, jhost); } xbt_dynar_free(&hosts); /* Cleanup java storages */ xbt_dynar_t storages = MSG_storages_as_dynar(); if(!xbt_dynar_is_empty(storages)){ for (unsigned long index = 0; index < xbt_dynar_length(storages) - 1; index++) { jobject jstorage = (jobject) xbt_lib_get_level(xbt_dynar_get_as(storages,index,msg_storage_t), JAVA_STORAGE_LEVEL); if (jstorage) jstorage_unref(env, jstorage); } } xbt_dynar_free(&storages); }
static void smx_ctx_boost_suspend_serial(smx_context_t context) { /* determine the next context */ smx_ctx_boost_t next_context; unsigned long int i = boost_process_index++; if (i < xbt_dynar_length(simix_global->process_to_run)) { /* execute the next process */ XBT_DEBUG("Run next process"); next_context = (smx_ctx_boost_t) xbt_dynar_get_as( simix_global->process_to_run, i, smx_process_t)->context; } else { /* all processes were run, return to maestro */ XBT_DEBUG("No more process to run"); next_context = (smx_ctx_boost_t) boost_maestro_context; } SIMIX_context_set_current((smx_context_t) next_context); #if HAVE_BOOST_CONTEXT == 1 boost::context::jump_fcontext( ((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context); #else boost::context::jump_fcontext( &((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context); #endif }
msg_error_t peer_wait_for_message(peer_t peer) { msg_error_t status; msg_comm_t comm = NULL; msg_task_t task = NULL; int idx = -1; int done = 0; while (!done) { comm = MSG_task_irecv(&task, peer->me); queue_pending_connection(comm, peer->pending_recvs); if ((idx = MSG_comm_waitany(peer->pending_recvs)) != -1) { comm = xbt_dynar_get_as(peer->pending_recvs, idx, msg_comm_t); status = MSG_comm_get_status(comm); XBT_DEBUG("peer_wait_for_message: error code = %d", status); xbt_assert(status == MSG_OK, "peer_wait_for_message() failed"); task = MSG_comm_get_task(comm); MSG_comm_destroy(comm); xbt_dynar_cursor_rm(peer->pending_recvs, (unsigned int*)&idx); done = peer_execute_task(peer, task); task_message_delete(task); task = NULL; } process_pending_connections(peer->pending_sends); } return status; }
int main(int argc, char **argv) { int i; msg_error_t res = MSG_OK; MSG_init(&argc, argv); surf_parse = surf_parse_bypass_platform; MSG_create_environment(NULL); MSG_function_register("host", host); xbt_dynar_t hosts = MSG_hosts_as_dynar(); nb_hosts = xbt_dynar_length(hosts); XBT_INFO("Number of host '%d'",nb_hosts); for(i = 0 ; i<nb_hosts; i++) { char* name_host = bprintf("%d",i); MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,msg_host_t) ); free(name_host); } xbt_dynar_free(&hosts); res = MSG_main(); XBT_INFO("Simulation time %g", MSG_get_clock()); if (res == MSG_OK) return 0; else return 1; }
static void vivaldi_get_route_and_latency( AS_t rc, sg_routing_edge_t src_p, sg_routing_edge_t dst_p, sg_platf_route_cbarg_t route, double *lat) { s_surf_parsing_link_up_down_t info; XBT_DEBUG("vivaldi_get_route_and_latency from '%s'[%d] '%s'[%d]",src_p->name,src_p->id,dst_p->name,dst_p->id); char *src = (char*)src_p->name; char *dst = (char*)dst_p->name; if(src_p->rc_type == SURF_NETWORK_ELEMENT_AS) { char *rp_src = ROUTER_PEER(src); char *rp_dst = ROUTER_PEER(dst); route->gw_src = xbt_lib_get_or_null(as_router_lib, rp_src, ROUTING_ASR_LEVEL); route->gw_dst = xbt_lib_get_or_null(as_router_lib, rp_dst, ROUTING_ASR_LEVEL); xbt_free(rp_src); xbt_free(rp_dst); } double euclidean_dist; xbt_dynar_t src_ctn, dst_ctn; char *tmp_src_name, *tmp_dst_name; if(src_p->rc_type == SURF_NETWORK_ELEMENT_HOST){ tmp_src_name = HOST_PEER(src); if(rc->link_up_down_list){ info = xbt_dynar_get_as(rc->link_up_down_list,src_p->id,s_surf_parsing_link_up_down_t); if(info.link_up) { // link up xbt_dynar_push_as(route->link_list,void*,info.link_up); if (lat) *lat += surf_network_model->extension.network.get_link_latency(info.link_up); }
void AsVivaldi::getRouteAndLatency(RoutingEdge *src, RoutingEdge *dst, sg_platf_route_cbarg_t route, double *lat) { s_surf_parsing_link_up_down_t info; XBT_DEBUG("vivaldi_get_route_and_latency from '%s'[%d] '%s'[%d]", src->getName(), src->getId(), dst->getName(), dst->getId()); if(src->getRcType() == SURF_NETWORK_ELEMENT_AS) { char *src_name = ROUTER_PEER(src->getName()); char *dst_name = ROUTER_PEER(dst->getName()); route->gw_src = (sg_routing_edge_t) xbt_lib_get_or_null(as_router_lib, src_name, ROUTING_ASR_LEVEL); route->gw_dst = (sg_routing_edge_t) xbt_lib_get_or_null(as_router_lib, dst_name, ROUTING_ASR_LEVEL); xbt_free(src_name); xbt_free(dst_name); } double euclidean_dist; xbt_dynar_t src_ctn, dst_ctn; char *tmp_src_name, *tmp_dst_name; if(src->getRcType() == SURF_NETWORK_ELEMENT_HOST){ tmp_src_name = HOST_PEER(src->getName()); if(p_linkUpDownList){ info = xbt_dynar_get_as(p_linkUpDownList, src->getId(), s_surf_parsing_link_up_down_t); if(info.link_up) { // link up xbt_dynar_push_as(route->link_list, void*, info.link_up); if (lat) *lat += static_cast<Link*>(info.link_up)->getLatency(); } }
static void smx_ctx_cojava_suspend(smx_context_t context) { smx_context_t previous_context = context; unsigned long int i = cojava_process_index++; jobject next_coroutine; if (i < xbt_dynar_length(cojava_processes)) { smx_context_t next_context = SIMIX_process_get_context(xbt_dynar_get_as( cojava_processes,i, smx_process_t)); my_current_context = next_context; XBT_DEBUG("Switching to %p",my_current_context); smx_ctx_cojava_t java_context = (smx_ctx_cojava_t)(next_context); if (!java_context->jprocess) { java_context->super.code(java_context->super.argc, java_context->super.argv); smx_ctx_cojava_create_coroutine(java_context); } else if (!java_context->bound) { java_context->bound = 1; smx_process_t process = SIMIX_process_self(); (*global_env)->SetLongField(global_env, java_context->jprocess, jprocess_field_Process_bind, (intptr_t)process); } next_coroutine = java_context->jcoroutine; } else { //Give maestro the control back. next_coroutine = cojava_maestro_coroutine; my_current_context = maestro_context; } (*global_env)->CallStaticVoidMethod(global_env, coclass, coroutine_yieldTo, next_coroutine); my_current_context = previous_context; }
void BoostSerialContext::suspend() { /* determine the next context */ BoostSerialContext* next_context = nullptr; unsigned long int i = process_index_++; if (i < xbt_dynar_length(simix_global->process_to_run)) { /* execute the next process */ XBT_DEBUG("Run next process"); next_context = static_cast<BoostSerialContext*>(xbt_dynar_get_as( simix_global->process_to_run, i, smx_process_t)->context); } else { /* all processes were run, return to maestro */ XBT_DEBUG("No more process to run"); next_context = static_cast<BoostSerialContext*>( maestro_context_); } SIMIX_context_set_current((smx_context_t) next_context); #if HAVE_BOOST_CONTEXTS == 1 boost::context::jump_fcontext( this->fc_, next_context->fc_, (intptr_t) next_context); #else boost::context::jump_fcontext( &this->fc_, next_context->fc_, (intptr_t) next_context); #endif }
void RawContextFactory::run_all_serial() { smx_process_t first_process = xbt_dynar_get_as(simix_global->process_to_run, 0, smx_process_t); raw_process_index = 1; static_cast<RawContext*>(first_process->context)->resume_serial(); }
int main(int argc, char **argv) { int i,res; MSG_init(&argc, argv); MSG_create_environment(argv[1]); xbt_dynar_t hosts = MSG_hosts_as_dynar(); MSG_function_register("host", host); unsigned long nb_hosts = xbt_dynar_length(hosts); XBT_INFO("Number of host '%lu'",nb_hosts); for(i = 0 ; i<nb_hosts; i++) { char* name_host = bprintf("%d",i); MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,msg_host_t) ); free(name_host); } xbt_dynar_free(&hosts); res = MSG_main(); XBT_INFO("Simulation time %g", MSG_get_clock()); if (res == MSG_OK) return 0; else return 1; }
static void smx_ctx_boost_runall_serial(void) { smx_process_t first_process = xbt_dynar_get_as(simix_global->process_to_run, 0, smx_process_t); boost_process_index = 1; /* execute the first process */ smx_ctx_boost_resume_serial(first_process); }
int master_fun(int argc, char *argv[]) { msg_vm_t vm; unsigned int i; xbt_dynar_t worker_pms = MSG_process_get_data(MSG_process_self()); int nb_workers = xbt_dynar_length(worker_pms); xbt_dynar_t vms = xbt_dynar_new(sizeof(msg_vm_t), NULL); /* Launch VMs and worker processes. One VM per PM, and one worker process per VM. */ XBT_INFO("# Launch %d VMs", nb_workers); for (i = 0; i< nb_workers; i++) { char *vm_name = bprintf("VM%02d", i); char *pr_name = bprintf("WRK%02d", i); msg_host_t pm = xbt_dynar_get_as(worker_pms, i, msg_host_t); XBT_INFO("create %s on PM(%s)", vm_name, MSG_host_get_name(pm)); msg_vm_t vm = MSG_vm_create_core(pm, vm_name); s_vm_params_t params; memset(¶ms, 0, sizeof(params)); params.ramsize = 1L * 1024 * 1024 * 1024; // 1Gbytes MSG_host_set_params(vm, ¶ms); MSG_vm_start(vm); xbt_dynar_push(vms, &vm); XBT_INFO("put a process (%s) on %s", pr_name, vm_name); MSG_process_create(pr_name, worker_fun, NULL, vm); xbt_free(vm_name); xbt_free(pr_name); } /* Send a bunch of work to every one */ XBT_INFO("# Send a task to %d worker process", nb_workers); send_tasks(nb_workers); XBT_INFO("# Suspend all VMs"); xbt_dynar_foreach(vms, i, vm) { const char *vm_name = MSG_host_get_name(vm); XBT_INFO("suspend %s", vm_name); MSG_vm_suspend(vm); } XBT_INFO("# Wait a while"); MSG_process_sleep(2); XBT_INFO("# Resume all VMs"); xbt_dynar_foreach(vms, i, vm) { MSG_vm_resume(vm); }
static void smx_ctx_cojava_runall(void) { cojava_processes = SIMIX_process_get_runnable(); smx_process_t process; if (!xbt_dynar_is_empty(cojava_processes)) { process = xbt_dynar_get_as(cojava_processes, 0, smx_process_t); cojava_process_index = 1; /* Execute the first process */ smx_ctx_cojava_resume(SIMIX_process_get_context(process)); } }
/** * \brief Returns the host given its index. * \param L a Lua state * \return number of values returned to Lua * * - Argument 1 (number): an index (1 is the first) * - Return value (host): the host at this index */ static int l_host_at(lua_State * L) { int index = luaL_checkinteger(L, 1); xbt_dynar_t hosts = sg_hosts_as_dynar(); sg_host_t host = xbt_dynar_get_as(hosts,index - 1,sg_host_t);// lua indexing start by 1 (lua[1] <=> C[0]) lua_newtable(L); /* create a table, put the userdata on top of it */ sg_host_t *lua_host = (sg_host_t *) lua_newuserdata(L, sizeof(sg_host_t)); *lua_host = host; luaL_getmetatable(L, HOST_MODULE_NAME); lua_setmetatable(L, -2); lua_setfield(L, -2, HOST_FIELDNAME); /* put the userdata as field of the table */ xbt_dynar_free(&hosts); return 1; }
int main(int argc, char *argv[]){ MSG_init(&argc, argv); xbt_assert(argc == 2); MSG_create_environment(argv[1]); xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar(); msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t); launch_master(pm0); int res = MSG_main(); XBT_INFO("Bye (simulation time %g)", MSG_get_clock()); xbt_dynar_free(&hosts_dynar); return !(res == MSG_OK); }
/* Business methods */ static void cluster_get_route_and_latency(AS_t as, sg_routing_edge_t src, sg_routing_edge_t dst, sg_platf_route_cbarg_t route, double *lat) { s_surf_parsing_link_up_down_t info; XBT_DEBUG("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]", src->name,src->id, dst->name,dst->id); if(src->rc_type != SURF_NETWORK_ELEMENT_ROUTER){ // No specific link for router info = xbt_dynar_get_as(as->link_up_down_list,src->id,s_surf_parsing_link_up_down_t); if(info.link_up) { // link up xbt_dynar_push_as(route->link_list,void*,info.link_up); if (lat) *lat += surf_network_model->extension.network.get_link_latency(info.link_up); }
void peer_shutdown(peer_t p) { unsigned int size = xbt_dynar_length(p->pending_sends); unsigned int idx; msg_comm_t *comms = xbt_new(msg_comm_t, size); for (idx = 0; idx < size; idx++) { comms[idx] = xbt_dynar_get_as(p->pending_sends, idx, msg_comm_t); } XBT_DEBUG("Waiting for sends to finish before shutdown..."); MSG_comm_waitall(comms, size, PEER_SHUTDOWN_DEADLINE); for (idx = 0; idx < size; idx++) { MSG_comm_destroy(comms[idx]); } xbt_free(comms); }
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg) { int index; jobjectArray jtable; jobject jhost; jstring jname; msg_host_t host; xbt_dynar_t table = MSG_hosts_as_dynar(); int count = xbt_dynar_length(table); jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host"); if (!cls) { return NULL; } jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL); if (!jtable) { jxbt_throw_jni(env, "Hosts table allocation failed"); return NULL; } for (index = 0; index < count; index++) { host = xbt_dynar_get_as(table,index,msg_host_t); jhost = (jobject) (MSG_host_get_data(host)); if (!jhost) { jname = (*env)->NewStringUTF(env, MSG_host_get_name(host)); jhost = Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname); /* FIXME: leak of jname ? */ } (*env)->SetObjectArrayElement(env, jtable, index, jhost); } xbt_dynar_free(&table); return jtable; }
void RawContext::suspend_serial() { /* determine the next context */ RawContext* next_context = nullptr; unsigned long int i; i = raw_process_index++; if (i < xbt_dynar_length(simix_global->process_to_run)) { /* execute the next process */ XBT_DEBUG("Run next process"); next_context = (RawContext*) xbt_dynar_get_as( simix_global->process_to_run, i, smx_process_t)->context; } else { /* all processes were run, return to maestro */ XBT_DEBUG("No more process to run"); next_context = (RawContext*) raw_maestro_context; } SIMIX_context_set_current(next_context); raw_swapcontext(&this->stack_top_, next_context->stack_top_); }
void BoostContextFactory::run_all() { #ifdef HAVE_THREAD_CONTEXTS if (BoostContext::parallel_) { BoostContext::threads_working_ = 0; xbt_parmap_apply(BoostContext::parmap_, [](void* arg) { smx_process_t process = static_cast<smx_process_t>(arg); BoostContext* context = static_cast<BoostContext*>(process->context); return context->resume(); }, simix_global->process_to_run); } else #endif { smx_process_t first_process = xbt_dynar_get_as(simix_global->process_to_run, 0, smx_process_t); BoostContext::process_index_ = 1; /* execute the first process */ static_cast<BoostContext*>(first_process->context)->resume(); } }
static int master_main(int argc, char *argv[]) { xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar(); msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t); msg_vm_t vm0; vm0 = MSG_vm_create_core(pm0, "VM0"); MSG_vm_start(vm0); //MSG_process_sleep(1); launch_computation_worker(vm0); while(MSG_get_clock()<10000) { if (atask != NULL) XBT_INFO("aTask remaining duration: %g", MSG_task_get_remaining_computation(atask)); MSG_process_sleep(100); } MSG_process_sleep(10000); MSG_vm_destroy(vm0); xbt_dynar_free(&hosts_dynar); return 1; }
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Storage_all(JNIEnv * env, jclass cls_arg) { int index; jobjectArray jtable; jobject jstorage; jstring jname; msg_storage_t storage; xbt_dynar_t table = MSG_storages_as_dynar(); int count = xbt_dynar_length(table); jclass cls = jxbt_get_class(env, "org/simgrid/msg/Storage"); if (!cls) { return NULL; } jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL); if (!jtable) { jxbt_throw_jni(env, "Storages table allocation failed"); return NULL; } for (index = 0; index < count; index++) { storage = xbt_dynar_get_as(table,index,msg_storage_t); jstorage = (jobject) (xbt_lib_get_level(storage, JAVA_STORAGE_LEVEL)); if (!jstorage) { jname = (*env)->NewStringUTF(env, MSG_storage_get_name(storage)); jstorage = Java_org_simgrid_msg_Storage_getByName(env, cls_arg, jname); } (*env)->SetObjectArrayElement(env, jtable, index, jstorage); } xbt_dynar_free(&table); return jtable; }
void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t synchros, double timeout) { smx_activity_t synchro; unsigned int cursor = 0; if (MC_is_active() || MC_record_replay_is_active()){ if (timeout > 0.0) xbt_die("Timeout not implemented for waitany in the model-checker"); int idx = SIMCALL_GET_MC_VALUE(simcall); synchro = xbt_dynar_get_as(synchros, idx, smx_activity_t); synchro->simcalls.push_back(simcall); simcall_comm_waitany__set__result(simcall, idx); synchro->state = SIMIX_DONE; SIMIX_comm_finish(synchro); return; } if (timeout < 0.0){ simcall->timer = NULL; } else { simcall->timer = SIMIX_timer_set(SIMIX_get_clock() + timeout, [simcall]() { SIMIX_waitany_remove_simcall_from_actions(simcall); simcall_comm_waitany__set__result(simcall, -1); SIMIX_simcall_answer(simcall); }); } xbt_dynar_foreach(synchros, cursor, synchro){ /* associate this simcall to the the synchro */ synchro->simcalls.push_back(simcall); /* see if the synchro is already finished */ if (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING){ SIMIX_comm_finish(synchro); break; } }
int LivenessChecker::main(void) { while (!explorationStack_.empty()){ std::shared_ptr<Pair> current_pair = explorationStack_.back(); /* Update current state in buchi automaton */ simgrid::mc::property_automaton->current_state = current_pair->automaton_state; XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d, interleave size = %zd, pair_num = %d, requests = %d)", current_pair->depth, current_pair->search_cycle, current_pair->graph_state->interleaveSize(), current_pair->num, current_pair->requests); if (current_pair->requests == 0) { this->backtrack(); continue; } std::shared_ptr<VisitedPair> reached_pair; if (current_pair->automaton_state->type == 1 && !current_pair->exploration_started && (reached_pair = this->insertAcceptancePair(current_pair.get())) == nullptr) { this->showAcceptanceCycle(current_pair->depth); return SIMGRID_MC_EXIT_LIVENESS; } /* Pair already visited ? stop the exploration on the current path */ int visited_num = -1; if ((!current_pair->exploration_started) && (visited_num = this->insertVisitedPair( reached_pair, current_pair.get())) != -1) { if (dot_output != nullptr){ fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", this->previousPair_, visited_num, this->previousRequest_.c_str()); fflush(dot_output); } XBT_DEBUG("Pair already visited (equal to pair %d), exploration on the current path stopped.", visited_num); current_pair->requests = 0; this->backtrack(); continue; } smx_simcall_t req = MC_state_get_request(current_pair->graph_state.get()); int req_num = current_pair->graph_state->transition.argument; if (dot_output != nullptr) { if (this->previousPair_ != 0 && this->previousPair_ != current_pair->num) { fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", this->previousPair_, current_pair->num, this->previousRequest_.c_str()); this->previousRequest_.clear(); } this->previousPair_ = current_pair->num; this->previousRequest_ = simgrid::mc::request_get_dot_output(req, req_num); if (current_pair->search_cycle) fprintf(dot_output, "%d [shape=doublecircle];\n", current_pair->num); fflush(dot_output); } XBT_DEBUG("Execute: %s", simgrid::mc::request_to_string( req, req_num, simgrid::mc::RequestType::simix).c_str()); /* Update stats */ mc_model_checker->executed_transitions++; if (!current_pair->exploration_started) visitedPairsCount_++; /* Answer the request */ mc_model_checker->handle_simcall(current_pair->graph_state->transition); /* Wait for requests (schedules processes) */ mc_model_checker->wait_for_requests(); current_pair->requests--; current_pair->exploration_started = true; /* Get values of atomic propositions (variables used in the property formula) */ std::shared_ptr<const std::vector<int>> prop_values = this->getPropositionValues(); // For each enabled transition in the property automaton, push a // (application_state, automaton_state) pair to the exploration stack: int cursor = xbt_dynar_length(current_pair->automaton_state->out) - 1; while (cursor >= 0) { xbt_automaton_transition_t transition_succ = (xbt_automaton_transition_t)xbt_dynar_get_as(current_pair->automaton_state->out, cursor, xbt_automaton_transition_t); if (evaluate_label(transition_succ->label, *prop_values)) explorationStack_.push_back(this->newPair( current_pair.get(), transition_succ->dst, prop_values)); cursor--; } } XBT_INFO("No property violation found."); simgrid::mc::session->logState(); return SIMGRID_MC_EXIT_SUCCESS; }
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat) { getRouteCheckParams(src, dst); int src_id = src->id(); int dst_id = dst->id(); int *pred_arr = nullptr; sg_platf_route_cbarg_t e_route; int size = 0; xbt_dynar_t nodes = xbt_graph_get_nodes(routeGraph_); /* Use the graph_node id mapping set to quickly find the nodes */ graph_node_map_element_t src_elm = nodeMapSearch(src_id); graph_node_map_element_t dst_elm = nodeMapSearch(dst_id); int src_node_id = ((graph_node_data_t) xbt_graph_node_get_data(src_elm->node))->graph_id; int dst_node_id = ((graph_node_data_t) xbt_graph_node_get_data(dst_elm->node))->graph_id; /* if the src and dst are the same */ if (src_node_id == dst_node_id) { xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t); xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t); xbt_edge_t edge = xbt_graph_get_edge(routeGraph_, node_s_v, node_e_v); if (edge == nullptr) THROWF(arg_error, 0, "No route from '%s' to '%s'", src->name(), dst->name()); e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge); for (auto link: *e_route->link_list) { route->link_list->insert(route->link_list->begin(), link); if (lat) *lat += static_cast<Link*>(link)->getLatency(); } } route_cache_element_t elm = nullptr; if (routeCache_) { /* cache mode */ elm = (route_cache_element_t) xbt_dict_get_or_null_ext(routeCache_, (char *) (&src_id), sizeof(int)); } if (elm) { /* cached mode and cache hit */ pred_arr = elm->pred_arr; } else { /* not cached mode, or cache miss */ int nr_nodes = xbt_dynar_length(nodes); double * cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */ pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */ xbt_heap_t pqueue = xbt_heap_new(nr_nodes, xbt_free_f); /* initialize */ cost_arr[src_node_id] = 0.0; for (int i = 0; i < nr_nodes; i++) { if (i != src_node_id) { cost_arr[i] = DBL_MAX; } pred_arr[i] = 0; /* initialize priority queue */ int *nodeid = xbt_new0(int, 1); *nodeid = i; xbt_heap_push(pqueue, nodeid, cost_arr[i]); } /* apply dijkstra using the indexes from the graph's node array */ while (xbt_heap_size(pqueue) > 0) { int *v_id = (int *) xbt_heap_pop(pqueue); xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t); xbt_edge_t edge = nullptr; unsigned int cursor; xbt_dynar_foreach(xbt_graph_node_get_outedges(v_node), cursor, edge) { xbt_node_t u_node = xbt_graph_edge_get_target(edge); graph_node_data_t data = (graph_node_data_t) xbt_graph_node_get_data(u_node); int u_id = data->graph_id; sg_platf_route_cbarg_t tmp_e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge); int cost_v_u = tmp_e_route->link_list->size(); /* count of links, old model assume 1 */ if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) { pred_arr[u_id] = *v_id; cost_arr[u_id] = cost_v_u + cost_arr[*v_id]; int *nodeid = xbt_new0(int, 1); *nodeid = u_id; xbt_heap_push(pqueue, nodeid, cost_arr[u_id]); } } /* free item popped from pqueue */ xbt_free(v_id); }
static int is_visited_state(){ if(_sg_mc_visited == 0) return -1; int raw_mem_set = (mmalloc_get_current_heap() == raw_heap); MC_SET_RAW_MEM; mc_visited_state_t new_state = visited_state_new(); MC_UNSET_RAW_MEM; if(xbt_dynar_is_empty(visited_states)){ MC_SET_RAW_MEM; xbt_dynar_push(visited_states, &new_state); MC_UNSET_RAW_MEM; if(raw_mem_set) MC_SET_RAW_MEM; return -1; }else{ MC_SET_RAW_MEM; size_t current_bytes_used = new_state->heap_bytes_used; int current_nb_processes = new_state->nb_processes; unsigned int cursor = 0; int previous_cursor = 0, next_cursor = 0; int start = 0; int end = xbt_dynar_length(visited_states) - 1; mc_visited_state_t state_test = NULL; size_t bytes_used_test; int nb_processes_test; int same_processes_and_bytes_not_found = 1; while(start <= end && same_processes_and_bytes_not_found){ cursor = (start + end) / 2; state_test = (mc_visited_state_t)xbt_dynar_get_as(visited_states, cursor, mc_visited_state_t); bytes_used_test = state_test->heap_bytes_used; nb_processes_test = state_test->nb_processes; if(nb_processes_test < current_nb_processes){ start = cursor + 1; }else if(nb_processes_test > current_nb_processes){ end = cursor - 1; }else if(nb_processes_test == current_nb_processes){ if(bytes_used_test < current_bytes_used) start = cursor + 1; if(bytes_used_test > current_bytes_used) end = cursor - 1; if(bytes_used_test == current_bytes_used){ same_processes_and_bytes_not_found = 0; if(snapshot_compare(new_state->system_state, state_test->system_state) == 0){ XBT_DEBUG("State %d already visited ! (equal to state %d)", new_state->num, state_test->num); if(raw_mem_set) MC_SET_RAW_MEM; else MC_UNSET_RAW_MEM; return state_test->num; }else{ /* Search another state with same number of bytes used in std_heap */ previous_cursor = cursor - 1; while(previous_cursor >= 0){ state_test = (mc_visited_state_t)xbt_dynar_get_as(visited_states, previous_cursor, mc_visited_state_t); bytes_used_test = state_test->system_state->heap_bytes_used; if(bytes_used_test != current_bytes_used) break; if(snapshot_compare(new_state->system_state, state_test->system_state) == 0){ XBT_DEBUG("State %d already visited ! (equal to state %d)", new_state->num, state_test->num); if(raw_mem_set) MC_SET_RAW_MEM; else MC_UNSET_RAW_MEM; return state_test->num; } previous_cursor--; } next_cursor = cursor + 1; while(next_cursor < xbt_dynar_length(visited_states)){ state_test = (mc_visited_state_t)xbt_dynar_get_as(visited_states, next_cursor, mc_visited_state_t); bytes_used_test = state_test->system_state->heap_bytes_used; if(bytes_used_test != current_bytes_used) break; if(snapshot_compare(new_state->system_state, state_test->system_state) == 0){ XBT_DEBUG("State %d already visited ! (equal to state %d)", new_state->num, state_test->num); if(raw_mem_set) MC_SET_RAW_MEM; else MC_UNSET_RAW_MEM; return state_test->num; } next_cursor++; } } } } } state_test = (mc_visited_state_t)xbt_dynar_get_as(visited_states, cursor, mc_visited_state_t); bytes_used_test = state_test->heap_bytes_used; if(bytes_used_test < current_bytes_used) xbt_dynar_insert_at(visited_states, cursor + 1, &new_state); else xbt_dynar_insert_at(visited_states, cursor, &new_state); if(xbt_dynar_length(visited_states) > _sg_mc_visited){ int min = mc_stats->expanded_states; unsigned int cursor2 = 0; unsigned int index = 0; xbt_dynar_foreach(visited_states, cursor2, state_test){ if(state_test->num < min){ index = cursor2; min = state_test->num; } } xbt_dynar_remove_at(visited_states, index, NULL); } MC_UNSET_RAW_MEM; if(raw_mem_set) MC_SET_RAW_MEM; return -1; }
host_data=MSG_host_get_data(host); //filter if (filter_host(host_data,task_data)) { //check score score=(host_data->ntasks+0.01)*1000000000.0/MSG_get_host_speed(host); //XBT_INFO("score %f %f",score,MSG_get_host_speed(host)); if (score<best) { bestpos=i; best=score; } } } host=xbt_dynar_get_as(hosts_dynar, bestpos, msg_host_t); allocate_vm(host,task_data); } int main(int argc, char *argv[]) { /* Get the arguments */ MSG_init(&argc, argv); /* load the platform file */ xbt_assert(argc == 4); MSG_create_environment(argv[1]); hosts_dynar = MSG_hosts_as_dynar();
char *MC_request_to_string(smx_simcall_t req, int value) { char *type = NULL, *args = NULL, *str = NULL, *p = NULL, *bs = NULL; smx_action_t act = NULL; size_t size = 0; switch(req->call){ case SIMCALL_COMM_ISEND: type = xbt_strdup("iSend"); p = pointer_to_string(simcall_comm_isend__get__src_buff(req)); bs = buff_size_to_string(simcall_comm_isend__get__src_buff_size(req)); args = bprintf("src=%s, buff=%s, size=%s", req->issuer->name, p, bs); break; case SIMCALL_COMM_IRECV: size = simcall_comm_irecv__get__dst_buff_size(req) ? *simcall_comm_irecv__get__dst_buff_size(req) : 0; type = xbt_strdup("iRecv"); p = pointer_to_string(simcall_comm_irecv__get__dst_buff(req)); bs = buff_size_to_string(size); args = bprintf("dst=%s, buff=%s, size=%s", req->issuer->name, p, bs); break; case SIMCALL_COMM_WAIT: act = simcall_comm_wait__get__comm(req); if(value == -1){ type = xbt_strdup("WaitTimeout"); p = pointer_to_string(act); args = bprintf("comm=%p", p); }else{ type = xbt_strdup("Wait"); p = pointer_to_string(act); args = bprintf("comm=%s [(%lu)%s -> (%lu)%s]", p, act->comm.src_proc ? act->comm.src_proc->pid : 0, act->comm.src_proc ? act->comm.src_proc->name : "", act->comm.dst_proc ? act->comm.dst_proc->pid : 0, act->comm.dst_proc ? act->comm.dst_proc->name : ""); } break; case SIMCALL_COMM_TEST: act = simcall_comm_test__get__comm(req); if(act->comm.src_proc == NULL || act->comm.dst_proc == NULL){ type = xbt_strdup("Test FALSE"); p = pointer_to_string(act); args = bprintf("comm=%s", p); }else{ type = xbt_strdup("Test TRUE"); p = pointer_to_string(act); args = bprintf("comm=%s [(%lu)%s -> (%lu)%s]", p, act->comm.src_proc->pid, act->comm.src_proc->name, act->comm.dst_proc->pid, act->comm.dst_proc->name); } break; case SIMCALL_COMM_WAITANY: type = xbt_strdup("WaitAny"); p = pointer_to_string(xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), value, smx_action_t)); args = bprintf("comm=%s (%d of %lu)", p, value+1, xbt_dynar_length(simcall_comm_waitany__get__comms(req))); break; case SIMCALL_COMM_TESTANY: if(value == -1){ type = xbt_strdup("TestAny FALSE"); args = xbt_strdup("-"); }else{ type = xbt_strdup("TestAny"); args = bprintf("(%d of %lu)", value+1, xbt_dynar_length(simcall_comm_testany__get__comms(req))); } break; case SIMCALL_MC_SNAPSHOT: type = xbt_strdup("MC_SNAPSHOT"); args = '\0'; break; case SIMCALL_MC_COMPARE_SNAPSHOTS: type = xbt_strdup("MC_COMPARE_SNAPSHOTS"); args = '\0'; break; default: THROW_UNIMPLEMENTED; } str = bprintf("[(%lu)%s] %s (%s)", req->issuer->pid ,req->issuer->name, type, args); xbt_free(type); xbt_free(args); xbt_free(p); xbt_free(bs); return str; }