Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Complete the other activityset examples in python
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 21 Jul 2023 18:09:21 +0000 (20:09 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 21 Jul 2023 18:09:21 +0000 (20:09 +0200)
13 files changed:
examples/cpp/activityset-waitall/s4u-activityset-waitall.cpp
examples/cpp/activityset-waitall/s4u-activityset-waitall.tesh
examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.cpp
examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.tesh
examples/cpp/activityset-waitany/s4u-activityset-waitany.cpp
examples/cpp/activityset-waitany/s4u-activityset-waitany.tesh
examples/python/CMakeLists.txt
examples/python/activityset-waitall/activityset-waitall.py [new file with mode: 0644]
examples/python/activityset-waitall/activityset-waitall.tesh [new file with mode: 0644]
examples/python/activityset-waitallfor/activityset-waitallfor.py [new file with mode: 0644]
examples/python/activityset-waitallfor/activityset-waitallfor.tesh [new file with mode: 0644]
examples/python/activityset-waitany/activityset-waitany.py [new file with mode: 0644]
examples/python/activityset-waitany/activityset-waitany.tesh [new file with mode: 0644]

index 176e50f..efbc3a0 100644 (file)
@@ -26,7 +26,7 @@ static void bob()
                                        boost::dynamic_pointer_cast<sg4::Activity>(comm),
                                        boost::dynamic_pointer_cast<sg4::Activity>(io)});
 
-  XBT_INFO("Wait for asynchrounous activities to complete, all in one shot.");
+  XBT_INFO("Wait for asynchronous activities to complete, all in one shot.");
   pending_activities.wait_all();
 
   XBT_INFO("All activities are completed.");
index 6f01429..889b405 100644 (file)
@@ -3,5 +3,5 @@
 $ ${bindir:=.}/s4u-activityset-waitall ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%7.6r]%e[%5a]%e%m%n"
 > [0.000000] [alice] Send 'Message'
 > [0.000000] [  bob] Create my asynchronous activities
-> [0.000000] [  bob] Wait for asynchrounous activities to complete, all in one shot.
+> [0.000000] [  bob] Wait for asynchronous activities to complete, all in one shot.
 > [5.197828] [  bob] All activities are completed.
index b1d405d..971d774 100644 (file)
@@ -24,7 +24,7 @@ static void bob()
 
   sg4::ActivitySet pending_activities({exec, comm, io});
 
-  XBT_INFO("Wait for asynchrounous activities to complete");
+  XBT_INFO("Wait for asynchronous activities to complete");
   while (not pending_activities.empty()) {
     try {
       pending_activities.wait_all_for(1);
index d0c1016..014c4f0 100644 (file)
@@ -3,7 +3,7 @@
 $ ${bindir:=.}/s4u-activityset-waitallfor ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%7.6r]%e[%5a]%e%m%n"
 > [0.000000] [alice] Send 'Message'
 > [0.000000] [  bob] Create my asynchronous activities
-> [0.000000] [  bob] Wait for asynchrounous activities to complete
+> [0.000000] [  bob] Wait for asynchronous activities to complete
 > [1.000000] [  bob] Not all activities are terminated yet.
 > [2.000000] [  bob] Not all activities are terminated yet.
 > [3.000000] [  bob] Not all activities are terminated yet.
index 1878a13..6f081b3 100644 (file)
@@ -26,7 +26,7 @@ static void bob()
                                        boost::dynamic_pointer_cast<sg4::Activity>(comm),
                                        boost::dynamic_pointer_cast<sg4::Activity>(io)});
 
-  XBT_INFO("Wait for asynchrounous activities to complete");
+  XBT_INFO("Wait for asynchronous activities to complete");
   while (not pending_activities.empty()) {
     auto completed_one = pending_activities.wait_any();
     if (completed_one != nullptr) {
index bc33cc4..b9ecf1e 100644 (file)
@@ -3,7 +3,7 @@
 $ ${bindir:=.}/s4u-activityset-waitany ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%7.6r]%e[%5a]%e%m%n"
 > [0.000000] [alice] Send 'Message'
 > [0.000000] [  bob] Create my asynchronous activities
-> [0.000000] [  bob] Wait for asynchrounous activities to complete
+> [0.000000] [  bob] Wait for asynchronous activities to complete
 > [3.000000] [  bob] Completed an I/O
 > [5.000000] [  bob] Completed an Exec
 > [5.197828] [  bob] Completed a Comm
index e54901c..265268b 100644 (file)
@@ -1,5 +1,5 @@
 foreach(example actor-create actor-daemon actor-join actor-kill actor-migrate actor-suspend actor-yield actor-lifetime
-        activityset-testany
+        activityset-testany activityset-waitall activityset-waitallfor activityset-waitany
         app-masterworkers
         comm-wait comm-waitall comm-waitallfor comm-waitany comm-failure comm-host2host comm-pingpong
         comm-ready comm-suspend comm-testany comm-throttling comm-waitallfor comm-waituntil
diff --git a/examples/python/activityset-waitall/activityset-waitall.py b/examples/python/activityset-waitall/activityset-waitall.py
new file mode 100644 (file)
index 0000000..36b70b8
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright (c) 2017-2023. 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.
+
+"""
+Usage: activityset-waitall.py platform_file [other parameters]
+"""
+
+import sys
+from simgrid import Actor, ActivitySet, Engine, Comm, Exec, Io, Host, Mailbox, this_actor
+
+def bob():
+  mbox = Mailbox.by_name("mbox")
+  disk = Host.current().get_disks()[0]
+
+  this_actor.info("Create my asynchronous activities")
+  exec = this_actor.exec_async(5e9)
+  comm, payload = mbox.get_async()
+  io   = disk.read_async(300000000)
+
+  pending_activities = ActivitySet([exec, comm])
+  pending_activities.push(io) # Activities can be pushed after creation, too
+  this_actor.info("Wait for asynchronous activities to complete, all in one shot.")
+  pending_activities.wait_all()
+
+  this_actor.info("All activities are completed.")
+
+def alice():
+  this_actor.info("Send 'Message'")
+  Mailbox.by_name("mbox").put("Message", 600000000)
+
+if __name__ == '__main__':
+  e = Engine(sys.argv)
+  e.set_log_control("root.fmt:[%4.6r]%e[%5a]%e%m%n")
+
+  # Load the platform description
+  e.load_platform(sys.argv[1])
+
+  Actor.create("bob",   Host.by_name("bob"), bob)
+  Actor.create("alice", Host.by_name("alice"), alice)
+
+  e.run()
diff --git a/examples/python/activityset-waitall/activityset-waitall.tesh b/examples/python/activityset-waitall/activityset-waitall.tesh
new file mode 100644 (file)
index 0000000..ab4b175
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/bin/env tesh
+
+$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${srcdir:=.}/activityset-waitall.py ${platfdir}/hosts_with_disks.xml
+> [0.000000] [alice] Send 'Message'
+> [0.000000] [  bob] Create my asynchronous activities
+> [0.000000] [  bob] Wait for asynchronous activities to complete, all in one shot.
+> [5.197828] [  bob] All activities are completed.
diff --git a/examples/python/activityset-waitallfor/activityset-waitallfor.py b/examples/python/activityset-waitallfor/activityset-waitallfor.py
new file mode 100644 (file)
index 0000000..4f28809
--- /dev/null
@@ -0,0 +1,58 @@
+# Copyright (c) 2017-2023. 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.
+
+"""
+Usage: activityset-waitallfor.py platform_file [other parameters]
+"""
+
+import sys
+from simgrid import Actor, ActivitySet, Engine, Comm, Exec, Io, Host, Mailbox, this_actor, TimeoutException
+
+def bob():
+  mbox = Mailbox.by_name("mbox")
+  disk = Host.current().get_disks()[0]
+
+  this_actor.info("Create my asynchronous activities")
+  exec = this_actor.exec_async(5e9)
+  comm, payload = mbox.get_async()
+  io   = disk.read_async(300000000)
+
+  pending_activities = ActivitySet([exec, comm])
+  pending_activities.push(io) # Activities can be pushed after creation, too
+  this_actor.info("Wait for asynchronous activities to complete")
+  while not pending_activities.empty():
+    try:
+      pending_activities.wait_all_for(1)
+    except TimeoutException:
+      this_actor.info("Not all activities are terminated yet.")
+
+    completed_one = pending_activities.test_any()
+    while completed_one != None:
+      if isinstance(completed_one, Comm):
+        this_actor.info("Completed a Comm")
+      elif isinstance(completed_one, Exec):
+        this_actor.info("Completed an Exec")
+      elif isinstance(completed_one, Io):
+        this_actor.info("Completed an I/O")
+      completed_one = pending_activities.test_any()
+
+  this_actor.info("Last activity is complete")
+
+def alice():
+  this_actor.info("Send 'Message'")
+  Mailbox.by_name("mbox").put("Message", 600000000)
+
+if __name__ == '__main__':
+  e = Engine(sys.argv)
+  e.set_log_control("root.fmt:[%4.6r]%e[%5a]%e%m%n")
+
+  # Load the platform description
+  e.load_platform(sys.argv[1])
+
+  Actor.create("bob",   Host.by_name("bob"), bob)
+  Actor.create("alice", Host.by_name("alice"), alice)
+
+  e.run()
diff --git a/examples/python/activityset-waitallfor/activityset-waitallfor.tesh b/examples/python/activityset-waitallfor/activityset-waitallfor.tesh
new file mode 100644 (file)
index 0000000..cf08947
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env tesh
+
+$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${srcdir:=.}/activityset-waitallfor.py ${platfdir}/hosts_with_disks.xml
+> [0.000000] [alice] Send 'Message'
+> [0.000000] [  bob] Create my asynchronous activities
+> [0.000000] [  bob] Wait for asynchronous activities to complete
+> [1.000000] [  bob] Not all activities are terminated yet.
+> [2.000000] [  bob] Not all activities are terminated yet.
+> [3.000000] [  bob] Not all activities are terminated yet.
+> [3.000000] [  bob] Completed an I/O
+> [4.000000] [  bob] Not all activities are terminated yet.
+> [5.000000] [  bob] Not all activities are terminated yet.
+> [5.000000] [  bob] Completed an Exec
+> [5.197828] [  bob] Completed a Comm
+> [5.197828] [  bob] Last activity is complete
diff --git a/examples/python/activityset-waitany/activityset-waitany.py b/examples/python/activityset-waitany/activityset-waitany.py
new file mode 100644 (file)
index 0000000..c2139a8
--- /dev/null
@@ -0,0 +1,120 @@
+# Copyright (c) 2017-2023. 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.
+
+"""
+Usage: activityset-waitany.py platform_file [other parameters]
+"""
+
+import sys
+from simgrid import Actor, ActivitySet, Engine, Comm, Exec, Io, Host, Mailbox, this_actor
+
+def bob():
+  mbox = Mailbox.by_name("mbox")
+  disk = Host.current().get_disks()[0]
+
+  this_actor.info("Create my asynchronous activities")
+  exec = this_actor.exec_async(5e9)
+  comm, payload = mbox.get_async()
+  io   = disk.read_async(300000000)
+
+  pending_activities = ActivitySet([exec, comm])
+  pending_activities.push(io) # Activities can be pushed after creation, too
+  this_actor.info("Wait for asynchronous activities to complete")
+  while not pending_activities.empty():
+    completed_one = pending_activities.wait_any()
+
+    if isinstance(completed_one, Comm):
+      this_actor.info("Completed a Comm")
+    elif isinstance(completed_one, Exec):
+      this_actor.info("Completed an Exec")
+    elif isinstance(completed_one, Io):
+      this_actor.info("Completed an I/O")
+
+  this_actor.info("Last activity is complete")
+
+def alice():
+  this_actor.info("Send 'Message'")
+  Mailbox.by_name("mbox").put("Message", 600000000)
+
+if __name__ == '__main__':
+  e = Engine(sys.argv)
+  e.set_log_control("root.fmt:[%4.6r]%e[%5a]%e%m%n")
+
+  # Load the platform description
+  e.load_platform(sys.argv[1])
+
+  Actor.create("bob",   Host.by_name("bob"), bob)
+  Actor.create("alice", Host.by_name("alice"), alice)
+
+  e.run()
+
+"""
+
+/* Copyright (c) 2010-2023. 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 "simgrid/s4u.hpp"
+#include <cstdlib>
+#include <iostream>
+#include <string>
+namespace sg4 = simgrid::s4u;
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_activity_waittany, "Messages specific for this s4u example");
+
+static void bob()
+{
+  sg4::Mailbox* mbox    = sg4::Mailbox::by_name("mbox");
+  const sg4::Disk* disk = sg4::Host::current()->get_disks().front();
+  std::string* payload;
+
+  XBT_INFO("Create my asynchronous activities");
+  auto exec = sg4::this_actor::exec_async(5e9);
+  auto comm = mbox->get_async(&payload);
+  auto io   = disk->read_async(3e8);
+
+  sg4::ActivitySet pending_activities({boost::dynamic_pointer_cast<sg4::Activity>(exec),
+                                       boost::dynamic_pointer_cast<sg4::Activity>(comm),
+                                       boost::dynamic_pointer_cast<sg4::Activity>(io)});
+
+  XBT_INFO("Wait for asynchronous activities to complete");
+  while (not pending_activities.empty()) {
+    auto completed_one = pending_activities.wait_any();
+    if (completed_one != nullptr) {
+      if (boost::dynamic_pointer_cast<sg4::Comm>(completed_one))
+        XBT_INFO("Completed a Comm");
+      if (boost::dynamic_pointer_cast<sg4::Exec>(completed_one))
+        XBT_INFO("Completed an Exec");
+      if (boost::dynamic_pointer_cast<sg4::Io>(completed_one))
+        XBT_INFO("Completed an I/O");
+    }
+  }
+  XBT_INFO("Last activity is complete");
+  delete payload;
+}
+
+static void alice()
+{
+  auto* payload = new std::string("Message");
+  XBT_INFO("Send '%s'", payload->c_str());
+  sg4::Mailbox::by_name("mbox")->put(payload, 6e8);
+}
+
+int main(int argc, char* argv[])
+{
+  sg4::Engine e(&argc, argv);
+
+  e.load_platform(argv[1]);
+
+  sg4::Actor::create("bob", e.host_by_name("bob"), bob);
+  sg4::Actor::create("alice", e.host_by_name("alice"), alice);
+
+  e.run();
+
+  return 0;
+}
+"""
\ No newline at end of file
diff --git a/examples/python/activityset-waitany/activityset-waitany.tesh b/examples/python/activityset-waitany/activityset-waitany.tesh
new file mode 100644 (file)
index 0000000..70b707b
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env tesh
+
+$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${srcdir:=.}/activityset-waitany.py ${platfdir}/hosts_with_disks.xml
+> [0.000000] [alice] Send 'Message'
+> [0.000000] [  bob] Create my asynchronous activities
+> [0.000000] [  bob] Wait for asynchronous activities to complete
+> [3.000000] [  bob] Completed an I/O
+> [5.000000] [  bob] Completed an Exec
+> [5.197828] [  bob] Completed a Comm
+> [5.197828] [  bob] Last activity is complete