-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 */
- msg_comm_t comm;
- while (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);
- }
-}
-
-/* My actions */
-static void action_send(const char *const *action)
-{
- char to[250];
- const char *size_str = action[3];
- double size = parse_double(size_str);
- double clock = MSG_get_clock();
-
- 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) {
- action_Isend(action);
- } else {
- MSG_task_send(MSG_task_create(to, 0, size, NULL), to);
- }
-
- log_action(action, MSG_get_clock() - clock);
- asynchronous_cleanup();
-}
-
-static void action_Isend(const char *const *action)
-{
- char to[250];
- const char *size = action[3];
- double clock = MSG_get_clock();
- process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
-
- 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);
-
- XBT_DEBUG("Isend on %s", MSG_process_get_name(MSG_process_self()));
- log_action(action, MSG_get_clock() - clock);
- asynchronous_cleanup();
-}
-
-static void action_recv(const char *const *action)
-{
- char mailbox_name[250];
- msg_task_t task = NULL;
- double clock = MSG_get_clock();
-
- 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);
- log_action(action, MSG_get_clock() - clock);
-
- if (res == MSG_OK) {
- MSG_task_destroy(task);
- }
- asynchronous_cleanup();
-}
-
-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()));
-
- 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((msg_task**)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 void action_wait(const char *const *action)
-{
- msg_task_t task = NULL;
- msg_comm_t comm;
- double clock = MSG_get_clock();
- process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
-
- xbt_assert(xbt_dynar_length(globals->irecvs), "action wait not preceded by any irecv: %s",
- xbt_str_join_array(action, " "));
-
- ACT_DEBUG("Entering %s", NAME);
- comm = xbt_dynar_pop_as(globals->irecvs, msg_comm_t);
- MSG_comm_wait(comm, -1);
- task = xbt_dynar_pop_as(globals->tasks, msg_task_t);
- MSG_comm_destroy(comm);
- MSG_task_destroy(task);
-
- log_action(action, MSG_get_clock() - clock);
-}
-
-/* FIXME: that's a poor man's implementation: we should take the message exchanges into account */
-static void action_barrier(const char *const *action)
-{
- // static smx_mutex_t mutex = NULL;
- // static smx_cond_t cond = NULL;
- static simgrid::s4u::Mutex *mutex = NULL;
- static simgrid::s4u::ConditionVariable *cond = NULL;
- static int processes_arrived_sofar = 0;
- if (mutex == NULL) { // first arriving on the barrier
- mutex = new simgrid::s4u::Mutex();
- cond = new simgrid::s4u::ConditionVariable();
- processes_arrived_sofar = 0;
- }
- ACT_DEBUG("Entering barrier: %s (%d already there)", NAME, processes_arrived_sofar);
-