static int server(int argc, char *argv[]) { msg_task_t task1 = NULL, task2 = NULL; msg_comm_t comm_received1 = NULL, comm_received2 = NULL; comm_received1 = MSG_task_irecv(&task1, "mymailbox"); comm_received2 = MSG_task_irecv(&task2, "mymailbox"); MSG_comm_wait(comm_received1, -1); MSG_comm_wait(comm_received2, -1); XBT_INFO("OK"); return 0; }
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; }
/** Receiver function */ int receiver(int argc, char *argv[]) { msg_task_t task = NULL; _XBT_GNUC_UNUSED msg_error_t res; int id = -1; char mailbox[80]; msg_comm_t res_irecv; _XBT_GNUC_UNUSED int read; read = sscanf(argv[1], "%d", &id); xbt_assert(read, "Invalid argument %s\n", argv[1]); MSG_process_sleep(10); sprintf(mailbox, "receiver-%d", id); while (1) { res_irecv = MSG_task_irecv(&(task), mailbox); XBT_INFO("Wait to receive a task"); res = MSG_comm_wait(res_irecv, -1); MSG_comm_destroy(res_irecv); xbt_assert(res == MSG_OK, "MSG_task_get failed"); XBT_INFO("Received \"%s\"", MSG_task_get_name(task)); if (!strcmp(MSG_task_get_name(task), "finalize")) { MSG_task_destroy(task); break; } XBT_INFO("Processing \"%s\"", MSG_task_get_name(task)); MSG_task_execute(task); XBT_INFO("\"%s\" done", MSG_task_get_name(task)); MSG_task_destroy(task); task = NULL; } XBT_INFO("I'm done. See you!"); return 0; } /* end_of_receiver */
int server(int argc, char *argv[]) { msg_task_t task1,task2; msg_comm_t comm1 = MSG_task_irecv(&task1, "mymailbox1"); msg_comm_t comm2 = MSG_task_irecv(&task2, "mymailbox2"); MSG_comm_wait(comm1, -1); MSG_comm_wait(comm2, -1); long val1 = xbt_str_parse_int(MSG_task_get_name(task1), "Task name is not a numerical ID: %s"); XBT_INFO("Received %lu", val1); MC_assert(val1 == 2); XBT_INFO("OK"); return 0; }
/** 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 */
int server(int argc, char *argv[]) { msg_task_t task1; long val1; msg_comm_t comm1, comm2; comm1 = MSG_task_irecv(&task1, "mymailbox1"); comm2 = MSG_task_irecv(&task1, "mymailbox2"); MSG_comm_wait(comm1, -1); MSG_comm_wait(comm2, -1); val1 = (long) MSG_task_get_data(task1); XBT_INFO("Received %lu", val1); MC_assert(val1 == 2); XBT_INFO("OK"); return 0; }
static void action_reduce(const char *const *action) { int i; char *reduce_identifier; char mailbox[80]; double comm_size = parse_double(action[2]); double comp_size = parse_double(action[3]); msg_task_t comp_task = NULL; const char *process_name; double clock = MSG_get_clock(); process_globals_t counters = (process_globals_t) MSG_process_get_data(MSG_process_self()); xbt_assert(communicator_size, "Size of Communicator is not defined, " "can't use collective operations"); process_name = MSG_process_get_name(MSG_process_self()); reduce_identifier = bprintf("reduce_%d", counters->reduce_counter++); if (!strcmp(process_name, "p0")) { XBT_DEBUG("%s: %s is the Root", reduce_identifier, process_name); msg_comm_t *comms = xbt_new0(msg_comm_t, communicator_size - 1); msg_task_t *tasks = xbt_new0(msg_task_t, communicator_size - 1); for (i = 1; i < communicator_size; i++) { sprintf(mailbox, "%s_p%d_p0", reduce_identifier, i); comms[i - 1] = MSG_task_irecv(&(tasks[i - 1]), mailbox); } MSG_comm_waitall(comms, communicator_size - 1, -1); for (i = 1; i < communicator_size; i++) { MSG_comm_destroy(comms[i - 1]); MSG_task_destroy(tasks[i - 1]); } xbt_free(comms); xbt_free(tasks); comp_task = MSG_task_create("reduce_comp", comp_size, 0, NULL); XBT_DEBUG("%s: computing 'reduce_comp'", reduce_identifier); MSG_task_execute(comp_task); MSG_task_destroy(comp_task); XBT_DEBUG("%s: computed", reduce_identifier); } else { XBT_DEBUG("%s: %s sends", reduce_identifier, process_name); sprintf(mailbox, "%s_%s_p0", reduce_identifier, process_name); XBT_DEBUG("put on %s", mailbox); MSG_task_send(MSG_task_create(reduce_identifier, 0, comm_size, NULL), mailbox); } log_action(action, MSG_get_clock() - clock); xbt_free(reduce_identifier); }
task_data receive_task(char mailbox[]){ m_task_t task = NULL; msg_comm_t res = NULL; res = MSG_task_irecv(&(task),mailbox); MSG_comm_wait(res,-1); task_data data = *(task_data *) task->data; XBT_INFO("received response task %s",MSG_task_get_name(task)); //MSG_comm_destroy(res); //MSG_task_destroy(task); return data; }
/** * Tracker main function * @param argc number of arguments * @param argv arguments */ int tracker(int argc, char *argv[]) { int i; RngStream stream = (RngStream) MSG_host_get_property_value(MSG_host_self(), "stream"); //Checking arguments xbt_assert(argc == 2, "Wrong number of arguments for the tracker."); //Retrieving end time double deadline = atof(argv[1]); xbt_assert(deadline > 0, "Wrong deadline supplied"); //Building peers array xbt_dynar_t peers_list = xbt_dynar_new(sizeof(int), NULL); XBT_INFO("Tracker launched."); msg_comm_t comm_received = NULL; msg_task_t task_received = NULL; while (MSG_get_clock() < deadline) { if (comm_received == NULL) { comm_received = MSG_task_irecv(&task_received, TRACKER_MAILBOX); } if (MSG_comm_test(comm_received)) { //Check for correct status if (MSG_comm_get_status(comm_received) == MSG_OK) { //Retrieve the data sent by the peer. tracker_task_data_t data = MSG_task_get_data(task_received); //Add the peer to our peer list. if (!is_in_list(peers_list, data->peer_id)) { xbt_dynar_push_as(peers_list, int, data->peer_id); } //Sending peers to the peer int next_peer; int peers_length = xbt_dynar_length(peers_list); for (i = 0; i < MAXIMUM_PAIRS && i < peers_length; i++) { do { next_peer = xbt_dynar_get_as(peers_list, RngStream_RandInt(stream, 0, peers_length - 1), int); } while (is_in_list(data->peers, next_peer)); xbt_dynar_push_as(data->peers, int, next_peer); } //setting the interval data->interval = TRACKER_QUERY_INTERVAL; //sending the task back to the peer. MSG_task_dsend(task_received, data->mailbox, task_free); //destroy the communication. } MSG_comm_destroy(comm_received); comm_received = NULL; task_received = NULL; } else {
/** 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; }
void run_service_cordel(int list_methods_len,chor_method_data list_methods[],char mailbox[]){ m_task_t received_task = NULL; MSG_error_t res = MSG_OK; msg_comm_t msg_recv = NULL; static int id_sender = 0; char sender_name[50]; sprintf(sender_name,"%s_%d",mailbox,id_sender++); int waiting_count = 0; while(1){ msg_recv = MSG_task_irecv(&(received_task),mailbox); res = MSG_comm_wait(msg_recv,-1); if(res == MSG_OK){ char task_name[100]; strcpy(task_name,MSG_task_get_name(received_task)); task_data *received_task_data = (task_data *) received_task->data; XBT_INFO("received task %lf",received_task_data->id); // double endtime = MSG_get_clock(); // write_log(received_task_data->starttime,endtime,"waiting time"); //received_task_data->starttime = endtime; int index_method = find_method(list_methods_len,list_methods,task_name); chor_method_data method_data = list_methods[index_method]; int i; for(i = 0;i<method_data.instructions_len;i++){ method_instruction instruction = method_data.instructions[i]; if(instruction.type == INVOKE){ service_invoke(instruction.role,instruction.method_name,instruction.input_size,sender_name); waiting_count++; }else if(instruction.type == INVOKE_A){ service_invoke_cordel(instruction.role,instruction.method_name,instruction.input_size,received_task_data); }else if(instruction.type == EXEC){ run_chor_task(task_name,method_data); } else if(instruction.type == WAIT){ wait_task(sender_name,waiting_count); waiting_count = 0; } else if(instruction.type == RETURN){ return_task(task_name,received_task,method_data.output_size); } } } received_task = NULL; } }
/* Receiver process expects 3 arguments: */ static int receiver(int argc, char *argv[]) { msg_task_t task = NULL; XBT_ATTRIB_UNUSED msg_error_t res; char mailbox[80]; msg_comm_t res_irecv; int id = xbt_str_parse_int(argv[1], "Invalid id: %s"); /* - unique id */ double sleep_start_time = xbt_str_parse_double(argv[2], "Invalid sleep start parameter: %s"); /* - start time */ double sleep_test_time = xbt_str_parse_double(argv[3], "Invalid sleep test parameter: %s"); /* - test time */ XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time); MSG_process_sleep(sleep_start_time); /* This process first sleeps for "start time" seconds. */ snprintf(mailbox,79, "receiver-%d", id); while (1) { res_irecv = MSG_task_irecv(&(task), mailbox); /* Then it posts asynchronous receives (@ref MSG_task_irecv) and*/ XBT_INFO("Wait to receive a task"); if (sleep_test_time > 0) { /* - if "test_time" is set to 0, wait on @ref MSG_comm_wait */ while (MSG_comm_test(res_irecv) == 0) { /* - Call @ref MSG_comm_test every "test_time" otherwise */ MSG_process_sleep(sleep_test_time); } } else { res = MSG_comm_wait(res_irecv, -1); xbt_assert(res == MSG_OK, "MSG_task_get failed"); } MSG_comm_destroy(res_irecv); XBT_INFO("Received \"%s\"", MSG_task_get_name(task)); if (strcmp(MSG_task_get_name(task), "finalize") == 0) { /* If the received task is "finalize", the process ends */ MSG_task_destroy(task); break; } XBT_INFO("Processing \"%s\"", MSG_task_get_name(task)); /* Otherwise, the task is processed */ MSG_task_execute(task); XBT_INFO("\"%s\" done", MSG_task_get_name(task)); MSG_task_destroy(task); task = NULL; } XBT_INFO("I'm done. See you!"); return 0; }
void worker(){ worker_t p_me = MSG_host_get_data(MSG_host_self()); while(1){ m_task_t p_task = MSG_TASK_UNINITIALIZED; msg_comm_t comm = MSG_task_irecv (&p_task, p_me->channel); MSG_comm_wait(comm, -1); MSG_comm_destroy(comm); task_t p_todo_task = MSG_task_get_data(p_task); if(p_todo_task!=FINALIZE){ MSG_task_destroy(p_task); double delay = 1.0 + p_me->lf_delay*(double)rand()/(double)(RAND_MAX); if(delay<0){ delay=0; } if (p_me->ps_ms_args->uc_coarse) { p_task = MSG_task_create(p_todo_task->name, delay*p_todo_task->f_unit_cost*MSG_get_host_speed(MSG_host_self()), 0, NULL); } else{ //p_task = MSG_task_create(p_todo_task->name, delay*p_todo_task->f_unit_cost*pow(p_todo_task->ui_tile_size,3)/3.0, 0, NULL); p_task = MSG_task_create(p_todo_task->name, delay*p_todo_task->f_unit_cost*MSG_get_host_speed(MSG_host_self()), 0, NULL); } MSG_task_execute(p_task); xbt_fifo_shift(p_me->a_workqueue); p_me->p_last_task = p_todo_task; p_todo_task->uc_done = 1; if(p_todo_task->e_type == Z || p_todo_task->e_type == ZS ){ /*put the topmost line again in the triangles*/ xbt_dynar_push_as(p_me->ps_ms_args->a_NT[p_todo_task->task.Z.ui_j],unsigned int,p_todo_task->task.Z.ui_ii); } else if (p_todo_task->e_type == F) {
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; }
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_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(); }
int service(int argc, char *argv[]){ //init list_methods method_data list_methods[50]; int list_methods_len = 0; //set mailbox char mailbox[50]; strcpy(mailbox,argv[1]); //create the list of methods int i; for(i = 2;i<argc;i = i+3){ make_method(&list_methods[list_methods_len++],argv[i],argv[i+1],argv[i+2]); } m_task_t received_task = NULL; MSG_error_t res = MSG_OK; msg_comm_t msg_recv = NULL; //receive request while(1){ msg_recv = MSG_task_irecv(&(received_task),mailbox); res = MSG_comm_wait(msg_recv,-1); if(res == MSG_OK){ char task_name[100]; strcpy(task_name,MSG_task_get_name(received_task)); task_data *received_task_data = (task_data *) received_task->data; //received_task_data->starttime = MSG_get_clock(); //double endtime = MSG_get_clock(); //write_log(received_task_data->starttime,endtime,"waiting time"); //received_task_data->starttime = endtime; XBT_INFO("received task %lf",received_task_data->id); run_task(task_name,list_methods_len,list_methods,received_task); } MSG_task_destroy(received_task); received_task = NULL; } }
/** Receiver function */ int receiver(int argc, char *argv[]) { msg_task_t task = NULL; _XBT_GNUC_UNUSED msg_error_t res; int id = -1; char mailbox[80]; msg_comm_t res_irecv; double sleep_start_time = atof(argv[2]); double sleep_test_time = atof(argv[3]); long senders_count = atol(argv[4]); XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time); int timeout = -1; int timeflag = 1; // set to 1 for no timeout _XBT_GNUC_UNUSED int read; read = sscanf(argv[1], "%d", &id); xbt_assert(read, "Invalid argument %s\n", argv[1]); MSG_process_sleep(sleep_start_time); sprintf(mailbox, "receiver-%d", id); while (1) { res_irecv = MSG_task_irecv(&(task), mailbox); XBT_INFO("Wait to receive a task - sleep_test = %f", sleep_test_time); if (sleep_test_time == 0) { if (MSG_get_clock() >= 3.9 && timeflag == 0) { timeflag = 1; timeout = 0.05; } res = MSG_comm_wait(res_irecv, timeout); //xbt_assert(res == MSG_OK, "MSG_task_get failed"); if (res != MSG_OK) { XBT_INFO("Timeout !!"); timeout = -1; MSG_comm_destroy(res_irecv); continue; } } else { while (MSG_comm_test(res_irecv) == 0) { XBT_INFO("Attente ..."); MSG_process_sleep(sleep_test_time); }; XBT_INFO("comm destroy"); MSG_comm_destroy(res_irecv); } XBT_INFO("Received \"%s\"", MSG_task_get_name(task)); if (!strcmp(MSG_task_get_name(task), "finalize")) { //MSG_task_destroy(task); //task = NULL; senders_count--; if (senders_count == 0) { break; } } else { XBT_INFO("Processing \"%s\"", MSG_task_get_name(task)); MSG_task_execute(task); XBT_INFO("\"%s\" done", MSG_task_get_name(task)); //MSG_task_destroy(task); //task = NULL; } MSG_task_destroy(task); task = NULL; } XBT_INFO("I'm done. See you!"); return 0; } /* end_of_receiver */
/* 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); } }
/** * \brief Node Function * Arguments: * - my id * - the id of a guy I know in the system (except for the first node) * - the time to sleep before I join (except for the first node) * - the deadline time */ static int node(int argc, char *argv[]) { double init_time = MSG_get_clock(); msg_task_t task_received = NULL; int join_success = 0; double deadline; xbt_assert(argc == 3 || argc == 5, "Wrong number of arguments for this node"); s_node_t node = {0}; node.id = xbt_str_parse_int(argv[1], "Invalid ID: %s"); node.known_id = -1; node.ready = -1; node.pending_tasks = xbt_fifo_new(); get_mailbox(node.id, node.mailbox); XBT_DEBUG("New node with id %s (%08x)", node.mailbox, node.id); int i,j,d; for (i=0; i<LEVELS_COUNT; i++){ d = domain(node.id, i); for (j=0; j<LEVEL_SIZE; j++) node.routing_table[i][j] = (d==j) ? node.id : -1; } for (i=0; i<NEIGHBORHOOD_SIZE; i++) node.neighborhood_set[i] = -1; for (i=0; i<NAMESPACE_SIZE; i++) node.namespace_set[i] = -1; if (argc == 3) { // first ring XBT_DEBUG("Hey! Let's create the system."); deadline = xbt_str_parse_double(argv[2], "Invalid deadline: %s"); create(&node); join_success = 1; } else { node.known_id = xbt_str_parse_int(argv[2], "Invalid known ID: %s"); double sleep_time = xbt_str_parse_double(argv[3], "Invalid sleep time: %s"); deadline = xbt_str_parse_double(argv[4], "Invalid deadline: %s"); // sleep before starting XBT_DEBUG("Let's sleep during %f", sleep_time); MSG_process_sleep(sleep_time); XBT_DEBUG("Hey! Let's join the system."); join_success = join(&node); } if (join_success) { XBT_DEBUG("Waiting …."); while (MSG_get_clock() < init_time + deadline // && MSG_get_clock() < node.last_change_date + 1000 && MSG_get_clock() < max_simulation_time) { if (node.comm_receive == NULL) { task_received = NULL; node.comm_receive = MSG_task_irecv(&task_received, node.mailbox); // FIXME: do not make MSG_task_irecv() calls from several functions } if (!MSG_comm_test(node.comm_receive)) { MSG_process_sleep(5); } else { // a transfer has occurred msg_error_t status = MSG_comm_get_status(node.comm_receive); if (status != MSG_OK) { XBT_DEBUG("Failed to receive a task. Nevermind."); MSG_comm_destroy(node.comm_receive); node.comm_receive = NULL; } else { // the task was successfully received MSG_comm_destroy(node.comm_receive); node.comm_receive = NULL; handle_task(&node, task_received); } } } print_node(&node); } return 1; }