Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into async-wait
authorZitagcc <toufik.boubehziz@inria.fr>
Mon, 2 Oct 2017 16:02:10 +0000 (18:02 +0200)
committerGitHub <noreply@github.com>
Mon, 2 Oct 2017 16:02:10 +0000 (18:02 +0200)
examples/s4u/CMakeLists.txt
examples/s4u/README.doc
examples/s4u/async-wait/s4u-async-wait.cpp [new file with mode: 0644]
examples/s4u/async-wait/s4u-async-wait.tesh [new file with mode: 0644]
examples/s4u/async-wait/s4u-async-wait_d.xml [new file with mode: 0644]
examples/s4u/async-waitall/s4u-async-waitall.cpp

index 1985706..0ee6b1e 100644 (file)
@@ -1,7 +1,7 @@
 foreach (example actions-comm actions-storage 
                  actor-create actor-daemon actor-kill actor-migration actor-suspend 
                  app-masterworker app-pingpong app-token-ring
-                async-waitany async-waitall
+                async-wait async-waitany async-waitall
                 plugin-hostload io mutex)
   add_executable       (s4u-${example}  ${example}/s4u-${example}.cpp)
   target_link_libraries(s4u-${example}  simgrid)
@@ -32,6 +32,7 @@ endforeach()
 set(examples_src  ${examples_src}                                                                          PARENT_SCOPE)
 set(tesh_files    ${tesh_files}   ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/s4u-app-bittorrent.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord.tesh
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall.tesh         PARENT_SCOPE)
 set(xml_files     ${xml_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm-split_d.xml
@@ -42,6 +43,7 @@ set(xml_files     ${xml_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a
                                   ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/s4u-app-masterworker_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall_d.xml
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord_d.xml                PARENT_SCOPE)
 set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm-split-p0.txt
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm-split-p1.txt
@@ -52,7 +54,7 @@ set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a
 foreach(example actions-comm actions-storage 
                 actor-create actor-daemon actor-kill actor-migration actor-suspend
                 app-bittorrent app-masterworker app-pingpong app-token-ring 
-               async-waitall async-waitany
+               async-wait async-waitall async-waitany
                dht-chord plugin-hostload io mutex)
   ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/${example} s4u-${example}.tesh)
 endforeach()
index 78c9933..c581f80 100644 (file)
@@ -40,6 +40,13 @@ documentation, but it should remain readable directly.
     
 @section msg_ex_async Asynchronous communications
 
+ - <b>Basic asynchronous communications</b>. 
+   @ref examples/s4u/async-wait/s4u-async-wait.cpp \n
+   Illustrates how to have non-blocking communications, that are
+   communications running in the background leaving the process free
+   to do something else during their completion. The main functions
+   involved are @ref put_async and @ref get.
+
  - <b>Waiting for all communications in a set</b>.
    @ref examples/s4u/async-waitall/s4u-async-waitall.cpp\n
    The @ref simgrid::s4u::Comm::wait_all() function is useful when you want to block
diff --git a/examples/s4u/async-wait/s4u-async-wait.cpp b/examples/s4u/async-wait/s4u-async-wait.cpp
new file mode 100644 (file)
index 0000000..73f3bff
--- /dev/null
@@ -0,0 +1,119 @@
+/* Copyright (c) 2010-2017. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+/* This example shows how to block until the completion of a communication.
+ */
+
+ #include "simgrid/s4u.hpp"
+ #include "xbt/str.h"
+ #include <cstdlib>
+ #include <iostream>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_wait, "Messages specific for this s4u example");
+
+/* Main function of the Sender process */
+class sender {
+  long messages_count;             /* - number of tasks */
+  long receivers_count;            /* - number of receivers */
+  double sleep_start_time;         /* - start time */
+  double sleep_test_time;          /* - test time */
+  double msg_size;                 /* - computational cost */
+  double task_comm_size;           /* - communication cost */
+  simgrid::s4u::MailboxPtr mbox;
+  
+public:
+  explicit sender(std::vector<std::string> args)
+{
+  xbt_assert(args.size() == 7, "The sender function expects 6 arguments from the XML deployment file");
+  messages_count = std::stol(args[1]);
+  msg_size = std::stod(args[2]); 
+  task_comm_size = std::stod(args[3]); 
+  receivers_count = std::stol(args[4]);    
+  double sleep_start_time = std::stod(args[5]);
+  double sleep_test_time = std::stod(args[6]);
+  XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);
+}
+void operator()()
+{
+  /* Start dispatching all messages to receivers, in a round robin fashion */
+  for (int i = 0; i < messages_count; i++) {
+    char mailbox[80];
+    char taskname[80];
+    
+    std::string mbox_name = std::string("receiver-") + std::to_string(i % receivers_count);
+    mbox = simgrid::s4u::Mailbox::byName(mbox_name);
+    snprintf(mailbox,79, "receiver-%ld", i % receivers_count);
+    snprintf(taskname,79, "Task_%d", i);
+    
+    /* Create a communication representing the ongoing communication */
+    simgrid::s4u::CommPtr comm = mbox->put_async((void*)mailbox, msg_size);
+    XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);
+    comm->wait(task_comm_size);
+  }
+  /* Start sending messages to let the workers know that they should stop */
+  for (int i = 0; i < receivers_count; i++) {
+    char mailbox[80];
+    char* payload   = xbt_strdup("finalize"); 
+    snprintf(mailbox, 79, "receiver-%d", i);
+    simgrid::s4u::CommPtr comm = mbox->put_async((void*)payload, 0);
+    comm->wait(task_comm_size);
+    XBT_INFO("Send to receiver-%d finalize", i);
+  }
+
+  XBT_INFO("Goodbye now!");
+
+}
+};
+
+/* Receiver process expects 3 arguments: */
+class receiver {
+  int id;                   /* - unique id */
+  double sleep_start_time;  /* - start time */
+  double sleep_test_time;   /* - test time */
+  simgrid::s4u::MailboxPtr mbox;
+  
+public:
+  explicit receiver(std::vector<std::string> args)
+  {
+  xbt_assert(args.size() == 4, "The relay_runner function does not accept any parameter from the XML deployment file");
+  id = std::stoi(args[1]);
+  sleep_start_time = std::stod(args[2]); 
+  sleep_test_time = std::stod(args[3]);   
+  XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);
+  std::string mbox_name = std::string("receiver-") + std::to_string(id);
+  mbox = simgrid::s4u::Mailbox::byName(mbox_name);
+}
+
+void operator()()
+{
+  char mailbox[80];
+  snprintf(mailbox,79, "receiver-%d", id);
+  while (1) {
+    char* received = static_cast<char*>(mbox->get());
+    XBT_INFO("Wait to receive a task");
+    XBT_INFO("I got a '%s'.", received);
+    if (std::strcmp(received, "finalize") == 0) { /* If it's a finalize message, we're done */
+      xbt_free(received);
+      break;
+    }
+  }
+}
+};
+
+int main(int argc, char *argv[])
+{
+  simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
+  
+    xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
+  
+    e->registerFunction<sender>("sender");
+    e->registerFunction<receiver>("receiver");
+  
+    e->loadPlatform(argv[1]);
+    e->loadDeployment(argv[2]);
+    e->run();
+  
+    return 0;
+}
diff --git a/examples/s4u/async-wait/s4u-async-wait.tesh b/examples/s4u/async-wait/s4u-async-wait.tesh
new file mode 100644 (file)
index 0000000..b46b2e8
--- /dev/null
@@ -0,0 +1,20 @@
+#! ./tesh
+
+p Test1 Sleep_sender > Sleep_receiver
+
+$ $SG_TEST_EXENV ${bindir:=.}/s4u-async-wait ${srcdir:=.}/small_platform_fatpipe.xml ${srcdir:=.}/../s4u/async-wait/s4u-async-wait_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:sender@Tremblay) sleep_start_time : 5.000000 , sleep_test_time : 0.100000
+> [  0.000000] (2:receiver@Ruby) sleep_start_time : 1.000000 , sleep_test_time : 0.100000
+> [  0.000000] (1:sender@Tremblay) Send to receiver-0 Task_0
+> [  0.105458] (2:receiver@Ruby) Wait to receive a task
+> [  0.105458] (2:receiver@Ruby) I got a 'receiver-0'.
+> [  0.105458] (1:sender@Tremblay) Send to receiver-0 Task_1
+> [  0.210917] (2:receiver@Ruby) Wait to receive a task
+> [  0.210917] (2:receiver@Ruby) I got a 'receiver-0'.
+> [  0.210917] (1:sender@Tremblay) Send to receiver-0 Task_2
+> [  0.316375] (2:receiver@Ruby) Wait to receive a task
+> [  0.316375] (2:receiver@Ruby) I got a 'receiver-0'.
+> [  0.318326] (2:receiver@Ruby) Wait to receive a task
+> [  0.318326] (2:receiver@Ruby) I got a 'finalize'.
+> [  0.318326] (1:sender@Tremblay) Send to receiver-0 finalize
+> [  0.318326] (1:sender@Tremblay) Goodbye now!
\ No newline at end of file
diff --git a/examples/s4u/async-wait/s4u-async-wait_d.xml b/examples/s4u/async-wait/s4u-async-wait_d.xml
new file mode 100644 (file)
index 0000000..580374b
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
+<platform version="4.1">
+  <!-- The master actor (with some arguments) -->
+  <actor host="Tremblay" function="sender">
+    <argument value="3"/>       <!-- Number of tasks -->
+    <argument value="50000000"/>  <!-- Computation size of tasks -->
+    <argument value="1000000"/>   <!-- Communication size of tasks -->
+    <argument value="1"/>         <!-- Number of receivers -->
+    <argument value="5"/>         <!-- Sleep_start_time -->
+    <argument value="0.1"/>      <!-- Time for test -->
+  </actor>
+  <!-- The receiver processes -->
+  <actor host="Ruby" function="receiver">
+    <argument value="0"/>
+    <argument value="1"/>         <!-- Sleep_start_time -->
+    <argument value="0.1"/>      <!-- Time for test -->
+  </actor>
+</platform>
\ No newline at end of file
index 3437e4a..55f645e 100644 (file)
@@ -17,7 +17,7 @@
 #include <cstdlib>
 #include <iostream>
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_waitall, "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_waitall, "Messages specific for this s4u example");
 
 class sender {
   long messages_count;