Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cut the backtrace displayed from sthread to the sthread_create to hide useless cruft
[simgrid.git] / examples / python / platform-comm-serialize / platform-comm-serialize.py
index bbd871d86997f17e054c42000c6cf417afa490df..f221f492cede152bbb6c9c8521814b76459817f1 100644 (file)
@@ -6,7 +6,7 @@
 from typing import List, Tuple
 import sys
 
-from simgrid import Engine, Actor, Comm, Host, LinkInRoute, Mailbox, NetZone, this_actor, PyGetAsync
+from simgrid import Engine, Actor, ActivitySet, Comm, Host, LinkInRoute, Mailbox, NetZone, this_actor
 
 
 RECEIVER_MAILBOX_NAME = "receiver"
@@ -19,7 +19,7 @@ class Sender(object):
 
     def __call__(self) -> None:
         # List in which we store all ongoing communications
-        pending_comms: List[Comm] = []
+        pending_comms = ActivitySet()
 
         # Make a vector of the mailboxes to use
         receiver_mailbox: Mailbox = Mailbox.by_name(RECEIVER_MAILBOX_NAME)
@@ -27,12 +27,12 @@ class Sender(object):
             message_content = f"Message {i}"
             this_actor.info(f"Send '{message_content}' to '{receiver_mailbox.name}'")
             # Create a communication representing the ongoing communication, and store it in pending_comms
-            pending_comms.append(receiver_mailbox.put_async(message_content, self.message_size))
+            pending_comms.push(receiver_mailbox.put_async(message_content, self.message_size))
 
         this_actor.info("Done dispatching all messages")
 
         # Now that all message exchanges were initiated, wait for their completion in one single call
-        Comm.wait_all(pending_comms)
+        pending_comms.wait_all()
 
         this_actor.info("Goodbye now!")
 
@@ -44,15 +44,13 @@ class Receiver(object):
 
     def __call__(self):
         # List in which we store all incoming msgs
-        pending_comms: List[Tuple[Comm, PyGetAsync]] = []
+        pending_comms = ActivitySet()
         this_actor.info(f"Wait for {self.messages_count} messages asynchronously")
         for _ in range(self.messages_count):
-            pending_comms.append(self.mailbox.get_async())
-        while pending_comms:
-            index = Comm.wait_any([comm for (comm, _) in pending_comms])
-            _, async_data = pending_comms[index]
-            this_actor.info(f"I got '{async_data.get()}'.")
-            pending_comms.pop(index)
+            pending_comms.push(self.mailbox.get_async())
+        while not pending_comms.empty():
+            comm = pending_comms.wait_any()
+            this_actor.info(f"I got '{comm.get_payload()}'.")
 
 
 def main():