1 # Copyright (c) 2010-2022. 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 Engine, Actor, Mailbox, this_actor
12 def create_parser() -> ArgumentParser:
13 parser = ArgumentParser()
18 help='path to the platform description'
23 def pinger(mailbox_in: Mailbox, mailbox_out: Mailbox):
24 this_actor.info(f"Ping from mailbox {mailbox_in.name} to mailbox {mailbox_out.name}")
26 # Do the ping with a 1-Byte payload (latency bound) ...
27 payload = Engine.clock
28 mailbox_out.put(payload, 1)
30 # ... then wait for the (large) pong
31 sender_time: float = mailbox_in.get()
32 communication_time = Engine.clock - sender_time
33 this_actor.info("Payload received : large communication (bandwidth bound)")
34 this_actor.info(f"Pong time (bandwidth bound): {communication_time:.3f}")
37 def ponger(mailbox_in: Mailbox, mailbox_out: Mailbox):
38 this_actor.info(f"Pong from mailbox {mailbox_in.name} to mailbox {mailbox_out.name}")
40 # Receive the (small) ping first ...
41 sender_time: float = mailbox_in.get()
42 communication_time = Engine.clock - sender_time
43 this_actor.info("Payload received : small communication (latency bound)")
44 this_actor.info(f"Ping time (latency bound) {communication_time:.3f}")
46 # ... Then send a 1GB pong back (bandwidth bound)
47 payload = Engine.clock
48 this_actor.info(f"payload = {payload:.3f}")
49 mailbox_out.put(payload, int(1e9))
53 settings = create_parser().parse_known_args()[0]
55 e.load_platform(settings.platform)
57 mb1: Mailbox = e.mailbox_by_name_or_create("Mailbox 1")
58 mb2: Mailbox = e.mailbox_by_name_or_create("Mailbox 2")
60 Actor.create("pinger", e.host_by_name("Tremblay"), pinger, mb1, mb2)
61 Actor.create("ponger", e.host_by_name("Jupiter"), ponger, mb2, mb1)
65 this_actor.info(f"Total simulation time: {e.clock:.3f}")
68 if __name__ == "__main__":