Add support for more than 2 timers

parent 2aae636f
...@@ -433,7 +433,7 @@ int main( int argc, char** argv ) { ...@@ -433,7 +433,7 @@ int main( int argc, char** argv ) {
// do time steps until next checkpoint is reached // do time steps until next checkpoint is reached
while( l_t < l_checkPoints[c] ) { while( l_t < l_checkPoints[c] ) {
//reset CPU-Communication clock //reset CPU-Communication clock
tools::Logger::logger.resetCpuCommunicationClockToCurrentTime(); tools::Logger::logger.resetClockToCurrentTime("CpuCommunication");
// exchange ghost and copy layers // exchange ghost and copy layers
exchangeLeftRightGhostLayers( l_leftNeighborRank, l_leftInflow, l_leftOutflow, exchangeLeftRightGhostLayers( l_leftNeighborRank, l_leftInflow, l_leftOutflow,
...@@ -445,7 +445,7 @@ int main( int argc, char** argv ) { ...@@ -445,7 +445,7 @@ int main( int argc, char** argv ) {
l_mpiRow ); l_mpiRow );
// reset the cpu clock // reset the cpu clock
tools::Logger::logger.resetCpuClockToCurrentTime(); tools::Logger::logger.resetClockToCurrentTime("Cpu");
// set values in ghost cells // set values in ghost cells
l_wavePropgationBlock.setGhostLayer(); l_wavePropgationBlock.setGhostLayer();
...@@ -457,7 +457,7 @@ int main( int argc, char** argv ) { ...@@ -457,7 +457,7 @@ int main( int argc, char** argv ) {
float l_maxTimeStepWidth = l_wavePropgationBlock.getMaxTimestep(); float l_maxTimeStepWidth = l_wavePropgationBlock.getMaxTimestep();
// update the cpu time in the logger // update the cpu time in the logger
tools::Logger::logger.updateCpuTime(); tools::Logger::logger.updateTime("Cpu");
//! maximum allowed time steps of all blocks //! maximum allowed time steps of all blocks
float l_maxTimeStepWidthGlobal; float l_maxTimeStepWidthGlobal;
...@@ -466,14 +466,14 @@ int main( int argc, char** argv ) { ...@@ -466,14 +466,14 @@ int main( int argc, char** argv ) {
MPI_Allreduce(&l_maxTimeStepWidth, &l_maxTimeStepWidthGlobal, 1, MPI_FLOAT, MPI_MIN, MPI_COMM_WORLD); MPI_Allreduce(&l_maxTimeStepWidth, &l_maxTimeStepWidthGlobal, 1, MPI_FLOAT, MPI_MIN, MPI_COMM_WORLD);
// reset the cpu time // reset the cpu time
tools::Logger::logger.resetCpuClockToCurrentTime(); tools::Logger::logger.resetClockToCurrentTime("Cpu");
// update the cell values // update the cell values
l_wavePropgationBlock.updateUnknowns(l_maxTimeStepWidthGlobal); l_wavePropgationBlock.updateUnknowns(l_maxTimeStepWidthGlobal);
// update the cpu and CPU-communication time in the logger // update the cpu and CPU-communication time in the logger
tools::Logger::logger.updateCpuTime(); tools::Logger::logger.updateTime("Cpu");
tools::Logger::logger.updateCpuCommunicationTime(); tools::Logger::logger.updateTime("CpuCommunication");
// update simulation time with time step width. // update simulation time with time step width.
l_t += l_maxTimeStepWidthGlobal; l_t += l_maxTimeStepWidthGlobal;
...@@ -511,10 +511,10 @@ int main( int argc, char** argv ) { ...@@ -511,10 +511,10 @@ int main( int argc, char** argv ) {
tools::Logger::logger.printStatisticsMessage(); tools::Logger::logger.printStatisticsMessage();
// print the cpu time // print the cpu time
tools::Logger::logger.printCpuTime("CPU time"); tools::Logger::logger.printTime("Cpu", "CPU time");
// print CPU + Communication time // print CPU + Communication time
tools::Logger::logger.printCpuCommunicationTime(); tools::Logger::logger.printTime("CpuCommunication", "CPU + Communication time");
// print the wall clock time (includes plotting) // print the wall clock time (includes plotting)
tools::Logger::logger.printWallClockTime(time(NULL)); tools::Logger::logger.printWallClockTime(time(NULL));
......
...@@ -235,7 +235,7 @@ int main( int argc, char** argv ) { ...@@ -235,7 +235,7 @@ int main( int argc, char** argv ) {
l_wavePropgationBlock.setGhostLayer(); l_wavePropgationBlock.setGhostLayer();
// reset the cpu clock // reset the cpu clock
tools::Logger::logger.resetCpuClockToCurrentTime(); tools::Logger::logger.resetClockToCurrentTime("Cpu");
// approximate the maximum time step // approximate the maximum time step
// TODO: This calculation should be replaced by the usage of the wave speeds occuring during the flux computation // TODO: This calculation should be replaced by the usage of the wave speeds occuring during the flux computation
...@@ -252,7 +252,7 @@ int main( int argc, char** argv ) { ...@@ -252,7 +252,7 @@ int main( int argc, char** argv ) {
l_wavePropgationBlock.updateUnknowns(l_maxTimeStepWidth); l_wavePropgationBlock.updateUnknowns(l_maxTimeStepWidth);
// update the cpu time in the logger // update the cpu time in the logger
tools::Logger::logger.updateCpuTime(); tools::Logger::logger.updateTime("Cpu");
// update simulation time with time step width. // update simulation time with time step width.
l_t += l_maxTimeStepWidth; l_t += l_maxTimeStepWidth;
...@@ -284,7 +284,7 @@ int main( int argc, char** argv ) { ...@@ -284,7 +284,7 @@ int main( int argc, char** argv ) {
tools::Logger::logger.printStatisticsMessage(); tools::Logger::logger.printStatisticsMessage();
// print the cpu time // print the cpu time
tools::Logger::logger.printCpuTime(); tools::Logger::logger.printTime("Cpu", "CPU time");
// print the wall clock time (includes plotting) // print the wall clock time (includes plotting)
tools::Logger::logger.printWallClockTime(time(NULL)); tools::Logger::logger.printWallClockTime(time(NULL));
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <mpi.h> #include <mpi.h>
#endif #endif
#include <map>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <ctime> #include <ctime>
...@@ -88,25 +89,15 @@ class tools::Logger { ...@@ -88,25 +89,15 @@ class tools::Logger {
//! definition of indentation //! definition of indentation
const std::string indentation; const std::string indentation;
//! CPU clock //! Clocks
#if (defined USEMPI && !defined CUDA) #if (defined USEMPI && !defined CUDA)
double cpuClock; std::map<std::string, double> clocks;
#else #else
clock_t cpuClock; std::map<std::string, clock_t> clocks;
#endif #endif
//! CPU-Communication clock //! Timer
#if (defined USEMPI && !defined CUDA) std::map<std::string, double> timer;
double cpuCommClock;
#else
clock_t cpuCommClock;
#endif
//! CPU time
double cpuTime;
//! CPU and communication time
double cpuCommTime;
//! wall clock time: cpu, communication, IO //! wall clock time: cpu, communication, IO
double wallClockTime; double wallClockTime;
...@@ -178,8 +169,6 @@ class tools::Logger { ...@@ -178,8 +169,6 @@ class tools::Logger {
midDelimiter(i_midDelimiter), midDelimiter(i_midDelimiter),
largeDelimiter(i_largeDelimiter), largeDelimiter(i_largeDelimiter),
indentation(i_indentation) { indentation(i_indentation) {
//set time to zero
cpuTime = cpuCommTime = wallClockTime = 0.;
#ifndef USEMPI #ifndef USEMPI
// Since we have one static logger, we do not know the MPI rank in this // Since we have one static logger, we do not know the MPI rank in this
...@@ -427,40 +416,30 @@ class tools::Logger { ...@@ -427,40 +416,30 @@ class tools::Logger {
} }
/** /**
* Update the CPU time. * Update a timer
*
* @param i_name Name of timer
*/ */
void updateCpuTime() { void updateTime(const std::string &i_name) {
// If the timer does not yet exist it will be initialized with 0 by std::map
// Works only with [] no with .at()
#if (defined USEMPI && !defined CUDA) #if (defined USEMPI && !defined CUDA)
cpuTime += MPI_Wtime() - cpuClock; timer[i_name] += MPI_Wtime() - clocks.at(i_name);
#else #else
cpuTime += (clock() - cpuClock)/(double)CLOCKS_PER_SEC; timer[i_name] += (clock() - clocks.at(i_name))/(double)CLOCKS_PER_SEC;
#endif #endif
} }
/** /**
* Update the CPU-Communication time. * Reset a clock to the current time
*
* @param i_name Name of timer/clock
*/ */
void updateCpuCommunicationTime() { void resetClockToCurrentTime(const std::string &i_name) {
#if (defined USEMPI && !defined CUDA)
cpuCommTime += MPI_Wtime() - cpuCommClock;
#else
cpuCommTime += (clock() - cpuCommClock)/(double)CLOCKS_PER_SEC;
#endif
}
void resetCpuClockToCurrentTime() {
#if (defined USEMPI && !defined CUDA) #if (defined USEMPI && !defined CUDA)
cpuClock = MPI_Wtime(); clocks[i_name] = MPI_Wtime();
#else #else
cpuClock = clock(); clocks[i_name] = clock();
#endif
}
void resetCpuCommunicationClockToCurrentTime() {
#if (defined USEMPI && !defined CUDA)
cpuCommClock = MPI_Wtime();
#else
cpuCommClock = clock();
#endif #endif
} }
...@@ -487,25 +466,15 @@ class tools::Logger { ...@@ -487,25 +466,15 @@ class tools::Logger {
} }
/** /**
* Print elapsed CPU time. * Print elapsed time.
*
* @param i_cpuTimeMessage cpu time message.
*/
void printCpuTime(const std::string i_cpuTimeMessage = "CPU time" ) {
timeCout() << indentation << "process " << processRank << " - "
<< i_cpuTimeMessage << ": "
<< cpuTime << " seconds"<< std::endl;
}
/**
* Print elapsed CPU + communication time.
* *
* @param i_cpuCommunicationTimeMessage CPU + communication time message. * @param i_name Name of the timer
* @param i_message time message.
*/ */
void printCpuCommunicationTime( const std::string i_cpuCommunicationTimeMessage = "CPU + communication time" ) { void printTime(const std::string &i_name, const std::string &i_message ) {
timeCout() << indentation << "process " << processRank << " - " timeCout() << indentation << "process " << processRank << " - "
<< i_cpuCommunicationTimeMessage << ": " << i_message << ": "
<< cpuCommTime << " seconds"<< std::endl; << timer.at(i_name) << " seconds"<< std::endl;
} }
/** /**
...@@ -523,7 +492,7 @@ class tools::Logger { ...@@ -523,7 +492,7 @@ class tools::Logger {
} }
public: public:
/** The logger all classes shoud use */ /** The logger all classes should use */
static Logger logger; static Logger logger;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment