Skip to content

Commit

Permalink
c: change the required shape of electric field to nloc * 3
Browse files Browse the repository at this point in the history
A segfault sometimes appears in the tests after deepmodeling#3223. The reason is that the required shape of electric field is set to nall * 3 in the C interface, but a vector of nloc * 3 is actually given in the tests and lammps and used in the C++ interface. It's only found by sanitizer as the program doesn't write to the invalid address (only reading it won't cause segfault).

Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz committed Feb 5, 2024
1 parent f5bb131 commit 37c19cc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions source/api_c/include/deepmd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1965,13 +1965,13 @@ class DipoleChargeModifier {
* @param[out] dfcorr_ The force correction on each atom.
* @param[out] dvcorr_ The virial correction.
* @param[in] dcoord_ The coordinates of atoms. The array should be of size
*natoms x 3.
* @param[in] datype_ The atom types. The list should contain natoms ints.
*nall x 3.
* @param[in] datype_ The atom types. The list should contain nall ints.
* @param[in] dbox The cell of the region. The array should be of size 9.
* @param[in] pairs The pairs of atoms. The list should contain npairs pairs
*of ints.
* @param[in] delef_ The electric field on each atom. The array should be of
*size natoms x 3.
*size nghost x 3.
* @param[in] nghost The number of ghost atoms.
* @param[in] lmp_list The neighbor list.
**/
Expand Down
2 changes: 1 addition & 1 deletion source/api_c/src/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ inline void DP_DipoleChargeModifierComputeNList_variant(
for (int i = 0; i < npairs; i++) {
pairs_.push_back(std::make_pair(pairs[i * 2], pairs[i * 2 + 1]));
}
std::vector<VALUETYPE> delef_(delef, delef + natoms * 3);
std::vector<VALUETYPE> delef_(delef, delef + (natoms - nghost) * 3);
std::vector<VALUETYPE> df, dv;

DP_REQUIRES_OK(dcm, dcm->dcm.compute(df, dv, coord_, atype_, cell_, pairs_,
Expand Down
6 changes: 3 additions & 3 deletions source/api_cc/include/DataModifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ class DipoleChargeModifier {
* @param[out] dfcorr_ The force correction on each atom.
* @param[out] dvcorr_ The virial correction.
* @param[in] dcoord_ The coordinates of atoms. The array should be of size
*natoms x 3.
* @param[in] datype_ The atom types. The list should contain natoms ints.
*nall x 3.
* @param[in] datype_ The atom types. The list should contain nall ints.
* @param[in] dbox The cell of the region. The array should be of size 9.
* @param[in] pairs The pairs of atoms. The list should contain npairs pairs
*of ints.
* @param[in] delef_ The electric field on each atom. The array should be of
*size natoms x 3.
*size nloc x 3.
* @param[in] nghost The number of ghost atoms.
* @param[in] lmp_list The neighbor list.
**/
Expand Down
6 changes: 3 additions & 3 deletions source/api_cc/include/DataModifierTF.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class DipoleChargeModifierTF : public DipoleChargeModifierBase {
* @param[out] dfcorr_ The force correction on each atom.
* @param[out] dvcorr_ The virial correction.
* @param[in] dcoord_ The coordinates of atoms. The array should be of size
*natoms x 3.
* @param[in] datype_ The atom types. The list should contain natoms ints.
*nall x 3.
* @param[in] datype_ The atom types. The list should contain nall ints.
* @param[in] dbox The cell of the region. The array should be of size 9.
* @param[in] pairs The pairs of atoms. The list should contain npairs pairs
*of ints.
* @param[in] delef_ The electric field on each atom. The array should be of
*size natoms x 3.
*size nloc x 3.
* @param[in] nghost The number of ghost atoms.
* @param[in] lmp_list The neighbor list.
**/
Expand Down

0 comments on commit 37c19cc

Please sign in to comment.