Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Otf2LibWrapper.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Otf2LibWrapper.h (C) 2000-2025 */
9/* */
10/* Class that encapsulates the useful functions of the Otf2 library. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_STD_OTF2LIBWRAPPER_H
13#define ARCANE_STD_OTF2LIBWRAPPER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include "arcane/utils/String.h"
20
21#include "arcane/core/ISubDomain.h"
22
23#include "otf2/otf2.h"
24
25#include <vector>
26#include <set>
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace Arcane
32{
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
42{
43 public:
44
45 Otf2LibWrapper(ISubDomain* sub_domain);
47
48 void init(const String& archive_name);
49 void finalize();
50
51 OTF2_EvtWriter* getEventWriter();
52 uint32_t getEntryPointId(const String& ep_name) const;
53 uint32_t getApplicationNameId() const;
54 uint32_t getSynchronizeId() const;
55 int getMpiRank() const;
56 int getMpiNbRank() const;
57
58 static OTF2_TimeStamp getTime();
59
60 private:
61
62 void _createOtf2Ids();
63 void _buildOtf2ClockAndStringDefinition(uint64_t global_start_time, uint64_t global_end_time);
68
69 static OTF2_FlushType _preFlush(void* user_data, OTF2_FileType file_type, OTF2_LocationRef location, void* caller_data, bool final);
70 static OTF2_TimeStamp _postFlush(void* user_data, OTF2_FileType file_type, OTF2_LocationRef location);
71
72 public:
73
74 // A simple structure to associate an entry point name with an identifier
75 struct EntryPointId
76 {
77 EntryPointId(String name, Integer id)
78 : m_name(name)
79 , m_id(id)
80 {}
81 String m_name;
82 Integer m_id;
83 // Functor to allow "heterogeneous lookup" from name to ID
85 {
86 using is_transparent = void;
87 bool operator()(const EntryPointId& lhs, const EntryPointId& rhs) const
88 {
89 return lhs.m_name < rhs.m_name;
90 }
91 bool operator()(const String& name, const EntryPointId& ep_id) const
92 {
93 return name < ep_id.m_name;
94 }
95 bool operator()(const EntryPointId& ep_id, const String& name) const
96 {
97 return ep_id.m_name < name;
98 }
99 };
100 };
101
102 private:
103
104 // Internal structure for managing indices and offsets...
106 {
107 uint32_t m_desc_offset; // Offset for descriptions of MPI operation names
108 uint32_t m_empty_id; // ID for the empty string
109 uint32_t m_thread_id; // ID for the CPU thread name mapped to the MPI process
110 uint32_t m_hostname_id; // ID for the machine name
111 uint32_t m_class_id; // ID for the machine class
112 uint32_t m_comm_world_id; // ID for the MPI_COMM_WOLRD
113 uint32_t m_mpi_id; // ID for the MPI string
114 uint32_t m_comm_id; // ID for the MPI paradigm string
115 uint32_t m_win_id; // ID for the MPI paradigm string
116 uint32_t m_comm_self_id; // ID for the "comme self" string
117 uint32_t m_ep_id; // ID for the Entry Point string
118 uint32_t m_sync_id; // ID for the Synchronize string
119 uint32_t m_app_name; // ID for the application name
120 uint32_t m_rank_offset; // Offset for MPI ranks
121 std::set<EntryPointId, EntryPointId::EntryPointIdCompare> m_ep_id_set;
122 // Set of entry point names and their IDs
123 };
124
125 ISubDomain* m_sub_domain = nullptr;
126 OTF2_Archive* m_archive = nullptr;
127 OTF2_FlushCallbacks m_flush_callbacks;
128 OTF2_EvtWriter* m_evt_writer = nullptr;
129 uint64_t m_evt_nb = 0;
130 OTF2_GlobalDefWriter* m_global_def_writer = nullptr;
131 static uint64_t s_epoch_start;
132 InternalIds m_id;
133 std::vector<uint64_t> m_comm_members;
134};
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
139} // namespace Arcane
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144#endif
Declarations of types for the 'base' component of Arccore.
Interface of the subdomain manager.
Definition ISubDomain.h:75
Otf2LibWrapper(ISubDomain *sub_domain)
Constructor.
void _buildOtf2ClockAndStringDefinition(uint64_t global_start_time, uint64_t global_end_time)
static uint64_t s_epoch_start
Static member.
void init(const String &archive_name)
Initialization method. Allows defining the path where the archive will be found, as well as its name.
void _buildOtf2ParadigmAndSystemDefinition()
uint32_t getApplicationNameId() const
Helper for the application name.
OTF2_EvtWriter * getEventWriter()
int getMpiNbRank() const
Helper for the number of MPI ranks.
void _buildOtf2LocationDefinition()
Internal method to write the system definition associated with the otf2 archive.
static OTF2_TimeStamp getTime()
Internal static method to retrieve the timestamp.
void finalize()
Method to call to finalize the archive creation (i.e., we no longer want to record events).
static OTF2_TimeStamp _postFlush(void *user_data, OTF2_FileType file_type, OTF2_LocationRef location)
Internal static method to set the callback to be called after the event is recorded.
static OTF2_FlushType _preFlush(void *user_data, OTF2_FileType file_type, OTF2_LocationRef location, void *caller_data, bool final)
Internal static method to set the callback to be called before the event is recorded.
int getMpiRank() const
Helper for the MPI rank number.
uint32_t getEntryPointId(const String &ep_name) const
Helper for the ID of an entry point via its name.
uint32_t getSynchronizeId() const
Helper for the string "synchronize".
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.