diff options
-rw-r--r-- | Carpet/CarpetLib/param.ccl | 11 | ||||
-rw-r--r-- | Carpet/CarpetLib/src/mem.cc | 4 | ||||
-rw-r--r-- | Carpet/CarpetLib/src/timestat.cc | 31 |
3 files changed, 22 insertions, 24 deletions
diff --git a/Carpet/CarpetLib/param.ccl b/Carpet/CarpetLib/param.ccl index 3338690d9..8d83a335f 100644 --- a/Carpet/CarpetLib/param.ccl +++ b/Carpet/CarpetLib/param.ccl @@ -44,12 +44,9 @@ CCTK_INT poison_value "Integer value (0..255) used to poison new timelevels (wit -BOOLEAN print_timestats "Print timing statistics at every iteration" STEERABLE=always -{ -} "no" - INT print_timestats_every "Print timing statistics periodically" STEERABLE=always { + -1 :: "don't report" 0 :: "don't report" 1:* :: "report every so many iterations" } 0 @@ -68,20 +65,18 @@ KEYWORD timestat_timer "Timer for timing statistics" STEERABLE=recover "none" :: "don't measure time" } "none" -BOOLEAN timestat_disable "Disable timing statistics" STEERABLE=always -{ -} "no" - INT print_memstats_every "Report periodically how much memory is used per process" STEERABLE=always { + -1 :: "don't report" 0 :: "don't report" 1:* :: "report every so many iterations" } 0 INT max_allowed_memory_MB "Maximum allowed amount of memory per process (in Megabytes)" STEERABLE=always { + -1 :: "no maximum" 0 :: "no maximum" 1:* :: "abort if more memory is used" } 0 diff --git a/Carpet/CarpetLib/src/mem.cc b/Carpet/CarpetLib/src/mem.cc index 8776e642b..a983fc497 100644 --- a/Carpet/CarpetLib/src/mem.cc +++ b/Carpet/CarpetLib/src/mem.cc @@ -54,7 +54,7 @@ mem (size_t const vectorlength, size_t const nelems, T * const memptr) DECLARE_CCTK_PARAMETERS; if (memptr == NULL) { const double nbytes = vectorlength * nelems * sizeof (T); - if (max_allowed_memory_MB + if (max_allowed_memory_MB > 0 and (total_allocated_bytes + nbytes > 1.0e6 * max_allowed_memory_MB)) { T Tdummy; @@ -142,7 +142,7 @@ void CarpetLib_printmemstats (CCTK_ARGUMENTS) DECLARE_CCTK_ARGUMENTS; DECLARE_CCTK_PARAMETERS; - if (print_memstats_every + if (print_memstats_every > 0 and cctk_iteration % print_memstats_every == 0) { cout << "Memory statistics from CarpetLib:" << endl diff --git a/Carpet/CarpetLib/src/timestat.cc b/Carpet/CarpetLib/src/timestat.cc index 358ef94ee..58f28bc18 100644 --- a/Carpet/CarpetLib/src/timestat.cc +++ b/Carpet/CarpetLib/src/timestat.cc @@ -32,6 +32,14 @@ namespace CarpetLib { + // The timer type + enum timer_type { + timer_unset, timer_MPI_Wtime, timer_rdtsc, timer_rtc, timer_none + }; + static timer_type timer = timer_unset; + + + // A faster timing routine for i386 processors: // Read the Intel CPU time stamp counter static @@ -44,11 +52,11 @@ namespace CarpetLib { // Test for i386 (should use autoconf instead) #if defined(__i386__) || defined(__x86_64__) // Serialise using cpuid - // (This is only strictly necessary on some systems) + // (This is strictly necessary only on some systems) __asm__ __volatile__("cpuid" : : ); - // Using "=A" does not work on x86_64, where it uses rax instead + // Using "=A" does not work on x86_64, where this uses rax instead // of (edx,eax) - // unsigned long long int val; + // unsigned long long val; // __asm__ __volatile__("rdtsc" : "=A" (val) : ); unsigned long eax, edx; asm volatile ("rdtsc" : "=a" (eax), "=d" (edx)); @@ -68,9 +76,9 @@ namespace CarpetLib { init_rdtsc () { // Make three warmup measurements - volatile double const rdummy1 = rdtsc (); - volatile double const rdummy2 = rdtsc (); - volatile double const rdummy3 = rdtsc (); + double const rdummy1 = rdtsc (); + double const rdummy2 = rdtsc (); + double const rdummy3 = rdtsc (); double const rstart = rdtsc (); double const wstart = MPI_Wtime (); int const ierr = usleep (1000 * 1000); @@ -113,10 +121,6 @@ namespace CarpetLib { call_timer () { DECLARE_CCTK_PARAMETERS; - enum timer_type { - timer_unset, timer_MPI_Wtime, timer_rdtsc, timer_rtc, timer_none - }; - static timer_type timer = timer_unset; if (timer == timer_unset) { if (CCTK_EQUALS (timestat_timer, "MPI_Wtime")) { timer = timer_MPI_Wtime; @@ -269,7 +273,7 @@ namespace CarpetLib { Timer::start () { DECLARE_CCTK_PARAMETERS; - if (timestat_disable) return; + if (timer == timer_none) return; assert (not running); running = true; starttime = call_timer (); @@ -282,7 +286,7 @@ namespace CarpetLib { Timer::stop (double const b) { DECLARE_CCTK_PARAMETERS; - if (timestat_disable) return; + if (timer == timer_none) return; assert (running); running = false; double const endtime = call_timer (); @@ -356,8 +360,7 @@ namespace CarpetLib { DECLARE_CCTK_ARGUMENTS; DECLARE_CCTK_PARAMETERS; - if (print_timestats or - (print_timestats_every and + if ((print_timestats_every > 0 and cctk_iteration % print_timestats_every == 0)) { ostringstream filenamebuf; |