Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[python] cleanup Engine getters/setters
[simgrid.git] / examples / python / platform-profile / platform-profile.py
1 # Copyright (c) 2010-2022. The SimGrid Team. All rights reserved.
2 #
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the license (GNU LGPL) which comes with this package.
5
6 from simgrid import Actor, Engine, Host, Link, this_actor
7 import sys
8
9 # This example demonstrates how to attach a profile to a host or a link, to specify external changes to the resource speed.
10 # The first way to do so is to use a file in the XML, while the second is to use the programmatic interface.
11
12 def watcher():
13   jupiter  = Host.by_name("Jupiter")
14   fafard   = Host.by_name("Fafard")
15   lilibeth = Host.by_name("Lilibeth")
16   link1    = Link.by_name("1")
17   link2    = Link.by_name("2")
18
19   (links, lat) = jupiter.route_to(fafard)
20   path = ""
21   for l in links:
22     path += ("" if len(path)==0 else ", ") + "link '" + l.name + "'"
23   this_actor.info(f"Path from Jupiter to Fafard: {path} (latency: {lat:.6f}s).")
24
25   for _ in range(10):
26     this_actor.info("Fafard: %.0fMflops, Jupiter: %4.0fMflops, Lilibeth: %3.1fMflops, Link1: (%.2fMB/s %.0fms), Link2: (%.2fMB/s %.0fms)" % (
27              fafard.speed * fafard.available_speed / 1000000,
28              jupiter.speed * jupiter.available_speed / 1000000,
29              lilibeth.speed * lilibeth.available_speed / 1000000, 
30              link1.bandwidth / 1000, link1.latency * 1000, 
31              link2.bandwidth / 1000, link2.latency * 1000))
32     this_actor.sleep_for(1)
33
34 if __name__ == '__main__':
35   e = Engine(sys.argv)
36   # Load the platform description
37   e.load_platform(sys.argv[1])
38
39   # Add a new host programmatically, and attach a simple speed profile to it (alternate between full and half speed every two seconds
40   lili = e.netzone_root.create_host("Lilibeth", 25e6)
41   lili.set_speed_profile("""0 1.0
42 2 0.5""", 2)
43   lili.seal()
44
45   # Add a watcher of the changes
46   Actor.create("watcher", Host.by_name("Fafard"), watcher)
47
48   e.run()