void xbt_log_postexit(void) { XBT_VERB("Exiting log"); xbt_os_mutex_destroy(log_cat_init_mutex); xbt_dynar_free(&xbt_log_settings); log_cat_exit(&_XBT_LOGV(XBT_LOG_ROOT_CAT)); }
void print_request(const char *message, MPI_Request request) { XBT_VERB ("%s request %p [buf = %p, size = %zu, src = %d, dst = %d, tag = %d, flags = %x]", message, request, request->buf, request->size, request->src, request->dst, request->tag, request->flags); }
void rctx_armageddon(rctx_t initiator, int exitcode) { unsigned int cursor; rctx_t job; const char *filepos = initiator && initiator->filepos ? initiator->filepos : "(master)"; XBT_DEBUG("Armageddon request by <%s> (exit=%d)", filepos, exitcode); xbt_os_mutex_acquire(armageddon_mutex); if (armageddon_initiator != NULL) { XBT_VERB("Armageddon already started. Let it go"); xbt_os_mutex_release(armageddon_mutex); return; } XBT_DEBUG("Armageddon request by <%s> got the lock. Let's go amok", filepos); armageddon_initiator = initiator; xbt_os_mutex_release(armageddon_mutex); /* Kill foreground command */ if (fg_job) rctx_armageddon_kill_one(initiator, filepos, rctx); /* Kill any background commands */ xbt_dynar_foreach(bg_jobs, cursor, job) { rctx_armageddon_kill_one(initiator, filepos, job); }
static void action_Irecv(const char *const *action) { int from = atoi(action[2]); double size=parse_double(action[3]); double clock = smpi_process_simulated_elapsed(); MPI_Request request; smpi_replay_globals_t globals = (smpi_replay_globals_t) smpi_process_get_user_data(); #ifdef HAVE_TRACING int rank = smpi_comm_rank(MPI_COMM_WORLD); int src_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), from); TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__); #endif request = smpi_mpi_irecv(NULL, size, MPI_BYTE, from, 0, MPI_COMM_WORLD); #ifdef HAVE_TRACING TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__); request->recv = 1; #endif xbt_dynar_push(globals->irecvs,&request); //TODO do the asynchronous cleanup if (XBT_LOG_ISENABLED(smpi_replay, xbt_log_priority_verbose)){ char *name = xbt_str_join_array(action, " "); XBT_VERB("%s %f", name, smpi_process_simulated_elapsed()-clock); free(name); } }
static void action_send(const char *const *action) { int to = atoi(action[2]); double size=parse_double(action[3]); double clock = smpi_process_simulated_elapsed(); #ifdef HAVE_TRACING int rank = smpi_comm_rank(MPI_COMM_WORLD); TRACE_smpi_computing_out(rank); int dst_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), to); TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__); TRACE_smpi_send(rank, rank, dst_traced); #endif smpi_mpi_send(NULL, size, MPI_BYTE, to , 0, MPI_COMM_WORLD); if (XBT_LOG_ISENABLED(smpi_replay, xbt_log_priority_verbose)){ char *name = xbt_str_join_array(action, " "); XBT_VERB("%s %f", name, smpi_process_simulated_elapsed()-clock); free(name); } #ifdef HAVE_TRACING TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__); TRACE_smpi_computing_in(rank); #endif }
void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory) { smx_ctx_base_factory_init(factory); XBT_VERB("Activating SYSV context factory"); (*factory)->finalize = smx_ctx_sysv_factory_finalize; (*factory)->create_context = smx_ctx_sysv_create_context; /* Do not overload that method (*factory)->finalize */ (*factory)->free = smx_ctx_sysv_free; (*factory)->name = "smx_sysv_context_factory"; if (SIMIX_context_is_parallel()) { #ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */ int nthreads = SIMIX_context_get_nthreads(); sysv_parmap = xbt_parmap_new(nthreads, SIMIX_context_get_parallel_mode()); sysv_workers_context = xbt_new(smx_ctx_sysv_t, nthreads); sysv_maestro_context = NULL; xbt_os_thread_key_create(&sysv_worker_id_key); (*factory)->stop = smx_ctx_sysv_stop_parallel; (*factory)->suspend = smx_ctx_sysv_suspend_parallel; (*factory)->runall = smx_ctx_sysv_runall_parallel; #else THROWF(arg_error, 0, "No thread support for parallel context execution"); #endif } else { (*factory)->stop = smx_ctx_sysv_stop_serial; (*factory)->suspend = smx_ctx_sysv_suspend_serial; (*factory)->runall = smx_ctx_sysv_runall_serial; } }
static void log_timed_action (const char *const *action, double clock){ if (XBT_LOG_ISENABLED(smpi_replay, xbt_log_priority_verbose)){ char *name = xbt_str_join_array(action, " "); XBT_VERB("%s %f", name, smpi_process_simulated_elapsed()-clock); xbt_free(name); } }
/* Sets the predecessor of the current node. * \param id the id to predecessor, or -1 to unset the predecessor */ void Node::setPredecessor(int predecessor_id) { if (predecessor_id != pred_id_) { pred_id_ = predecessor_id; XBT_VERB("My new predecessor is %d", predecessor_id); } }
/* Sets a finger of the current node. * * \param node the current node * \param finger_index index of the finger to set (0 to nb_bits - 1) * \param id the id to set for this finger */ void Node::setFinger(int finger_index, int id) { if (id != fingers_[finger_index]) { fingers_[finger_index] = id; XBT_VERB("My new finger #%d is %d", finger_index, id); } }
/** \ingroup msg_mailbox_management * \brief Set the mailbox to receive in asynchronous mode * * All messages sent to this mailbox will be transferred to * the receiver without waiting for the receive call. * The receive call will still be necessary to use the received data. * If there is a need to receive some messages asynchronously, and some not, * two different mailboxes should be used. * * \param alias The name of the mailbox */ void MSG_mailbox_set_async(const char *alias){ msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias); simcall_rdv_set_receiver(mailbox, SIMIX_process_self()); XBT_VERB("%s mailbox set to receive eagerly for process %p\n",alias, SIMIX_process_self()); }
static void log_action(const char *const *action, double date) { if (XBT_LOG_ISENABLED(storage_actions, xbt_log_priority_verbose)) { char *name = xbt_str_join_array(action, " "); XBT_VERB("%s %f", name, date); xbt_free(name); } }
/* Changes the state of a task. Updates the sd_global->watch_point_reached flag. */ void SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state) { std::set<SD_task_t>::iterator idx; XBT_DEBUG("Set state of '%s' to %d", task->name, new_state); switch (new_state) { case SD_NOT_SCHEDULED: case SD_SCHEDULABLE: if (SD_task_get_state(task) == SD_FAILED){ sd_global->completed_tasks->erase(task); sd_global->initial_tasks->insert(task); } break; case SD_SCHEDULED: if (SD_task_get_state(task) == SD_RUNNABLE){ sd_global->initial_tasks->insert(task); sd_global->runnable_tasks->erase(task); } break; case SD_RUNNABLE: idx = sd_global->initial_tasks->find(task); if (idx != sd_global->initial_tasks->end()) { sd_global->runnable_tasks->insert(*idx); sd_global->initial_tasks->erase(idx); } break; case SD_RUNNING: sd_global->runnable_tasks->erase(task); break; case SD_DONE: sd_global->completed_tasks->insert(task); task->start_time = task->surf_action->getStartTime(); task->finish_time = task->surf_action->getFinishTime(); task->surf_action->unref(); task->surf_action = nullptr; task->remains = 0; #if HAVE_JEDULE jedule_log_sd_event(task); #endif break; case SD_FAILED: sd_global->completed_tasks->insert(task); task->start_time = task->surf_action->getStartTime(); task->finish_time = surf_get_clock(); task->surf_action->unref(); task->surf_action = nullptr; break; default: xbt_die( "Invalid state"); } task->state = new_state; if (task->watch_points & new_state) { XBT_VERB("Watch point reached with task '%s'!", SD_task_get_name(task)); sd_global->watch_point_reached = true; SD_task_unwatch(task, new_state); /* remove the watch point */ } }
static void action_compute(const char *const *action) { double clock = smpi_process_simulated_elapsed(); smpi_execute_flops(parse_double(action[2])); if (XBT_LOG_ISENABLED(smpi_replay, xbt_log_priority_verbose)){ char *name = xbt_str_join_array(action, " "); XBT_VERB("%s %f", name, smpi_process_simulated_elapsed()-clock); free(name); } }
static int master(int argc, char *argv[]) { XBT_INFO("Launching our nice bugged recursive function..."); unsigned i = 1; do { i *= 2; unsigned res = collatz(i, i); XBT_VERB("collatz(%u, %u) returned %u", i, i, res); } while (i <= 0x80000000u); return 0; }
/* * \brief Destroys a host (internal call only) */ void __MSG_host_destroy(msg_host_priv_t host) { #ifdef MSG_USE_DEPRECATED if (msg_global->max_channel > 0) free(host->mailboxes); #endif if (xbt_swag_size(host->vms) > 0 ) { XBT_VERB("Host shut down, but it still hosts %d VMs. They will be leaked.",xbt_swag_size(host->vms)); } xbt_swag_free(host->vms); free(host); }
JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_internalmig(JNIEnv *env, jobject jvm, jobject jhost) { msg_vm_t vm = jvm_get_native(env,jvm); msg_host_t host = jhost_get_native(env, jhost); try { MSG_vm_migrate(vm,host); } catch(xbt_ex& e){ XBT_VERB("CATCH EXCEPTION MIGRATION %s",e.what()); jxbt_throw_host_failure(env, (char*)"during migration"); } }
void ClusterZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* route, double* lat) { XBT_VERB("cluster getLocalRoute from '%s'[%u] to '%s'[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id()); xbt_assert(not private_links_.empty(), "Cluster routing: no links attached to the source node - did you use host_link tag?"); if ((src->id() == dst->id()) && has_loopback_) { xbt_assert(not src->is_router(), "Routing from a cluster private router to itself is meaningless"); std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos(src->id())); route->link_list.push_back(info.first); if (lat) *lat += info.first->get_latency(); return; } if (not src->is_router()) { // No private link for the private router if (has_limiter_) { // limiter for sender std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos_with_loopback(src->id())); route->link_list.push_back(info.first); } std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos_with_loopback_limiter(src->id())); if (info.first) { // link up route->link_list.push_back(info.first); if (lat) *lat += info.first->get_latency(); } } if (backbone_) { route->link_list.push_back(backbone_); if (lat) *lat += backbone_->get_latency(); } if (not dst->is_router()) { // No specific link for router std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos_with_loopback_limiter(dst->id())); if (info.second) { // link down route->link_list.push_back(info.second); if (lat) *lat += info.second->get_latency(); } if (has_limiter_) { // limiter for receiver info = private_links_.at(node_pos_with_loopback(dst->id())); route->link_list.push_back(info.first); } } }
int client(int argc, char *argv[]) { gras_socket_t mysock; /* socket on which I listen */ gras_socket_t toserver; /* socket used to write to the server */ gras_init(&argc, argv); message_declaration(); mysock = gras_socket_server_range(1024, 10000, 0, 0); XBT_VERB("Client ready; listening on %d", gras_socket_my_port(mysock)); gras_os_sleep(1.5); /* sleep 1 second and half */ toserver = gras_socket_client(argv[1], atoi(argv[2])); long long_to_convert = 4321; char *string_result; XBT_INFO("Ask to convert %ld", long_to_convert); gras_msg_rpccall(toserver, 60, "convert i2a", &long_to_convert, &string_result); XBT_INFO("The server says that %ld is equal to \"%s\".", long_to_convert, string_result); free(string_result); char *string_to_convert = "1234"; long long_result; XBT_INFO("Ask to convert %s", string_to_convert); gras_msg_rpccall(toserver, 60, "convert a2i", &string_to_convert, &long_result); XBT_INFO("The server says that \"%s\" is equal to %d.", string_to_convert, long_result); xbt_ex_t e; string_to_convert = "azerty"; TRY { gras_msg_rpccall(toserver, 60, "convert a2i", &string_to_convert, &long_result); } CATCH(e) { XBT_INFO ("The server refuses to convert %s. Here is the received exception:", string_to_convert); xbt_ex_display(&e); xbt_ex_free(e); XBT_INFO("Again, previous exception was excepted"); } gras_msg_send(toserver, "done", NULL); XBT_INFO("Stopped the server"); gras_exit(); return 0; }
/** \brief Destructor * \param m the mallocator you want to destroy * * Destroy the mallocator and all its data. The function * free_f is called on each object in the mallocator. * * \see xbt_mallocator_new() */ void xbt_mallocator_free(xbt_mallocator_t m) { int i; xbt_assert(m != NULL, "Invalid parameter"); XBT_VERB("Frees mallocator %p (size:%d/%d)", m, m->current_size, m->max_size); for (i = 0; i < m->current_size; i++) { m->free_f(m->objects[i]); } xbt_free(m->objects); xbt_free(m); }
static void get_sub_matrix(xbt_matrix_t *sM, int selfid) { msg_task_t task = NULL; char node_mbox[MAILBOX_NAME_SIZE]; msg_error_t err; XBT_VERB("Get sub-matrix"); snprintf(node_mbox, MAILBOX_NAME_SIZE - 1, "%d", selfid); err = MSG_task_receive(&task, node_mbox); if (err != MSG_OK) xbt_die("Error while receiving from %s (%d)", node_mbox, (int)err); *sM = (xbt_matrix_t)MSG_task_get_data(task); MSG_task_destroy(task); }
static node_job_t wait_job(int selfid) { msg_task_t task = NULL; char self_mbox[MAILBOX_NAME_SIZE]; node_job_t job; msg_error_t err; snprintf(self_mbox, MAILBOX_NAME_SIZE - 1, "%d", selfid); err = MSG_task_receive(&task, self_mbox); if (err != MSG_OK) xbt_die("Error while receiving from %s (%d)", self_mbox, (int)err); job = (node_job_t)MSG_task_get_data(task); MSG_task_destroy(task); XBT_VERB("Got Job (%d,%d)", job->row, job->col); return job; }
/* * Broadcast the jobs to the nodes of the grid (except to node 0) */ static void broadcast_jobs(node_job_t *jobs) { int node; char node_mbox[MAILBOX_NAME_SIZE]; msg_task_t task; msg_comm_t comms[GRID_NUM_NODES - 1] = {0}; XBT_VERB("Broadcast Jobs"); for (node = 1; node < GRID_NUM_NODES; node++) { task = MSG_task_create("Job", 100, 100, jobs[node-1]); snprintf(node_mbox, MAILBOX_NAME_SIZE - 1, "%d", node); comms[node-1] = MSG_task_isend(task, node_mbox); } MSG_comm_waitall(comms, GRID_NUM_NODES-1, -1); for (node = 1; node < GRID_NUM_NODES; node++) MSG_comm_destroy(comms[node - 1]); }
/* callback of the plugin variable */ static void _sg_cfg_cb__plugin(const char *name, int pos) { char *val; XBT_VERB("PLUGIN"); xbt_assert(_sg_cfg_init_status < 2, "Cannot load a plugin after the initialization"); val = xbt_cfg_get_string(_sg_cfg_set, name); if (!strcmp(val, "help")) { model_help("plugin", surf_plugin_description); sg_cfg_exit_early(); } /* New Module missing */ int plugin_id = find_model_description(surf_plugin_description, val); surf_plugin_description[plugin_id].model_init_preparse(); }
void xbt_multidict_set_ext(xbt_dict_t mdict, xbt_dynar_t keys, xbt_dynar_t lens, void *data, void_f_pvoid_t free_ctn) { xbt_dict_t thislevel, nextlevel = NULL; int i; unsigned long int thislen; char *thiskey; int keys_len = xbt_dynar_length(keys); xbt_assert(xbt_dynar_length(keys) == xbt_dynar_length(lens)); xbt_assert(keys_len, "Can't set a zero-long key set in a multidict"); XBT_DEBUG("xbt_multidict_set(%p,%d)", mdict, keys_len); for (i = 0, thislevel = mdict; i < keys_len - 1; i++, thislevel = nextlevel) { xbt_dynar_get_cpy(keys, i, &thiskey); xbt_dynar_get_cpy(lens, i, &thislen); XBT_DEBUG("multi_set: at level %d, len=%ld, key=%p |%*s|", i, thislen, thiskey, (int) thislen, thiskey); /* search the dict of next level */ nextlevel = xbt_dict_get_or_null_ext(thislevel, thiskey, thislen); if (nextlevel == NULL) { /* make sure the dict of next level exists */ nextlevel = xbt_dict_new(); XBT_VERB("Create a dict (%p)", nextlevel); xbt_dict_set_ext(thislevel, thiskey, thislen, nextlevel, &_free_dict); } } xbt_dynar_get_cpy(keys, i, &thiskey); xbt_dynar_get_cpy(lens, i, &thislen); xbt_dict_set_ext(thislevel, thiskey, thislen, data, free_ctn); }
static void action_barrier(const char *const *action){ double clock = smpi_process_simulated_elapsed(); #ifdef HAVE_TRACING int rank = smpi_comm_rank(MPI_COMM_WORLD); TRACE_smpi_computing_out(rank); TRACE_smpi_collective_in(rank, -1, __FUNCTION__); #endif smpi_mpi_barrier(MPI_COMM_WORLD); #ifdef HAVE_TRACING TRACE_smpi_collective_out(rank, -1, __FUNCTION__); TRACE_smpi_computing_in(rank); #endif if (XBT_LOG_ISENABLED(smpi_replay, xbt_log_priority_verbose)){ char *name = xbt_str_join_array(action, " "); XBT_VERB("%s %f", name, smpi_process_simulated_elapsed()-clock); free(name); } }
static void create_jobs(xbt_matrix_t A, xbt_matrix_t B, node_job_t *jobs) { int node, j, k, row = 0, col = 0; for (node = 0; node < GRID_NUM_NODES; node++) { XBT_VERB("Create job %d", node); jobs[node] = xbt_new0(s_node_job_t, 1); jobs[node]->row = row; jobs[node]->col = col; /* Compute who are the nodes in the same row and column */ /* than the node receiving this job */ for (j = 0, k = 0; j < GRID_SIZE; j++) { if (node != (GRID_SIZE * row) + j) { jobs[node]->nodes_in_row[k] = (GRID_SIZE * row) + j; k++; } } for (j = 0, k = 0; j < GRID_SIZE; j++) { if (node != (GRID_SIZE * j) + col) { jobs[node]->nodes_in_col[k] = (GRID_SIZE * j) + col; k++; } } /* Assign a sub matrix of A and B to the job */ jobs[node]->A = xbt_matrix_new_sub(A, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE * row, NODE_MATRIX_SIZE * col, NULL); jobs[node]->B = xbt_matrix_new_sub(B, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE * row, NODE_MATRIX_SIZE * col, NULL); if (++col >= GRID_SIZE) { col = 0; row++; } } }
/** * \brief Constructor * \param size size of the internal stack: number of objects the mallocator * will be able to store * \param new_f function to allocate a new object of your datatype, called * in \a xbt_mallocator_get() when the mallocator is empty * \param free_f function to free an object of your datatype, called * in \a xbt_mallocator_release() when the stack is full, and when * the mallocator is freed. * \param reset_f function to reinitialise an object of your datatype, called * when you extract an object from the mallocator (can be NULL) * * Create and initialize a new mallocator for a given datatype. * * \return pointer to the created mallocator * \see xbt_mallocator_free() */ xbt_mallocator_t xbt_mallocator_new(int size, pvoid_f_void_t new_f, void_f_pvoid_t free_f, void_f_pvoid_t reset_f) { xbt_mallocator_t m; xbt_assert(size > 0, "size must be positive"); xbt_assert(new_f != NULL && free_f != NULL, "invalid parameter"); m = xbt_new0(s_xbt_mallocator_t, 1); XBT_VERB("Create mallocator %p (%s)", m, xbt_mallocator_is_active() ? "enabled" : "disabled"); m->current_size = 0; m->new_f = new_f; m->free_f = free_f; m->reset_f = reset_f; m->max_size = size; return m; }
static void receive_results(result_t *results) { int node; msg_comm_t comms[GRID_NUM_NODES-1] = {0}; msg_task_t tasks[GRID_NUM_NODES-1] = {0}; XBT_VERB("Receive Results."); /* Get the result from the nodes in the GRID */ for (node = 1; node < GRID_NUM_NODES; node++) { comms[node-1] = MSG_task_irecv(&tasks[node-1], "0"); } MSG_comm_waitall(comms, GRID_NUM_NODES - 1, -1); for (node = 1; node < GRID_NUM_NODES; node++) MSG_comm_destroy(comms[node - 1]); /* Reconstruct the result matrix */ for (node = 1; node < GRID_NUM_NODES; node++) { results[node] = (result_t)MSG_task_get_data(tasks[node-1]); MSG_task_destroy(tasks[node-1]); } }
static void action_wait(const char *const *action){ double clock = smpi_process_simulated_elapsed(); MPI_Request request; MPI_Status status; smpi_replay_globals_t globals = (smpi_replay_globals_t) smpi_process_get_user_data(); xbt_assert(xbt_dynar_length(globals->irecvs), "action wait not preceded by any irecv: %s", xbt_str_join_array(action," ")); request = xbt_dynar_pop_as(globals->irecvs,MPI_Request); #ifdef HAVE_TRACING int rank = request && request->comm != MPI_COMM_NULL ? smpi_comm_rank(request->comm) : -1; TRACE_smpi_computing_out(rank); MPI_Group group = smpi_comm_group(request->comm); int src_traced = smpi_group_rank(group, request->src); int dst_traced = smpi_group_rank(group, request->dst); int is_wait_for_receive = request->recv; TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__); #endif smpi_mpi_wait(&request, &status); #ifdef HAVE_TRACING TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__); if (is_wait_for_receive) { TRACE_smpi_recv(rank, src_traced, dst_traced); } TRACE_smpi_computing_in(rank); #endif if (XBT_LOG_ISENABLED(smpi_replay, xbt_log_priority_verbose)){ char *name = xbt_str_join_array(action, " "); XBT_VERB("%s %f", name, smpi_process_simulated_elapsed()-clock); free(name); } }
static void action_allReduce(const char *const *action) { double comm_size = parse_double(action[2]); double comp_size = parse_double(action[3]); double clock = smpi_process_simulated_elapsed(); #ifdef HAVE_TRACING int rank = smpi_comm_rank(MPI_COMM_WORLD); TRACE_smpi_computing_out(rank); TRACE_smpi_collective_in(rank, -1, __FUNCTION__); #endif smpi_mpi_reduce(NULL, NULL, comm_size, MPI_BYTE, MPI_OP_NULL, 0, MPI_COMM_WORLD); smpi_execute_flops(comp_size); smpi_mpi_bcast(NULL, comm_size, MPI_BYTE, 0, MPI_COMM_WORLD); #ifdef HAVE_TRACING TRACE_smpi_collective_out(rank, -1, __FUNCTION__); TRACE_smpi_computing_in(rank); #endif if (XBT_LOG_ISENABLED(smpi_replay, xbt_log_priority_verbose)){ char *name = xbt_str_join_array(action, " "); XBT_VERB("%s %f", name, smpi_process_simulated_elapsed()-clock); free(name); } }