1 # Copyright (c) 2018-2023. 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.
7 Usage: exec-async.py platform_file [other parameters]
11 from simgrid import Actor, Engine, Host, this_actor
16 This actor simply waits for its task completion after starting it.
17 That's exactly equivalent to synchronous execution.
21 computation_amount = this_actor.get_host().speed
22 this_actor.info("Waiter executes {:.0f} flops, should take 1 second.".format(computation_amount))
23 activity = this_actor.exec_init(computation_amount)
27 this_actor.info("Goodbye from waiter!")
31 """This actor tests the ongoing execution until its completion, and don't wait before it's terminated."""
34 computation_amount = this_actor.get_host().speed
35 this_actor.info("Monitor executes {:.0f} flops, should take 1 second.".format(computation_amount))
36 activity = this_actor.exec_init(computation_amount).start()
38 while not activity.test():
39 this_actor.info("Remaining amount of flops: {:.0f} ({:.0f}%)".format(
40 activity.remaining, 100 * activity.remaining_ratio))
41 this_actor.sleep_for(0.3)
44 this_actor.info("Goodbye from monitor!")
48 """This actor cancels the ongoing execution after a while."""
51 computation_amount = this_actor.get_host().speed
52 this_actor.info("Canceller executes {:.0f} flops, should take 1 second.".format(computation_amount))
53 activity = this_actor.exec_async(computation_amount)
55 this_actor.sleep_for(0.5)
56 this_actor.info("I changed my mind, cancel!")
59 this_actor.info("Goodbye from canceller!")
62 if __name__ == '__main__':
65 raise AssertionError("Usage: exec-async.py platform_file [other parameters]")
67 e.load_platform(sys.argv[1])
69 Actor.create("wait", Host.by_name("Fafard"), Waiter())
70 Actor.create("monitor", Host.by_name("Ginette"), Monitor())
71 Actor.create("cancel", Host.by_name("Boivin"), Canceller())