10#include "CollectiveCommunication.h"
42 if (_communicationInitiated) {
43 MPI_Wait(_request.get(), MPI_STATUS_IGNORE);
46 if (_agglomeratedTypeAddOperator != MPI_OP_NULL) {
47 MPI_CHECK(MPI_Op_free(&_agglomeratedTypeAddOperator));
56 if (_communicationInitiated) {
66 if (_communicationInitiated) {
69 std::vector<valType> toSendValues =
_values;
73 initAllreduceSum(toSendValues);
75 std::vector<valType> previous = _tempValues;
86 void init(MPI_Comm communicator,
int numValues,
int key = 0)
override {
90 mardyn_assert(
static_cast<int>(
_values.size()) == numValues);
113 void waitAndUpdateData() {
114 MPI_CHECK(MPI_Wait(_request.get(), MPI_STATUS_IGNORE));
118 _communicationInitiated =
false;
122 void initAllreduceSum(std::vector<valType> values) {
126 _tempValues = values;
127#if ENABLE_AGGLOMERATED_REDUCE
131 const int commutative = 1;
132 valType * startOfValues = &(_tempValues[0]);
133 if (_agglomeratedTypeAddOperator == MPI_OP_NULL) {
136 &_agglomeratedTypeAddOperator));
140 _communicationInitiated =
true;
142 for(
unsigned int i = 0; i <
_types.size(); i++ ) {
149 std::unique_ptr<MPI_Request> _request{
new MPI_Request()};
150 MPI_Op _agglomeratedTypeAddOperator{MPI_OP_NULL};
151 bool _communicationInitiated{
false};
152 bool _valuesValid{
false};
154 std::vector<valType> _tempValues;
155 bool _firstComm{
true};
virtual void finalize() override
delete memory and MPI_Type
Definition: CollectiveCommBase.h:152
std::vector< valType > _values
Vector to store the values which shall be communicated.
Definition: CollectiveCommBase.h:162
Definition: CollectiveCommunicationSingleNonBlocking.h:17
void allreduceSumAllowPrevious() override
Definition: CollectiveCommunicationSingleNonBlocking.h:54
CollectiveCommunicationSingleNonBlocking()=default
CollectiveCommunicationSingleNonBlocking(const CollectiveCommunicationSingleNonBlocking &)=delete
~CollectiveCommunicationSingleNonBlocking() override
Definition: CollectiveCommunicationSingleNonBlocking.h:40
void init(MPI_Comm communicator, int numValues, int key=0) override
allocate memory for the values to be sent, initialize counters
Definition: CollectiveCommunicationSingleNonBlocking.h:86
CollectiveCommunicationSingleNonBlocking & operator=(const CollectiveCommunicationSingleNonBlocking &)=delete
void finalize() override
delete memory and MPI_Type
Definition: CollectiveCommunicationSingleNonBlocking.h:96
This class is used to transfer several values of different types with a single command.
Definition: CollectiveCommunication.h:65
void setMPIType()
defines a MPI datatype which can be used to transfer a CollectiveCommunication object
Definition: CollectiveCommunication.h:245
MPI_Comm _communicator
Communicator to be used by the communication commands.
Definition: CollectiveCommunication.h:399
virtual void init(MPI_Comm communicator, int numValues, int key=0) override
allocate memory for the values to be sent, initialize counters
Definition: CollectiveCommunication.h:78
void allreduceSum() override
Performs an all-reduce (sum)
Definition: CollectiveCommunication.h:142
std::vector< MPI_Datatype > _types
Vector of the corresponding MPI types for the values stored in _values.
Definition: CollectiveCommunication.h:392
MPI_Datatype _agglomeratedType
Definition: CollectiveCommunication.h:396
static void add(valType *invec, valType *inoutvec, int *, MPI_Datatype *dtype)
method used by MPI to add variables of this type
Definition: CollectiveCommunication.h:277