36 #ifndef GENERICEVENTHANDLER_HPP_ 37 #define GENERICEVENTHANDLER_HPP_ 57 template <
unsigned NUM_EVENTS,
class CONCRETE>
60 friend class TestGenericEventHandler;
61 friend class TestCellBasedEventHandler;
62 friend class TestHeartEventHandler;
95 return wallTime*1000.0;
116 static CONCRETE inst;
157 return Instance()->GetElapsedTimeImpl(event);
212 mWallTime.resize(NUM_EVENTS, 0.0);
213 mHasBegun.resize(NUM_EVENTS,
false);
223 for (
unsigned event=0;
event<NUM_EVENTS;
event++)
225 mWallTime[
event] = 0.0;
226 mHasBegun[
event] =
false;
243 #ifdef CHASTE_EVENT_BARRIERS 247 assert(event<NUM_EVENTS);
249 if (event != NUM_EVENTS-1)
251 if (!mHasBegun[NUM_EVENTS-1])
257 if (mHasBegun[event])
260 msg +=
"The event associated with the counter for '";
261 msg += CONCRETE::EventName[event];
262 msg +=
"' had already begun when BeginEvent was called.";
263 std::cerr << msg << std::endl << std::flush;
268 mHasBegun[event] =
true;
279 assert(event<NUM_EVENTS);
284 #ifdef CHASTE_EVENT_BARRIERS 287 if (!mHasBegun[event])
290 msg +=
"Error: The event associated with the counter for '";
291 msg += CONCRETE::EventName[event];
292 msg +=
"' had not begun when EndEvent was called.";
296 mHasBegun[event] =
false;
309 assert(event<NUM_EVENTS);
312 EXCEPTION(
"Asked to report on a disabled event handler. Check for contributory errors above.");
315 if (mHasBegun[event])
321 time = mWallTime[event];
338 EXCEPTION(
"Asked to report on a disabled event handler. Check for contributory errors above.");
342 EXCEPTION(
"Asked to report on an event handler which is set to zero.");
345 for (
unsigned event=0;
event<NUM_EVENTS;
event++)
347 if (mHasBegun[
event])
353 const unsigned top_event = NUM_EVENTS-1;
358 if (total > 999999.0)
362 else if (total > 9999.0)
379 for (
unsigned event=0;
event<NUM_EVENTS;
event++)
382 printf(format, secs);
383 printf(
"(%3.0f%%) ", total == 0.0 ? 0.0 : (secs/total*100.0));
385 std::cout <<
"(seconds) \n";
392 double total_cpu_time[NUM_EVENTS];
393 MPI_Reduce(&mWallTime[0], total_cpu_time, NUM_EVENTS, MPI_DOUBLE, MPI_SUM, 0,
PetscTools::GetWorld());
398 for (
unsigned event=0;
event<NUM_EVENTS;
event++)
402 printf(
"(%3.0f%%) ", total == 0.0 ? 0.0 : (secs/total*100.0));
404 std::cout <<
"(seconds) \n";
407 double max_cpu_time[NUM_EVENTS];
408 MPI_Reduce(&mWallTime[0], max_cpu_time, NUM_EVENTS, MPI_DOUBLE, MPI_MAX, 0,
PetscTools::GetWorld());
413 for (
unsigned event=0;
event<NUM_EVENTS;
event++)
416 printf(format, secs);
417 printf(
"(%3.0f%%) ", total == 0.0 ? 0.0 : (secs/total*100.0));
419 std::cout <<
"(seconds) \n";
445 for (
unsigned event=0;
event<NUM_EVENTS;
event++)
447 printf(
"%15s%2s", CONCRETE::EventName[
event],
"");
double GetElapsedTimeImpl(unsigned event)
static double GetWallTime()
std::vector< double > mWallTime
#define EXCEPTION(message)
static void BeginEvent(unsigned event)
static double GetElapsedTime()
static GenericEventHandler< NUM_EVENTS, CONCRETE > * Instance()
double ConvertWallTimeToSeconds(double wallTime)
void EndEventImpl(unsigned event)
static double GetElapsedTime(unsigned event)
double ConvertWallTimeToMilliseconds(double wallTime)
static void MilliSleep(unsigned milliseconds)
static void EndEvent(unsigned event)
void BeginEventImpl(unsigned event)
std::vector< bool > mHasBegun