Skip to content
Snippets Groups Projects
Commit 2652f929 authored by Lasse Hinrichsen-Bischoff's avatar Lasse Hinrichsen-Bischoff Committed by Christoph Grüninger
Browse files

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
No related branches found
No related tags found
1 merge request!737Add copy-constructor and copy-assign to VariableSizeCommunicator
Pipeline #23082 passed
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment