Logo AND Algorithmique Numérique Distribuée

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