Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
yet another example: actor-suspend.py
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 3 Jan 2019 22:07:16 +0000 (23:07 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 3 Jan 2019 22:07:16 +0000 (23:07 +0100)
examples/python/CMakeLists.txt
examples/python/actor-suspend/actor-suspend.py [new file with mode: 0644]
examples/python/actor-suspend/actor-suspend.tesh [new file with mode: 0644]
src/bindings/python/simgrid_python.cpp

index 7ba5189..367f795 100644 (file)
@@ -1,4 +1,4 @@
-foreach(example actor-create actor-join actor-migrate actor-yield 
+foreach(example actor-create actor-join actor-migrate actor-suspend actor-yield 
                 exec-basic)
   set(tesh_files    ${tesh_files}   ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.tesh)
   set(examples_src  ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.py)
diff --git a/examples/python/actor-suspend/actor-suspend.py b/examples/python/actor-suspend/actor-suspend.py
new file mode 100644 (file)
index 0000000..e3036ed
--- /dev/null
@@ -0,0 +1,70 @@
+# Copyright (c) 2017-2018. 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. 
+
+from simgrid import *
+import sys
+
+# The Lazy guy only wants to sleep, but can be awaken by the dream_master process. 
+def lazy_guy():
+    this_actor.info("Nobody's watching me ? Let's go to sleep.")
+    this_actor.suspend() # - Start by suspending itself 
+    this_actor.info("Uuuh ? Did somebody call me ?")
+
+    this_actor.info("Going to sleep...") # - Then repetitively go to sleep, but get awaken 
+    this_actor.sleep_for(10)
+    this_actor.info("Mmm... waking up.")
+
+    this_actor.info("Going to sleep one more time (for 10 sec)...")
+    this_actor.sleep_for(10)
+    this_actor.info("Waking up once for all!")
+
+    this_actor.info("Ok, let's do some work, then (for 10 sec on Boivin).")
+    this_actor.execute(980.95e6)
+
+    this_actor.info("Mmmh, I'm done now. Goodbye.")
+
+# The Dream master
+def dream_master():
+    this_actor.info("Let's create a lazy guy.")  # Create a lazy_guy process 
+    lazy = Actor.create("Lazy", this_actor.get_host(), lazy_guy)
+    this_actor.info("Let's wait a little bit...")
+    this_actor.sleep_for(10) # Wait for 10 seconds
+    this_actor.info("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!")
+    lazy.resume() # Then wake up the lazy_guy 
+
+    this_actor.sleep_for(5) # Repeat two times:
+    this_actor.info("Suspend the lazy guy while he's sleeping...")
+    lazy.suspend() # Suspend the lazy_guy while he's asleep 
+    this_actor.info("Let him finish his siesta.")
+    this_actor.sleep_for(10) # Wait for 10 seconds 
+    this_actor.info("Wake up, lazy guy!")
+    lazy.resume() # Then wake up the lazy_guy again 
+
+    this_actor.sleep_for(5)
+    this_actor.info("Suspend again the lazy guy while he's sleeping...")
+    lazy.suspend()
+    this_actor.info("This time, don't let him finish his siesta.")
+    this_actor.sleep_for(2)
+    this_actor.info("Wake up, lazy guy!")
+    lazy.resume()
+
+    this_actor.sleep_for(5)
+    this_actor.info("Give a 2 seconds break to the lazy guy while he's working...")
+    lazy.suspend()
+    this_actor.sleep_for(2)
+    this_actor.info("Back to work, lazy guy!")
+    lazy.resume()
+
+    this_actor.info("OK, I'm done here.")
+
+if __name__ == '__main__':
+    e = Engine(sys.argv)
+    if len(sys.argv) < 2: raise AssertionError("Usage: actor-suspend.py platform_file [other parameters]")
+
+    e.load_platform(sys.argv[1]) # Load the platform description 
+    list = e.get_all_hosts()
+    Actor.create("dream_master", list[0], dream_master)
+
+    e.run() # Run the simulation 
diff --git a/examples/python/actor-suspend/actor-suspend.tesh b/examples/python/actor-suspend/actor-suspend.tesh
new file mode 100644 (file)
index 0000000..e648398
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env tesh
+
+p Testing the suspend/resume feature of SimGrid
+
+! output sort 19
+$ python3 ${bindir:=.}/actor-suspend.py ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [  0.000000] (dream_master@Boivin) Let's create a lazy guy.
+> [  0.000000] (Lazy@Boivin) Nobody's watching me ? Let's go to sleep.
+> [  0.000000] (dream_master@Boivin) Let's wait a little bit...
+> [ 10.000000] (dream_master@Boivin) Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!
+> [ 10.000000] (Lazy@Boivin) Uuuh ? Did somebody call me ?
+> [ 10.000000] (Lazy@Boivin) Going to sleep...
+> [ 15.000000] (dream_master@Boivin) Suspend the lazy guy while he's sleeping...
+> [ 15.000000] (dream_master@Boivin) Let him finish his siesta.
+> [ 25.000000] (dream_master@Boivin) Wake up, lazy guy!
+> [ 25.000000] (Lazy@Boivin) Mmm... waking up.
+> [ 25.000000] (Lazy@Boivin) Going to sleep one more time (for 10 sec)...
+> [ 30.000000] (dream_master@Boivin) Suspend again the lazy guy while he's sleeping...
+> [ 30.000000] (dream_master@Boivin) This time, don't let him finish his siesta.
+> [ 32.000000] (dream_master@Boivin) Wake up, lazy guy!
+> [ 35.000000] (Lazy@Boivin) Waking up once for all!
+> [ 35.000000] (Lazy@Boivin) Ok, let's do some work, then (for 10 sec on Boivin).
+> [ 37.000000] (dream_master@Boivin) Give a 2 seconds break to the lazy guy while he's working...
+> [ 39.000000] (dream_master@Boivin) Back to work, lazy guy!
+> [ 39.000000] (dream_master@Boivin) OK, I'm done here.
+> [ 47.000000] (Lazy@Boivin) Mmmh, I'm done now. Goodbye.
index d42f180..ca377e6 100644 (file)
@@ -79,6 +79,7 @@ PYBIND11_MODULE(simgrid, m)
         // Currently this can be dangling, we should wrap this somehow.
         return new simgrid::s4u::Engine(&argc, argv.get());
       }))
+      .def("get_all_hosts", &Engine::get_all_hosts, "Returns the list of all hosts found in the platform")
       .def("get_clock", &Engine::get_clock, "Retrieve the simulation time")
       .def("load_platform", &Engine::load_platform,
           "Load a platform file describing the environment, see :cpp:func:`simgrid::s4u::Engine::load_platform()`")