Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1347c247a8a4953fc86da827deb3e803fb9343b2
[simgrid.git] / src / smpi / internals / smpi_dvfs.cpp
1 /* Copyright (c) 2013-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 #include <xbt/log.h>
7
8 // FIXME: this plugin should be separated from the core
9 #include "simgrid/s4u/Host.hpp"
10 #include <simgrid/plugins/energy.h>
11 #include <simgrid/simix.h>
12
13 #include <smpi/smpi.h>
14
15 #include "src/internal_config.h"
16
17 #if SMPI_FORTRAN
18
19 // FIXME: rework these bindings, or kill them completely
20
21 #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
22 typedef int integer;
23 #else
24 typedef long int integer;
25 #endif
26 typedef double doublereal;
27
28 /**
29  * @brief Return the speed of the processor (in flop/s) at a given pstate
30  *
31  * @param pstate_index pstate to test
32  * @return Returns the processor speed associated with pstate_index
33  */
34 extern "C" XBT_PUBLIC doublereal smpi_get_host_power_peak_at_(integer* pstate_index);
35 doublereal smpi_get_host_power_peak_at_(integer *pstate_index)
36 {
37   return static_cast<doublereal>(sg_host_self()->get_pstate_speed(static_cast<int>(*pstate_index)));
38 }
39
40 /**
41  * @brief Return the current speed of the processor (in flop/s)
42  *
43  * @return Returns the current processor speed
44  */
45 extern "C" XBT_PUBLIC doublereal smpi_get_host_current_power_peak_();
46 doublereal smpi_get_host_current_power_peak_()
47 {
48   return static_cast<doublereal>(sg_host_self()->get_speed());
49 }
50
51 /**
52  * @brief Return the number of pstates defined for the current host
53  */
54 extern "C" XBT_PUBLIC integer smpi_get_host_nb_pstates_();
55 integer smpi_get_host_nb_pstates_()
56 {
57   return static_cast<integer>(sg_host_self()->get_pstate_count());
58 }
59
60 /**
61  * @brief Sets the pstate at which the processor should run
62  *
63  * @param pstate_index pstate to switch to
64  */
65 extern "C" XBT_PUBLIC void smpi_set_host_pstate_(integer* pstate_index);
66 void smpi_set_host_pstate_(integer *pstate_index)
67 {
68   sg_host_set_pstate(sg_host_self(), (static_cast<int>(*pstate_index)));
69 }
70
71 /**
72  * @brief Gets the pstate at which the processor currently running
73  */
74 extern "C" XBT_PUBLIC integer smpi_get_host_pstate_();
75 integer smpi_get_host_pstate_()
76 {
77   return static_cast<integer>(sg_host_get_pstate(sg_host_self()));
78 }
79 /**
80  * @brief Return the total energy consumed by a host (in Joules)
81  *
82  * @return Returns the consumed energy
83  */
84 extern "C" XBT_PUBLIC doublereal smpi_get_host_consumed_energy_();
85 doublereal smpi_get_host_consumed_energy_()
86 {
87   return static_cast<doublereal>(sg_host_get_consumed_energy(sg_host_self()));
88 }
89
90 #endif