X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/70e4dad5ffd1ba6f56eb7bc97408411b9a73119b..a3a9277b2d833bad63f6ca22dcf9cc563fbe0f68:/src/smpi/smpi_sender.c diff --git a/src/smpi/smpi_sender.c b/src/smpi/smpi_sender.c index f02e0abfa0..26f5125a64 100644 --- a/src/smpi/smpi_sender.c +++ b/src/smpi/smpi_sender.c @@ -1,9 +1,12 @@ #include "private.h" +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_sender, smpi, "Logging specific to SMPI (sender)"); + int smpi_sender(int argc, char **argv) { smx_process_t self; smx_host_t shost; + int index; xbt_fifo_t request_queue; @@ -15,9 +18,10 @@ int smpi_sender(int argc, char **argv) smx_host_t dhost; - char communication[] = "communication"; smx_action_t action; + e_surf_action_state_t state; + smpi_received_message_t message; int dindex; @@ -29,7 +33,7 @@ int smpi_sender(int argc, char **argv) // make sure root is done before own initialization SIMIX_mutex_lock(smpi_global->start_stop_mutex); - if (!smpi_global->root_ready) { + while (!smpi_global->root_ready) { SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex); } SIMIX_mutex_unlock(smpi_global->start_stop_mutex); @@ -44,11 +48,12 @@ int smpi_sender(int argc, char **argv) // wait for all nodes to signal initializatin complete SIMIX_mutex_lock(smpi_global->start_stop_mutex); smpi_global->ready_process_count++; - if (smpi_global->ready_process_count < 3 * smpi_global->host_count) { - SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex); - } else { + if (smpi_global->ready_process_count >= 3 * smpi_global->host_count) { SIMIX_cond_broadcast(smpi_global->start_stop_cond); } + while (smpi_global->ready_process_count < 3 * smpi_global->host_count) { + SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex); + } SIMIX_mutex_unlock(smpi_global->start_stop_mutex); do { @@ -78,10 +83,6 @@ int smpi_sender(int argc, char **argv) message->forward = (request->forward - 1) / 2; request->forward = request->forward / 2; - SIMIX_mutex_lock(smpi_global->received_message_queues_mutexes[dindex]); - xbt_fifo_push(smpi_global->received_message_queues[dindex], message); - SIMIX_mutex_unlock(smpi_global->received_message_queues_mutexes[dindex]); - if (0 < request->forward) { request->dst = (request->dst + message->forward + 1) % request->comm->size; SIMIX_mutex_lock(request_queue_mutex); @@ -91,11 +92,25 @@ int smpi_sender(int argc, char **argv) request->completed = 1; } - action = SIMIX_action_communicate(shost, dhost, communication, request->datatype->size * request->count, -1.0); + action = SIMIX_action_communicate(shost, dhost, "communication", request->datatype->size * request->count, -1.0); SIMIX_register_action_to_condition(action, request->cond); - SIMIX_cond_wait(request->cond, request->mutex); + + for ( + state = SIMIX_action_get_state(action); + state == SURF_ACTION_READY || + state == SURF_ACTION_RUNNING; + state = SIMIX_action_get_state(action) + ) { + SIMIX_cond_wait(request->cond, request->mutex); + } + + SIMIX_mutex_lock(smpi_global->received_message_queues_mutexes[dindex]); + xbt_fifo_push(smpi_global->received_message_queues[dindex], message); + SIMIX_mutex_unlock(smpi_global->received_message_queues_mutexes[dindex]); + SIMIX_unregister_action_to_condition(action, request->cond); + SIMIX_action_destroy(action); SIMIX_mutex_unlock(request->mutex);