Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bc9d903607ce88ed4eae24635300c47f07a7b62a
[simgrid.git] / src / smpi / smpi_dvfs.cpp
1 /* Copyright (c) 2013-2017. 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 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_dvfs, smpi, "Logging specific to SMPI (experimental DVFS support)");
18
19 /**
20  * \brief Return the speed of the processor (in flop/s) at a given pstate
21  *
22  * \param pstate_index pstate to test
23  * \return Returns the processor speed associated with pstate_index
24  */
25 double smpi_get_host_power_peak_at(int pstate_index)
26 {
27   return SIMIX_host_self()->getPstateSpeed(pstate_index);
28 }
29
30 /**
31  * \brief Return the current speed of the processor (in flop/s)
32  *
33  * \return Returns the current processor speed
34  */
35 double smpi_get_host_current_power_peak()
36 {
37   return SIMIX_host_self()->speed();
38 }
39
40 /**
41  * \brief Return the number of pstates defined for the current host
42  */
43 int smpi_get_host_nb_pstates()
44 {
45   return sg_host_get_nb_pstates(SIMIX_host_self());
46 }
47
48 /**
49  * \brief Sets the pstate at which the processor should run
50  *
51  * \param pstate_index pstate to switch to
52  */
53 void smpi_set_host_pstate(int pstate_index)
54 {
55   sg_host_set_pstate(SIMIX_host_self(), pstate_index);
56 }
57 /** @brief Gets the pstate at which the processor currently running */
58 int smpi_get_host_pstate() {
59   return sg_host_get_pstate(SIMIX_host_self());
60 }
61
62 /**
63  * \brief Return the total energy consumed by a host (in Joules)
64  *
65  * \return Returns the consumed energy
66  */
67 double smpi_get_host_consumed_energy() {
68   return sg_host_get_consumed_energy(SIMIX_host_self());
69 }
70
71 #if SMPI_FORTRAN
72
73 #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
74 typedef int integer;
75 #else
76 typedef long int integer;
77 #endif
78 typedef char *address;
79 typedef short int shortint;
80 typedef float real;
81 typedef double doublereal;
82 typedef struct {
83   real r;
84   real i;
85 } complex;
86 typedef struct {
87   doublereal r;
88   doublereal i;
89 } doublecomplex;
90
91 extern "C" XBT_PUBLIC(doublereal) smpi_get_host_power_peak_at_(integer *pstate_index);
92 doublereal smpi_get_host_power_peak_at_(integer *pstate_index)
93 {
94   return static_cast<doublereal>(smpi_get_host_power_peak_at((int)*pstate_index));
95 }
96
97 extern "C" XBT_PUBLIC(doublereal) smpi_get_host_current_power_peak_();
98 doublereal smpi_get_host_current_power_peak_()
99 {
100   return smpi_get_host_current_power_peak();
101 }
102
103 extern "C" XBT_PUBLIC(integer) smpi_get_host_nb_pstates_();
104 integer smpi_get_host_nb_pstates_()
105 {
106   return static_cast<integer>(smpi_get_host_nb_pstates());
107 }
108
109 extern "C" XBT_PUBLIC(void) smpi_set_host_pstate_(integer *pstate_index);
110 void smpi_set_host_pstate_(integer *pstate_index)
111 {
112   smpi_set_host_pstate(static_cast<int>(*pstate_index));
113 }
114
115 extern "C" XBT_PUBLIC(doublereal) smpi_get_host_consumed_energy_();
116 doublereal smpi_get_host_consumed_energy_()
117 {
118   return static_cast<doublereal>(smpi_get_host_consumed_energy());
119 }
120
121 #endif