From 1f5808f84cc12dea546153a02379815243ba7c4f Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Wed, 25 Jul 2012 22:24:42 +0200 Subject: Carpet: Introduce more timers to measure communication time --- Carpet/Carpet/src/Comm.cc | 51 ++++++++++++++++++++++++++++++++++++++++++- Carpet/Carpet/src/Restrict.cc | 39 +++++++++++++++++++++++++++++++-- Carpet/Carpet/src/SetupGH.cc | 37 +++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 3 deletions(-) diff --git a/Carpet/Carpet/src/Comm.cc b/Carpet/Carpet/src/Comm.cc index ab6106c2b..55be38251 100644 --- a/Carpet/Carpet/src/Comm.cc +++ b/Carpet/Carpet/src/Comm.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -180,8 +181,29 @@ namespace Carpet { // use the current time here (which may be modified by the user) const CCTK_REAL time = cctkGH->cctk_time; + + static vector timers; + if (timers.empty()) { + timers.push_back(new Timer("comm_state[0].create")); + for (astate state = static_cast(0); + state != state_done; + state = static_cast(static_cast(state)+1)) + { + ostringstream name1; + name1 << "comm_state[" << timers.size() << "]" + << "." << tostring(state) << ".user"; + timers.push_back(new Timer(name1.str())); + ostringstream name2; + name2 << "comm_state[" << timers.size() << "]" + << "." << tostring(state) << ".step"; + timers.push_back(new Timer(name2.str())); + } + } + vector::iterator ti = timers.begin(); + (*ti)->start(); for (comm_state state; not state.done(); state.step()) { + (*ti)->stop(); ++ti; (*ti)->start(); for (int group = 0; group < (int)groups.size(); ++group) { const int g = groups.AT(group); const int grouptype = CCTK_GroupTypeI (g); @@ -202,7 +224,10 @@ namespace Carpet { } } } + (*ti)->stop(); ++ti; (*ti)->start(); } + (*ti)->stop(); + ++ti; assert(ti == timers.end()); } @@ -219,7 +244,28 @@ namespace Carpet { Accelerator_PreSync(cctkGH, &groups.front(), groups.size()); } + static vector timers; + if (timers.empty()) { + timers.push_back(new Timer("comm_state[0].create")); + for (astate state = static_cast(0); + state != state_done; + state = static_cast(static_cast(state)+1)) + { + ostringstream name1; + name1 << "comm_state[" << timers.size() << "]" + << "." << tostring(state) << ".user"; + timers.push_back(new Timer(name1.str())); + ostringstream name2; + name2 << "comm_state[" << timers.size() << "]" + << "." << tostring(state) << ".step"; + timers.push_back(new Timer(name2.str())); + } + } + + vector::iterator ti = timers.begin(); + (*ti)->start(); for (comm_state state; not state.done(); state.step()) { + (*ti)->stop(); ++ti; (*ti)->start(); for (int group = 0; group < (int)groups.size(); ++group) { const int g = groups.AT(group); const int grouptype = CCTK_GroupTypeI (g); @@ -235,8 +281,11 @@ namespace Carpet { } } } + (*ti)->stop(); ++ti; (*ti)->start(); } - + (*ti)->stop(); + ++ti; assert(ti == timers.end()); + if (CCTK_IsFunctionAliased("Accelerator_PostSync")) { Accelerator_PostSync(cctkGH, &groups.front(), groups.size()); } diff --git a/Carpet/Carpet/src/Restrict.cc b/Carpet/Carpet/src/Restrict.cc index 8ede1ebcd..e24198dcd 100644 --- a/Carpet/Carpet/src/Restrict.cc +++ b/Carpet/Carpet/src/Restrict.cc @@ -9,6 +9,7 @@ #include #include +#include @@ -51,10 +52,20 @@ namespace Carpet { } // Restrict - RestrictGroups (cctkGH, groups); + { + static Timer timer ("Restrict"); + timer.start(); + RestrictGroups (cctkGH, groups); + timer.stop(); + } // Synchronise - SyncGroups (cctkGH, groups); + { + static Timer timer ("RestrictSync"); + timer.start(); + SyncGroups (cctkGH, groups); + timer.stop(); + } } @@ -62,7 +73,28 @@ namespace Carpet { static void RestrictGroups (const cGH* cctkGH, const vector& groups) { DECLARE_CCTK_PARAMETERS; + static vector timers; + if (timers.empty()) { + timers.push_back(new Timer("comm_state[0].create")); + for (astate state = static_cast(0); + state != state_done; + state = static_cast(static_cast(state)+1)) + { + ostringstream name1; + name1 << "comm_state[" << timers.size() << "]" + << "." << tostring(state) << ".user"; + timers.push_back(new Timer(name1.str())); + ostringstream name2; + name2 << "comm_state[" << timers.size() << "]" + << "." << tostring(state) << ".step"; + timers.push_back(new Timer(name2.str())); + } + } + + vector::iterator ti = timers.begin(); + (*ti)->start(); for (comm_state state; not state.done(); state.step()) { + (*ti)->stop(); ++ti; (*ti)->start(); for (int group = 0; group < (int)groups.size(); ++group) { const int g = groups.AT(group); const int active_tl = CCTK_ActiveTimeLevelsGI (cctkGH, g); @@ -75,7 +107,10 @@ namespace Carpet { } } } // loop over groups + (*ti)->stop(); ++ti; (*ti)->start(); } // for state + (*ti)->stop(); + ++ti; assert(ti == timers.end()); } } // namespace Carpet diff --git a/Carpet/Carpet/src/SetupGH.cc b/Carpet/Carpet/src/SetupGH.cc index 2e814628f..6369c059d 100644 --- a/Carpet/Carpet/src/SetupGH.cc +++ b/Carpet/Carpet/src/SetupGH.cc @@ -493,6 +493,43 @@ namespace Carpet { "The number of threads for this process is larger its number of cores. This may indicate a performance problem."); } } + +#pragma omp parallel + for (int thread=0; thread mask(CPU_SETSIZE, false); + cpu_set_t cpumask; + int const ierr = sched_getaffinity (0, sizeof cpumask, &cpumask); + assert (not ierr); + for (int n=0; n= 0 and not mask.at(n)) { + if (n-1 > first_active) buf << "-" << n-1; + first_active = -1; + } + } + CCTK_VInfo (CCTK_THORNSTRING, + "Thread %d runs on %d core%s: %s", + thread, + num_cores, num_cores==1 ? "" : "s", buf.str().c_str()); + } +#pragma omp barrier + } #else CCTK_INFO ("Cannot determine core affinity"); #endif -- cgit v1.2.3