Skip to content

Commit 553a09d

Browse files
author
Fei Yang
committed
fix: preserve MDCell build and MPI ownership
1 parent cea80b8 commit 553a09d

5 files changed

Lines changed: 64 additions & 0 deletions

File tree

source/Makefile.Objects

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ OBJS_CELL=atom_pseudo.o\
210210
read_pseudo.o\
211211
cal_wfc.o\
212212
cal_ux.o\
213+
distributed_mdcell_reader.o\
214+
md_cell.o\
213215

214216
OBJS_DEEPKS=LCAO_deepks.o\
215217
deepks_basic.o\

source/source_cell/md_cell.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class MDCell : public BaseCell
3434
{
3535
public:
3636
MDCell(UnitCell& ucell, double cutoff, double skin);
37+
MDCell(const MDCell&) = delete;
38+
MDCell& operator=(const MDCell&) = delete;
39+
MDCell(MDCell&&) = default;
40+
MDCell& operator=(MDCell&&) = default;
41+
3742
MDCell(const ModuleBase::Matrix3& latvec,
3843
const ModuleBase::Matrix3& gt,
3944
double lat0,

source/source_cell/module_neighlist/domain_decomposition.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,55 @@ DomainDecomposition::~DomainDecomposition()
4040
}
4141
}
4242

43+
DomainDecomposition::DomainDecomposition(DomainDecomposition&& other) noexcept
44+
: comm_(other.comm_),
45+
cart_comm_(other.cart_comm_),
46+
owns_cart_comm_(other.owns_cart_comm_),
47+
rank_(other.rank_),
48+
size_(other.size_),
49+
dims_(other.dims_),
50+
coords_(other.coords_),
51+
margin_(other.margin_),
52+
latvec_(other.latvec_),
53+
inv_latvec_(other.inv_latvec_),
54+
lat0_(other.lat0_),
55+
cutoff_(other.cutoff_),
56+
skin_(other.skin_)
57+
{
58+
other.comm_ = MPI_COMM_NULL;
59+
other.cart_comm_ = MPI_COMM_NULL;
60+
other.owns_cart_comm_ = false;
61+
}
62+
63+
DomainDecomposition& DomainDecomposition::operator=(DomainDecomposition&& other) noexcept
64+
{
65+
if (this != &other)
66+
{
67+
if (owns_cart_comm_ && cart_comm_ != MPI_COMM_NULL)
68+
{
69+
MPI_Comm_free(&cart_comm_);
70+
}
71+
comm_ = other.comm_;
72+
cart_comm_ = other.cart_comm_;
73+
owns_cart_comm_ = other.owns_cart_comm_;
74+
rank_ = other.rank_;
75+
size_ = other.size_;
76+
dims_ = other.dims_;
77+
coords_ = other.coords_;
78+
margin_ = other.margin_;
79+
latvec_ = other.latvec_;
80+
inv_latvec_ = other.inv_latvec_;
81+
lat0_ = other.lat0_;
82+
cutoff_ = other.cutoff_;
83+
skin_ = other.skin_;
84+
85+
other.comm_ = MPI_COMM_NULL;
86+
other.cart_comm_ = MPI_COMM_NULL;
87+
other.owns_cart_comm_ = false;
88+
}
89+
return *this;
90+
}
91+
4392
double DomainDecomposition::wrap_fractional(double value)
4493
{
4594
value -= std::floor(value);

source/source_cell/module_neighlist/domain_decomposition.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class DomainDecomposition
2626
public:
2727
DomainDecomposition();
2828
~DomainDecomposition();
29+
DomainDecomposition(const DomainDecomposition&) = delete;
30+
DomainDecomposition& operator=(const DomainDecomposition&) = delete;
31+
DomainDecomposition(DomainDecomposition&& other) noexcept;
32+
DomainDecomposition& operator=(DomainDecomposition&& other) noexcept;
2933

3034
void init(MPI_Comm comm,
3135
const ModuleBase::Matrix3& latvec,

source/source_cell/module_neighlist/test/distributed_mdcell_reader_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include <mpi.h>
1010
#include <set>
1111
#include <string>
12+
#include <type_traits>
13+
14+
static_assert(!std::is_copy_constructible<MDCell>::value,
15+
"MDCell must not copy MPI communicator ownership.");
1216

1317
namespace
1418
{

0 commit comments

Comments
 (0)