Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
freq_adapt.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2015: G-CSC, Goethe University Frankfurt
3 * Author: Andreas Vogel
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__UG__COMMON__PROFILER__FREQ_ADAPT__
34#define __H__UG__COMMON__PROFILER__FREQ_ADAPT__
35
36#include <stack>
37#include <vector>
38#include <string>
39#include <pthread.h> // used to start separate thread controlling freqency
40
42
44// FreqAdaptNodeManager
46
48{
49 public:
50 static void add(AutoFreqAdaptNode* node);
51 static void release_latest();
52
53 private:
56
57 public:
58 static FreqAdaptNodeManager& inst();
59
60// private:
61 std::stack<AutoFreqAdaptNode*> m_nodes;
62};
63
65// AutoFreqAdaptNode
67
70
71 public:
72 AutoFreqAdaptNode(unsigned long freq);
74
75 private:
76 void release();
77 inline bool is_active() {return m_bActive;}
78
79 protected:
81 unsigned long m_prevFreq;
82};
83
84
86// FreqAdaptValues
88
90 friend class AutoFreqAdaptNode;
91
92 private:
93 // disallow constructor, destructor; copy and assignment (intentionally left unimplemented)
98
99 // Singleton provider
100 static FreqAdaptValues& inst();
101
102 private:
103 // return freq if adjusted; if not contained, return 0
104 unsigned long find_freq(const char* file, const int line);
105
106 private:
108 std::string file;
109 int line;
110 unsigned long freq;
111 FreqAdaptPoint(std::string _file, int _line, unsigned long _freq) :
112 file(_file), line(_line), freq(_freq) {}
113 };
114
115 // returns the continuous information
116 static std::vector<FreqAdaptPoint> m_pos;
117
118 public:
119 // returns requested frequency (or 0 if freq not adjusted) at file and line
120 static unsigned long freq(const char* file, const int line){
121 return inst().find_freq(file, line);
122 }
123
124 // reads the database of (file, line, required frequency)
125 static void set_freqs(std::string csvFile);
126
127 // adjust the frequency of the cpu
128 static void adjust_freq(unsigned long freq);
129
130 protected:
131 static void* freqAdaptWorker(void* This);
132
133 static unsigned long newFreq;
134 static pthread_mutex_t freqAdapt_mutex;
135 static pthread_cond_t freqAdapt_condVar;
136
137 static pthread_attr_t freqAdaptWorkerThreadAttr;
138 static cpu_set_t processor_mask;
139 static pthread_t freqAdaptWorkerThread;
140
141};
142
143
144#endif /* __H__UG__COMMON__PROFILER__FREQ_ADAPT__ */
Definition freq_adapt.h:68
bool is_active()
Definition freq_adapt.h:77
bool m_bActive
Definition freq_adapt.h:80
void release()
Definition freq_adapt.cpp:123
unsigned long m_prevFreq
Definition freq_adapt.h:81
~AutoFreqAdaptNode()
Definition freq_adapt.cpp:116
Definition freq_adapt.h:48
FreqAdaptNodeManager()
Definition freq_adapt.cpp:64
~FreqAdaptNodeManager()
Definition freq_adapt.cpp:66
static void add(AutoFreqAdaptNode *node)
Definition freq_adapt.cpp:50
static FreqAdaptNodeManager & inst()
Definition freq_adapt.cpp:73
static void release_latest()
Definition freq_adapt.cpp:55
std::stack< AutoFreqAdaptNode * > m_nodes
Definition freq_adapt.h:61
Definition freq_adapt.h:89
static unsigned long newFreq
Definition freq_adapt.h:133
static void * freqAdaptWorker(void *This)
Definition freq_adapt.cpp:177
static unsigned long freq(const char *file, const int line)
Definition freq_adapt.h:120
FreqAdaptValues & operator=(const FreqAdaptValues &)
static pthread_mutex_t freqAdapt_mutex
Definition freq_adapt.h:134
static void set_freqs(std::string csvFile)
Definition freq_adapt.cpp:236
static pthread_t freqAdaptWorkerThread
Definition freq_adapt.h:139
unsigned long find_freq(const char *file, const int line)
Definition freq_adapt.cpp:162
FreqAdaptValues()
Definition freq_adapt.h:94
~FreqAdaptValues()
Definition freq_adapt.h:97
static cpu_set_t processor_mask
Definition freq_adapt.h:138
static std::vector< FreqAdaptPoint > m_pos
Definition freq_adapt.h:116
FreqAdaptValues(const FreqAdaptValues &)
static pthread_cond_t freqAdapt_condVar
Definition freq_adapt.h:135
static void adjust_freq(unsigned long freq)
Definition freq_adapt.cpp:226
static FreqAdaptValues & inst()
Definition freq_adapt.cpp:156
static pthread_attr_t freqAdaptWorkerThreadAttr
Definition freq_adapt.h:137
Definition freq_adapt.h:107
std::string file
Definition freq_adapt.h:108
unsigned long freq
Definition freq_adapt.h:110
int line
Definition freq_adapt.h:109
FreqAdaptPoint(std::string _file, int _line, unsigned long _freq)
Definition freq_adapt.h:111