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(c): call C++ interface without atomic properties when they are not requested #4010

Merged
merged 2 commits into from
Jul 26, 2024
Merged
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
53 changes: 42 additions & 11 deletions source/api_c/src/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,13 @@ inline void DP_DeepPotCompute_variant(DP_DeepPot* dp,
std::vector<double> e;
std::vector<VALUETYPE> f, v, ae, av;

DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_,
fparam_, aparam_));
if (atomic_energy || atomic_virial) {
DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_,
fparam_, aparam_));
} else {
DP_REQUIRES_OK(
dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, fparam_, aparam_));
}
// copy from C++ vectors to C arrays, if not NULL pointer
if (energy) {
std::copy(e.begin(), e.end(), energy);
Expand Down Expand Up @@ -286,8 +291,14 @@ inline void DP_DeepPotComputeNList_variant(DP_DeepPot* dp,
std::vector<double> e;
std::vector<VALUETYPE> f, v, ae, av;

DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_,
nghost, nlist->nl, ago, fparam_, aparam_));
if (atomic_energy || atomic_virial) {
DP_REQUIRES_OK(
dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_, nghost,
nlist->nl, ago, fparam_, aparam_));
} else {
DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, nghost,
nlist->nl, ago, fparam_, aparam_));
}
// copy from C++ vectors to C arrays, if not NULL pointer
if (energy) {
std::copy(e.begin(), e.end(), energy);
Expand Down Expand Up @@ -468,8 +479,13 @@ void DP_DeepPotModelDeviCompute_variant(DP_DeepPotModelDevi* dp,
std::vector<double> e;
std::vector<std::vector<VALUETYPE>> f, v, ae, av;

DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_,
fparam_, aparam_));
if (atomic_energy || atomic_virial) {
DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_,
fparam_, aparam_));
} else {
DP_REQUIRES_OK(
dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, fparam_, aparam_));
}
// 2D vector to 2D array, flatten first
if (energy) {
std::copy(e.begin(), e.end(), energy);
Expand Down Expand Up @@ -567,8 +583,14 @@ void DP_DeepPotModelDeviComputeNList_variant(DP_DeepPotModelDevi* dp,
std::vector<double> e;
std::vector<std::vector<VALUETYPE>> f, v, ae, av;

DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_,
nghost, nlist->nl, ago, fparam_, aparam_));
if (atomic_energy || atomic_virial) {
DP_REQUIRES_OK(
dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_, nghost,
nlist->nl, ago, fparam_, aparam_));
} else {
DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, nghost,
nlist->nl, ago, fparam_, aparam_));
}
// 2D vector to 2D array, flatten first
if (energy) {
std::copy(e.begin(), e.end(), energy);
Expand Down Expand Up @@ -744,7 +766,11 @@ inline void DP_DeepTensorCompute_variant(DP_DeepTensor* dt,
}
std::vector<VALUETYPE> t, f, v, at, av;

DP_REQUIRES_OK(dt, dt->dt.compute(t, f, v, at, av, coord_, atype_, cell_));
if (atomic_virial || atomic_tensor) {
DP_REQUIRES_OK(dt, dt->dt.compute(t, f, v, at, av, coord_, atype_, cell_));
} else {
DP_REQUIRES_OK(dt, dt->dt.compute(t, f, v, coord_, atype_, cell_));
}
// copy from C++ vectors to C arrays, if not NULL pointer
if (global_tensor) {
std::copy(t.begin(), t.end(), global_tensor);
Expand Down Expand Up @@ -816,8 +842,13 @@ inline void DP_DeepTensorComputeNList_variant(DP_DeepTensor* dt,
}
std::vector<VALUETYPE> t, f, v, at, av;

DP_REQUIRES_OK(dt, dt->dt.compute(t, f, v, at, av, coord_, atype_, cell_,
nghost, nlist->nl));
if (atomic_virial || atomic_tensor) {
DP_REQUIRES_OK(dt, dt->dt.compute(t, f, v, at, av, coord_, atype_, cell_,
nghost, nlist->nl));
} else {
DP_REQUIRES_OK(
dt, dt->dt.compute(t, f, v, coord_, atype_, cell_, nghost, nlist->nl));
}
// copy from C++ vectors to C arrays, if not NULL pointer
if (global_tensor) {
std::copy(t.begin(), t.end(), global_tensor);
Expand Down