|
Gromacs
2026.0-dev-20251119-5f0a571d
|
#include <gromacs/utility/mpicomm.h>
MPI communicator with optimized reduction functionality.
This class refers to an MPI communicator and derived data and provides summation reductions that can be hierarchical.
Classes | |
| struct | SingleRank |
| Helper type to differentiate single-rank constructor. More... | |
Public Member Functions | |
| MpiComm (MPI_Comm comm) | |
Constructs an object for MPI communicator comm. | |
| MpiComm (SingleRank) | |
| Constructs a communicator with a single rank. More... | |
| MpiComm (const MpiComm &other) | |
| Copy constructor. | |
| MpiComm (MpiComm &&other)=delete | |
| Move constructor. | |
| ~MpiComm () | |
| Destructor. | |
| MpiComm & | operator= (const MpiComm &other) |
| Copy assignment. | |
| MpiComm & | operator= (MpiComm &&other) noexcept |
| Move assignment. | |
| MPI_Comm | comm () const |
| int | size () const |
| Returns the number of ranks in the communicator. | |
| bool | isSerial () const |
Returns true when size() == 1. | |
| bool | isParallel () const |
Returns true when size() > 1. | |
| int | rank () const |
| Returns our rank id in the communicator. | |
| bool | isMainRank () const |
| Returns whether our rank is the main rank. | |
| int | mainRank () const |
| Returns the rank id of the main rank. | |
| void | initializeHierarchicalReductions (int physicalNodeIdHash) |
| Initializes hierarchical reductions. More... | |
| std::optional< std::string > | getHierarchicalReductionsReport () const |
| Returns a string describing the hierarchical reduction, when it is active. | |
| void | sumReduce (ArrayRef< int > data) const |
| Reduce ints over all ranks, results on all ranks, can use hierarchical reduction. | |
| void | sumReduce (ArrayRef< float > data) const |
| Reduce floats over all ranks, results on all ranks, can use hierarchical reduction. | |
| void | sumReduce (ArrayRef< double > data) const |
| Reduce doubles over all ranks, results on all ranks, can use hierarchical reduction. | |
| void | sumReduce (std::size_t nr, int *data) const |
| Reduce ints over all ranks, results on all ranks, can use hierarchical reduction. | |
| void | sumReduce (std::size_t nr, float *data) const |
| Reduce floats over all ranks, results on all ranks, can use hierarchical reduction. | |
| void | sumReduce (std::size_t nr, double *data) const |
| Reduce doubles over all ranks, results on all ranks, can use hierarchical reduction. | |
| std::vector< std::string > | collectStrings (std::string_view myString) const |
| Collect strings from all ranks onto the main. | |
| gmx::MpiComm::MpiComm | ( | SingleRank | ) |
Constructs a communicator with a single rank.
comm() method will return MPI_COMM_NULL. This communicator should not be passed to MPI calls. Thus any code that might take an MpiComm object constructed by this constructor should check for size() > 1 before calling MPI calls. Note that the sumReduce() methods of this class are safe to call. | void gmx::MpiComm::initializeHierarchicalReductions | ( | int | physicalNodeIdHash | ) |
Initializes hierarchical reductions.
When running on system with many nodes, it can be faster to reduce within nodes first and the reduce over nodes using one rank per node. This method initializes such hierarchical reductions. The request is only granted when there is actually such a hierarchy and then is a sufficient number of ranks involved. When that is the case, all later calls to sumReduce() will use hierarchical redution. When not, a single reduction will be used.
| physicalNodeIdHash | An integer that should be unique for each physical node |
1.8.5