/* 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; }
static MPI_Group get_group(int group) { if(group == -2) { return MPI_GROUP_EMPTY; } else if(group_lookup && group >= 0 && group < (int)xbt_dynar_length(group_lookup)) { return *(MPI_Group*)xbt_dynar_get_ptr(group_lookup, group); } return MPI_COMM_NULL; }
static MPI_Comm get_comm(int comm) { if(comm == -2) { return MPI_COMM_SELF; } else if(comm_lookup && comm >= 0 && comm < (int)xbt_dynar_length(comm_lookup)) { return *(MPI_Comm*)xbt_dynar_get_ptr(comm_lookup, comm); } return MPI_COMM_NULL; }
void read_element(AddressSpace const& as, void* local, remote_ptr<s_xbt_dynar_t> addr, size_t i, size_t len) { s_xbt_dynar_t d; as.read_bytes(&d, sizeof(d), addr); if (i >= d.used) xbt_die("Out of bound index %zi/%lu", i, d.used); if (len != d.elmsize) xbt_die("Bad size in simgrid::mc::read_element"); as.read_bytes(local, len, remote(xbt_dynar_get_ptr(&d, i))); }
static container_t lowestCommonAncestor (container_t a1, container_t a2) { //this is only an optimization (since most of a1 and a2 share the same parent) if (a1->father == a2->father) return a1->father; //create an array with all ancestors of a1 xbt_dynar_t ancestors_a1 = xbt_dynar_new(sizeof(container_t), NULL); container_t p; p = a1->father; while (p){ xbt_dynar_push_as (ancestors_a1, container_t, p); p = p->father; } //create an array with all ancestors of a2 xbt_dynar_t ancestors_a2 = xbt_dynar_new(sizeof(container_t), NULL); p = a2->father; while (p){ xbt_dynar_push_as (ancestors_a2, container_t, p); p = p->father; } //find the lowest ancestor p = NULL; int i = xbt_dynar_length (ancestors_a1) - 1; int j = xbt_dynar_length (ancestors_a2) - 1; while (i >= 0 && j >= 0){ container_t a1p = *(container_t*)xbt_dynar_get_ptr (ancestors_a1, i); container_t a2p = *(container_t*)xbt_dynar_get_ptr (ancestors_a2, j); if (a1p == a2p){ p = a1p; }else{ break; } i--; j--; } xbt_dynar_free (&ancestors_a1); xbt_dynar_free (&ancestors_a2); return p; }
tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input, double periodicity) { tmgr_trace_t trace = NULL; int linecount = 0; s_tmgr_event_t event; tmgr_event_t last_event = NULL; xbt_dynar_t list; unsigned int cpt; char *val; if (trace_list) { trace = xbt_dict_get_or_null(trace_list, id); if (trace) { XBT_WARN("Ignoring redefinition of trace %s", id); return trace; } } xbt_assert(periodicity >= 0, "Invalid periodicity %lg (must be positive)", periodicity); trace = xbt_new0(s_tmgr_trace_t, 1); trace->type = e_trace_list; trace->s_list.event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL); list = xbt_str_split(input, "\n\r"); xbt_dynar_foreach(list, cpt, val) { linecount++; xbt_str_trim(val, " \t\n\r\x0B"); if (val[0] == '#' || val[0] == '\0' || val[0] == '%') continue; if (sscanf(val, "PERIODICITY " "%lg" "\n", &periodicity) == 1) continue; if (sscanf(val, "%lg" " " "%lg" "\n", &event.delta, &event.value) != 2) xbt_die("%s:%d: Syntax error in trace\n%s", id, linecount, input); if (last_event) { if (last_event->delta > event.delta) { xbt_die("%s:%d: Invalid trace: Events must be sorted, " "but time %lg > time %lg.\n%s", id, linecount, last_event->delta, event.delta, input); } last_event->delta = event.delta - last_event->delta; } xbt_dynar_push(trace->s_list.event_list, &event); last_event = xbt_dynar_get_ptr(trace->s_list.event_list, xbt_dynar_length(trace->s_list.event_list) - 1); }
static void output_categories (const char *name, xbt_dynar_t cats, FILE *file) { unsigned int i; fprintf (file, " values = ("); for (i = xbt_dynar_length(cats); i > 0; i--) { char *cat = *(char**)xbt_dynar_get_ptr(cats, i - 1); fprintf (file, "\"%s%s\"", name, cat); if (i - 1 > 0){ fprintf (file, ","); }else{ fprintf (file, ");\n"); } } xbt_dynar_free (&cats); }
static void output_types (const char *name, xbt_dynar_t types, FILE *file) { unsigned int i; fprintf (file, " %s = (", name); for (i = xbt_dynar_length(types); i > 0; i--) { char *type = *(char**)xbt_dynar_get_ptr(types, i - 1); fprintf (file, "\"%s\"", type); if (i - 1 > 0){ fprintf (file, ","); }else{ fprintf (file, ");\n"); } } xbt_dynar_free (&types); }
xbt_workload_elm_t xbt_workload_elm_parse(char *line) { xbt_workload_elm_t res = xbt_new(s_xbt_workload_elm_t, 1); res->date = -1; res->comment = NULL; /* it's not enough to memset for valgrind, apparently */ res->who = NULL; res->str_arg = NULL; xbt_dynar_t w = xbt_str_split(line, " "); if (xbt_dynar_length(w) == 0) { free(res); xbt_dynar_free(&w); return NULL; } char **words = xbt_dynar_get_ptr(w, 0); int i = 0; if (words[i][0] == '[') { sscanf(words[i] + 1, "%lg", &(res->date)); i++; } res->who = xbt_strdup(words[i++]); if (!strcmp(words[i], "recv")) { res->action = XBT_WORKLOAD_RECV; res->str_arg = xbt_strdup(words[++i]); sscanf(words[++i], "%lg", &(res->d_arg)); } else if (!strcmp(words[i], "send")) { res->action = XBT_WORKLOAD_SEND; res->str_arg = xbt_strdup(words[++i]); sscanf(words[++i], "%lg", &(res->d_arg)); } else if (!strcmp(words[i], "compute")) { res->action = XBT_WORKLOAD_COMPUTE; sscanf(words[++i], "%lg", &(res->d_arg)); } else { xbt_die("Unparsable command: %s (in %s)", words[i], line); } i++; if (words[i] && words[i][0] == '#') { res->comment = xbt_strdup(strchr(line, '#') + 1); } xbt_dynar_free(&w); return res; }
tmgr_trace_t tmgr_trace_new_from_string(const char *name, const char *input, double periodicity) { int linecount = 0; tmgr_event_t last_event = nullptr; unsigned int cpt; char *val; xbt_assert(trace_list.find(name) == trace_list.end(), "Refusing to define trace %s twice", name); xbt_assert(periodicity >= 0, "Invalid periodicity %g (must be positive)", periodicity); tmgr_trace_t trace = new simgrid::trace_mgr::trace(); xbt_dynar_t list = xbt_str_split(input, "\n\r"); xbt_dynar_foreach(list, cpt, val) { s_tmgr_event_t event; linecount++; xbt_str_trim(val, " \t\n\r\x0B"); if (val[0] == '#' || val[0] == '\0' || val[0] == '%') // pass comments continue; if (sscanf(val, "PERIODICITY " "%lg" "\n", &periodicity) == 1) continue; xbt_assert(sscanf(val, "%lg" " " "%lg" "\n", &event.delta, &event.value) == 2, "%s:%d: Syntax error in trace\n%s", name, linecount, input); if (last_event) { xbt_assert(last_event->delta <= event.delta, "%s:%d: Invalid trace: Events must be sorted, but time %g > time %g.\n%s", name, linecount, last_event->delta, event.delta, input); last_event->delta = event.delta - last_event->delta; } else { if(event.delta > 0.0){ s_tmgr_event_t first_event; first_event.delta=event.delta; first_event.value=-1.0; xbt_dynar_push(trace->event_list, &first_event); } } xbt_dynar_push(trace->event_list, &event); last_event = (tmgr_event_t)xbt_dynar_get_ptr(trace->event_list, xbt_dynar_length(trace->event_list) - 1); }
static void action_Irecv(const char *const *action) { char mailbox[250]; double clock = MSG_get_clock(); process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self()); XBT_DEBUG("Irecv on %s", MSG_process_get_name(MSG_process_self())); sprintf(mailbox, "%s_%s", action[2], MSG_process_get_name(MSG_process_self())); msg_task_t t = NULL; xbt_dynar_push(globals->tasks, &t); msg_comm_t c = MSG_task_irecv(xbt_dynar_get_ptr (globals->tasks, xbt_dynar_length(globals->tasks) - 1), mailbox); xbt_dynar_push(globals->irecvs, &c); log_action(action, MSG_get_clock() - clock); asynchronous_cleanup(); }
static MPI_Op get_op(int op) { return op >= 0 ? *(MPI_Op*)xbt_dynar_get_ptr(op_lookup, op) : MPI_OP_NULL; }
static MPI_Datatype get_datatype(int datatype) { return datatype >= 0 ? *(MPI_Datatype*)xbt_dynar_get_ptr(datatype_lookup, datatype) : MPI_DATATYPE_NULL; }
void xbt_workload_sort_who_date(xbt_dynar_t c) { qsort(xbt_dynar_get_ptr(c, 0), xbt_dynar_length(c), sizeof(xbt_workload_elm_t), xbt_workload_elm_cmp_who_date); }
xbt_dynar_t SD_dotload_generic(const char * filename, seq_par_t seq_or_par, bool schedule){ xbt_assert(filename, "Unable to use a null file descriptor\n"); FILE *in_file = fopen(filename, "r"); xbt_assert(in_file != nullptr, "Failed to open file: %s", filename); unsigned int i; SD_task_t root; SD_task_t end; SD_task_t task; xbt_dict_t computers; xbt_dynar_t computer = nullptr; xbt_dict_cursor_t dict_cursor; bool schedule_success = true; xbt_dict_t jobs = xbt_dict_new_homogeneous(nullptr); xbt_dynar_t result = xbt_dynar_new(sizeof(SD_task_t), dot_task_p_free); Agraph_t * dag_dot = agread(in_file, NIL(Agdisc_t *)); if (schedule) computers = xbt_dict_new_homogeneous(nullptr); /* Create all the nodes */ Agnode_t *node = nullptr; for (node = agfstnode(dag_dot); node; node = agnxtnode(dag_dot, node)) { char *name = agnameof(node); double amount = atof(agget(node, (char*)"size")); task = static_cast<SD_task_t>(xbt_dict_get_or_null(jobs, name)); if (task == nullptr) { if (seq_or_par == sequential){ XBT_DEBUG("See <job id=%s amount =%.0f>", name, amount); task = SD_task_create_comp_seq(name, nullptr , amount); } else { double alpha = atof(agget(node, (char *) "alpha")); XBT_DEBUG("See <job id=%s amount =%.0f alpha = %.3f>", name, amount, alpha); task = SD_task_create_comp_par_amdahl(name, nullptr , amount, alpha); } xbt_dict_set(jobs, name, task, nullptr); if (strcmp(name,"root") && strcmp(name,"end")) xbt_dynar_push(result, &task); if((seq_or_par == sequential) && ((schedule && schedule_success) || XBT_LOG_ISENABLED(sd_dotparse, xbt_log_priority_verbose))){ /* try to take the information to schedule the task only if all is right*/ char *char_performer = agget(node, (char *) "performer"); char *char_order = agget(node, (char *) "order"); /* Tasks will execute on in a given "order" on a given set of "performer" hosts */ int performer = ((!char_performer || !strcmp(char_performer,"")) ? -1:atoi(char_performer)); int order = ((!char_order || !strcmp(char_order, ""))? -1:atoi(char_order)); if((performer != -1 && order != -1) && performer < (int) sg_host_count()){ /* required parameters are given and less performers than hosts are required */ XBT_DEBUG ("Task '%s' is scheduled on workstation '%d' in position '%d'", task->name, performer, order); if(!(computer = (xbt_dynar_t) xbt_dict_get_or_null(computers, char_performer))){ computer = xbt_dynar_new(sizeof(SD_task_t), nullptr); xbt_dict_set(computers, char_performer, computer, nullptr); } if((unsigned int)order < xbt_dynar_length(computer)){ SD_task_t *task_test = (SD_task_t *)xbt_dynar_get_ptr(computer,order); if(*task_test && *task_test != task){ /* the user gave the same order to several tasks */ schedule_success = false; XBT_VERB("Task '%s' wants to start on performer '%s' at the same position '%s' as task '%s'", (*task_test)->name, char_performer, char_order, task->name); continue; } } /* the parameter seems to be ok */ xbt_dynar_set_as(computer, order, SD_task_t, task); } else { /* one of required parameters is not given */ schedule_success = false; XBT_VERB("The schedule is ignored, task '%s' can not be scheduled on %d hosts", task->name, performer); } } } else { XBT_WARN("Task '%s' is defined more than once", name); } } /*Check if 'root' and 'end' nodes have been explicitly declared. If not, create them. */ if (!(root = (SD_task_t)xbt_dict_get_or_null(jobs, "root"))) root = (seq_or_par == sequential?SD_task_create_comp_seq("root", nullptr, 0): SD_task_create_comp_par_amdahl("root", nullptr, 0, 0)); SD_task_set_state(root, SD_SCHEDULABLE); /* by design the root task is always SCHEDULABLE */ xbt_dynar_insert_at(result, 0, &root); /* Put it at the beginning of the dynar */ if (!(end = (SD_task_t)xbt_dict_get_or_null(jobs, "end"))) end = (seq_or_par == sequential?SD_task_create_comp_seq("end", nullptr, 0): SD_task_create_comp_par_amdahl("end", nullptr, 0, 0)); /* Create edges */ xbt_dynar_t edges = xbt_dynar_new(sizeof(Agedge_t*), nullptr); for (node = agfstnode(dag_dot); node; node = agnxtnode(dag_dot, node)) { Agedge_t * edge; xbt_dynar_reset(edges); for (edge = agfstout(dag_dot, node); edge; edge = agnxtout(dag_dot, edge)) xbt_dynar_push_as(edges, Agedge_t *, edge); /* Be sure edges are sorted */ xbt_dynar_sort(edges, edge_compare); xbt_dynar_foreach(edges, i, edge) { char *src_name=agnameof(agtail(edge)), *dst_name=agnameof(aghead(edge)); double size = atof(agget(edge, (char *) "size")); SD_task_t src = static_cast<SD_task_t>(xbt_dict_get_or_null(jobs, src_name)); SD_task_t dst = static_cast<SD_task_t>(xbt_dict_get_or_null(jobs, dst_name)); if (size > 0) { char *name = bprintf("%s->%s", src_name, dst_name); XBT_DEBUG("See <transfer id=%s amount = %.0f>", name, size); task = static_cast<SD_task_t>(xbt_dict_get_or_null(jobs, name)); if (task == nullptr) { if (seq_or_par == sequential) task = SD_task_create_comm_e2e(name, nullptr , size); else task = SD_task_create_comm_par_mxn_1d_block(name, nullptr , size); SD_task_dependency_add(nullptr, nullptr, src, task); SD_task_dependency_add(nullptr, nullptr, task, dst); xbt_dict_set(jobs, name, task, nullptr); xbt_dynar_push(result, &task); } else { XBT_WARN("Task '%s' is defined more than once", name); } xbt_free(name); } else { SD_task_dependency_add(nullptr, nullptr, src, dst); } } }