Rev | Line | |
---|
[688] | 1 | #include "timerRemap.hpp" |
---|
[694] | 2 | #include "mpi.hpp" |
---|
[688] | 3 | #include <string> |
---|
| 4 | #include <map> |
---|
| 5 | #include <iostream> |
---|
| 6 | |
---|
| 7 | namespace sphereRemap { |
---|
| 8 | |
---|
| 9 | using namespace std; |
---|
| 10 | |
---|
[1146] | 11 | map<string,CTimer*> *CTimer::allTimer = 0; |
---|
[688] | 12 | |
---|
| 13 | CTimer::CTimer(const string& name_) : name(name_) |
---|
| 14 | { |
---|
| 15 | reset(); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | double CTimer::getTime(void) |
---|
| 19 | { |
---|
| 20 | return MPI_Wtime(); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | void CTimer::suspend(void) |
---|
| 24 | { |
---|
| 25 | if (!suspended) |
---|
| 26 | cumulatedTime+=getTime()-lastTime; |
---|
| 27 | suspended=true; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | void CTimer::resume(void) |
---|
| 31 | { |
---|
| 32 | if (suspended) |
---|
| 33 | lastTime=getTime(); |
---|
| 34 | suspended=false; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | void CTimer::reset(void) |
---|
| 38 | { |
---|
| 39 | cumulatedTime=0.; |
---|
| 40 | suspended=true; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | double CTimer::getCumulatedTime(void) |
---|
| 44 | { |
---|
| 45 | return cumulatedTime; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | void CTimer::print(void) |
---|
| 49 | { |
---|
| 50 | #ifdef TIMEIT |
---|
| 51 | cout << " Time for "<<name<<" : "<<getCumulatedTime() <<" s"<<endl; |
---|
| 52 | #endif |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | CTimer& CTimer::get(const string name) |
---|
| 56 | { |
---|
[1146] | 57 | if(allTimer == 0) allTimer = new map<string,CTimer*>; |
---|
[688] | 58 | map<string,CTimer*>::iterator it; |
---|
[1146] | 59 | it=(*allTimer).find(name); |
---|
| 60 | if (it==(*allTimer).end()) it=(*allTimer).insert(pair<string,CTimer*>(name,new CTimer(name))).first; |
---|
[688] | 61 | return *(it->second); |
---|
| 62 | } |
---|
| 63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.