static void action_test(const char *const *action){ CHECK_ACTION_PARAMS(action, 0, 0); double clock = smpi_process_simulated_elapsed(); MPI_Request request; MPI_Status status; int flag = TRUE; request = xbt_dynar_pop_as(get_reqq_self(),MPI_Request); //if request is null here, this may mean that a previous test has succeeded //Different times in traced application and replayed version may lead to this //In this case, ignore the extra calls. if(request){ int rank = smpi_process_index(); instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1); extra->type=TRACING_TEST; TRACE_smpi_testing_in(rank, extra); flag = smpi_mpi_test(&request, &status); XBT_DEBUG("MPI_Test result: %d", flag); /* push back request in dynar to be caught by a subsequent wait. if the test * did succeed, the request is now NULL. */ xbt_dynar_push_as(get_reqq_self(),MPI_Request, request); TRACE_smpi_testing_out(rank); } log_timed_action (action, clock); }
static xbt_dynar_t parse_factor(const char *smpi_coef_string) { char *value = NULL; unsigned int iter = 0; s_smpi_factor_t fact; xbt_dynar_t smpi_factor, radical_elements, radical_elements2 = NULL; smpi_factor = xbt_dynar_new(sizeof(s_smpi_factor_t), NULL); radical_elements = xbt_str_split(smpi_coef_string, ";"); xbt_dynar_foreach(radical_elements, iter, value) { radical_elements2 = xbt_str_split(value, ":"); surf_parse_assert(xbt_dynar_length(radical_elements2) == 2, "Malformed radical '%s' for smpi factor. I was expecting something like 'a:b'", value); char *errmsg = bprintf("Invalid factor in chunk #%d: %%s", iter+1); fact.factor = xbt_str_parse_int(xbt_dynar_get_as(radical_elements2, 0, char *), errmsg); xbt_free(errmsg); fact.value = xbt_str_parse_double(xbt_dynar_get_as(radical_elements2, 1, char *), errmsg); errmsg = bprintf("Invalid factor value in chunk #%d: %%s", iter+1); xbt_free(errmsg); xbt_dynar_push_as(smpi_factor, s_smpi_factor_t, fact); XBT_DEBUG("smpi_factor:\t%ld : %f", fact.factor, fact.value); xbt_dynar_free(&radical_elements2); }
void AsFloyd::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t res, double *lat) { /* set utils vars */ size_t table_size = xbt_dynar_length(p_indexNetworkElm); this->srcDstCheck(src, dst); /* create a result route */ xbt_dynar_t route_stack = xbt_dynar_new(sizeof(sg_platf_route_cbarg_t), NULL); int pred; int cur = dst->getId(); do { pred = TO_FLOYD_PRED(src->getId(), cur); if (pred == -1) THROWF(arg_error, 0, "No route from '%s' to '%s'", src->getName(), dst->getName()); xbt_dynar_push_as(route_stack, sg_platf_route_cbarg_t, TO_FLOYD_LINK(pred, cur)); cur = pred; } while (cur != src->getId()); if (p_hierarchy == SURF_ROUTING_RECURSIVE) { res->gw_src = xbt_dynar_getlast_as(route_stack, sg_platf_route_cbarg_t)->gw_src; res->gw_dst = xbt_dynar_getfirst_as(route_stack, sg_platf_route_cbarg_t)->gw_dst; } sg_routing_edge_t prev_dst_gw = NULL; while (!xbt_dynar_is_empty(route_stack)) { sg_platf_route_cbarg_t e_route = xbt_dynar_pop_as(route_stack, sg_platf_route_cbarg_t); xbt_dynar_t links; void *link; unsigned int cpt; if (p_hierarchy == SURF_ROUTING_RECURSIVE && prev_dst_gw != NULL && strcmp(prev_dst_gw->getName(), e_route->gw_src->getName())) { routing_get_route_and_latency(prev_dst_gw, e_route->gw_src, &res->link_list, lat); } links = e_route->link_list; xbt_dynar_foreach(links, cpt, link) { xbt_dynar_push_as(res->link_list, sg_routing_link_t, link); if (lat) *lat += static_cast<NetworkLinkPtr>(link)->getLatency(); } prev_dst_gw = e_route->gw_dst; }
void SIMIX_request_answer(smx_req_t req) { if (req->issuer != simix_global->maestro_process){ XBT_DEBUG("Answer request %s (%d)", SIMIX_request_name(req->call), req->call); req->issuer->request.call = REQ_NO_REQ; xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, req->issuer); } }
/** Sender function */ int sender(int argc, char *argv[]) { long number_of_tasks = atol(argv[1]); double task_comp_size = atof(argv[2]); double task_comm_size = atof(argv[3]); long receivers_count = atol(argv[4]); int diff_com = atol(argv[5]); double coef = 0; xbt_dynar_t d = xbt_dynar_new(sizeof(msg_comm_t), NULL); int i; msg_task_t task; char mailbox[256]; char sprintf_buffer[256]; msg_comm_t comm; for (i = 0; i < number_of_tasks; i++) { if (diff_com == 0) coef = 1; else coef = (i + 1); sprintf(mailbox, "receiver-%ld", (i % receivers_count)); sprintf(sprintf_buffer, "Task_%d", i); task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size / coef, NULL); comm = MSG_task_isend(task, mailbox); xbt_dynar_push_as(d, msg_comm_t, comm); XBT_INFO("Send to receiver-%ld %s comm_size %f", i % receivers_count, sprintf_buffer, task_comm_size / coef); } /* Here we are waiting for the completion of all communications */ while (!xbt_dynar_is_empty(d)) { xbt_dynar_remove_at(d, MSG_comm_waitany(d), &comm); MSG_comm_destroy(comm); } xbt_dynar_free(&d); /* Here we are waiting for the completion of all tasks */ sprintf(mailbox, "finalize"); msg_comm_t res_irecv; _XBT_GNUC_UNUSED msg_error_t res_wait; for (i = 0; i < receivers_count; i++) { task = NULL; res_irecv = MSG_task_irecv(&(task), mailbox); res_wait = MSG_comm_wait(res_irecv, -1); xbt_assert(res_wait == MSG_OK, "MSG_comm_wait failed"); MSG_comm_destroy(res_irecv); MSG_task_destroy(task); } XBT_INFO("Goodbye now!"); return 0; } /* end_of_sender */
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; }
void SIMIX_simcall_answer(smx_simcall_t simcall) { if (simcall->issuer != simix_global->maestro_process){ XBT_DEBUG("Answer simcall %s (%d) issued by %s (%p)", SIMIX_simcall_name(simcall->call), (int)simcall->call, simcall->issuer->name, simcall->issuer); simcall->issuer->simcall.call = SIMCALL_NONE; /* This check should be useless and slows everyone. Reactivate if you see something * weird in process scheduling. */ /* if(!xbt_dynar_member(simix_global->process_to_run, &(simcall->issuer))) */ xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, simcall->issuer); /* else DIE_IMPOSSIBLE; */ } }
/** Receiver function */ int receiver(int argc, char *argv[]) { int id = -1; int i; char mailbox[80]; xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL); int tasks = atof(argv[2]); msg_task_t *task = xbt_new(msg_task_t, tasks); _XBT_GNUC_UNUSED int read; read = sscanf(argv[1], "%d", &id); xbt_assert(read, "Invalid argument %s\n", argv[1]); sprintf(mailbox, "receiver-%d", id); MSG_process_sleep(10); msg_comm_t res_irecv; for (i = 0; i < tasks; i++) { XBT_INFO("Wait to receive task %d", i); task[i] = NULL; res_irecv = MSG_task_irecv(&task[i], mailbox); xbt_dynar_push_as(comms, msg_comm_t, res_irecv); } /* Here we are waiting for the receiving of all communications */ msg_task_t task_com; while (!xbt_dynar_is_empty(comms)) { _XBT_GNUC_UNUSED msg_error_t err; xbt_dynar_remove_at(comms, MSG_comm_waitany(comms), &res_irecv); task_com = MSG_comm_get_task(res_irecv); MSG_comm_destroy(res_irecv); XBT_INFO("Processing \"%s\"", MSG_task_get_name(task_com)); MSG_task_execute(task_com); XBT_INFO("\"%s\" done", MSG_task_get_name(task_com)); err = MSG_task_destroy(task_com); xbt_assert(err == MSG_OK, "MSG_task_destroy failed"); } xbt_dynar_free(&comms); xbt_free(task); /* Here we tell to sender that all tasks are done */ sprintf(mailbox, "finalize"); res_irecv = MSG_task_isend(MSG_task_create(NULL, 0, 0, NULL), mailbox); MSG_comm_wait(res_irecv, -1); MSG_comm_destroy(res_irecv); XBT_INFO("I'm done. See you!"); return 0; } /* end_of_receiver */
static int sender(int argc, char *argv[]) { xbt_assert(argc==6, "This function expects 5 parameters from the XML deployment file"); long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s"); double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s"); double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s"); long receivers_count = xbt_str_parse_int(argv[4], "Invalid amount of receivers: %s"); int diff_com = xbt_str_parse_int(argv[5], "Invalid value for diff_comm: %s"); xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL); /* First pack the communications in the dynar */ for (int i = 0; i < number_of_tasks; i++) { double coef = (diff_com == 0) ? 1 : (i + 1); char mailbox[80]; char taskname[80]; snprintf(mailbox,79, "receiver-%ld", (i % receivers_count)); snprintf(taskname,79, "Task_%d", i); msg_task_t task = MSG_task_create(taskname, task_comp_size, task_comm_size / coef, NULL); msg_comm_t comm = MSG_task_isend(task, mailbox); xbt_dynar_push_as(comms, msg_comm_t, comm); XBT_INFO("Send to receiver-%ld %s comm_size %f", i % receivers_count, taskname, task_comm_size / coef); } /* Here we are waiting for the completion of all communications */ while (xbt_dynar_is_empty(comms) == 0) { msg_comm_t comm; xbt_dynar_remove_at(comms, MSG_comm_waitany(comms), &comm); MSG_comm_destroy(comm); } xbt_dynar_free(&comms); /* Here we are waiting for the completion of all tasks */ for (int i = 0; i < receivers_count; i++) { msg_task_t task = NULL; msg_comm_t comm = MSG_task_irecv(&task, "finalize"); msg_error_t res_wait = MSG_comm_wait(comm, -1); xbt_assert(res_wait == MSG_OK, "MSG_comm_wait failed"); MSG_comm_destroy(comm); MSG_task_destroy(task); } XBT_INFO("Goodbye now!"); return 0; }
int main(int argc, char **argv) { xbt_os_timer_t timer = xbt_os_timer_new(); /* initialization of SD */ SD_init(&argc, argv); if (argc > 1) { SD_create_environment(argv[1]); } else { SD_create_environment("../../platforms/One_cluster_no_backbone.xml"); } ws_list = SD_workstation_get_list(); reclaimed = xbt_dynar_new(sizeof(bcast_task_t),xbt_free_ref); xbt_dynar_t done = NULL; xbt_os_cputimer_start(timer); send_one(0,SD_workstation_get_number()); do { if (done != NULL && !xbt_dynar_is_empty(done)) { unsigned int cursor; SD_task_t task; xbt_dynar_foreach(done, cursor, task) { bcast_task_t bt = SD_task_get_data(task); if (bt->i != bt->j -1) send_one(bt->i,bt->j); if (bt->j != bt->k -1) send_one(bt->j,bt->k); if (xbt_dynar_length(reclaimed)<100) { xbt_dynar_push_as(reclaimed,bcast_task_t,bt); } else { free(bt); } SD_task_destroy(task); } xbt_dynar_free(&done); }
static int receiver(int argc, char *argv[]) { xbt_assert(argc==3, "This function expects 2 parameters from the XML deployment file"); int id = xbt_str_parse_int(argv[1], "ID should be numerical, not %s"); int task_amount = xbt_str_parse_int(argv[2], "Invalid amount of tasks: %s"); msg_task_t *tasks = xbt_new(msg_task_t, task_amount); xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL); char mailbox[80]; snprintf(mailbox,79, "receiver-%d", id); MSG_process_sleep(10); for (int i = 0; i < task_amount; i++) { XBT_INFO("Wait to receive task %d", i); tasks[i] = NULL; msg_comm_t comm = MSG_task_irecv(&tasks[i], mailbox); xbt_dynar_push_as(comms, msg_comm_t, comm); } /* Here we are waiting for the receiving of all communications */ while (!xbt_dynar_is_empty(comms)) { msg_comm_t comm; // MSG_comm_waitany returns the rank of the comm that just ended. Remove it. xbt_dynar_remove_at(comms, MSG_comm_waitany(comms), &comm); msg_task_t task = MSG_comm_get_task(comm); MSG_comm_destroy(comm); XBT_INFO("Processing \"%s\"", MSG_task_get_name(task)); MSG_task_execute(task); XBT_INFO("\"%s\" done", MSG_task_get_name(task)); msg_error_t err = MSG_task_destroy(task); xbt_assert(err == MSG_OK, "MSG_task_destroy failed"); } xbt_dynar_free(&comms); xbt_free(tasks); /* Here we tell to sender that all tasks are done */ MSG_task_send(MSG_task_create(NULL, 0, 0, NULL), "finalize"); XBT_INFO("I'm done. See you!"); return 0; }
/* Master Process */ int master(int argc, char *argv[]) { char * key; struct HdmsgHost *hdmsg_host; xbt_dict_cursor_t cursor = NULL; int i = 0; long remaining_inits = 0; long remaining_mappers = 0; long remaining_shufflers = 0; long remaining_reducers = 0; long expected_messages = 0; msg_comm_t res_irecv; msg_task_t task_com; msg_task_t *tasks = xbt_new(msg_task_t, number_of_workers); xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL); XBT_INFO("INITIALIZATION BEGIN"); // Initialize processes (mappers, shufflers, and reducers) on each host xbt_dict_foreach(hosts, cursor, key, hdmsg_host) { if (hdmsg_host->is_worker) { MSG_process_create("Init", initializeProcs, NULL, hdmsg_host->host); tasks[remaining_inits] = NULL; res_irecv = MSG_task_irecv(&tasks[remaining_inits], "master"); xbt_dynar_push_as(comms, msg_comm_t, res_irecv); remaining_inits++; } } while (!xbt_dynar_is_empty(comms)) { xbt_dynar_remove_at(comms, MSG_comm_waitany(comms), &res_irecv); task_com = MSG_comm_get_task(res_irecv); if (!strcmp(MSG_task_get_name(task_com), "init_exit")) { msg_host_t h = MSG_task_get_source(task_com); MSG_task_destroy(task_com); const char *host_name = MSG_host_get_name(h); struct HdmsgHost *hdmsg_host = xbt_dict_get(hosts, host_name); remaining_mappers += get_mapper_count(hdmsg_host); remaining_shufflers += get_shuffler_count(hdmsg_host); remaining_reducers += get_reducer_count(hdmsg_host); remaining_inits--; if (remaining_inits == 0) { XBT_INFO("INITIALIZATION COMPLETE"); // Add an extra message to account for the message sent when the shuffle phase begins expected_messages = 1 + remaining_mappers + remaining_shufflers + remaining_reducers; free(tasks); tasks = xbt_new(msg_task_t, expected_messages); for (i = 0; i < expected_messages; i++) { tasks[i] = NULL; res_irecv = MSG_task_irecv(&tasks[i], "master"); xbt_dynar_push_as(comms, msg_comm_t, res_irecv); } XBT_INFO("MAP PHASE BEGIN"); // Activate Mappers xbt_dict_foreach(hosts, cursor, key, hdmsg_host) { activate_mappers(hdmsg_host); } }
task_t new_task(task_type_t e_type, msched_args_t ps_args, task_t p_ancestor, unsigned int ui_a1, unsigned int ui_a2, unsigned int ui_a3, unsigned int ui_a4) { task_t p_task = (task_t)xbt_new(s_task_t,1); p_task->uc_done = 0; p_task->p_proc_map = NULL; p_task->e_type = e_type; p_task->ui_tile_size = ps_args->ui_tile_size; p_task->a_ancestors = xbt_dynar_new(sizeof(task_t),NULL); switch (e_type) { case F: p_task->task.F.ui_i = ui_a1; p_task->task.F.ui_j = ui_a2; if (ps_args->uc_coarse) { p_task->f_unit_cost = 0; } else { p_task->f_unit_cost = 4; } sprintf(p_task->name,"F(%u,%u)",ui_a1,ui_a2); xbt_fifo_push(ps_args->a_tile_updates[p_task->task.F.ui_i*ps_args->ui_q+p_task->task.F.ui_j], p_task); break; case H: p_task->task.H.ui_i = ui_a1; p_task->task.H.ui_j = ui_a2; p_task->task.H.ui_k = ui_a3; if (ps_args->uc_coarse) { p_task->f_unit_cost = 0; }else{ p_task->f_unit_cost = 6; } sprintf(p_task->name,"H(%u,%u,%u)",ui_a1,ui_a2,ui_a3); /*place the update in the tile fifo*/ xbt_fifo_push(ps_args->a_tile_updates[p_task->task.H.ui_i*ps_args->ui_q+p_task->task.H.ui_k], p_task); xbt_dynar_push_as(p_task->a_ancestors,task_t,p_ancestor); break; case Z: p_task->task.Z.ui_i = ui_a1; p_task->task.Z.ui_ii = ui_a2; p_task->task.Z.ui_j = ui_a3; if (ps_args->uc_coarse) { p_task->f_unit_cost = 1; }else{ p_task->f_unit_cost = 2; } xbt_fifo_push(ps_args->a_tile_updates[p_task->task.Z.ui_i*ps_args->ui_q+p_task->task.Z.ui_j], p_task); xbt_fifo_push(ps_args->a_tile_updates[p_task->task.Z.ui_ii*ps_args->ui_q+p_task->task.Z.ui_j], p_task); sprintf(p_task->name,"Z(%u,%u,%u)",ui_a1,ui_a2,ui_a3); break; case ZS: p_task->task.Z.ui_i = ui_a1; p_task->task.Z.ui_ii = ui_a2; p_task->task.Z.ui_j = ui_a3; if (ps_args->uc_coarse) { p_task->f_unit_cost = 1; }else{ p_task->f_unit_cost = 6; } /*place the update in the tile fifo*/ xbt_fifo_push(ps_args->a_tile_updates[p_task->task.Z.ui_i*ps_args->ui_q+p_task->task.Z.ui_j], p_task); xbt_fifo_push(ps_args->a_tile_updates[p_task->task.Z.ui_ii*ps_args->ui_q+p_task->task.Z.ui_j], p_task); sprintf(p_task->name,"ZS(%u,%u,%u)",ui_a1,ui_a2,ui_a3); break; case V: p_task->task.V.ui_i = ui_a1; p_task->task.V.ui_ii = ui_a2; p_task->task.V.ui_j = ui_a3; p_task->task.V.ui_k = ui_a4; if (ps_args->uc_coarse) { if(ps_args->fptr_handle_finish!=NULL){ p_task->f_unit_cost = 0; } else{ p_task->f_unit_cost = 1; } }else{ p_task->f_unit_cost = 6; } xbt_dynar_push_as(p_task->a_ancestors,task_t,p_ancestor); /*place the update in the tile fifo*/ xbt_fifo_push(ps_args->a_tile_updates[p_task->task.V.ui_i*ps_args->ui_q+p_task->task.V.ui_k], p_task); xbt_fifo_push(ps_args->a_tile_updates[p_task->task.V.ui_ii*ps_args->ui_q+p_task->task.V.ui_k], p_task); sprintf(p_task->name,"V(%u,%u,%u,%u)",ui_a1,ui_a2,ui_a3,ui_a4); break; case VS: p_task->task.V.ui_i = ui_a1; p_task->task.V.ui_ii = ui_a2; p_task->task.V.ui_j = ui_a3; p_task->task.V.ui_k = ui_a4; if (ps_args->uc_coarse) { if(ps_args->fptr_handle_finish!=NULL){ p_task->f_unit_cost = 0; } else{ p_task->f_unit_cost = 1; } }else{ p_task->f_unit_cost = 12; } xbt_dynar_push_as(p_task->a_ancestors,task_t,p_ancestor); /*place the update in the tile fifo*/ xbt_fifo_push(ps_args->a_tile_updates[p_task->task.V.ui_i*ps_args->ui_q+p_task->task.V.ui_k], p_task); xbt_fifo_push(ps_args->a_tile_updates[p_task->task.V.ui_ii*ps_args->ui_q+p_task->task.V.ui_k], p_task); sprintf(p_task->name,"VS(%u,%u,%u,%u)",ui_a1,ui_a2,ui_a3,ui_a4); break; default: exit(-1); break; } operation_cnt+=ceil(p_task->f_unit_cost); xbt_dynar_push_as(ps_args->a_ET, task_t,p_task); xbt_fifo_push(ps_args->a_general_workqueue, p_task); return p_task; }