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
7 from typing import List
10 from simgrid import Engine, Actor, Comm, Mailbox, this_actor
13 def create_parser() -> ArgumentParser:
14 parser = ArgumentParser()
19 help='path to the platform description'
25 rank0_mailbox: Mailbox = Mailbox.by_name("rank0")
26 this_actor.info("Post my asynchronous receives")
27 comm1 = rank0_mailbox.get_async()
28 comm2 = rank0_mailbox.get_async()
29 comm3 = rank0_mailbox.get_async()
30 pending_comms: List[Comm] = [comm1, comm2, comm3]
32 this_actor.info("Send some data to rank-1")
33 rank1_mailbox: Mailbox = Mailbox.by_name("rank1")
35 rank1_mailbox.put(i, 1)
37 this_actor.info("Test for completed comms")
39 flag = Comm.test_any(pending_comms)
41 pending_comms.pop(flag)
42 this_actor.info("Remove a pending comm.")
44 # Nothing matches, wait for a little bit
45 this_actor.sleep_for(0.1)
46 this_actor.info("Last comm is complete")
50 rank0_mailbox: Mailbox = Mailbox.by_name("rank0")
51 rank1_mailbox: Mailbox = Mailbox.by_name("rank1")
53 data: int = rank1_mailbox.get()
54 this_actor.info(f"Received {data}")
55 msg_content = f"Message {i}"
56 this_actor.info(f"Send '{msg_content}'")
57 rank0_mailbox.put(msg_content, int(1e6))
61 settings = create_parser().parse_known_args()[0]
63 e.load_platform(settings.platform)
65 Actor.create("rank0", e.host_by_name("Tremblay"), rank0)
66 Actor.create("rank1", e.host_by_name("Fafard"), rank1)
71 if __name__ == "__main__":