Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into 'master'
[simgrid.git] / examples / python / comm-waitall / comm-waitall.py
index 38a34f148d030c25a5f2dbfcf9fda4bc26c0eb95..68dacca86a83dc21832b2ca349dd63680cf22b08 100644 (file)
@@ -1,55 +1,57 @@
-# 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.
 
-from simgrid import Actor,Comm, Engine, Host, Mailbox, this_actor
-import sys
+"""
+This example shows how to block on the completion of a set of communications.
 
-# This example shows how to block on the completion of a set of communications.
-#
-# As for the other asynchronous examples, the sender initiate all the messages it wants to send and
-# pack the resulting simgrid.Comm objects in a list. All messages thus occur concurrently.
-#
-# The sender then blocks until all ongoing communication terminate, using simgrid.Comm.wait_all()
+As for the other asynchronous examples, the sender initiate all the messages it wants to send and
+pack the resulting simgrid.Comm objects in a list. All messages thus occur concurrently.
+
+The sender then blocks until all ongoing communication terminate, using simgrid.Comm.wait_all()
+"""
+
+import sys
+from simgrid import Actor, Comm, Engine, Host, Mailbox, this_actor
 
 
 def sender(messages_count, msg_size, receivers_count):
-     # List in which we store all ongoing communications
-     pending_comms = []
+    # List in which we store all ongoing communications
+    pending_comms = []
 
-     # Vector of the used mailboxes
-     mboxes = [Mailbox.by_name("receiver-{:d}".format(i))
-               for i in range(0, receivers_count)]
+    # Vector of the used mailboxes
+    mboxes = [Mailbox.by_name("receiver-{:d}".format(i))
+              for i in range(0, receivers_count)]
 
-     # Start dispatching all messages to receivers, in a round robin fashion
-     for i in range(0, messages_count):
-         content = "Message {:d}".format(i)
-         mbox = mboxes[i % receivers_count]
+    # Start dispatching all messages to receivers, in a round robin fashion
+    for i in range(0, messages_count):
+        content = "Message {:d}".format(i)
+        mbox = mboxes[i % receivers_count]
 
-         this_actor.info("Send '{:s}' to '{:s}'".format(content, str(mbox)))
+        this_actor.info("Send '{:s}' to '{:s}'".format(content, str(mbox)))
 
-         # Create a communication representing the ongoing communication, and store it in pending_comms
-         comm = mbox.put_async(content, msg_size)
-         pending_comms.append(comm)
+        # Create a communication representing the ongoing communication, and store it in pending_comms
+        comm = mbox.put_async(content, msg_size)
+        pending_comms.append(comm)
 
-     # Start sending messages to let the workers know that they should stop
-     for i in range(0, receivers_count):
-         mbox = mboxes[i]
-         this_actor.info("Send 'finalize' to '{:s}'".format(str(mbox)))
-         comm = mbox.put_async("finalize", 0)
-         pending_comms.append(comm)
+    # Start sending messages to let the workers know that they should stop
+    for i in range(0, receivers_count):
+        mbox = mboxes[i]
+        this_actor.info("Send 'finalize' to '{:s}'".format(str(mbox)))
+        comm = mbox.put_async("finalize", 0)
+        pending_comms.append(comm)
 
-     this_actor.info("Done dispatching all messages")
+    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)
+    # Now that all message exchanges were initiated, wait for their completion in one single call
+    Comm.wait_all(pending_comms)
 
-     this_actor.info("Goodbye now!")
+    this_actor.info("Goodbye now!")
 
 
-def receiver(id):
-    mbox = Mailbox.by_name("receiver-{:d}".format(id))
+def receiver(my_id):
+    mbox = Mailbox.by_name("receiver-{:d}".format(my_id))
 
     this_actor.info("Wait for my first message")
     while True: