Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
chaned global execute_mutex and execute_cond to host-specific and wrapped all
[simgrid.git] / src / smpi / smpi_receiver.c
index 283e5f2..edfb213 100644 (file)
@@ -1,5 +1,7 @@
 #include "private.h"
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_receiver, smpi, "Logging specific to SMPI (receiver)");
+
 int smpi_receiver(int argc, char **argv)
 {
        smx_process_t self;
@@ -22,7 +24,7 @@ int smpi_receiver(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);
@@ -39,11 +41,12 @@ int smpi_receiver(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 {
@@ -83,8 +86,18 @@ stopsearch:
                        SIMIX_mutex_lock(request->mutex);
                        memcpy(request->buf, message->buf, request->datatype->size * request->count);
                        request->src = message->src;
-                       request->completed = 1;
-                       SIMIX_cond_broadcast(request->cond);
+                       request->data = message->data;
+                       request->forward = message->forward;
+
+                       if (0 == request->forward) {
+                               request->completed = 1;
+                               SIMIX_cond_broadcast(request->cond);
+                       } else {
+                               request->src = request->comm->index_to_rank_map[index];
+                               request->dst = (request->src + 1) % request->comm->size;
+                               smpi_mpi_isend(request);
+                       }
+
                        SIMIX_mutex_unlock(request->mutex);
 
                        xbt_free(message->buf);