Add support for more than 2 timers

parent 2aae636f
......@@ -433,7 +433,7 @@ int main( int argc, char** argv ) {
// do time steps until next checkpoint is reached
while( l_t < l_checkPoints[c] ) {
//reset CPU-Communication clock
tools::Logger::logger.resetCpuCommunicationClockToCurrentTime();
tools::Logger::logger.resetClockToCurrentTime("CpuCommunication");
// exchange ghost and copy layers
exchangeLeftRightGhostLayers( l_leftNeighborRank, l_leftInflow, l_leftOutflow,
......@@ -445,7 +445,7 @@ int main( int argc, char** argv ) {
l_mpiRow );
// reset the cpu clock
tools::Logger::logger.resetCpuClockToCurrentTime();
tools::Logger::logger.resetClockToCurrentTime("Cpu");
// set values in ghost cells
l_wavePropgationBlock.setGhostLayer();
......@@ -457,7 +457,7 @@ int main( int argc, char** argv ) {
float l_maxTimeStepWidth = l_wavePropgationBlock.getMaxTimestep();
// update the cpu time in the logger
tools::Logger::logger.updateCpuTime();
tools::Logger::logger.updateTime("Cpu");
//! maximum allowed time steps of all blocks
float l_maxTimeStepWidthGlobal;
......@@ -466,14 +466,14 @@ int main( int argc, char** argv ) {
MPI_Allreduce(&l_maxTimeStepWidth, &l_maxTimeStepWidthGlobal, 1, MPI_FLOAT, MPI_MIN, MPI_COMM_WORLD);
// reset the cpu time
tools::Logger::logger.resetCpuClockToCurrentTime();
tools::Logger::logger.resetClockToCurrentTime("Cpu");
// update the cell values
l_wavePropgationBlock.updateUnknowns(l_maxTimeStepWidthGlobal);
// update the cpu and CPU-communication time in the logger
tools::Logger::logger.updateCpuTime();
tools::Logger::logger.updateCpuCommunicationTime();
tools::Logger::logger.updateTime("Cpu");
tools::Logger::logger.updateTime("CpuCommunication");
// update simulation time with time step width.
l_t += l_maxTimeStepWidthGlobal;
......@@ -511,10 +511,10 @@ int main( int argc, char** argv ) {
tools::Logger::logger.printStatisticsMessage();
// print the cpu time
tools::Logger::logger.printCpuTime("CPU time");
tools::Logger::logger.printTime("Cpu", "CPU time");
// print CPU + Communication time
tools::Logger::logger.printCpuCommunicationTime();
tools::Logger::logger.printTime("CpuCommunication", "CPU + Communication time");
// print the wall clock time (includes plotting)
tools::Logger::logger.printWallClockTime(time(NULL));
......
......@@ -235,7 +235,7 @@ int main( int argc, char** argv ) {
l_wavePropgationBlock.setGhostLayer();
// reset the cpu clock
tools::Logger::logger.resetCpuClockToCurrentTime();
tools::Logger::logger.resetClockToCurrentTime("Cpu");
// approximate the maximum time step
// 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 ) {
l_wavePropgationBlock.updateUnknowns(l_maxTimeStepWidth);
// update the cpu time in the logger
tools::Logger::logger.updateCpuTime();
tools::Logger::logger.updateTime("Cpu");
// update simulation time with time step width.
l_t += l_maxTimeStepWidth;
......@@ -284,7 +284,7 @@ int main( int argc, char** argv ) {
tools::Logger::logger.printStatisticsMessage();
// print the cpu time
tools::Logger::logger.printCpuTime();
tools::Logger::logger.printTime("Cpu", "CPU time");
// print the wall clock time (includes plotting)
tools::Logger::logger.printWallClockTime(time(NULL));
......
......@@ -33,6 +33,7 @@
#include <mpi.h>
#endif
#include <map>
#include <string>
#include <iostream>
#include <ctime>
......@@ -88,25 +89,15 @@ class tools::Logger {
//! definition of indentation
const std::string indentation;
//! CPU clock
//! Clocks
#if (defined USEMPI && !defined CUDA)
double cpuClock;
std::map<std::string, double> clocks;
#else
clock_t cpuClock;
std::map<std::string, clock_t> clocks;
#endif
//! CPU-Communication clock
#if (defined USEMPI && !defined CUDA)
double cpuCommClock;
#else
clock_t cpuCommClock;
#endif
//! CPU time
double cpuTime;
//! CPU and communication time
double cpuCommTime;
//! Timer
std::map<std::string, double> timer;
//! wall clock time: cpu, communication, IO
double wallClockTime;
......@@ -178,8 +169,6 @@ class tools::Logger {
midDelimiter(i_midDelimiter),
largeDelimiter(i_largeDelimiter),
indentation(i_indentation) {
//set time to zero
cpuTime = cpuCommTime = wallClockTime = 0.;
#ifndef USEMPI
// Since we have one static logger, we do not know the MPI rank in this
......@@ -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)
cpuTime += MPI_Wtime() - cpuClock;
timer[i_name] += MPI_Wtime() - clocks.at(i_name);
#else
cpuTime += (clock() - cpuClock)/(double)CLOCKS_PER_SEC;
timer[i_name] += (clock() - clocks.at(i_name))/(double)CLOCKS_PER_SEC;
#endif
}
/**
* Update the CPU-Communication time.
* Reset a clock to the current time
*
* @param i_name Name of timer/clock
*/
void updateCpuCommunicationTime() {
#if (defined USEMPI && !defined CUDA)
cpuCommTime += MPI_Wtime() - cpuCommClock;
#else
cpuCommTime += (clock() - cpuCommClock)/(double)CLOCKS_PER_SEC;
#endif
}
void resetCpuClockToCurrentTime() {
void resetClockToCurrentTime(const std::string &i_name) {
#if (defined USEMPI && !defined CUDA)
cpuClock = MPI_Wtime();
clocks[i_name] = MPI_Wtime();
#else
cpuClock = clock();
#endif
}
void resetCpuCommunicationClockToCurrentTime() {
#if (defined USEMPI && !defined CUDA)
cpuCommClock = MPI_Wtime();
#else
cpuCommClock = clock();
clocks[i_name] = clock();
#endif
}
......@@ -487,25 +466,15 @@ class tools::Logger {
}
/**
* Print elapsed CPU 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.
* Print elapsed 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 << " - "
<< i_cpuCommunicationTimeMessage << ": "
<< cpuCommTime << " seconds"<< std::endl;
<< i_message << ": "
<< timer.at(i_name) << " seconds"<< std::endl;
}
/**
......@@ -523,7 +492,7 @@ class tools::Logger {
}
public:
/** The logger all classes shoud use */
/** The logger all classes should use */
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