1 # Copyright (c) 2010-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.
6 from argparse import ArgumentParser
9 from simgrid import Actor, Barrier, Engine, Host, this_actor
12 def create_parser() -> ArgumentParser:
13 parser = ArgumentParser()
18 help='path to the platform description'
24 help="Number of actors to start"
29 def worker(barrier: Barrier):
30 """ Wait on the barrier and exits.
31 :param barrier: Barrier to be awaited
33 this_actor.info("Waiting on the barrier")
35 this_actor.info("Bye")
38 def master(actor_count: int):
39 """ Create barrier with `actor_count` expected actors, spawns `actor_count - 1` workers, then wait on the barrier
41 :param actor_count: Spawn actor_count-1 workers and do a barrier with them
43 barrier = Barrier(actor_count)
44 workers_count = actor_count - 1
45 this_actor.info(f"Spawning {workers_count} workers")
46 for i in range(workers_count):
47 Actor.create(f"worker-{i}", Host.by_name("Jupiter"), worker, barrier)
48 this_actor.info("Waiting on the barrier")
50 this_actor.info("Bye")
54 settings = create_parser().parse_known_args()[0]
55 if settings.actors < 1:
56 raise ValueError("--actors must be greater than 0")
58 e.load_platform(settings.platform)
59 Actor.create("master", Host.by_name("Tremblay"), master, settings.actors)
63 if __name__ == "__main__":