Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
update comm status BEFORE sending signals
[simgrid.git] / examples / python / plugin-host-load / plugin-host-load.py
1 # Copyright (c) 2006-2023. 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
7 from argparse import ArgumentParser
8 import sys
9 from simgrid import Engine, Host, this_actor, Actor, sg_host_load_plugin_init
10
11 def parse():
12     parser = ArgumentParser()
13     parser.add_argument(
14         '--platform',
15         type=str,
16         required=True,
17         help='path to the platform description'
18     )
19     return parser.parse_args()
20
21 def execute_load_test():
22   host = Host.by_name('MyHost1')
23   this_actor.info(f'Initial peak speed: {host.speed:.0E} flop/s; number of flops computed so far: {host.computed_flops:.0E} (should be 0) and current average load: {host.avg_load} (should be 0)')
24
25   start = Engine.clock
26   this_actor.info('Sleep for 10 seconds')
27   this_actor.sleep_for(10)
28
29   speed = host.speed
30   this_actor.info(f'Done sleeping {Engine.clock - start}s; peak speed: {host.speed:.0E} flop/s; number of flops computed so far: {host.computed_flops:.0E} (nothing should have changed)')
31
32   # Run an activity
33   start = e.clock
34   this_actor.info(f'Run an activity of {200E6:.0E} flops at current speed of {host.speed:.0E} flop/s')
35   this_actor.execute(200E6)
36
37   this_actor.info(f'Done working on my activity; this took {Engine.clock - start}s; current peak speed: {host.speed:.0E} flop/s (when I started the computation, \
38 the speed was set to {speed:.0E} flop/s); number of flops computed so \
39 far: {host.computed_flops:.0E}, average load as reported by the HostLoad plugin: {host.avg_load:.5f} (should be {200E6 / (10.5 * speed * host.core_count + (Engine.clock - start - 0.5) * host.speed * host.core_count):.5f})')
40
41   # ========= Change power peak =========
42   pstate = 1
43   host.pstate = pstate
44   this_actor.info(f'========= Requesting pstate {pstate} (speed should be of {host.pstate_speed(pstate):.0E} flop/s and is of {host.speed:.0E} flop/s, average load is {host.avg_load:.5f})')
45
46   # Run a second activity
47   start = Engine.clock
48   this_actor.info(f'Run an activity of {100E6:.0E} flops')
49   this_actor.execute(100E6)
50   this_actor.info(f'Done working on my activity; this took {Engine.clock - start}s; current peak speed: {host.speed:.0E} flop/s; number of flops computed so far: {host.computed_flops:.0E}')
51   Engine
52   start = Engine.clock
53   this_actor.info("========= Requesting a reset of the computation and load counters")
54   host.reset_load()
55   this_actor.info(f'After reset: {host.computed_flops:.0E} flops computed; load is {host.avg_load}')
56   this_actor.info('Sleep for 4 seconds')
57   this_actor.sleep_for(4)
58   this_actor.info(f'Done sleeping {Engine.clock - start}s; peak speed: {host.speed:.0E} flop/s; number of flops computed so far: {host.computed_flops:.0E}')
59
60   # =========== Turn the other host off ==========
61   host2 = Host.by_name('MyHost2')
62   this_actor.info(f'Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed {host2.computed_flops:.0E} flops so far and has an average load of {host2.avg_load}')
63   host2.turn_off()
64   start = Engine.clock
65   this_actor.sleep_for(10)
66   this_actor.info(f'Done sleeping {Engine.clock - start}s; peak speed: {host.speed:.0E} flop/s; number of flops computed so far: {host.computed_flops:.0E}')
67
68 def change_speed():
69   host = Host.by_name('MyHost1')
70   this_actor.sleep_for(10.5)
71   this_actor.info("I slept until now, but now I'll change the speed of this host while the other actor is still computing! This should slow the computation down.")
72   host.pstate = 2
73
74 if __name__ == '__main__':
75   args = parse()
76   
77   sg_host_load_plugin_init()
78   e = Engine(sys.argv)
79   e.load_platform(args.platform)
80
81   Actor.create('load_test', e.host_by_name('MyHost1'), execute_load_test)
82   Actor.create('change_speed', e.host_by_name('MyHost1'), change_speed)
83
84   e.run()
85
86   this_actor.info(f'Total simulation time: {Engine.clock}')
87