MueLu/Ifpack2/Tpetra: Fix issues with RCPs associated with Teuchos::TimeMonitor and Kokkos profiling tool integration
Created by: csiefer2
Fix issues with RCPs associated with Teuchos::TimeMonitor and Kokkos profiling tool integration.
As per @mhoemmen :
FYI, @ibaned pointed out a difficulty over the phone today: Kokkos Profiling expects that regions always form a tree -- any two regions are either disjoint, or one fully encloses the other. However, MueLu's use of RCP to handle TimeMonitor breaks this assumption. For example:
RCP mon = rcp (new TimeMonitor (*TimeMonitor::getNewCounter ("A"))); code_A_to_time (); mon = rcp (new TimeMonitor (*TimeMonitor::getNewCounter ("B"))); code_B_to_time (); // ... etc. ...
The problem is that the right-hand side of mon = rcp (new TimeMonitor (...)); gets evaluated first, and creates the second TimeMonitor, before the first TimeMonitor's destructor gets called. This means that the second TimeMonitor instance overlaps in time with the first one. @ibaned noticed that this can result in timing differences in practice -- just a few nanoseconds, but it breaks the tree invariant and thus causes some regions to have artificially small timings.