Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
* added support for optimized collectives:
[simgrid.git] / src / smpi / smpi_receiver.c
index b81c997..90d6ea8 100644 (file)
@@ -3,17 +3,15 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_receiver, smpi,
                                 "Logging specific to SMPI (receiver)");
 
-int smpi_receiver(int argc, char*argv[])
+int smpi_receiver(int argc, char *argv[])
 {
-       smpi_host_data_t mydata = SIMIX_process_get_data(SIMIX_process_self());
+  smpi_process_data_t mydata = SIMIX_process_get_data(SIMIX_process_self());
   smx_process_t self;
   int index = mydata->index;
 
   xbt_fifo_t request_queue;
   xbt_fifo_t message_queue;
 
-  int running_hosts_count;
-
   smpi_mpi_request_t request;
   smpi_received_message_t message;
 
@@ -23,15 +21,22 @@ int smpi_receiver(int argc, char*argv[])
   self = SIMIX_process_self();
 
   request_queue = mydata->pending_recv_request_queue;
-  message_queue = smpi_global->received_message_queues[index];
+  message_queue = mydata->received_message_queue;
+
 
-  do {
 
+  while (1) {
     // FIXME: better algorithm, maybe some kind of balanced tree? or a heap?
 
-       xbt_fifo_foreach(request_queue,request_item,request,smpi_mpi_request_t){
-         xbt_fifo_foreach(message_queue,message_item,message, smpi_received_message_t) {
+    xbt_fifo_foreach(request_queue, request_item, request, smpi_mpi_request_t) {
+      xbt_fifo_foreach(message_queue, message_item, message,
+                       smpi_received_message_t) {
 
+//#define DEBUG_MATCH
+#ifdef DEBUG_MATCH
+        printf("[%s] try match (req_src=%d,msg_src=%d)x(req_tag=%d,msg_tag=%d)\n",
+                        __FILE__,request->src,message->src,request->tag, message->tag);
+#endif
         if (request->comm == message->comm &&
             (MPI_ANY_SOURCE == request->src || request->src == message->src)
             && (MPI_ANY_TAG == request->tag || request->tag == message->tag)) {
@@ -39,6 +44,10 @@ int smpi_receiver(int argc, char*argv[])
           xbt_fifo_free_item(request_item);
           xbt_fifo_remove_item(message_queue, message_item);
           xbt_fifo_free_item(message_item);
+#ifdef DEBUG_MATCH
+        printf("[%s] found match: req_src=%d,msg_src=%d)x(req_tag=%d,msg_tag=%d)\n",
+                        __FILE__,request->src,message->src,request->tag, message->tag);
+#endif
           goto stopsearch;
         }
       }
@@ -48,9 +57,9 @@ int smpi_receiver(int argc, char*argv[])
     message = NULL;
 
   stopsearch:
-    if (NULL == request || NULL == message) {
-      SIMIX_process_suspend(self);
-    } else {
+    if (NULL != request) {
+      if (NULL == message)
+        DIE_IMPOSSIBLE;
 
       SIMIX_mutex_lock(request->mutex);
       memcpy(request->buf, message->buf,
@@ -73,11 +82,15 @@ int smpi_receiver(int argc, char*argv[])
       xbt_free(message->buf);
       xbt_mallocator_release(smpi_global->message_mallocator, message);
 
+    } else if (mydata->finalize > 0) {  /* main wants me to die and nothing to do */
+      // FIXME: display the list of remaining requests and messages (user code synchronization faulty?)
+      mydata->finalize--;
+      SIMIX_cond_signal(mydata->cond);
+      return 0;
+    } else {
+      SIMIX_process_suspend(self);
     }
-
-    running_hosts_count = smpi_global->running_hosts_count;
-
-  } while (0 < running_hosts_count);
+  }
 
   return 0;
 }