Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace sprintf by snprintf.
[simgrid.git] / src / smpi / smpi_dvfs.cpp
1 /* Copyright (c) 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "simgrid/plugins/energy.h" // FIXME: this plugin should be separated from the core
8 #include "xbt/log.h"
9 #include "simgrid/simix.h"
10 #include "smpi/smpi.h"
11 #include "src/internal_config.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_dvfs, smpi, "Logging specific to SMPI (experimental DVFS support)");
14
15 /**
16  * \brief Return the speed of the processor (in flop/s) at a given pstate
17  *
18  * \param pstate_index pstate to test
19  * \return Returns the processor speed associated with pstate_index
20  */
21 double smpi_get_host_power_peak_at(int pstate_index)
22 {
23   return SIMIX_host_self()->powerPeakAt(pstate_index);
24 }
25
26 /**
27  * \brief Return the current speed of the processor (in flop/s)
28  *
29  * \return Returns the current processor speed
30  */
31 double smpi_get_host_current_power_peak(void)
32 {
33   return SIMIX_host_self()->currentPowerPeak();
34 }
35
36 /**
37  * \brief Return the number of pstates defined for the current host
38  */
39 int smpi_get_host_nb_pstates(void)
40 {
41   return sg_host_get_nb_pstates(SIMIX_host_self());
42 }
43
44 /**
45  * \brief Sets the pstate at which the processor should run
46  *
47  * \param pstate_index pstate to switch to
48  */
49 void smpi_set_host_pstate(int pstate_index)
50 {
51   sg_host_set_pstate(SIMIX_host_self(), pstate_index);
52 }
53 /** @brief Gets the pstate at which the processor currently running */
54 int smpi_get_host_pstate() {
55   return sg_host_get_pstate(SIMIX_host_self());
56 }
57
58 /**
59  * \brief Return the total energy consumed by a host (in Joules)
60  *
61  * \return Returns the consumed energy
62  */
63 double smpi_get_host_consumed_energy(void) {
64   return sg_host_get_consumed_energy(SIMIX_host_self());
65 }
66
67 #if SMPI_FORTRAN
68
69 #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
70 typedef int integer;
71 typedef unsigned int uinteger;
72 #else
73 typedef long int integer;
74 typedef unsigned long int uinteger;
75 #endif
76 typedef char *address;
77 typedef short int shortint;
78 typedef float real;
79 typedef double doublereal;
80 typedef struct { real r, i; } complex;
81 typedef struct { doublereal r, i; } doublecomplex;
82
83 extern "C" XBT_PUBLIC(doublereal) smpi_get_host_power_peak_at_(integer *pstate_index);
84 doublereal smpi_get_host_power_peak_at_(integer *pstate_index)
85 {
86   return (doublereal)smpi_get_host_power_peak_at((int)*pstate_index);
87 }
88
89 extern "C" XBT_PUBLIC(doublereal) smpi_get_host_current_power_peak_(void);
90 doublereal smpi_get_host_current_power_peak_(void)
91 {
92   return smpi_get_host_current_power_peak();
93 }
94
95 extern "C" XBT_PUBLIC(integer) smpi_get_host_nb_pstates_(void);
96 integer smpi_get_host_nb_pstates_(void)
97 {
98   return (integer)smpi_get_host_nb_pstates();
99 }
100
101 extern "C" XBT_PUBLIC(void) smpi_set_host_pstate_(integer *pstate_index);
102 void smpi_set_host_pstate_(integer *pstate_index)
103 {
104   smpi_set_host_pstate((int)*pstate_index);
105 }
106
107 extern "C" XBT_PUBLIC(doublereal) smpi_get_host_consumed_energy_(void);
108 doublereal smpi_get_host_consumed_energy_(void)
109 {
110   return (doublereal)smpi_get_host_consumed_energy();
111 }
112
113 #endif