X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ce07073eff21e1ee0470d9bdad1ae4a38fe4b502..3f9b311ec56db95ec539001a860ae3c838c48312:/examples/python/comm-ready/comm-ready.py diff --git a/examples/python/comm-ready/comm-ready.py b/examples/python/comm-ready/comm-ready.py index 646d4d1af1..20065327c5 100644 --- a/examples/python/comm-ready/comm-ready.py +++ b/examples/python/comm-ready/comm-ready.py @@ -1,4 +1,4 @@ -# Copyright (c) 2010-2022. The SimGrid Team. All rights reserved. +# Copyright (c) 2010-2023. The SimGrid Team. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the license (GNU LGPL) which comes with this package. @@ -7,7 +7,7 @@ from argparse import ArgumentParser from typing import List import sys -from simgrid import Actor, Comm, Engine, Mailbox, this_actor +from simgrid import Actor, ActivitySet, Comm, Engine, Mailbox, this_actor FINALIZE_MESSAGE = "finalize" @@ -31,7 +31,7 @@ def get_peer_mailbox(peer_id: int) -> Mailbox: def peer(my_id: int, message_count: int, payload_size: int, peers_count: int): my_mailbox: Mailbox = get_peer_mailbox(my_id) my_mailbox.set_receiver(Actor.self()) - pending_comms: List[Comm] = [] + pending_comms = ActivitySet() # Start dispatching all messages to peers others that myself for i in range(message_count): for peer_id in range(peers_count): @@ -39,14 +39,14 @@ def peer(my_id: int, message_count: int, payload_size: int, peers_count: int): peer_mailbox = get_peer_mailbox(peer_id) message = f"Message {i} from peer {my_id}" this_actor.info(f"Send '{message}' to '{peer_mailbox.name}'") - pending_comms.append(peer_mailbox.put_async(message, payload_size)) + pending_comms.push(peer_mailbox.put_async(message, payload_size)) # Start sending messages to let peers know that they should stop for peer_id in range(peers_count): if peer_id != my_id: peer_mailbox = get_peer_mailbox(peer_id) payload = str(FINALIZE_MESSAGE) - pending_comms.append(peer_mailbox.put_async(payload, payload_size)) + pending_comms.push(peer_mailbox.put_async(payload, payload_size)) this_actor.info(f"Send '{payload}' to '{peer_mailbox.name}'") this_actor.info("Done dispatching all messages") @@ -58,7 +58,7 @@ def peer(my_id: int, message_count: int, payload_size: int, peers_count: int): start = Engine.clock received: str = my_mailbox.get() waiting_time = Engine.clock - start - if waiting_time != 0.0: + if waiting_time > 0.0: raise AssertionError(f"Expecting the waiting time to be 0.0 because the communication was supposedly " f"ready, but got {waiting_time} instead") this_actor.info(f"I got a '{received}'.") @@ -69,7 +69,7 @@ def peer(my_id: int, message_count: int, payload_size: int, peers_count: int): this_actor.sleep_for(0.01) this_actor.info("I'm done, just waiting for my peers to receive the messages before exiting") - Comm.wait_all(pending_comms) + pending_comms.wait_all() this_actor.info("Goodbye now!")