X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/blobdiff_plain/f29b38ef2a056daa14bbfda2fce78063faa773d4..ef5d9613299a5a47244f7edec76d0dfc70edfddc:/simple_async.cpp diff --git a/simple_async.cpp b/simple_async.cpp index b2d8bc0..8e04ba9 100644 --- a/simple_async.cpp +++ b/simple_async.cpp @@ -3,6 +3,7 @@ #include // clock() #include #include +#include "simgrid_features.h" // Creates a new log category and makes it the default XBT_LOG_NEW_DEFAULT_CATEGORY(simu, "Simulation messages"); @@ -19,11 +20,11 @@ enum { EXIT_FAILURE_CLEAN = 0x08, // error at cleanup }; -int sender(int, char *[]) +int sender(int, char* []) { char mbox_stack[N_MBOX][100]; msg_comm_t comm_stack[N_MBOX * N_MESG]; - msg_comm_t *comm = comm_stack; + msg_comm_t* pcomm = comm_stack; for (int i = 0 ; i < N_MBOX ; i++) sprintf(mbox_stack[i], "MBox_%02d", i); @@ -32,7 +33,7 @@ int sender(int, char *[]) for (int i = 0 ; i < N_MBOX ; i++) for (int j = 0 ; j < N_MESG ; j++) { char task_name[100]; - const char *mailbox = mbox_stack[i]; + const char* mailbox = mbox_stack[i]; unsigned shift = j; unsigned comm_size = 1 << shift; m_task_t task; @@ -42,18 +43,22 @@ int sender(int, char *[]) INFO4("At %02d, send %s, size %.0f to \"%s\"", n, MSG_task_get_name(task), MSG_task_get_data_size(task), mailbox); - *comm++ = MSG_task_isend(task, mailbox); + *pcomm++ = MSG_task_isend(task, mailbox); ++n; } INFO0("Wait for communications to terminate..."); - MSG_comm_waitall(comm_stack, comm - comm_stack, -1.0); + MSG_comm_waitall(comm_stack, pcomm - comm_stack, -1.0); + if (!MSG_WAIT_DESTROYS_COMMS) { + while (pcomm > comm_stack) + MSG_comm_destroy(*--pcomm); + } INFO0("Finished."); return 0; } -int receiver(int, char *[]) +int receiver(int, char* []) { char mbox[N_MBOX][100]; int comm_count[N_MBOX]; @@ -77,7 +82,7 @@ int receiver(int, char *[]) } } int n = 0; - while (xbt_dynar_length(dcomms)) { + while (!xbt_dynar_is_empty(dcomms)) { MSG_comm_waitany(dcomms); xbt_dynar_reset(dcomms); for (int i = 0 ; i < N_MBOX ; i++) { @@ -111,10 +116,10 @@ int receiver(int, char *[]) return 0; } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { - const char *platform_file; - const char *application_file; + const char* platform_file; + const char* application_file; // Note: variables used after THROW must be declared as volatile. volatile int exit_status; // global exit status volatile double simulated_time = -1.0; @@ -128,7 +133,7 @@ int main(int argc, char *argv[]) MSG_global_init(&argc, argv); exit_status = EXIT_FAILURE_ARGS; // ===== - TRY { + TRY { // Parse global parameters if (argc != 3) {