Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / examples / python / exec-dvfs / exec-dvfs.py
1 # Copyright (c) 2007-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 Usage: exec-dvfs.py platform_file [other parameters]
8 """
9
10 import sys
11 from simgrid import Actor, Engine, Host, this_actor
12
13
14 class Dvfs:
15     def __call__(self):
16         workload = 100E6
17         host = this_actor.get_host()
18
19         nb = host.pstate_count
20         this_actor.info("Count of Processor states={:d}".format(nb))
21
22         this_actor.info("Current power peak={:f}".format(host.speed))
23
24         # Run a task
25         this_actor.execute(workload)
26
27         task_time = Engine.clock
28         this_actor.info("Task1 duration: {:.2f}".format(task_time))
29
30         # Change power peak
31         new_pstate = 2
32
33         this_actor.info("Changing power peak value to {:f} (at index {:d})".format(host.pstate_speed(new_pstate),
34                                                                                    new_pstate))
35
36         host.pstate = new_pstate
37
38         this_actor.info("Changed power peak={:f}".format(host.speed))
39
40         # Run a second task
41         this_actor.execute(workload)
42
43         task_time = Engine.clock - task_time
44         this_actor.info("Task2 duration: {:.2f}".format(task_time))
45
46         # Verify that the default pstate is set to 0
47         host2 = Host.by_name("MyHost2")
48         this_actor.info("Count of Processor states={:d}".format(host2.pstate_count))
49
50         this_actor.info("Final power peak={:f}".format(host2.speed))
51
52 if __name__ == '__main__':
53     e = Engine(sys.argv)
54     if len(sys.argv) < 2:
55         raise AssertionError("Usage: exec-dvfs.py platform_file [other parameters] (got {:d} params)"
56                              .format(len(sys.argv)))
57
58     e.load_platform(sys.argv[1])
59     Actor.create("dvfs_test", Host.by_name("MyHost1"), Dvfs())
60     Actor.create("dvfs_test", Host.by_name("MyHost2"), Dvfs())
61
62     e.run()