SIRIUS 7.5.0
Electronic structure library and applications
power.hpp
Go to the documentation of this file.
1/** \file power.hpp
2 *
3 * \brief Read power counters on Cray.
4 */
5
6#include <fstream>
7#include <string>
8
9namespace sirius {
10namespace power {
11
12static double read_pm_file(const std::string& fname)
13{
14 double result = 0.;
15 std::ifstream fid(fname.c_str());
16
17 fid >> result;
18 // std::cout << fname << " :: " << result << std::endl;
19 return result;
20}
21
22static double device_energy(void)
23{
24 return read_pm_file("/sys/cray/pm_counters/accel_energy");
25}
26
27static double energy()
28{
29 return read_pm_file("/sys/cray/pm_counters/energy");
30}
31
32static double device_power()
33{
34 return read_pm_file("/sys/cray/pm_counters/accel_power");
35}
36
37static double power()
38{
39 return read_pm_file("/sys/cray/pm_counters/power");
40}
41
42static int num_nodes()
43{
44 // find out the number of nodes
45 char* ptr = std::getenv("SLURM_JOB_NUM_NODES");
46 if (ptr) {
47 return atoi(ptr);
48 } else {
49 return -1;
50 }
51}
52
53} // namespace power
54} // namespace sirius
Namespace of the SIRIUS library.
Definition: sirius.f90:5