|
| 1 | +// Copyright (c) 2021, Lawrence Livermore National Security, LLC. |
| 2 | +// See top-level LICENSE file for details. |
| 3 | + |
| 4 | +#pragma once |
| 5 | + |
| 6 | +#ifndef CALI_CUSTOM_OUTPUT_CONTROLLER_H |
| 7 | +#define CALI_CUSTOM_OUTPUT_CONTROLLER_H |
| 8 | + |
| 9 | +#include "caliper/ChannelController.h" |
| 10 | + |
| 11 | +#include <string> |
| 12 | + |
| 13 | +namespace cali |
| 14 | +{ |
| 15 | + |
| 16 | +class Aggregator; |
| 17 | +class CaliperMetadataDB; |
| 18 | +class OutputStream; |
| 19 | + |
| 20 | +namespace internal |
| 21 | +{ |
| 22 | + |
| 23 | +/// \brief Base class for a channel controller implementing a custom communication |
| 24 | +/// scheme. |
| 25 | +/// |
| 26 | +/// Lets us switch communication between serial, MPI, and potentially other |
| 27 | +/// communication protocols. |
| 28 | +class CustomOutputController : public cali::ChannelController |
| 29 | +{ |
| 30 | + typedef void (*FlushFn)(CustomOutputController*); |
| 31 | + static FlushFn s_flush_fn; |
| 32 | + |
| 33 | +public: |
| 34 | + |
| 35 | + /// \brief Set the flush function for MPI (or other) communication |
| 36 | + /// protocols. |
| 37 | + /// |
| 38 | + /// This callback lets us specify alternate flush implementations, in |
| 39 | + /// particular for MPI. The MPI build sets this in mpi_setup.cpp. |
| 40 | + static void set_flush_fn(FlushFn); |
| 41 | + |
| 42 | + /// \brief Base class for the communication protocol. Implements serial |
| 43 | + /// (no-op) communication. |
| 44 | + class Comm { |
| 45 | + public: |
| 46 | + |
| 47 | + virtual ~Comm(); |
| 48 | + |
| 49 | + virtual int rank() const; |
| 50 | + |
| 51 | + virtual int bcast_int(int val) const; |
| 52 | + virtual std::string bcast_str(const std::string& str) const; |
| 53 | + |
| 54 | + virtual void cross_aggregate(CaliperMetadataDB& db, Aggregator& agg) const; |
| 55 | + }; |
| 56 | + |
| 57 | + /// \brief Override to implement custom collective flush operation using |
| 58 | + /// \a comm and \a stream. |
| 59 | + virtual void collective_flush(OutputStream& stream, Comm& comm) = 0; |
| 60 | + |
| 61 | + /// \brief Perform default flush (no user-provided comm or stream) |
| 62 | + /// |
| 63 | + /// Invokes s_flush_fn() if set, which in turn invokes the collective_flush() |
| 64 | + /// method overriden by derived classes. The s_flush_fn() specifies the |
| 65 | + /// communication protocol, e.g. MPI. The default implementation is serial. |
| 66 | + virtual void flush() override; |
| 67 | + |
| 68 | + CustomOutputController(const char* name, int flags, const config_map_t& initial_config); |
| 69 | +}; |
| 70 | + |
| 71 | +} // namespace internal |
| 72 | + |
| 73 | +} // namespace cali |
| 74 | + |
| 75 | +#endif |
0 commit comments