Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add more Mc Mini tests
[simgrid.git] / examples / python / exec-async / exec-async.py
index 1f74851dd5ef490541c4a50c298684cc90f0cd99..5892dca6ea366f565780cd0679af5991b4d327b7 100644 (file)
@@ -1,23 +1,30 @@
-# Copyright (c) 2018-2019. The SimGrid Team. All rights reserved.
+# Copyright (c) 2018-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: exec-async.py platform_file [other parameters]
+"""
+
 import sys
-from simgrid import *
+from simgrid import Actor, Engine, Host, this_actor
 
 
 class Waiter:
-    """ This actor simply waits for its task completion after starting it. That's exactly equivalent to synchronous execution. """
+    """
+    This actor simply waits for its task completion after starting it.
+    That's exactly equivalent to synchronous execution.
+    """
 
     def __call__(self):
         computation_amount = this_actor.get_host().speed
-        this_actor.info("Execute {:.0f} flops, should take 1 second.".format(computation_amount))
+        this_actor.info("Waiter executes {:.0f} flops, should take 1 second.".format(computation_amount))
         activity = this_actor.exec_init(computation_amount)
         activity.start()
         activity.wait()
 
-        this_actor.info("Goodbye now!")
+        this_actor.info("Goodbye from waiter!")
 
 
 class Monitor:
@@ -25,7 +32,7 @@ class Monitor:
 
     def __call__(self):
         computation_amount = this_actor.get_host().speed
-        this_actor.info("Execute {:.0f} flops, should take 1 second.".format(computation_amount))
+        this_actor.info("Monitor executes {:.0f} flops, should take 1 second.".format(computation_amount))
         activity = this_actor.exec_init(computation_amount).start()
 
         while not activity.test():
@@ -34,7 +41,7 @@ class Monitor:
             this_actor.sleep_for(0.3)
         activity.wait()
 
-        this_actor.info("Goodbye now!")
+        this_actor.info("Goodbye from monitor!")
 
 
 class Canceller:
@@ -42,18 +49,20 @@ class Canceller:
 
     def __call__(self):
         computation_amount = this_actor.get_host().speed
-        this_actor.info("Execute {:.0f} flops, should take 1 second.".format(computation_amount))
-        activity = this_actor.exec_init(computation_amount).start()
+        this_actor.info("Canceller executes {:.0f} flops, should take 1 second.".format(computation_amount))
+        activity = this_actor.exec_async(computation_amount)
 
         this_actor.sleep_for(0.5)
         this_actor.info("I changed my mind, cancel!")
         activity.cancel()
 
-        this_actor.info("Goodbye now!")
+        this_actor.info("Goodbye from canceller!")
 
 
 if __name__ == '__main__':
     e = Engine(sys.argv)
+    if len(sys.argv) < 2:
+        raise AssertionError("Usage: exec-async.py platform_file [other parameters]")
 
     e.load_platform(sys.argv[1])