Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
profiling.hpp
Go to the documentation of this file.
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Smith Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
13 #pragma once
14 
15 #include <string>
16 #include <sstream>
17 
18 #include "smith/smith_config.hpp"
19 
20 #ifdef SMITH_USE_ADIAK
21 #include "adiak.hpp"
22 #endif
23 
24 #ifdef SMITH_USE_CALIPER
25 #include "caliper/cali-manager.h"
26 #include "caliper/cali.h"
27 #endif
28 
29 #include "mpi.h"
30 
36 #ifdef SMITH_USE_ADIAK
37 #define SMITH_SET_METADATA(name, data) adiak::value(name, data)
38 #else
39 #define SMITH_SET_METADATA(name, data)
40 #endif
41 
77 // NOTE: The motivation behind wrapping Caliper macros to avoid conflicting macro definitions in the no-op case, and
78 // give downstream users the option to disable profiling Smith if it pollutes their timings.
79 
80 #ifdef SMITH_USE_CALIPER
81 #define SMITH_MARK_FUNCTION CALI_CXX_MARK_FUNCTION
82 #define SMITH_MARK_LOOP_BEGIN(id, name) CALI_CXX_MARK_LOOP_BEGIN(id, name)
83 #define SMITH_MARK_LOOP_ITERATION(id, i) CALI_CXX_MARK_LOOP_ITERATION(id, i)
84 #define SMITH_MARK_LOOP_END(id) CALI_CXX_MARK_LOOP_END(id)
85 #define SMITH_MARK_BEGIN(name) CALI_MARK_BEGIN(name)
86 #define SMITH_MARK_END(name) CALI_MARK_END(name)
87 #define SMITH_MARK_SCOPE(name) CALI_CXX_MARK_SCOPE(name)
88 #else
89 // Define no-op macros in case Smith has not been configured with Caliper
90 #define SMITH_MARK_FUNCTION
91 #define SMITH_MARK_LOOP_BEGIN(id, name)
92 #define SMITH_MARK_LOOP_ITERATION(id, i)
93 #define SMITH_MARK_LOOP_END(id)
94 #define SMITH_MARK_BEGIN(name)
95 #define SMITH_MARK_END(name)
96 #define SMITH_MARK_SCOPE(name)
97 #endif
98 
100 namespace smith::profiling {
101 
108 void initialize([[maybe_unused]] MPI_Comm comm = MPI_COMM_WORLD, [[maybe_unused]] std::string options = "");
109 
113 void finalize();
114 
116 template <typename... T>
117 std::string concat(T... args)
118 {
119  std::stringstream ss;
120  // this fold expression is a more elegant way to implement the concatenation,
121  // but nvcc incorrectly generates warning "warning: expression has no effect"
122  // when using the fold expression version
123  // (ss << ... << args);
124  ((ss << args), ...);
125  return ss.str();
126 }
127 
128 } // namespace smith::profiling
profiling namespace
Definition: profiling.cpp:16
void initialize([[maybe_unused]] MPI_Comm comm, [[maybe_unused]] std::string options)
Initializes performance monitoring using the Caliper and Adiak libraries.
Definition: profiling.cpp:24
std::string concat(T... args)
Produces a string by applying << to all arguments.
Definition: profiling.hpp:117
void finalize()
Concludes performance monitoring and writes collected data to a file.
Definition: profiling.cpp:59