Commit 2652f929 authored by Lasse Hinrichsen's avatar Lasse Hinrichsen Committed by Christoph Grüninger

Add copy-constructor and copy-assign to VariableSizeCommunicator

This basically implements the rule of 3, as we have a custom destructor.
Without this patch, copying a VariableSizeCommunicator will lead to double frees.
parent 13411d62
Pipeline #23082 passed with stage
in 5 minutes and 49 seconds
......@@ -392,6 +392,31 @@ public:
MPI_Comm_free(&communicator_);
}
/**
* @brief Copy-constructs a communicator
* @param other VariableSizeCommunicator that is copied.
*/
VariableSizeCommunicator(const VariableSizeCommunicator& other) {
maxBufferSize_ = other.maxBufferSize_;
interface_ = other.interface_;
MPI_Comm_dup(other.communicator_, &communicator_);
}
/**
* @brief Copy-assignes a communicator
* @param other VariableSizeCommunicator that is copied.
*/
VariableSizeCommunicator& operator=(const VariableSizeCommunicator& other) {
if(this == &other) // don't do anything if objects are the same
return *this;
maxBufferSize_ = other.maxBufferSize_;
interface_ = other.interface_;
MPI_Comm_free(&communicator_);
MPI_Comm_dup(other.communicator_, &communicator_);
return *this;
}
/**
* @brief Communicate forward.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment