1 # Copyright (c) 2010-2022. The SimGrid Team. All rights reserved.
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.
6 from simgrid import Actor, Engine, Host, Link, this_actor
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.
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")
19 (links, lat) = jupiter.route_to(fafard)
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).")
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)
34 if __name__ == '__main__':
36 # Load the platform description
37 e.load_platform(sys.argv[1])
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
45 # Add a watcher of the changes
46 Actor.create("watcher", Host.by_name("Fafard"), watcher)