static mc_mem_region_t MC_region_new(void *start_addr, size_t size) { mc_mem_region_t new_reg = xbt_new0(s_mc_mem_region_t, 1); new_reg->start_addr = start_addr; new_reg->size = size; new_reg->data = xbt_malloc0(size); memcpy(new_reg->data, start_addr, size); return new_reg; }
static int dvfs(int argc, char *argv[]) { msg_host_t host = NULL; double task_time = 0; host = MSG_host_self(); double current_peak = MSG_get_host_current_power_peak(host); XBT_INFO("Current power peak=%f", current_peak); double consumed_energy = MSG_get_host_consumed_energy(host); XBT_INFO("Total energy (Joules): %f", consumed_energy); // Process 1 - long CPU task int argc1 = 1; char** params1 = xbt_malloc0(sizeof(char *) * argc1); params1[0] = xbt_strdup("400.0E6"); MSG_process_create_with_arguments("proc1", process_code, NULL, host, argc1, params1); // Process 2 - sleep 2 sec + CPU task int argc2 = 2; char** params2 = xbt_malloc0(sizeof(char *) * argc2); params2[0] = xbt_strdup("100.0E6"); params2[1] = xbt_strdup("2"); MSG_process_create_with_arguments("proc2", process_code, NULL, host, argc2, params2); // Process 3 - sleep 2 sec + CPU task int argc3 = 2; char** params3 = xbt_malloc0(sizeof(char *) * argc3); params3[0] = xbt_strdup("100.0E6"); params3[1] = xbt_strdup("2"); MSG_process_create_with_arguments("proc3", process_code, NULL, host, argc3, params3); // Main process MSG_process_sleep(8); task_time = MSG_get_clock() - task_time; XBT_INFO("Task simulation time: %e", task_time); consumed_energy = MSG_get_host_consumed_energy(host); XBT_INFO("Total energy (Joules): %f", consumed_energy); return 0; }
/** @brief handles dup at the exit Update the table of file descriptors, and also the pipe objects if needed */ void syscall_dup_post(reg_s * reg, process_descriptor_t * proc) { proc_outside(proc); unsigned int oldfd = (int) reg->arg[0]; unsigned int newfd = (int) reg->ret; fd_descriptor_t *file_desc = process_descriptor_get_fd(proc, oldfd); file_desc->refcount++; process_descriptor_set_fd(proc, newfd, file_desc); if (strace_option) fprintf(stderr, "[%d] dup(%d, %d) = %d \n", proc->pid, oldfd, newfd, (int) reg->ret); if (file_desc->type == FD_PIPE) { pipe_t *pipe = file_desc->pipe; // look for the fd in the read end of the pipe xbt_dynar_t read_end = pipe->read_end; unsigned int cpt_in; pipe_end_t end_in; xbt_dynar_foreach(read_end, cpt_in, end_in) { if (end_in->fd == oldfd && end_in->proc == proc) { pipe_end_t dup_end = xbt_malloc0(sizeof(pipe_end_s)); dup_end->fd = newfd; dup_end->proc = end_in->proc; xbt_dynar_push(read_end, &dup_end); } } // look for the fd in the write end of the pipe xbt_dynar_t write_end = pipe->write_end; unsigned int cpt_out; pipe_end_t end_out; xbt_dynar_foreach(write_end, cpt_out, end_out) { if (end_out->fd == oldfd && end_out->proc == proc) { pipe_end_t dup_end = xbt_malloc0(sizeof(pipe_end_s)); dup_end->fd = newfd; dup_end->proc = end_out->proc; xbt_dynar_push(write_end, &dup_end); } } }
void *smpi_shared_malloc(size_t size, const char *file, int line) { char *loc = bprintf("%s:%d:%zu", file, line, size); shared_data_t *data; if (!allocs) { allocs = xbt_dict_new(); } data = xbt_dict_get_or_null(allocs, loc); if (!data) { data = (shared_data_t *) xbt_malloc0(sizeof(int) + size); data->count = 1; xbt_dict_set(allocs, loc, data, &free); } else { data->count++; } free(loc); return data->data; }
void NetworkIBModel::updateIBfactors(NetworkActionPtr action, IBNode *from, IBNode * to, int remove) { if (from == to)//disregard local comms (should use loopback) return; bool* updated=(bool*)xbt_malloc0(xbt_dict_size(active_nodes)*sizeof(bool)); ActiveComm* comm=NULL; if(remove){ if(to->ActiveCommsDown[from]==1) to->ActiveCommsDown.erase(from); else to->ActiveCommsDown[from]-=1; to->nbActiveCommsDown--; for (std::vector<ActiveComm*>::iterator it= from->ActiveCommsUp.begin(); it != from->ActiveCommsUp.end(); ++it) { if((*it)->action==action){ comm=(*it); from->ActiveCommsUp.erase(it); break; } } action->unref(); }else{ action->ref(); ActiveComm* comm=new ActiveComm(); comm->action=action; comm->destination=to; from->ActiveCommsUp.push_back(comm); to->ActiveCommsDown[from]+=1; to->nbActiveCommsDown++; } XBT_DEBUG("IB - Updating %d", from->id); updateIBfactors_rec(from, updated); XBT_DEBUG("IB - Finished updating %d", from->id); if(comm) delete comm; xbt_free(updated); }
void lmm_print(lmm_system_t sys) { lmm_constraint_t cnst = NULL; lmm_element_t elem = NULL; lmm_variable_t var = NULL; xbt_swag_t cnst_list = NULL; xbt_swag_t var_list = NULL; xbt_swag_t elem_list = NULL; char print_buf[1024]; char *trace_buf = xbt_malloc0(sizeof(char)); double sum = 0.0; /* Printing Objective */ var_list = &(sys->variable_set); sprintf(print_buf, "MAX-MIN ( "); trace_buf = xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); xbt_swag_foreach(var, var_list) { sprintf(print_buf, "'%d'(%f) ", var->id_int, var->weight); trace_buf = xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); }