2.2 (revision 4737)
|
This is a example of how to use the OTF2 reading interface with MPI. It shows how to define and register callbacks and how to use the provided MPI collective callbacks to read all events of a given OTF2 archive in parallel. This example is available as source code in the file otf2_mpi_reader_example.c .
We start with inclusion of some standard headers.
And than include the MPI and OTF2 header.
Now prepare the inclusion of the <otf2/OTF2_MPI_Collectives.h> header. As it is a header-only interface, it needs some information about the used MPI environment. In particular the MPI datatypes which match the C99 types uint64_t
and int64_t
. In case you have a MPI 3.0 conforming MPI implementation you can skip this. If not, provide #define's for the following macros prior the #include statement. In this example, we assume a LP64 platform.
After this preparatory step, we can include the <otf2/OTF2_MPI_Collectives.h> header.
The following section until describing main
is the same as in the Usage in reading mode - a simple example.
Define an event callback for entering and leaving a region.
The global definition file provides all location IDs that are included in the OTF2 trace archive. When reading the global definitions these location IDs must be collected and stored by the user. Probably, the easiest way to do that is to use a C++ container.
Now everything is prepared to begin with the main program.
First initialize the MPI environment and query the size and rank.
Create a new reader handle. The path to the OTF2 anchor file must be provided as argument.
Now we provide the OTF2 reader object the MPI collectives.
OTF2 provides an API to query the number of locations prior reading the global definitions. We use this to pre-allocate the storage for all locations.
All ranks need to read the global definitions to know the list of locations in the trace. Get a global definition reader with the above reader handle as argument.
Register the above defined global definition callbacks. All other definition callbacks will be deactivated. And instruct the reader to pass the locations object to each call of the callbacks.
Read all global definitions. Every time a location definition is read, the previously registered callback is triggered. In definitions_read
the number of read definitions is returned.
After reading all global definitions all location IDs are stored in the generic container ListOfLocations
. After that, the locations that are supposed to be read are selected. We distribute the locations round-robin to all ranks in MPI_COMM_WORLD
. We need also to remember, whether this rank actually reads any locations.
When the locations are selected the according event and definition files can be opened. Note that the local definition files are optional, thus we need to remember the success of this call.
When the files are opened the event and definition reader handle can be requested. We distribute the locations round-robin to all ranks in MPI_COMM_WORLD
. To apply mapping tables stored in the local definitions, the local definitions must be read. Though the existence of these files are optional. The call to OTF2_Reader_GetEvtReader is mandatory, but the result is unused.
The definition files can now be closed, if it was successfully opened in the first place.
Only these ranks which actually read events for locations, can now open a new global event reader. This global reader automatically contains all previously opened local event readers.
Register the above defined global event callbacks. All other global event callbacks will be deactivated.
Read all events in the OTF2 archive. The events are automatically ordered by the time they occurred in the trace. Every time an enter or leave event is read, the previously registered callbacks are triggered. In events_read
the number of read events is returned.
The global event reader can now be closed and the event files too.
As the call to OTF2_Reader_CloseEvtFiles is a collective operation all ranks need to call this, not only those which read events.
At the end, close the reader and exit. All opened event and definition readers are closed automatically. Free resources and finalize the MPI environment.
To compile your program use a command like the following. Note that we need to activate the C99 standard explicitly for GCC.
Now you can link your program with: