Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lmp): apply NEIGHMASK to neighbor list #4269

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion source/api_c/include/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C" {
/** C API version. Bumped whenever the API is changed.
* @since API version 22
*/
#define DP_C_API_VERSION 22
#define DP_C_API_VERSION 23

/**
* @brief Neighbor list.
Expand Down Expand Up @@ -68,6 +68,16 @@ extern DP_Nlist* DP_NewNlist_comm(int inum_,
int* recvproc,
void* world);

/*
* @brief Set mask for a neighbor list.
*
* @param nl Neighbor list.
* @param mask mask.
* @since API version 23
*
**/
extern void DP_NlistSetMask(DP_Nlist* nl, int mask);

/**
* @brief Delete a neighbor list.
*
Expand Down
4 changes: 4 additions & 0 deletions source/api_c/include/deepmd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ struct InputNlist {
int *numneigh;
/// @brief Array stores the core region atom's neighbor index
int **firstneigh;
/**
* @brief Set mask for this neighbor list.
*/
void set_mask(int mask) { DP_NlistSetMask(nl, mask); };
};

/**
Expand Down
1 change: 1 addition & 0 deletions source/api_c/src/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ DP_Nlist* DP_NewNlist_comm(int inum_,
DP_Nlist* new_nl = new DP_Nlist(nl);
return new_nl;
}
void DP_NlistSetMask(DP_Nlist* nl, int mask) { nl->nl.set_mask(mask); }
void DP_DeleteNlist(DP_Nlist* nl) { delete nl; }

DP_DeepPot::DP_DeepPot() {}
Expand Down
3 changes: 3 additions & 0 deletions source/api_cc/src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ void deepmd::NeighborListData::copy_from_nlist(const InputNlist& inlist) {
int jnum = inlist.numneigh[ii];
jlist[ii].resize(jnum);
memcpy(&jlist[ii][0], inlist.firstneigh[ii], jnum * sizeof(int));
for (int jj = 0; jj < jnum; ++jj) {
jlist[ii][jj] &= inlist.mask;
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions source/lib/include/neighbor_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct InputNlist {
int* recvproc;
/// MPI_comm data in lmp
void* world;
/// mask to the neighbor index
int mask = 0xFFFFFFFF;
InputNlist()
: inum(0),
ilist(NULL),
Expand Down Expand Up @@ -93,6 +95,10 @@ struct InputNlist {
recvproc(recvproc),
world(world) {};
~InputNlist() {};
/**
* @brief Set mask for this neighbor list.
*/
void set_mask(int mask_) { mask = mask_; };
};

/**
Expand Down
1 change: 1 addition & 0 deletions source/lmp/compute_deeptensor_atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void ComputeDeeptensorAtom::compute_peratom() {
neighbor->build_one(list);
deepmd_compat::InputNlist lmp_list(list->inum, list->ilist, list->numneigh,
list->firstneigh);
lmp_list.set_mask(NEIGHMASK);

// declare outputs
std::vector<VALUETYPE> gtensor, force, virial, atensor, avirial;
Expand Down
1 change: 1 addition & 0 deletions source/lmp/fix_dplr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ void FixDPLR::pre_force(int vflag) {
NeighList *list = pair_deepmd->list;
deepmd_compat::InputNlist lmp_list(list->inum, list->ilist, list->numneigh,
list->firstneigh);
lmp_list.set_mask(NEIGHMASK);
// declear output
vector<FLOAT_PREC> tensor;
// compute
Expand Down
2 changes: 2 additions & 0 deletions source/lmp/pair_deepmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@
commdata_->nswap, commdata_->sendnum, commdata_->recvnum,
commdata_->firstrecv, commdata_->sendlist, commdata_->sendproc,
commdata_->recvproc, &world);
lmp_list.set_mask(NEIGHMASK);
deepmd_compat::InputNlist extend_lmp_list;
if (atom->sp_flag) {
extend(extend_inum, extend_ilist, extend_numneigh, extend_neigh,
Expand All @@ -574,6 +575,7 @@
extend_lmp_list =
deepmd_compat::InputNlist(extend_inum, &extend_ilist[0],
&extend_numneigh[0], &extend_firstneigh[0]);
extend_lmp_list.set_mask(NEIGHMASK);

Check warning on line 578 in source/lmp/pair_deepmd.cpp

View check run for this annotation

Codecov / codecov/patch

source/lmp/pair_deepmd.cpp#L578

Added line #L578 was not covered by tests
}
if (single_model || multi_models_no_mod_devi) {
// cvflag_atom is the right flag for the cvatom matrix
Expand Down