diff options
-rw-r--r-- | Carpet/Carpet/src/CallFunction.cc | 6 | ||||
-rw-r--r-- | Carpet/Carpet/src/Evolve.cc | 16 | ||||
-rw-r--r-- | Carpet/Carpet/src/Initialise.cc | 4 | ||||
-rw-r--r-- | Carpet/Carpet/src/Shutdown.cc | 4 | ||||
-rw-r--r-- | Carpet/Carpet/src/Timers.cc | 76 | ||||
-rw-r--r-- | Carpet/Carpet/src/Timers.hh | 29 |
6 files changed, 68 insertions, 67 deletions
diff --git a/Carpet/Carpet/src/CallFunction.cc b/Carpet/Carpet/src/CallFunction.cc index 0c67de1b0..3d4d5d841 100644 --- a/Carpet/Carpet/src/CallFunction.cc +++ b/Carpet/Carpet/src/CallFunction.cc @@ -30,9 +30,9 @@ namespace Carpet { { DECLARE_CCTK_PARAMETERS; - static Timer total_timer (timerSet(), "CallFunction"); - static Timer user_timer (timerSet(), "CallFunction::thorns"); - static Timer sync_timer (timerSet(), "CallFunction::syncs"); + static Timer total_timer ("CallFunction"); + static Timer user_timer ("CallFunction::thorns"); + static Timer sync_timer ("CallFunction::syncs"); total_timer.start(); diff --git a/Carpet/Carpet/src/Evolve.cc b/Carpet/Carpet/src/Evolve.cc index c1e7bf889..e810cc334 100644 --- a/Carpet/Carpet/src/Evolve.cc +++ b/Carpet/Carpet/src/Evolve.cc @@ -45,7 +45,7 @@ namespace Carpet { cGH* cctkGH = fc->GH[convlev]; // Main loop - static Timer timer (timerSet(), "Evolve"); + static Timer timer ("Evolve"); timer.start(); while (not do_terminate (cctkGH)) { @@ -69,7 +69,7 @@ namespace Carpet { cctkGH->cctk_iteration % output_timers_every == 0 and cctkGH->cctk_iteration % do_every == 0) { - timerSet().printData (cctkGH, timer_file); + TimerSet::writeData (cctkGH, timer_file); } } // end main loop @@ -87,7 +87,7 @@ namespace Carpet { { DECLARE_CCTK_PARAMETERS; - static Timer timer (timerSet(), "Evolve::do_terminate"); + static Timer timer ("Evolve::do_terminate"); timer.start(); bool term; @@ -171,7 +171,7 @@ namespace Carpet { { DECLARE_CCTK_PARAMETERS; - static Timer timer (timerSet(), "Evolve::AdvanceTime"); + static Timer timer ("Evolve::AdvanceTime"); timer.start(); ++ cctkGH->cctk_iteration; @@ -203,7 +203,7 @@ namespace Carpet { { DECLARE_CCTK_PARAMETERS; - static Timer timer (timerSet(), "Evolve::CallRegrid"); + static Timer timer ("Evolve::CallRegrid"); timer.start(); assert (is_level_mode()); @@ -302,7 +302,7 @@ namespace Carpet { { DECLARE_CCTK_PARAMETERS; - static Timer timer (timerSet(), "Evolve::CallEvol"); + static Timer timer ("Evolve::CallEvol"); timer.start(); for (int ml=mglevels-1; ml>=0; --ml) { @@ -374,7 +374,7 @@ namespace Carpet { void CallRestrict (cGH * const cctkGH) { - static Timer timer (timerSet(), "Evolve::CallRestrict"); + static Timer timer ("Evolve::CallRestrict"); timer.start(); for (int ml=mglevels-1; ml>=0; --ml) { @@ -406,7 +406,7 @@ namespace Carpet { { DECLARE_CCTK_PARAMETERS; - static Timer timer (timerSet(), "Evolve::CallAnalysis"); + static Timer timer ("Evolve::CallAnalysis"); timer.start(); for (int ml=mglevels-1; ml>=0; --ml) { diff --git a/Carpet/Carpet/src/Initialise.cc b/Carpet/Carpet/src/Initialise.cc index c05d50305..c320dad95 100644 --- a/Carpet/Carpet/src/Initialise.cc +++ b/Carpet/Carpet/src/Initialise.cc @@ -55,7 +55,7 @@ namespace Carpet { // Timing statistics InitTiming (cctkGH); - static Timer timer (timerSet(), "Initialise"); + static Timer timer ("Initialise"); timer.start(); #warning "TODO: add more timers" @@ -100,7 +100,7 @@ namespace Carpet { print_internal_data (); timer.stop(); - timerSet().printData (cctkGH, timer_file); + TimerSet::writeData (cctkGH, timer_file); Waypoint ("Done with initialisation"); diff --git a/Carpet/Carpet/src/Shutdown.cc b/Carpet/Carpet/src/Shutdown.cc index 32bec0073..3c929c1ef 100644 --- a/Carpet/Carpet/src/Shutdown.cc +++ b/Carpet/Carpet/src/Shutdown.cc @@ -27,7 +27,7 @@ namespace Carpet { const int convlev = 0; cGH* cctkGH = fc->GH[convlev]; - static Timer timer (timerSet(), "Shutdown"); + static Timer timer ("Shutdown"); timer.start(); for (int rl=reflevels-1; rl>=0; --rl) { BEGIN_REVERSE_MGLEVEL_LOOP(cctkGH) { @@ -58,7 +58,7 @@ namespace Carpet { } END_REVERSE_MGLEVEL_LOOP; timer.stop(); - timerSet().printData (cctkGH, timer_file); + TimerSet::writeData (cctkGH, timer_file); // earlier checkpoint before finalising MPI Waypoint ("Done with shutdown"); diff --git a/Carpet/Carpet/src/Timers.cc b/Carpet/Carpet/src/Timers.cc index 4d2d34ed1..70daf3514 100644 --- a/Carpet/Carpet/src/Timers.cc +++ b/Carpet/Carpet/src/Timers.cc @@ -24,11 +24,8 @@ namespace Carpet { // A global timer set - TimerSet & timerSet () - { - static TimerSet timerSet_; - return timerSet_; - } + static + TimerSet timerSet; @@ -52,7 +49,7 @@ namespace Carpet { // Print all timer names void - TimerSet::print () + TimerSet::printNames () const { printf ("Timer names:\n"); @@ -69,39 +66,46 @@ namespace Carpet { // Print all timer data void - TimerSet::printData (cGH const * const cctkGH, - char const * const filename) + TimerSet::printData () { - redirect (cctkGH, filename); - printf ("********************************************************************************\n"); - printf ("Carpet timing information at iteration %d time %g:\n", - cctkGH->cctk_iteration, (double) cctkGH->cctk_time); for (list <Timer *>::const_iterator itimer = timers.begin(); itimer != timers.end(); ++ itimer) { (* itimer)->printData (); } + } + + + + // Print all timer data + void + TimerSet::writeData (cGH const * const cctkGH, + char const * const filename) + { + int const oldfd = redirect (cctkGH, filename); printf ("********************************************************************************\n"); - unredirect (); + printf ("Carpet timing information at iteration %d time %g:\n", + cctkGH->cctk_iteration, (double) cctkGH->cctk_time); + timerSet.printData (); + unredirect (oldfd); } // If filename is not empty, then redirect stdout to a file - void + int TimerSet::redirect (cGH const * const cctkGH, char const * const filename) { DECLARE_CCTK_PARAMETERS; if (CCTK_EQUALS (filename, "")) { - fdsave = -1; - return; + return -1; } #ifndef HAVE_UNISTD_H CCTK_WARN (1, "Cannot redirect timer output to a file; the operating system does not support this"); - return; + return -1; #else int const myproc = CCTK_MyProc (cctkGH); @@ -120,19 +124,19 @@ namespace Carpet { // Temporarily redirect stdout fflush (stdout); - fdsave = dup (1); // fd 1 is stdout - int const mode = 0644; // rw-r--r--, or a+r u+w + int const oldfd = dup (1); // fd 1 is stdout + int const mode = 0644; // rw-r--r--, or a+r u+w int const fdfile = open (fullname, flags, mode); if (fdfile < 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Could not open timer output file \"%s\"", fullname); - close (fdsave); - fdsave = -1; - return; + close (oldfd); + return -1; } close (1); - dup (fdfile); // dup to 1, i.e., stdout again + dup (fdfile); // dup to 1, i.e., stdout again close (fdfile); + return oldfd; #endif } @@ -140,28 +144,26 @@ namespace Carpet { // Redirect stdout back void - TimerSet::unredirect () + TimerSet::unredirect (int const oldfd) { - if (fdsave < 0) return; + if (oldfd < 0) return; #ifdef HAVE_UNISTD_H fflush (stdout); close (1); - dup (fdsave); - close (fdsave); + dup (oldfd); + close (oldfd); #endif } - // Create a new Cactus timer with the give name, which belongs to a - // certain timer set - Timer::Timer (TimerSet & timerSet_, char const * const name) - : running (false), - timerSet (timerSet_) + // Create a new Cactus timer with the given name + Timer::Timer (char const * const timername) + : running (false) { - assert (name); - handle = CCTK_TimerCreate (name); + assert (timername); + handle = CCTK_TimerCreate (timername); assert (handle >= 0); timerSet.add (this); @@ -184,9 +186,9 @@ namespace Carpet { Timer::name () const { - char const * const name_ = CCTK_TimerName (handle); - assert (name_); - return name_; + char const * const timername = CCTK_TimerName (handle); + assert (timername); + return timername; } diff --git a/Carpet/Carpet/src/Timers.hh b/Carpet/Carpet/src/Timers.hh index 32297813d..2c2543168 100644 --- a/Carpet/Carpet/src/Timers.hh +++ b/Carpet/Carpet/src/Timers.hh @@ -31,32 +31,34 @@ namespace Carpet { // Print all timer names void - print () + printNames () const; - // Print all timer data + // Print timer data + void + printData (); + + // Write all timer data + static void - printData (cGH const * cctkGH, + writeData (cGH const * cctkGH, char const * filename); private: - int fdsave; - // If filename is not empty, then redirect stdout to a file - void + static + int redirect (cGH const * cctkGH, char const * filename); // Redirect stdout back + static void - unredirect (); + unredirect (int oldfd); }; // class TimerSet - // A global timer set - TimerSet & timerSet (); - // A timer, which is a wrapper around a Cactus timer @@ -64,14 +66,11 @@ namespace Carpet { int handle; bool running; - TimerSet & timerSet; public: - // Create a new Cactus timer with the give name, which belongs to - // a certain timer set - Timer (TimerSet & timerSet_, - char const * timername); + // Create a new Cactus timer with the given name + Timer (char const * timername); // Destroy a timer ~Timer (); |