Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
profiling.cpp
1 // Copyright (c) 2019-2024, 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 
8 
10 
11 #ifdef SERAC_USE_CALIPER
12 #include <optional>
13 #endif
14 
15 namespace serac::profiling {
16 
17 #ifdef SERAC_USE_CALIPER
18 namespace {
19 std::optional<cali::ConfigManager> mgr;
20 } // namespace
21 #endif
22 
23 void initialize([[maybe_unused]] MPI_Comm comm, [[maybe_unused]] std::string options)
24 {
25 #ifdef SERAC_USE_ADIAK
26  // Initialize Adiak
27  adiak::init(&comm);
28 
29  adiak::launchdate();
30  adiak::executable();
31  adiak::cmdline();
32  adiak::clustername();
33  adiak::jobsize();
34  adiak::walltime();
35  adiak::cputime();
36  adiak::systime();
37 #endif
38 
39 #ifdef SERAC_USE_CALIPER
40  // Initialize Caliper
41  mgr = cali::ConfigManager();
42  auto check_result = mgr->check(options.c_str());
43 
44  if (check_result.empty()) {
45  mgr->add(options.c_str());
46  } else {
47  SLIC_WARNING_ROOT("Caliper options invalid, ignoring: " << check_result);
48  }
49 
50  // Defaults, should probably always be enabled
51  mgr->add("runtime-report,spot");
52  mgr->start();
53 #endif
54 }
55 
56 void finalize()
57 {
58 #ifdef SERAC_USE_ADIAK
59  // Finalize Adiak
60  adiak::fini();
61 #endif
62 
63 #ifdef SERAC_USE_CALIPER
64  // Finalize Caliper
65  if (mgr) {
66  mgr->stop();
67  mgr->flush();
68  }
69 
70  mgr.reset();
71 #endif
72 }
73 
75 namespace detail {
76 
77 void startCaliperRegion([[maybe_unused]] const char* name)
78 {
79 #ifdef SERAC_USE_CALIPER
80  CALI_MARK_BEGIN(name);
81 #endif
82 }
83 
84 void endCaliperRegion([[maybe_unused]] const char* name)
85 {
86 #ifdef SERAC_USE_CALIPER
87  CALI_MARK_END(name);
88 #endif
89 }
90 
91 } // namespace detail
93 } // namespace serac::profiling
This file contains the all the necessary functions and macros required for logging as well as a helpe...
void endCaliperRegion(const char *name)
Caliper methods for marking the end of a region.
void startCaliperRegion(const char *name)
Caliper method for marking the start of a profiling region.
profiling namespace
Definition: profiling.cpp:15
void finalize()
Concludes performance monitoring and writes collected data to a file.
Definition: profiling.cpp:56
void initialize([[maybe_unused]] MPI_Comm comm, [[maybe_unused]] std::string options)
Initializes performance monitoring using the Caliper and Adiak libraries.
Definition: profiling.cpp:23
Various helper functions and macros for profiling using Caliper.