X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c4b490069d7cdcaa3af5c0709d9967321cf48f9f..9f21f35eadfc5d1f43d3e7a4b591711fd7fb9616:/examples/msg/actions-comm/actions-comm.c diff --git a/examples/msg/actions-comm/actions-comm.c b/examples/msg/actions-comm/actions-comm.c index f840d898de..e9888db542 100644 --- a/examples/msg/actions-comm/actions-comm.c +++ b/examples/msg/actions-comm/actions-comm.c @@ -19,7 +19,9 @@ typedef struct { /* Used to implement irecv+wait */ xbt_dynar_t irecvs; /* of msg_comm_t */ xbt_dynar_t tasks; /* of msg_task_t */ -} s_process_globals_t, *process_globals_t; +} s_process_globals_t; + +typedef s_process_globals_t *process_globals_t; /* Helper function */ static double parse_double(const char *string) @@ -54,10 +56,12 @@ static void asynchronous_cleanup(void) process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self()); /* Destroy any isend which correspond to completed communications */ - int found; msg_comm_t comm; - while ((found = MSG_comm_testany(globals->isends)) != -1) { - xbt_dynar_remove_at(globals->isends, found, &comm); + while (1/*true*/) { + int pos_found = MSG_comm_testany(globals->isends); + if (pos_found == -1) /* none remaining */ + break; + xbt_dynar_remove_at(globals->isends, pos_found, &comm); MSG_comm_destroy(comm); } } @@ -70,7 +74,7 @@ static void action_send(const char *const *action) double size = parse_double(size_str); double clock = MSG_get_clock(); - sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()), action[2]); + snprintf(to,249, "%s_%s", MSG_process_get_name(MSG_process_self()), action[2]); ACT_DEBUG("Entering Send: %s (size: %g)", NAME, size); if (size < 65536) { @@ -90,7 +94,7 @@ static void action_Isend(const char *const *action) double clock = MSG_get_clock(); process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self()); - sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()), action[2]); + snprintf(to,249, "%s_%s", MSG_process_get_name(MSG_process_self()), action[2]); msg_comm_t comm = MSG_task_isend(MSG_task_create(to, 0, parse_double(size), NULL), to); xbt_dynar_push(globals->isends, &comm); @@ -105,7 +109,7 @@ static void action_recv(const char *const *action) msg_task_t task = NULL; double clock = MSG_get_clock(); - sprintf(mailbox_name, "%s_%s", action[2], MSG_process_get_name(MSG_process_self())); + snprintf(mailbox_name,249, "%s_%s", action[2], MSG_process_get_name(MSG_process_self())); ACT_DEBUG("Receiving: %s", NAME); msg_error_t res = MSG_task_receive(&task, mailbox_name); @@ -125,7 +129,7 @@ static void action_Irecv(const char *const *action) 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())); + snprintf(mailbox,249, "%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); @@ -170,7 +174,8 @@ static void action_barrier(const char *const *action) ACT_DEBUG("Entering barrier: %s (%d already there)", NAME, processes_arrived_sofar); simcall_mutex_lock(mutex); - if (++processes_arrived_sofar == communicator_size) { + processes_arrived_sofar++; + if (processes_arrived_sofar == communicator_size) { simcall_cond_broadcast(cond); simcall_mutex_unlock(mutex); } else { @@ -181,9 +186,9 @@ static void action_barrier(const char *const *action) ACT_DEBUG("Exiting barrier: %s", NAME); processes_arrived_sofar--; - if (!processes_arrived_sofar) { - SIMIX_cond_destroy(cond); - SIMIX_mutex_destroy(mutex); + if (processes_arrived_sofar<=0) { + SIMIX_cond_unref(cond); + SIMIX_mutex_unref(mutex); mutex = NULL; } } @@ -201,7 +206,8 @@ static void action_bcast(const char *const *action) const char * process_name = MSG_process_get_name(MSG_process_self()); - char *bcast_identifier = bprintf("bcast_%d", counters->bcast_counter++); + char *bcast_identifier = bprintf("bcast_%d", counters->bcast_counter); + counters->bcast_counter++; if (!strcmp(process_name, "p0")) { XBT_DEBUG("%s: %s is the Root", bcast_identifier, process_name); @@ -209,7 +215,7 @@ static void action_bcast(const char *const *action) msg_comm_t *comms = xbt_new0(msg_comm_t, communicator_size - 1); for (int i = 1; i < communicator_size; i++) { - sprintf(mailbox, "%s_p0_p%d", bcast_identifier, i); + snprintf(mailbox,79, "%s_p0_p%d", bcast_identifier, i); comms[i - 1] = MSG_task_isend(MSG_task_create(mailbox, 0, comm_size, NULL), mailbox); } MSG_comm_waitall(comms, communicator_size - 1, -1); @@ -219,7 +225,7 @@ static void action_bcast(const char *const *action) XBT_DEBUG("%s: all messages sent by %s have been received", bcast_identifier, process_name); } else { - sprintf(mailbox, "%s_p0_%s", bcast_identifier, process_name); + snprintf(mailbox,79, "%s_p0_%s", bcast_identifier, process_name); MSG_task_receive(&task, mailbox); MSG_task_destroy(task); XBT_DEBUG("%s: %s has received", bcast_identifier, process_name); @@ -274,8 +280,6 @@ static void action_finalize(const char *const *action) int main(int argc, char *argv[]) { - msg_error_t res = MSG_OK; - /* Check the given arguments */ MSG_init(&argc, argv); /* Explicit initialization of the action module is required now*/ @@ -306,7 +310,7 @@ int main(int argc, char *argv[]) xbt_replay_action_register("compute", action_compute); /* Actually do the simulation using MSG_action_trace_run */ - res = MSG_action_trace_run(argv[3]); // it's ok to pass a NULL argument here + msg_error_t res = MSG_action_trace_run(argv[3]); // it's ok to pass a NULL argument here XBT_INFO("Simulation time %g", MSG_get_clock());