6 #include <otf2/OTF2_MPI_Collectives.h>
52 spdlog::warn(
"write() has been called on an OTF2TracerDummy; no OTF2 trace file will be written! You may need to install libotf2.");
62 double t = MPI_Wtime() * 1e9;
67 OTF2_FileType fileType,
68 OTF2_LocationRef location,
76 OTF2_FileType fileType,
77 OTF2_LocationRef location )
97 OTF2Tracer(std::string archive_path, std::string archive_name) {
98 MPI_Comm_size( MPI_COMM_WORLD, &
size );
99 MPI_Comm_rank( MPI_COMM_WORLD, &
rank );
100 archive = OTF2_Archive_Open( archive_path.c_str(),
101 archive_name.c_str(),
105 OTF2_SUBSTRATE_POSIX,
106 OTF2_COMPRESSION_NONE );
108 OTF2_MPI_Archive_SetCollectiveCallbacks(
archive,
111 OTF2_Archive_OpenEvtFiles(
archive );
167 OTF2_Archive_CloseEvtFiles(
archive );
168 OTF2_Archive_OpenDefFiles(
archive );
169 OTF2_DefWriter* def_writer = OTF2_Archive_GetDefWriter(
archive,
171 OTF2_Archive_CloseDefWriter(
archive, def_writer );
172 OTF2_Archive_CloseDefFiles(
archive );
173 uint64_t global_epoch_start;
176 1, OTF2_MPI_UINT64_T, MPI_MIN,
178 uint64_t global_epoch_end;
179 MPI_Reduce( &epoch_end,
181 1, OTF2_MPI_UINT64_T, MPI_MAX,
185 OTF2_GlobalDefWriter* global_def_writer = OTF2_Archive_GetGlobalDefWriter(
archive );
186 OTF2_GlobalDefWriter_WriteClockProperties( global_def_writer,
189 global_epoch_end - global_epoch_start + 1 );
190 OTF2_GlobalDefWriter_WriteString( global_def_writer, 0,
"" );
191 OTF2_GlobalDefWriter_WriteString( global_def_writer, 1,
"Master Thread" );
192 OTF2_GlobalDefWriter_WriteString( global_def_writer, 2,
"MPI_Barrier" );
193 OTF2_GlobalDefWriter_WriteString( global_def_writer, 3,
"PMPI_Barrier" );
194 OTF2_GlobalDefWriter_WriteString( global_def_writer, 4,
"barrier" );
195 OTF2_GlobalDefWriter_WriteString( global_def_writer, 5,
"MyHost" );
196 OTF2_GlobalDefWriter_WriteString( global_def_writer, 6,
"node" );
197 OTF2_GlobalDefWriter_WriteString( global_def_writer, 7,
"MPI" );
198 OTF2_GlobalDefWriter_WriteString( global_def_writer, 8,
"MPI_COMM_WORLD" );
203 OTF2_GlobalDefWriter_WriteString( global_def_writer, num_strings, regionNamePair.second.c_str() );
204 OTF2_GlobalDefWriter_WriteRegion( global_def_writer,
205 regionNamePair.first ,
209 OTF2_REGION_ROLE_CODE,
211 OTF2_REGION_FLAG_NONE,
217 OTF2_GlobalDefWriter_WriteSystemTreeNode( global_def_writer,
221 OTF2_UNDEFINED_SYSTEM_TREE_NODE );
223 for (
int r = 0; r <
size; r++ )
225 char process_name[ 32 ];
226 sprintf( process_name,
"MPI Rank %d", r );
227 OTF2_GlobalDefWriter_WriteString( global_def_writer,
230 OTF2_GlobalDefWriter_WriteLocationGroup( global_def_writer,
233 OTF2_LOCATION_GROUP_TYPE_PROCESS,
235 OTF2_GlobalDefWriter_WriteLocation( global_def_writer,
238 OTF2_LOCATION_TYPE_CPU_THREAD,
242 uint64_t comm_locations[
size ];
243 for (
int r = 0; r <
size; r++ )
245 comm_locations[ r ] = r;
247 OTF2_GlobalDefWriter_WriteGroup( global_def_writer,
250 OTF2_GROUP_TYPE_COMM_LOCATIONS,
252 OTF2_GROUP_FLAG_NONE,
255 OTF2_GlobalDefWriter_WriteGroup( global_def_writer,
258 OTF2_GROUP_TYPE_COMM_GROUP,
260 OTF2_GROUP_FLAG_NONE,
263 OTF2_GlobalDefWriter_WriteComm( global_def_writer,
267 OTF2_UNDEFINED_COMM );
268 OTF2_Archive_CloseGlobalDefWriter(
archive,
Base interface for OTF2 tracer implemetations.
virtual void leaveRegion(TracerRegions region)=0
virtual void enterRegion(TracerRegions region)=0
Fallback dummy implementation not doing anything; Does not require libotf2.
void leaveRegion(TracerRegions region) override
OTF2TracerDummy(std::string archive_path, std::string archive_name)
void enterRegion(TracerRegions region) override
Tracer implementation writing to OTF2 via libotf2 The result can be viewed by several programs,...
void enterRegion(TracerRegions region) override
Call this to mark that a certain tracer region has been entered.
void leaveRegion(TracerRegions region) override
Call this to mark that a certain tracer region has been left.
OTF2Tracer(std::string archive_path, std::string archive_name)
void setRegionName(TracerRegions region, std::string name)
void ensureRegionName(TracerRegions region)
Makes sure a region name has been defined, otherwise generates a default region name.
OTF2_EvtWriter * evt_writer
std::map< int, std::string > regionNames
static OTF2_TimeStamp post_flush(void *userData, OTF2_FileType fileType, OTF2_LocationRef location)
static OTF2_FlushCallbacks flush_callbacks
static OTF2_TimeStamp get_time(void)
static OTF2_FlushType pre_flush(void *userData, OTF2_FileType fileType, OTF2_LocationRef location, void *callerData, bool final)
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values