// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LGPL-2.1-or-later #ifndef DUNE_UGGRID_PARALLEL_PPIF_PPIFCONTEXT_HH #define DUNE_UGGRID_PARALLEL_PPIF_PPIFCONTEXT_HH 1 #include #include #if ModelP # include #endif #include namespace PPIF { /** * context object for low-level parallel communication */ class PPIFContext { public: /** * constructor. * * By default `MPI_COMM_WORLD` is used for communication. * * \note This is a MPI collective operation (invokes `MPI_Comm_dup`) */ PPIFContext(); /** * destructor * * \note This is a MPI collective operation (invokes `MPI_Comm_free`) */ ~PPIFContext(); /** * our rank; in the interval [0, procs) */ int me() const { return me_; } /** * rank of the master process (usually 0) */ int master() const { return master_; } /** * returns `true` if local process is master */ bool isMaster() const { return me() == master(); } /** * number of processes */ int procs() const { return procs_; } protected: int me_ = 0; int master_ = 0; int procs_ = 1; #if ModelP || DOXYGEN public: /** * maximum number of downtree nodes max * log2(P) */ static const int MAXT = 15; /** * constructor. * * \note This is a MPI collective operation (invokes `MPI_Comm_dup`) */ explicit PPIFContext(const MPI_Comm& comm); /** * MPI communicator */ MPI_Comm comm() const { return comm_; } int dimX() const { return dims_[0]; } int dimY() const { return dims_[1]; } int dimZ() const { return dims_[2]; } /** * degree of downtree nodes */ int degree() const { return degree_; } /** * channel uptree */ VChannelPtr uptree() const { return uptree_; } /** * channels downtree (may be empty) */ const std::array& downtree() const { return downtree_; } /** * number of processors in subtree */ const std::array& slvcnt() const { return slvcnt_; } protected: MPI_Comm comm_ = MPI_COMM_NULL; std::array dims_ = {{1, 1, 1}}; int degree_ = 0; VChannelPtr uptree_ = nullptr; std::array downtree_ = {}; std::array slvcnt_ = {}; friend void InitPPIF(PPIFContext&); friend void ExitPPIF(PPIFContext&); #endif }; } /* namespace PPIF */ #endif