Skip to content

Commit

Permalink
Merge pull request #7084 from cgcgcg/stackedTimerFix
Browse files Browse the repository at this point in the history
Teuchos Stacked timer histogram fix
  • Loading branch information
cgcgcg authored Mar 27, 2020
2 parents 1a4bdce + 45b640c commit 9339b78
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/teuchos/comm/src/Teuchos_StackedTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ StackedTimer::collectRemoteData(Teuchos::RCP<const Teuchos::Comm<int> > comm, co
if (used[i]) {
int bin=(time[i]- min_[i])/dh;
bins[i] = std::max(std::min(bin,options.num_histogram-1) , 0);
}
} else
bins[i] = -1;
}
// Recycle the used array for the temp bin array
for (int j=0; j<options.num_histogram; ++j){
Expand Down
7 changes: 7 additions & 0 deletions packages/teuchos/comm/test/StackedTimer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ TRIBITS_ADD_EXECUTABLE_AND_TEST(
COMM serial mpi
NUM_MPI_PROCS 2
)

TRIBITS_ADD_EXECUTABLE_AND_TEST(
stacked_timer4
SOURCES stacked_timer4.cpp
COMM serial mpi
NUM_MPI_PROCS 4
)
89 changes: 89 additions & 0 deletions packages/teuchos/comm/test/StackedTimer/stacked_timer4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// @HEADER
// @HEADER

#include "Teuchos_UnitTestHarness.hpp"
#include "Teuchos_UnitTestRepository.hpp"
#include "Teuchos_GlobalMPISession.hpp"
#include "Teuchos_PerformanceMonitorBase.hpp"
#include "Teuchos_TimeMonitor.hpp"
#include "Teuchos_StackedTimer.hpp"
#include "Teuchos_DefaultComm.hpp"
#include <sstream>
#include <thread> // std::this_thread::sleep_for;
#include <tuple>
#include <regex>
#include <iterator>
#include <limits>

#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE)
#include "Kokkos_Core.hpp"
#endif


TEUCHOS_UNIT_TEST(StackedTimer, minmax_hist)
{

Teuchos::StackedTimer timer("L0");
timer.stopBaseTimer();

const Teuchos::RCP<const Teuchos::Comm<int>> comm = Teuchos::DefaultComm<int>::getComm();
if (comm->getSize() != 4)
return;
const int myRank = Teuchos::rank(*comm);

if ((myRank == 1) || (myRank == 2)) {
timer.start("T0");
timer.stop("T0");
const_cast<Teuchos::BaseTimer*>(timer.findBaseTimer("L0@T0"))->setAccumulatedTime(Teuchos::as<double>(myRank));
} else {
timer.start("T1");
timer.stop("T1");
const_cast<Teuchos::BaseTimer*>(timer.findBaseTimer("L0@T1"))->setAccumulatedTime(Teuchos::as<double>(myRank));
}

Teuchos::StackedTimer::OutputOptions options;

out << "\n### Printing default report ###" << std::endl;
options.output_minmax=true;
options.output_proc_minmax=true;
options.output_histogram=true;
options.num_histogram=2;
options.output_fraction=false;
timer.report(out, comm, options);
{
std::ostringstream os;
timer.report(os, comm, options);
if (myRank == 0) {
TEST_ASSERT(os.str().find("min=1, max=2, proc min=1, proc max=2") != std::string::npos);
TEST_ASSERT(os.str().find("<1, 1>") != std::string::npos);
TEST_ASSERT(os.str().find("min=0, max=3, proc min=0, proc max=3") != std::string::npos);
}
}
}

// Use our own main to initialize kokkos before calling
// runUnitTestsFromMain(). The kokkos space_time_stack profiler seg
// faults due to inconsistent push/pop of timers in the teuchos unit
// test startup code. By calling initialize here we can use the
// space_time_stack profiler with this unit test.
int main( int argc, char* argv[] )
{
// Note that the dtor for GlobalMPISession will call
// Kokkos::finalize_all().
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE)
Kokkos::initialize(argc,argv);
#endif
{
Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
out.setOutputToRootOnly(0);
}
Teuchos::UnitTestRepository::setGloballyReduceTestResult(true);

auto return_val = Teuchos::UnitTestRepository::runUnitTestsFromMain(argc, argv);
#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE)
if (Kokkos::is_initialized())
Kokkos::finalize_all();
#endif
return return_val;
}

0 comments on commit 9339b78

Please sign in to comment.