Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce the differences between the s4u_async examples
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 10 Sep 2017 15:57:36 +0000 (17:57 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 10 Sep 2017 15:57:36 +0000 (17:57 +0200)
examples/s4u/async-waitall/s4u_async-waitall.cpp
examples/s4u/async-waitany/s4u_async-waitany.cpp
examples/s4u/async-waitany/s4u_async-waitany_d.xml

index 612aabf..c7ca1c5 100644 (file)
@@ -29,7 +29,8 @@ class sender {
 public:
   explicit sender(std::vector<std::string> args)
 {
-  xbt_assert(args.size()== 4, "This function expects 5 parameters from the XML deployment file");
+  xbt_assert(args.size() == 4, "This function expects 4 parameters from the XML deployment file but got %zu",
+             args.size());
   messages_count  = std::stol(args[1]);
   msg_size        = std::stod(args[2]);
   receivers_count = std::stol(args[3]);
@@ -37,7 +38,7 @@ public:
 }
 void operator()()
 {
-  simgrid::s4u::CommPtr* comms = new simgrid::s4u::CommPtr[messages_count + receivers_count];
+  std::vector<simgrid::s4u::CommPtr>* pending_comms = new std::vector<simgrid::s4u::CommPtr>();
 
   /* Start dispatching all messages to receivers, in a round robin fashion */
   for (int i = 0; i < messages_count; i++) {
@@ -48,7 +49,10 @@ void operator()()
     char* payload = xbt_strdup(msgName.c_str()); // copy the data we send: 'msgName' is not a stable storage location
 
     XBT_INFO("Send '%s' to '%s'", msgName.c_str(), mboxName.c_str());
-    comms[i] = mbox->put_async((void*)payload, msg_size);
+    /* Create a communication representing the ongoing communication */
+    simgrid::s4u::CommPtr comm = mbox->put_async((void*)payload, msg_size);
+    /* Add this comm to the vector of all known comms */
+    pending_comms->push_back(comm);
   }
   /* Start sending messages to let the workers know that they should stop */
   for (int i = 0; i < receivers_count; i++) {
@@ -56,17 +60,18 @@ void operator()()
     simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mbox_name);
     char* payload                 = xbt_strdup("finalize"); // Make a copy of the data we will send
 
-    comms[i + messages_count] = mbox->put_async((void*)payload, 0);
+    simgrid::s4u::CommPtr comm = mbox->put_async((void*)payload, 0);
+    pending_comms->push_back(comm);
     XBT_INFO("Send 'finalize' to 'receiver-%ld'", i % receivers_count);
   }
   XBT_INFO("Done dispatching all messages");
 
   /* Now that all message exchanges were initiated, this loop waits for the termination of them all */
   for (int i = 0; i < messages_count + receivers_count; i++)
-    comms[i]->wait();
+    pending_comms->at(i)->wait();
 
-  delete [] comms;
   XBT_INFO("Goodbye now!");
+  delete pending_comms;
 }
 };
 
@@ -92,7 +97,7 @@ void operator()()
       xbt_free(received);
       break;
     }
-    /*  - Otherwise receiving the message was all we were supposed to do */
+    /* Otherwise receiving the message was all we were supposed to do */
     xbt_free(received);
   }
 }
index 235269b..64370ca 100644 (file)
@@ -90,17 +90,15 @@ void operator()()
 
 class receiver {
   simgrid::s4u::MailboxPtr mbox;
-  int message_count;
 
 public:
   explicit receiver(std::vector<std::string> args)
 {
-  xbt_assert(args.size() == 3, "This function expects 2 parameters from the XML deployment file but got %zu",
+  xbt_assert(args.size() == 2, "This function expects 2 parameters from the XML deployment file but got %zu",
              args.size());
   int id = xbt_str_parse_int(args[1].c_str(), "Any process of this example must have a numerical name, not %s");
   std::string mbox_name = std::string("receiver-") + std::to_string(id);
   mbox                  = simgrid::s4u::Mailbox::byName(mbox_name);
-  message_count         = xbt_str_parse_int(args[2].c_str(), "message_count parameter must be numerical but got '%s'");
 }
 void operator()()
 {
index 8a3ff72..4296dbb 100644 (file)
   <!-- The receiver processes -->
   <actor host="Fafard" function="receiver">
     <argument value="0"/>       <!-- My name -->
-    <argument value="3"/>       <!-- Number of tasks -->
   </actor>
   <actor host="Jupiter" function="receiver">
     <argument value="1"/>       <!-- My name -->
-    <argument value="3"/>       <!-- Number of tasks -->
   </actor>
 </platform>