Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a test in teshsuite for Comm::wait_all_for.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 22 Jun 2021 09:48:41 +0000 (11:48 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 22 Jun 2021 20:00:06 +0000 (22:00 +0200)
MANIFEST.in
teshsuite/s4u/CMakeLists.txt
teshsuite/s4u/wait-all-for/wait-all-for.cpp [new file with mode: 0644]
teshsuite/s4u/wait-all-for/wait-all-for.tesh [new file with mode: 0644]

index 01ad524..3245396 100644 (file)
@@ -767,6 +767,8 @@ include teshsuite/s4u/vm-live-migration/vm-live-migration.cpp
 include teshsuite/s4u/vm-live-migration/vm-live-migration.tesh
 include teshsuite/s4u/vm-suicide/vm-suicide.cpp
 include teshsuite/s4u/vm-suicide/vm-suicide.tesh
+include teshsuite/s4u/wait-all-for/wait-all-for.cpp
+include teshsuite/s4u/wait-all-for/wait-all-for.tesh
 include teshsuite/s4u/wait-any-for/wait-any-for.cpp
 include teshsuite/s4u/wait-any-for/wait-any-for.tesh
 include teshsuite/simdag/availability/availability.c
index 43f0ca1..2e24879 100644 (file)
@@ -1,6 +1,6 @@
 foreach(x actor actor-autorestart actor-suspend
         activity-lifecycle
-        comm-get-sender comm-pt2pt wait-any-for
+        comm-get-sender comm-pt2pt wait-all-for wait-any-for
         cloud-interrupt-migration cloud-two-execs
         concurrent_rw 
         host-on-off host-on-off-actors host-on-off-recv
@@ -27,7 +27,7 @@ set_property(TARGET activity-lifecycle APPEND PROPERTY INCLUDE_DIRECTORIES "${IN
 ## Add the tests.
 ## Some need to be run with all factories, some don't need tesh to run
 foreach(x actor actor-autorestart actor-suspend
-        activity-lifecycle comm-get-sender wait-any-for
+        activity-lifecycle comm-get-sender wait-all-for wait-any-for
         cloud-interrupt-migration cloud-two-execs concurrent_rw
        vm-live-migration vm-suicide)
   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh)
diff --git a/teshsuite/s4u/wait-all-for/wait-all-for.cpp b/teshsuite/s4u/wait-all-for/wait-all-for.cpp
new file mode 100644 (file)
index 0000000..7c7453d
--- /dev/null
@@ -0,0 +1,53 @@
+/* Copyright (c) 2019-2021. 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. */
+
+#include <cstdlib>
+#include <iostream>
+#include <simgrid/s4u.hpp>
+#include <string>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(meh, "meh");
+
+static void worker()
+{
+  auto mbox  = simgrid::s4u::Mailbox::by_name("meh");
+  int input1 = 42;
+  int input2 = 51;
+
+  XBT_INFO("Sending and receiving %d and %d asynchronously", input1, input2);
+
+  auto put1 = mbox->put_async(&input1, 1000 * 1000 * 500);
+  auto put2 = mbox->put_async(&input2, 1000 * 1000 * 1000);
+
+  int* out1;
+  auto get1 = mbox->get_async<int>(&out1);
+
+  int* out2;
+  auto get2 = mbox->get_async<int>(&out2);
+
+  XBT_INFO("All comms have started");
+  std::vector<simgrid::s4u::CommPtr> comms = {put1, put2, get1, get2};
+
+  while (not comms.empty()) {
+    size_t index = simgrid::s4u::Comm::wait_all_for(&comms, 0.5);
+    if (index < comms.size())
+      XBT_INFO("wait_all_for: Timeout reached");
+    XBT_INFO("wait_all_for: %zu comms finished (#comms=%zu)", index, comms.size());
+    comms.erase(comms.begin(), comms.begin() + index);
+  }
+
+  XBT_INFO("All comms have finished");
+  XBT_INFO("Got %d and %d", *out1, *out2);
+}
+
+int main(int argc, char* argv[])
+
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  e.load_platform(argv[1]);
+  simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Tremblay"), worker);
+  e.run();
+  return 0;
+}
diff --git a/teshsuite/s4u/wait-all-for/wait-all-for.tesh b/teshsuite/s4u/wait-all-for/wait-all-for.tesh
new file mode 100644 (file)
index 0000000..c7b30a9
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env tesh
+
+p Testing the wait_all_for feature of S4U
+
+! output sort 19
+$ ${bindir:=.}/wait-all-for ${platfdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
+> [  0.000000] (1:worker@Tremblay) Sending and receiving 42 and 51 asynchronously
+> [  0.000000] (1:worker@Tremblay) All comms have started
+> [  0.500000] (1:worker@Tremblay) wait_all_for: Timeout reached
+> [  0.500000] (1:worker@Tremblay) wait_all_for: 0 comms finished (#comms=4)
+> [  1.000000] (1:worker@Tremblay) wait_all_for: Timeout reached
+> [  1.000000] (1:worker@Tremblay) wait_all_for: 0 comms finished (#comms=4)
+> [  1.500000] (1:worker@Tremblay) wait_all_for: Timeout reached
+> [  1.500000] (1:worker@Tremblay) wait_all_for: 1 comms finished (#comms=4)
+> [  2.000000] (1:worker@Tremblay) wait_all_for: Timeout reached
+> [  2.000000] (1:worker@Tremblay) wait_all_for: 0 comms finished (#comms=3)
+> [  2.070331] (1:worker@Tremblay) wait_all_for: 3 comms finished (#comms=3)
+> [  2.070331] (1:worker@Tremblay) All comms have finished
+> [  2.070331] (1:worker@Tremblay) Got 42 and 51