Skip to content
Snippets Groups Projects
Commit fcfd0eb4 authored by Christoph Grüninger's avatar Christoph Grüninger
Browse files

[!737] Add copy-constructor and copy-assign to VariableSizeCommunicator

Merge branch 'feature/variablesizecomm-copy' into 'master'

ref:core/dune-common This basically implements the rule of 3, as we have a
custom destructor. Without this patch, copying a VariableSizeCommunicator will
lead to double frees.

Supersedes [!690]

See merge request [!737]

  [!690]: gitlab.dune-project.org/NoneNone/merge_requests/690
  [!737]: gitlab.dune-project.org/core/dune-common/merge_requests/737
parents 13411d62 2652f929
No related branches found
No related tags found
1 merge request!737Add copy-constructor and copy-assign to VariableSizeCommunicator
Pipeline #23086 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.
Finish editing this message first!
Please register or to comment