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 Engine, Actor, Comm, Mailbox, this_actor
12 def create_parser() -> ArgumentParser:
13 parser = ArgumentParser()
18 help='path to the platform description'
23 def sender(mailbox: Mailbox):
24 this_actor.info("Send at full bandwidth")
26 # First send a 2.5e8 Bytes payload at full bandwidth (1.25e8 Bps)
27 payload = Engine.clock
28 mailbox.put(payload, int(2.5e8))
30 this_actor.info("Throttle the bandwidth at the Comm level")
31 # ... then send it again but throttle the Comm
32 payload = Engine.clock
33 # get a handler on the comm first
34 comm: Comm = mailbox.put_init(payload, int(2.5e8))
36 # let throttle the communication. It amounts to set the rate of the comm to half the nominal bandwidth of the link,
37 # i.e., 1.25e8 / 2. This second communication will thus take approximately twice as long as the first one
38 comm.set_rate(int(1.25e8 / 2)).wait()
41 def receiver(mailbox: Mailbox):
42 # Receive the first payload sent at full bandwidth
43 sender_time = mailbox.get()
44 communication_time = Engine.clock - sender_time
45 this_actor.info(f"Payload received (full bandwidth) in {communication_time} seconds")
47 # ... Then receive the second payload sent with a throttled Comm
48 sender_time = mailbox.get()
49 communication_time = Engine.clock - sender_time
50 this_actor.info(f"Payload received (throttled) in {communication_time} seconds")
54 settings = create_parser().parse_known_args()[0]
56 e.load_platform(settings.platform)
58 mailbox = e.mailbox_by_name_or_create("Mailbox")
60 Actor.create("sender", e.host_by_name("node-0.simgrid.org"), sender, mailbox)
61 Actor.create("receiver", e.host_by_name("node-1.simgrid.org"), receiver, mailbox)
66 if __name__ == "__main__":