23#define PAPI_CHECK(BOOL,MSG) do { \
25 std::cerr << "PAPI_ERROR: " << MSG << std::endl; \
29#define PAPI_CHECK(BOOL,MSG) (BOOL);
33class PAPI_Initializer{
36 static bool initialized =
false;
39 PAPI_CHECK( PAPI_library_init(PAPI_VER_CURRENT) != PAPI_OK,
"Failed initializing PAPI library." );
40 PAPI_CHECK( PAPI_thread_init(pthread_self) != PAPI_OK,
"Failed initializing PAPI thread support." );
41 this->initialized =
true;
45 bool papi_initialized() {
return this->initialized; }
48 bool initialized =
false;
67 long long *_papi_start;
68 long long *_papi_stop;
69 long long *_papi_counter;
70 int _papi_num_counters;
71 int _papi_num_avail_counters;
81 _start(0), _stop(0), _etime(0), _state(TIMER_HALTED), _synced(
false), _active(
true)
83 , _papi_start(0), _papi_stop(0), _papi_counter(0), _papi_num_counters(0), _papi_num_avail_counters(0), _papi_EventSet(0), _collect_papi(
false)
88 static PAPI_Initializer pi;
89 if (!pi.papi_initialized()) {
90 std::cerr <<
"PAPI not initialized!!!1" << std::endl;
100 delete[] _papi_counter;
116 double get_etime_running() {
117 return timer() - _start;
119 timer_state get_state() {
123 void activateTimer(){ _active =
true; }
124 void deactivateTimer(){ _active =
false; }
125 bool isActive(){
return _active; }
133 int add_papi_counters(
int n,
char *papi_event_list[]) {
135 std::cerr <<
"PAPI ERROR: PAPI counters already started." << std::endl;
137 _papi_num_avail_counters = PAPI_num_counters();
138 if(_papi_num_avail_counters < 0) {
139 std::cerr <<
"PAPI ERROR: This machine does not provide hardware counters.";
142 _papi_start =
new long long[_papi_num_avail_counters];
143 _papi_stop =
new long long[_papi_num_avail_counters];
144 _papi_counter =
new long long[_papi_num_avail_counters];
145 _papi_num_counters = n;
146 _papi_EventSet = PAPI_NULL;
147 PAPI_CHECK( (PAPI_create_eventset(&_papi_EventSet) != PAPI_OK),
"Failed creating event set.");
148 if (_papi_num_avail_counters < _papi_num_counters) {
149 std::cerr <<
"PAPI WARNING: Not enough hw counter available. Skipping counters " << _papi_num_avail_counters <<
" - " << _papi_num_counters << std::endl;
150 _papi_num_counters = _papi_num_avail_counters;
152 for (
int i = 0; i < _papi_num_counters; i++) {
154 std::cerr <<
"PAPI INFO: adding HW Counter [" << i <<
"] " << papi_event_list[i] << std::endl;
156 PAPI_CHECK( (PAPI_add_named_event(_papi_EventSet, papi_event_list[i]) != PAPI_OK),
"Could not add counter to event set.");
157 _papi_counter[i] = 0;
159 PAPI_CHECK( (PAPI_start(_papi_EventSet) != PAPI_OK),
"Could not start PAPI counters.");
161 _collect_papi =
true;
162 return _papi_num_counters;
165 int get_papi_num_counters() {
166 return _papi_num_counters;
169 long long get_papi_counter(
int index) {
170 return (_papi_counter[index]);
172 long long get_global_papi_counter(
int index) {
173 long long counter = _papi_counter[index];
175 MPI_Allreduce(MPI_IN_PLACE, &counter, 1, MPI_LONG_LONG, MPI_SUM, MPI_COMM_WORLD);
186 MPI_Barrier(MPI_COMM_WORLD);
189 struct timeval tmp_time;
190 gettimeofday(&tmp_time, NULL);
191 time = (1.0e6 * (double) tmp_time.tv_sec + (
double) tmp_time.tv_usec) / 1.0e6;
This class is used to measure times in sequential and parallel versions.
Definition: Timer.h:59
void set_sync(bool sync)
Synchronize counter (across MPI processes)
Definition: Timer.h:128
::xsd::cxx::tree::time< char, simple_type > time
C++ type corresponding to the time XML Schema built-in type.
Definition: vtk-punstructured.h:438