1 # Copyright (c) 2006-2023. 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.
7 from argparse import ArgumentParser
9 from simgrid import Engine, Host, this_actor, Actor, sg_host_load_plugin_init
12 parser = ArgumentParser()
17 help='path to the platform description'
19 return parser.parse_args()
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)')
26 this_actor.info('Sleep for 10 seconds')
27 this_actor.sleep_for(10)
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)')
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)
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})')
41 # ========= Change power peak =========
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})')
46 # Run a second activity
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}')
53 this_actor.info("========= Requesting a reset of the computation and load counters")
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}')
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}')
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}')
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.")
74 if __name__ == '__main__':
77 sg_host_load_plugin_init()
79 e.load_platform(args.platform)
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)
86 this_actor.info(f'Total simulation time: {Engine.clock}')