Skip to content

Commit 95f0ed5

Browse files
authored
fix(lmp): apply NEIGHMASK to neighbor list (#4269)
Fix #4250. See lammps/lammps#581 (comment) for an explanation of `NEIGHMASK`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Introduced a new function to set a mask for neighbor lists, enhancing configurability. - Added a method to the `InputNlist` structure for setting the mask. - Enhanced `ComputeDeeptensorAtom` and `FixDPLR` classes to utilize neighbor list masks in computations. - **Bug Fixes** - Improved validation of bonded pairs in the `FixDPLR` class with enhanced error handling. - **Documentation** - Updated documentation for new methods and functionalities related to neighbor list management. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
1 parent 40b3ea1 commit 95f0ed5

File tree

8 files changed

+29
-1
lines changed

8 files changed

+29
-1
lines changed

source/api_c/include/c_api.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern "C" {
1212
/** C API version. Bumped whenever the API is changed.
1313
* @since API version 22
1414
*/
15-
#define DP_C_API_VERSION 22
15+
#define DP_C_API_VERSION 23
1616

1717
/**
1818
* @brief Neighbor list.
@@ -68,6 +68,16 @@ extern DP_Nlist* DP_NewNlist_comm(int inum_,
6868
int* recvproc,
6969
void* world);
7070

71+
/*
72+
* @brief Set mask for a neighbor list.
73+
*
74+
* @param nl Neighbor list.
75+
* @param mask mask.
76+
* @since API version 23
77+
*
78+
**/
79+
extern void DP_NlistSetMask(DP_Nlist* nl, int mask);
80+
7181
/**
7282
* @brief Delete a neighbor list.
7383
*

source/api_c/include/deepmd.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,10 @@ struct InputNlist {
611611
int *numneigh;
612612
/// @brief Array stores the core region atom's neighbor index
613613
int **firstneigh;
614+
/**
615+
* @brief Set mask for this neighbor list.
616+
*/
617+
void set_mask(int mask) { DP_NlistSetMask(nl, mask); };
614618
};
615619

616620
/**

source/api_c/src/c_api.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ DP_Nlist* DP_NewNlist_comm(int inum_,
4242
DP_Nlist* new_nl = new DP_Nlist(nl);
4343
return new_nl;
4444
}
45+
void DP_NlistSetMask(DP_Nlist* nl, int mask) { nl->nl.set_mask(mask); }
4546
void DP_DeleteNlist(DP_Nlist* nl) { delete nl; }
4647

4748
DP_DeepPot::DP_DeepPot() {}

source/api_cc/src/common.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ void deepmd::NeighborListData::copy_from_nlist(const InputNlist& inlist) {
241241
int jnum = inlist.numneigh[ii];
242242
jlist[ii].resize(jnum);
243243
memcpy(&jlist[ii][0], inlist.firstneigh[ii], jnum * sizeof(int));
244+
for (int jj = 0; jj < jnum; ++jj) {
245+
jlist[ii][jj] &= inlist.mask;
246+
}
244247
}
245248
}
246249

source/lib/include/neighbor_list.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ struct InputNlist {
4242
int* recvproc;
4343
/// MPI_comm data in lmp
4444
void* world;
45+
/// mask to the neighbor index
46+
int mask = 0xFFFFFFFF;
4547
InputNlist()
4648
: inum(0),
4749
ilist(NULL),
@@ -93,6 +95,10 @@ struct InputNlist {
9395
recvproc(recvproc),
9496
world(world) {};
9597
~InputNlist() {};
98+
/**
99+
* @brief Set mask for this neighbor list.
100+
*/
101+
void set_mask(int mask_) { mask = mask_; };
96102
};
97103

98104
/**

source/lmp/compute_deeptensor_atom.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ void ComputeDeeptensorAtom::compute_peratom() {
136136
neighbor->build_one(list);
137137
deepmd_compat::InputNlist lmp_list(list->inum, list->ilist, list->numneigh,
138138
list->firstneigh);
139+
lmp_list.set_mask(NEIGHMASK);
139140

140141
// declare outputs
141142
std::vector<VALUETYPE> gtensor, force, virial, atensor, avirial;

source/lmp/fix_dplr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ void FixDPLR::pre_force(int vflag) {
463463
NeighList *list = pair_deepmd->list;
464464
deepmd_compat::InputNlist lmp_list(list->inum, list->ilist, list->numneigh,
465465
list->firstneigh);
466+
lmp_list.set_mask(NEIGHMASK);
466467
// declear output
467468
vector<FLOAT_PREC> tensor;
468469
// compute

source/lmp/pair_deepmd.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ void PairDeepMD::compute(int eflag, int vflag) {
565565
commdata_->nswap, commdata_->sendnum, commdata_->recvnum,
566566
commdata_->firstrecv, commdata_->sendlist, commdata_->sendproc,
567567
commdata_->recvproc, &world);
568+
lmp_list.set_mask(NEIGHMASK);
568569
deepmd_compat::InputNlist extend_lmp_list;
569570
if (atom->sp_flag) {
570571
extend(extend_inum, extend_ilist, extend_numneigh, extend_neigh,
@@ -574,6 +575,7 @@ void PairDeepMD::compute(int eflag, int vflag) {
574575
extend_lmp_list =
575576
deepmd_compat::InputNlist(extend_inum, &extend_ilist[0],
576577
&extend_numneigh[0], &extend_firstneigh[0]);
578+
extend_lmp_list.set_mask(NEIGHMASK);
577579
}
578580
if (single_model || multi_models_no_mod_devi) {
579581
// cvflag_atom is the right flag for the cvatom matrix

0 commit comments

Comments
 (0)