Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
profiling.hpp
Go to the documentation of this file.
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Serac 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 "serac/serac_config.hpp"
19 
20 #ifdef SERAC_USE_ADIAK
21 #include "adiak.hpp"
22 #endif
23 
24 #ifdef SERAC_USE_CALIPER
25 #include "caliper/cali-manager.h"
26 #include "caliper/cali.h"
27 #endif
28 
29 #include "mpi.h"
30 
36 #ifdef SERAC_USE_ADIAK
37 #define SERAC_SET_METADATA(name, data) adiak::value(name, data)
38 #else
39 #define SERAC_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 Serac if it pollutes their timings.
79 
80 #ifdef SERAC_USE_CALIPER
81 #define SERAC_MARK_FUNCTION CALI_CXX_MARK_FUNCTION
82 #define SERAC_MARK_LOOP_BEGIN(id, name) CALI_CXX_MARK_LOOP_BEGIN(id, name)
83 #define SERAC_MARK_LOOP_ITERATION(id, i) CALI_CXX_MARK_LOOP_ITERATION(id, i)
84 #define SERAC_MARK_LOOP_END(id) CALI_CXX_MARK_LOOP_END(id)
85 #define SERAC_MARK_BEGIN(name) CALI_MARK_BEGIN(name)
86 #define SERAC_MARK_END(name) CALI_MARK_END(name)
87 #define SERAC_MARK_SCOPE(name) CALI_CXX_MARK_SCOPE(name)
88 #else
89 // Define no-op macros in case Serac has not been configured with Caliper
90 #define SERAC_MARK_FUNCTION
91 #define SERAC_MARK_LOOP_BEGIN(id, name)
92 #define SERAC_MARK_LOOP_ITERATION(id, i)
93 #define SERAC_MARK_LOOP_END(id)
94 #define SERAC_MARK_BEGIN(name)
95 #define SERAC_MARK_END(name)
96 #define SERAC_MARK_SCOPE(name)
97 #endif
98 
100 namespace serac::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 serac::profiling
profiling namespace
Definition: profiling.cpp:16
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
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