Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Pylint docs/source/tuto_s4u/*.py.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 17 Feb 2022 15:02:16 +0000 (16:02 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 17 Feb 2022 15:02:16 +0000 (16:02 +0100)
docs/source/tuto_s4u/master-workers-lab1.py
docs/source/tuto_s4u/master-workers-lab2.py

index 98b71d3..26216a6 100644 (file)
@@ -1,56 +1,57 @@
-# Copyright (c) 2010-2022. The SimGrid Team. All rights reserved.          
+# Copyright (c) 2010-2022. 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. 
+# under the terms of the license (GNU LGPL) which comes with this package.
 
+"""
 # ##################################################################################
 # Take this tutorial online: https://simgrid.org/doc/latest/Tutorial_Algorithms.html
 # ##################################################################################
+"""
 
-from simgrid import Actor, Engine, Host, Mailbox, this_actor
 import sys
+from simgrid import Engine, Mailbox, this_actor
 
 # master-begin
 def master(*args):
-  if len(args) == 2:
-    raise AssertionError(
-            f"Actor master requires 4 parameters, but only {len(args)}")
-  worker_count = int(args[0])           
-  tasks_count = int(args[1])
-  compute_cost = int(args[2])
-  communicate_cost = int(args[3])
-  this_actor.info(f"Got {worker_count} workers and {tasks_count} tasks to process")
-
-  for i in range(tasks_count): # For each task to be executed: 
-      # - Select a worker in a round-robin way
-      mailbox = Mailbox.by_name(str(i % worker_count))
-
-      # - Send the computation amount to the worker
-      if (tasks_count < 10000 or (tasks_count < 100000 and i % 10000 == 0) or i % 100000 == 0):
-        this_actor.info(f"Sending task {i} of {tasks_count} to mailbox '{mailbox.name}'")
-      mailbox.put(compute_cost, communicate_cost)
-
-  this_actor.info("All tasks have been dispatched. Request all workers to stop.")
-  for i in range (worker_count):
-      # The workers stop when receiving a negative compute_cost
-      mailbox = Mailbox.by_name(str(i))
-      mailbox.put(-1, 0)
+    if len(args) == 2:
+        raise AssertionError(f"Actor master requires 4 parameters, but only {len(args)}")
+    worker_count = int(args[0])
+    tasks_count = int(args[1])
+    compute_cost = int(args[2])
+    communicate_cost = int(args[3])
+    this_actor.info(f"Got {worker_count} workers and {tasks_count} tasks to process")
+
+    for i in range(tasks_count): # For each task to be executed:
+        # - Select a worker in a round-robin way
+        mailbox = Mailbox.by_name(str(i % worker_count))
+
+        # - Send the computation amount to the worker
+        if (tasks_count < 10000 or (tasks_count < 100000 and i % 10000 == 0) or i % 100000 == 0):
+            this_actor.info(f"Sending task {i} of {tasks_count} to mailbox '{mailbox.name}'")
+        mailbox.put(compute_cost, communicate_cost)
+
+    this_actor.info("All tasks have been dispatched. Request all workers to stop.")
+    for i in range(worker_count):
+        # The workers stop when receiving a negative compute_cost
+        mailbox = Mailbox.by_name(str(i))
+        mailbox.put(-1, 0)
 # master-end
 
 # worker-begin
 def worker(*args):
-  assert len(args) == 1, "The worker expects one argument"
-
-  mailbox = Mailbox.by_name(args[0])
-  done = False
-  while not done:
-    compute_cost = mailbox.get()
-    if compute_cost > 0: # If compute_cost is valid, execute a computation of that cost 
-      this_actor.execute(compute_cost)
-    else: # Stop when receiving an invalid compute_cost
-      done = True
-
-  this_actor.info("Exiting now.")
+    assert len(args) == 1, "The worker expects one argument"
+
+    mailbox = Mailbox.by_name(args[0])
+    done = False
+    while not done:
+        compute_cost = mailbox.get()
+        if compute_cost > 0: # If compute_cost is valid, execute a computation of that cost
+            this_actor.execute(compute_cost)
+        else: # Stop when receiving an invalid compute_cost
+            done = True
+
+    this_actor.info("Exiting now.")
 # worker-end
 
 # main-begin
@@ -64,11 +65,11 @@ if __name__ == '__main__':
     e.register_actor("worker", worker)
 
     # Load the platform description and then deploy the application
-    e.load_platform(sys.argv[1]) 
+    e.load_platform(sys.argv[1])
     e.load_deployment(sys.argv[2])
 
     # Run the simulation
     e.run()
 
     this_actor.info("Simulation is over")
-# main-end
\ No newline at end of file
+# main-end
index 6ed833b..58caaf1 100644 (file)
@@ -1,61 +1,62 @@
-# Copyright (c) 2010-2022. The SimGrid Team. All rights reserved.          
+# Copyright (c) 2010-2022. 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. 
+# under the terms of the license (GNU LGPL) which comes with this package.
 
+"""
 # ##################################################################################
 # Take this tutorial online: https://simgrid.org/doc/latest/Tutorial_Algorithms.html
 # ##################################################################################
+"""
 
-from simgrid import Actor, Engine, Host, Mailbox, this_actor
 import sys
+from simgrid import Actor, Engine, Mailbox, this_actor
 
 # master-begin
 def master(*args):
-  if len(args) == 2:
-    raise AssertionError(
-            f"Actor master requires 4 parameters, but only {len(args)}")
-  tasks_count = int(args[0])
-  compute_cost = int(args[1])
-  communicate_cost = int(args[2])
-
-  this_actor.info(f"Got {tasks_count} tasks to process")
-
-  hosts = Engine.instance().get_all_hosts()
-
-  for h in hosts:
-    Actor.create(f'Worker-{h.name}', h, worker)
-
-  for i in range(tasks_count): # For each task to be executed: 
-      # - Select a worker in a round-robin way
-      mailbox = Mailbox.by_name(f'Worker-{hosts[i%len(hosts)].name}')
-
-      # - Send the computation amount to the worker
-      if (tasks_count < 10000 or (tasks_count < 100000 and i % 10000 == 0) or i % 100000 == 0):
-        this_actor.info(f"Sending task {i} of {tasks_count} to mailbox '{mailbox.name}'")
-      mailbox.put(compute_cost, communicate_cost)
-
-  this_actor.info("All tasks have been dispatched. Request all workers to stop.")
-  for h in hosts:
-      # The workers stop when receiving a negative compute_cost
-      mailbox = Mailbox.by_name(f'Worker-{h.name}')
-      mailbox.put(-1, 0)
+    if len(args) == 2:
+        raise AssertionError(f"Actor master requires 4 parameters, but only {len(args)}")
+    tasks_count = int(args[0])
+    compute_cost = int(args[1])
+    communicate_cost = int(args[2])
+
+    this_actor.info(f"Got {tasks_count} tasks to process")
+
+    hosts = Engine.instance().get_all_hosts()
+
+    for h in hosts:
+        Actor.create(f'Worker-{h.name}', h, worker)
+
+    for i in range(tasks_count): # For each task to be executed:
+        # - Select a worker in a round-robin way
+        mailbox = Mailbox.by_name(f'Worker-{hosts[i%len(hosts)].name}')
+
+        # - Send the computation amount to the worker
+        if (tasks_count < 10000 or (tasks_count < 100000 and i % 10000 == 0) or i % 100000 == 0):
+            this_actor.info(f"Sending task {i} of {tasks_count} to mailbox '{mailbox.name}'")
+        mailbox.put(compute_cost, communicate_cost)
+
+    this_actor.info("All tasks have been dispatched. Request all workers to stop.")
+    for h in hosts:
+        # The workers stop when receiving a negative compute_cost
+        mailbox = Mailbox.by_name(f'Worker-{h.name}')
+        mailbox.put(-1, 0)
 # master-end
 
 # worker-begin
 def worker(*args):
-  assert len(args) == 0, "The worker expects no argument"
-
-  mailbox = Mailbox.by_name(f'Worker-{this_actor.get_host().name}')
-  done = False
-  while not done:
-    compute_cost = mailbox.get()
-    if compute_cost > 0: # If compute_cost is valid, execute a computation of that cost 
-      this_actor.execute(compute_cost)
-    else: # Stop when receiving an invalid compute_cost
-      done = True
-
-  this_actor.info("Exiting now.")
+    assert not args, "The worker expects no argument"
+
+    mailbox = Mailbox.by_name(f'Worker-{this_actor.get_host().name}')
+    done = False
+    while not done:
+        compute_cost = mailbox.get()
+        if compute_cost > 0: # If compute_cost is valid, execute a computation of that cost
+            this_actor.execute(compute_cost)
+        else: # Stop when receiving an invalid compute_cost
+            done = True
+
+    this_actor.info("Exiting now.")
 # worker-end
 
 # main-begin
@@ -69,11 +70,11 @@ if __name__ == '__main__':
     e.register_actor("worker", worker)
 
     # Load the platform description and then deploy the application
-    e.load_platform(sys.argv[1]) 
+    e.load_platform(sys.argv[1])
     e.load_deployment(sys.argv[2])
 
     # Run the simulation
     e.run()
 
     this_actor.info("Simulation is over")
-# main-end
\ No newline at end of file
+# main-end