Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update python/clusters-multicpu to the new API.
[simgrid.git] / examples / python / clusters-multicpu / clusters-multicpu.py
index 637eab5..6a4d783 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2006-2022. The SimGrid Team. All rights reserved.
+# Copyright (c) 2006-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.
@@ -28,19 +28,19 @@ class Sender:
     # Actors that are created as object will execute their __call__ method.
     # So, the following constitutes the main function of the Sender actor.
     def __call__(self):
-        pending_comms = []
+        pending_comms = simgrid.ActivitySet()
         mboxes = []
 
         for host in self.hosts:
             msg = "Hello, I'm alive and running on " + simgrid.this_actor.get_host().name
             mbox = simgrid.Mailbox.by_name(host.name)
             mboxes.append(mbox)
-            pending_comms.append(mbox.put_async(msg, self.msg_size))
+            pending_comms.push(mbox.put_async(msg, self.msg_size))
 
         simgrid.this_actor.info("Done dispatching all messages")
 
         # Now that all message exchanges were initiated, wait for their completion in one single call
-        simgrid.Comm.wait_all(pending_comms)
+        pending_comms.wait_all()
 
         simgrid.this_actor.info("Goodbye now!")
 
@@ -58,8 +58,7 @@ class Receiver:
 #####################################################################################################
 
 
-def create_hostzone(zone: simgrid.NetZone, coord: typing.List[int], ident: int) -> typing.Tuple[simgrid.NetPoint,
-                                                                                                simgrid.NetPoint]:
+def create_hostzone(zone: simgrid.NetZone, coord: typing.List[int], ident: int) -> simgrid.NetZone:
     r"""
     Callback to set a cluster leaf/element
 
@@ -94,24 +93,22 @@ def create_hostzone(zone: simgrid.NetZone, coord: typing.List[int], ident: int)
     # setting my Torus parent zone
     host_zone.set_parent(zone)
 
-    gateway = None
     # create CPUs
     for i in range(num_cpus):
         cpu_name = hostname + "-cpu" + str(i)
         host = host_zone.create_host(cpu_name, speed).seal()
         # the first CPU is the gateway
         if i == 0:
-            gateway = host
+            host_zone.set_gateway(host.netpoint)
         # create split-duplex link
         link = host_zone.create_split_duplex_link("link-" + cpu_name, link_bw)
         link.set_latency(link_lat).seal()
         # connecting CPU to outer world
-        host_zone.add_route(host.netpoint, None, None, None,
-                            [simgrid.LinkInRoute(link, simgrid.LinkInRoute.Direction.UP)], True)
+        host_zone.add_route(host, None, [simgrid.LinkInRoute(link, simgrid.LinkInRoute.Direction.UP)], True)
 
     # seal newly created netzone
     host_zone.seal()
-    return host_zone.netpoint, gateway.netpoint
+    return host_zone
 
 #####################################################################################################