1 from argparse import ArgumentParser
4 from simgrid import Actor, Barrier, Engine, Host, this_actor
7 def create_parser() -> ArgumentParser:
8 parser = ArgumentParser()
13 help='path to the platform description'
19 help="Number of actors to start"
24 def worker(barrier: Barrier):
25 """ Wait on the barrier and exits.
26 :param barrier: Barrier to be awaited
28 this_actor.info(f"Waiting on the barrier")
30 this_actor.info("Bye")
33 def master(actor_count: int):
34 """ Create barrier with `actor_count` expected actors, spawns `actor_count - 1` workers, then wait on the barrier
36 :param actor_count: Spawn actor_count-1 workers and do a barrier with them
38 barrier = Barrier(actor_count)
39 workers_count = actor_count - 1
40 this_actor.info(f"Spawning {workers_count} workers")
41 for i in range(workers_count):
42 Actor.create(f"worker-{i}", Host.by_name("Jupiter"), worker, barrier)
43 this_actor.info(f"Waiting on the barrier")
45 this_actor.info("Bye")
49 settings = create_parser().parse_known_args()[0]
50 if settings.actors < 1:
51 raise ValueError("--actors must be greater than 0")
53 e.load_platform(settings.platform)
54 Actor.create("master", Host.by_name("Tremblay"), master, settings.actors)
58 if __name__ == "__main__":