1 # Copyright (c) 2018-2020. The SimGrid Team. All rights reserved.
3 # This program is free software you can redistribute it and/or modify it
4 # under the terms of the license (GNU LGPL) which comes with this package.
6 from simgrid import Actor, Engine, Host, this_actor
11 """ This actor simply waits for its task completion after starting it. That's exactly equivalent to synchronous execution. """
14 computation_amount = this_actor.get_host().speed
15 this_actor.info("Waiter executes {:.0f} flops, should take 1 second.".format(computation_amount))
16 activity = this_actor.exec_init(computation_amount)
20 this_actor.info("Goodbye from waiter!")
24 """This actor tests the ongoing execution until its completion, and don't wait before it's terminated."""
27 computation_amount = this_actor.get_host().speed
28 this_actor.info("Monitor executes {:.0f} flops, should take 1 second.".format(computation_amount))
29 activity = this_actor.exec_init(computation_amount).start()
31 while not activity.test():
32 this_actor.info("Remaining amount of flops: {:.0f} ({:.0f}%)".format(
33 activity.remaining, 100 * activity.remaining_ratio))
34 this_actor.sleep_for(0.3)
37 this_actor.info("Goodbye from monitor!")
41 """This actor cancels the ongoing execution after a while."""
44 computation_amount = this_actor.get_host().speed
45 this_actor.info("Canceller executes {:.0f} flops, should take 1 second.".format(computation_amount))
46 activity = this_actor.exec_init(computation_amount).start()
48 this_actor.sleep_for(0.5)
49 this_actor.info("I changed my mind, cancel!")
52 this_actor.info("Goodbye from canceller!")
55 if __name__ == '__main__':
58 raise AssertionError("Usage: exec-async.py platform_file [other parameters]")
60 e.load_platform(sys.argv[1])
62 Actor.create("wait", Host.by_name("Fafard"), Waiter())
63 Actor.create("monitor", Host.by_name("Ginette"), Monitor())
64 Actor.create("cancel", Host.by_name("Boivin"), Canceller())