| 1 |
/* |
| 2 |
* (C) Copyright 2013 ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <array> |
| 14 |
|
| 15 |
#include "atlas/parallel/mpi/mpi.h" |
| 16 |
#include "atlas/runtime/Trace.h" |
| 17 |
|
| 18 |
#define ATLAS_TRACE_MPI(...) |
| 19 |
|
| 20 |
#if ATLAS_HAVE_TRACE |
| 21 |
|
| 22 |
#include "atlas/library/detail/BlackMagic.h" |
| 23 |
|
| 24 |
#undef ATLAS_TRACE_MPI |
| 25 |
#define ATLAS_TRACE_MPI(...) ATLAS_TRACE_MPI_(::atlas::mpi::Trace, Here(), __VA_ARGS__) |
| 26 |
#define ATLAS_TRACE_MPI_(Type, location, operation, ...) \ |
| 27 |
__ATLAS_TYPE_SCOPE(Type, location, __ATLAS_TRACE_MPI_ENUM(operation) __ATLAS_COMMA_ARGS(__VA_ARGS__)) |
| 28 |
|
| 29 |
#define __ATLAS_TRACE_MPI_ENUM(operation) ::atlas::mpi::Operation::__ATLAS_STRINGIFY(operation) |
| 30 |
|
| 31 |
#endif |
| 32 |
|
| 33 |
namespace atlas { |
| 34 |
namespace mpi { |
| 35 |
|
| 36 |
struct StatisticsTimerTraits { |
| 37 |
using Barriers = runtime::trace::NoBarriers; |
| 38 |
using Tracing = runtime::trace::NoLogging; |
| 39 |
}; |
| 40 |
|
| 41 |
enum class Operation |
| 42 |
{ |
| 43 |
BROADCAST, |
| 44 |
ALLREDUCE, |
| 45 |
ALLGATHER, |
| 46 |
ALLTOALL, |
| 47 |
REDUCE, |
| 48 |
GATHER, |
| 49 |
SCATTER, |
| 50 |
BARRIER, |
| 51 |
SENDRECEIVE, |
| 52 |
ISEND, |
| 53 |
IRECEIVE, |
| 54 |
WAIT, |
| 55 |
_COUNT_ |
| 56 |
}; |
| 57 |
|
| 58 |
static const std::string& name(Operation c) { |
| 59 |
static std::array<std::string, static_cast<size_t>(Operation::_COUNT_)> names{ |
| 60 |
"mpi.broadcast", "mpi.allreduce", "mpi.allgather", "mpi.alltoall", "mpi.reduce", "mpi.gather", |
| 61 |
"mpi.scatter", "mpi.barrier", "mpi.sendreceive", "mpi.isend", "mpi.ireceive", "mpi.wait"}; |
| 62 |
return names[static_cast<size_t>(c)]; |
| 63 |
} |
| 64 |
|
| 65 |
class Trace : public runtime::trace::TraceT<StatisticsTimerTraits> { |
| 66 |
using Base = runtime::trace::TraceT<StatisticsTimerTraits>; |
| 67 |
|
| 68 |
public: |
| 69 |
Trace(const eckit::CodeLocation& loc, Operation c): Base(loc, name(c), make_labels(c)) {} |
| 70 |
Trace(const eckit::CodeLocation& loc, Operation c, const std::string& title): Base(loc, title, make_labels(c)) {} |
| 71 |
|
| 72 |
private: |
| 73 |
static std::vector<std::string> make_labels(Operation c) { return {"mpi", name(c)}; } |
| 74 |
}; |
| 75 |
|
| 76 |
} // namespace mpi |
| 77 |
} // namespace atlas |