Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Missing files
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 8 Jan 2019 22:25:58 +0000 (23:25 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 8 Jan 2019 22:26:56 +0000 (23:26 +0100)
examples/python/CMakeLists.txt
examples/python/actor-lifetime/actor-lifetime.py [new file with mode: 0644]
examples/python/actor-lifetime/actor-lifetime.tesh [new file with mode: 0644]
examples/python/actor-lifetime/actor-lifetime_d.xml [new file with mode: 0644]

index a997211..d9dbfc9 100644 (file)
@@ -15,5 +15,7 @@ endforeach()
 
 set(tesh_files    examples/python/actor-create/actor-create_d.xml
                   examples/python/actor-lifetime/actor-lifetime_d.xml
 
 set(tesh_files    examples/python/actor-create/actor-create_d.xml
                   examples/python/actor-lifetime/actor-lifetime_d.xml
+                 examples/python/actor-lifetime/actor-lifetime.py     # example broken so far
+                 examples/python/actor-lifetime/actor-lifetime.tesh
                   ${tesh_files}    PARENT_SCOPE)
 set(examples_src  ${examples_src}  PARENT_SCOPE)
                   ${tesh_files}    PARENT_SCOPE)
 set(examples_src  ${examples_src}  PARENT_SCOPE)
diff --git a/examples/python/actor-lifetime/actor-lifetime.py b/examples/python/actor-lifetime/actor-lifetime.py
new file mode 100644 (file)
index 0000000..f408dc1
--- /dev/null
@@ -0,0 +1,36 @@
+# Copyright (c) 2007-2019. 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 Python file acts as the foil to the corresponding XML file, where the
+# action takes place: Actors are started and stopped at predefined time
+
+from simgrid import *
+import sys
+
+
+class Sleeper:
+    """This actor just sleeps until termination"""
+
+    def __init__(self, *args):
+        this_actor.on_exit(lambda: print("BAAA")) # sys.exit(1); simgrid.info("Exiting now (done sleeping or got killed)."))
+
+    def __call__(self):
+        this_actor.info("Hello! I go to sleep.")
+        this_actor.sleep_for(10)
+        this_actor.info("Done sleeping.")
+
+
+if __name__ == '__main__':
+    e = Engine(sys.argv)
+    if len(sys.argv) < 2:
+        raise AssertionError(
+            "Usage: actor-lifetime.py platform_file actor-lifetime_d.xml [other parameters]")
+
+    e.load_platform(sys.argv[1])     # Load the platform description
+    e.register_actor("sleeper", Sleeper)
+    # Deploy the sleeper processes with explicit start/kill times
+    e.load_deployment(sys.argv[2])
+
+    e.run()
diff --git a/examples/python/actor-lifetime/actor-lifetime.tesh b/examples/python/actor-lifetime/actor-lifetime.tesh
new file mode 100644 (file)
index 0000000..4e52a38
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/env tesh
+
+$ python3 ${bindir:=.}/actor-lifetime.py ${platfdir}/cluster_backbone.xml actor-lifetime_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:sleeper@node-0.simgrid.org) Hello! I go to sleep.
+> [  0.000000] (2:sleeper@node-1.simgrid.org) Hello! I go to sleep.
+> [  2.000000] (3:sleeper@node-0.simgrid.org) Hello! I go to sleep.
+> [  3.000000] (2:sleeper@node-1.simgrid.org) Exiting now (done sleeping or got killed).
+> [  4.000000] (4:sleeper@node-2.simgrid.org) Hello! I go to sleep.
+> [  7.000000] (4:sleeper@node-2.simgrid.org) Exiting now (done sleeping or got killed).
+> [ 10.000000] (1:sleeper@node-0.simgrid.org) Done sleeping.
+> [ 10.000000] (1:sleeper@node-0.simgrid.org) Exiting now (done sleeping or got killed).
+> [ 12.000000] (3:sleeper@node-0.simgrid.org) Done sleeping.
+> [ 12.000000] (3:sleeper@node-0.simgrid.org) Exiting now (done sleeping or got killed).
+
diff --git a/examples/python/actor-lifetime/actor-lifetime_d.xml b/examples/python/actor-lifetime/actor-lifetime_d.xml
new file mode 100644 (file)
index 0000000..e877e7e
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
+
+<!-- This shows how to use the start_time and kill_time attributes of <actors> -->
+
+<platform version="4.1">
+  <actor host="node-0.simgrid.org" function="sleeper"                              />
+  <actor host="node-0.simgrid.org" function="sleeper" start_time="2"               />
+  <actor host="node-1.simgrid.org" function="sleeper"                kill_time="3" />
+  <actor host="node-2.simgrid.org" function="sleeper" start_time="4" kill_time="7" />
+</platform>