NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble_profiling_timer.h
Go to the documentation of this file.
1/*
2//@HEADER
3// ************************************************************************
4//
5// NimbleSM
6// Copyright 2018
7// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
8//
9// Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government
10// retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY EXPRESS OR IMPLIED
28// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
30// NO EVENT SHALL NTESS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact David Littlewood (djlittl@sandia.gov)
39//
40// ************************************************************************
41//@HEADER
42*/
43
44#ifndef NIMBLESM_NIMBLE_PROFILING_TIMER_H
45#define NIMBLESM_NIMBLE_PROFILING_TIMER_H
46
47#include <memory>
48#include <stack>
49#include <string>
50
51#include "nimble_timer.h"
52
53#ifdef NIMBLE_HAVE_KOKKOS
54#include "Kokkos_Timer.hpp"
55#endif
56
57namespace nimble {
58
60{
61 public:
63 {
64#ifndef NIMBLE_HAVE_KOKKOS
65 n_timer_ = std::unique_ptr<nimble::Timer>(new nimble::Timer());
66#endif
67 }
68
69 ~ProfilingTimer() = default;
70
71 inline void
72 push_region(const std::string& profiling_region_name)
73 {
74 current_region_.push(profiling_region_name);
75#ifdef NIMBLE_HAVE_KOKKOS
76 Kokkos::Profiling::pushRegion("NimbleSM: " + profiling_region_name);
77 k_timer_.reset();
78#else
79 n_timer_->Start(profiling_region_name);
80#endif
81 }
82
83 inline double
85 {
86 double t = 0.0;
87#ifdef NIMBLE_HAVE_KOKKOS
88 t = k_timer_.seconds();
89 Kokkos::Profiling::popRegion();
90#else
91 t = n_timer_->StopReport(current_region_.top());
92#endif
93 current_region_.pop();
94 return t;
95 }
96
97 private:
98 std::stack<std::string> current_region_;
99
100 std::unique_ptr<nimble::Timer> n_timer_ = nullptr;
101#ifdef NIMBLE_HAVE_KOKKOS
102 Kokkos::Timer k_timer_;
103#endif
104};
105
106} // namespace nimble
107
108#endif // NIMBLESM_NIMBLE_PROFILING_TIMER_H
void push_region(const std::string &profiling_region_name)
Definition nimble_profiling_timer.h:72
double pop_region_and_report_time()
Definition nimble_profiling_timer.h:84
ProfilingTimer()
Definition nimble_profiling_timer.h:62
Definition nimble_timer.h:97
Definition kokkos_contact_manager.h:49