From 2942f81a538aa4ad3b3bf2fb86a495be38fbab14 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 22 Jun 2023 15:08:16 -0400 Subject: [PATCH 1/2] Insert braces after control statements in C++ Signed-off-by: Jinzhe Zeng --- .clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-format b/.clang-format index 727520b46b..1da466d870 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,5 @@ --- BasedOnStyle: Google BinPackParameters: false +InsertBraces: true ... From bba6bcded9bea673e35cd9443b78fde77710cd1a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 22 Jun 2023 19:09:12 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/infer_water/infer_water.c | 8 +- examples/infer_water/infer_water_hpp.cpp | 8 +- examples/infer_water/infer_water_nlist.cpp | 8 +- source/api_c/include/deepmd.hpp | 36 ++- source/api_c/src/c_api.cc | 132 ++++++++--- source/api_c/tests/test_dipolecharge.cc | 4 +- source/api_c/tests/test_select_map.cc | 8 +- source/api_cc/src/DeepPot.cc | 46 ++-- source/api_cc/src/common.cc | 16 +- source/api_cc/tests/test_dipolecharge.cc | 4 +- source/api_cc/tests/test_select_map.cc | 16 +- source/ipi/driver.cc | 38 +++- source/ipi/src/sockets.c | 16 +- source/lib/include/ComputeDescriptor.h | 175 +++++++++++---- source/lib/include/SimulationRegion_Impl.h | 29 ++- source/lib/include/gpu_cuda.h | 16 +- source/lib/include/gpu_rocm.h | 7 +- source/lib/src/coord.cc | 12 +- source/lib/src/cuda/coord.cu | 29 ++- source/lib/src/cuda/cudart/cudart_stub.cc | 32 ++- source/lib/src/cuda/neighbor_list.cu | 4 +- source/lib/src/cuda/prod_env_mat.cu | 11 +- source/lib/src/cuda/prod_force_grad.cu | 8 +- source/lib/src/cuda/prod_virial.cu | 4 +- source/lib/src/cuda/tabulate.cu | 18 +- source/lib/src/env_mat.cc | 46 +++- source/lib/src/env_mat_nvnmd.cc | 8 +- source/lib/src/ewald.cc | 27 ++- source/lib/src/fmt_nlist.cc | 7 +- source/lib/src/map_aparam.cc | 4 +- source/lib/src/neighbor_list.cc | 207 +++++++++++++----- source/lib/src/prod_force.cc | 8 +- source/lib/src/prod_force_grad.cc | 16 +- source/lib/src/prod_virial.cc | 8 +- source/lib/src/prod_virial_grad.cc | 8 +- source/lib/src/rocm/coord.hip.cu | 29 ++- source/lib/src/rocm/neighbor_list.hip.cu | 4 +- source/lib/src/rocm/prod_env_mat.hip.cu | 11 +- source/lib/src/rocm/prod_force_grad.hip.cu | 8 +- source/lib/src/rocm/prod_virial.hip.cu | 4 +- source/lib/src/rocm/tabulate.hip.cu | 21 +- source/lib/src/soft_min_switch.cc | 8 +- source/lib/src/soft_min_switch_force.cc | 4 +- source/lib/src/soft_min_switch_force_grad.cc | 8 +- source/lib/src/soft_min_switch_virial.cc | 4 +- source/lib/src/soft_min_switch_virial_grad.cc | 4 +- source/lib/src/tabulate.cc | 12 +- source/lib/tests/test_env_mat_a.cc | 8 +- source/lib/tests/test_env_mat_a_mix.cc | 8 +- source/lib/tests/test_env_mat_r.cc | 8 +- source/lib/tests/test_soft_min_switch.cc | 4 +- source/lmp/compute_deeptensor_atom.cpp | 4 +- source/lmp/fix_dplr.cpp | 7 +- source/lmp/pair_deepmd.cpp | 120 +++++++--- source/lmp/pppm_dplr.cpp | 54 +++-- source/md/include/common.h | 5 +- source/md/mdnn.cc | 12 +- source/md/src/AdWeight.cc | 4 +- source/md/src/Convert.cc | 4 +- source/md/src/GroFileManager.cc | 5 +- source/md/src/HarmonicBond.cc | 8 +- source/md/src/Interpolation.cpp | 8 +- source/md/src/LJInter.cc | 12 +- source/md/src/MaxShift.cc | 4 +- source/md/src/Poly.cpp | 16 +- source/md/src/RandomGenerator_MT19937.cc | 7 +- source/md/src/StringSplit.cpp | 4 +- source/md/src/TF.cc | 5 +- source/md/src/Tabulated.cc | 24 +- source/md/src/Trajectory.cc | 16 +- source/md/src/XyzFileManager.cc | 7 +- source/md/src/ZM.cc | 8 +- source/md/src/ZMFunctions.cpp | 8 +- source/op/descrpt.cc | 36 ++- source/op/descrpt_se_a_ef.cc | 12 +- source/op/descrpt_se_a_ef_para.cc | 12 +- source/op/descrpt_se_a_ef_vert.cc | 12 +- source/op/ewald_recp.cc | 9 +- source/op/matmul_flt_nvnmd.cc | 8 +- source/op/neighbor_stat.cc | 17 +- source/op/optimizer/parallel.cc | 12 +- source/op/prod_env_mat_multi_device.cc | 24 +- source/op/prod_env_mat_multi_device_nvnmd.cc | 4 +- source/op/prod_force.cc | 12 +- source/op/prod_force_grad.cc | 16 +- source/op/prod_force_multi_device.cc | 12 +- source/op/prod_virial.cc | 12 +- source/op/prod_virial_grad.cc | 12 +- source/op/quantize_nvnmd.cc | 5 +- 89 files changed, 1260 insertions(+), 466 deletions(-) diff --git a/examples/infer_water/infer_water.c b/examples/infer_water/infer_water.c index 48e2248508..03fce140f2 100644 --- a/examples/infer_water/infer_water.c +++ b/examples/infer_water/infer_water.c @@ -19,8 +19,12 @@ int main() { DP_DeepPotCompute(dp, 3, coord, atype, cell, e, f, v, ae, av); // print results printf("energy: %f\n", *e); - for (int ii = 0; ii < 9; ++ii) printf("force[%d]: %f\n", ii, f[ii]); - for (int ii = 0; ii < 9; ++ii) printf("force[%d]: %f\n", ii, v[ii]); + for (int ii = 0; ii < 9; ++ii) { + printf("force[%d]: %f\n", ii, f[ii]); + } + for (int ii = 0; ii < 9; ++ii) { + printf("force[%d]: %f\n", ii, v[ii]); + } // free memory free(e); free(f); diff --git a/examples/infer_water/infer_water_hpp.cpp b/examples/infer_water/infer_water_hpp.cpp index a6563e8951..e8b7f57c7f 100644 --- a/examples/infer_water/infer_water_hpp.cpp +++ b/examples/infer_water/infer_water_hpp.cpp @@ -12,6 +12,10 @@ int main() { dp.compute(e, f, v, coord, atype, cell); // print results printf("energy: %f\n", e); - for (int ii = 0; ii < 9; ++ii) printf("force[%d]: %f\n", ii, f[ii]); - for (int ii = 0; ii < 9; ++ii) printf("force[%d]: %f\n", ii, v[ii]); + for (int ii = 0; ii < 9; ++ii) { + printf("force[%d]: %f\n", ii, f[ii]); + } + for (int ii = 0; ii < 9; ++ii) { + printf("force[%d]: %f\n", ii, v[ii]); + } } diff --git a/examples/infer_water/infer_water_nlist.cpp b/examples/infer_water/infer_water_nlist.cpp index c234c6b755..8de3a2fb0d 100644 --- a/examples/infer_water/infer_water_nlist.cpp +++ b/examples/infer_water/infer_water_nlist.cpp @@ -30,6 +30,10 @@ int main() { dp.compute(e, f, v, coord, atype, cell, 0, nlist, 0); // print results printf("energy: %f\n", e); - for (int ii = 0; ii < 9; ++ii) printf("force[%d]: %f\n", ii, f[ii]); - for (int ii = 0; ii < 9; ++ii) printf("force[%d]: %f\n", ii, v[ii]); + for (int ii = 0; ii < 9; ++ii) { + printf("force[%d]: %f\n", ii, f[ii]); + } + for (int ii = 0; ii < 9; ++ii) { + printf("force[%d]: %f\n", ii, v[ii]); + } } diff --git a/source/api_c/include/deepmd.hpp b/source/api_c/include/deepmd.hpp index f9bccc8124..c342a9cbb9 100644 --- a/source/api_c/include/deepmd.hpp +++ b/source/api_c/include/deepmd.hpp @@ -1107,7 +1107,9 @@ class DeepPotModelDevi { } std::vector cstrings; cstrings.reserve(models.size()); - for (std::string const &str : models) cstrings.push_back(str.data()); + for (std::string const &str : models) { + cstrings.push_back(str.data()); + } std::vector c_file_contents; std::vector size_file_contents; @@ -1189,9 +1191,12 @@ class DeepPotModelDevi { ener[i] = energy_flat[i]; force[i].resize(natoms * 3); virial[i].resize(9); - for (int j = 0; j < natoms * 3; j++) + for (int j = 0; j < natoms * 3; j++) { force[i][j] = force_flat[i * natoms * 3 + j]; - for (int j = 0; j < 9; j++) virial[i][j] = virial_flat[i * 9 + j]; + } + for (int j = 0; j < 9; j++) { + virial[i][j] = virial_flat[i * 9 + j]; + } } }; /** @@ -1267,13 +1272,18 @@ class DeepPotModelDevi { virial[i].resize(9); atom_energy[i].resize(natoms); atom_virial[i].resize(natoms * 9); - for (int j = 0; j < natoms * 3; j++) + for (int j = 0; j < natoms * 3; j++) { force[i][j] = force_flat[i * natoms * 3 + j]; - for (int j = 0; j < 9; j++) virial[i][j] = virial_flat[i * 9 + j]; - for (int j = 0; j < natoms; j++) + } + for (int j = 0; j < 9; j++) { + virial[i][j] = virial_flat[i * 9 + j]; + } + for (int j = 0; j < natoms; j++) { atom_energy[i][j] = atom_energy_flat[i * natoms + j]; - for (int j = 0; j < natoms * 9; j++) + } + for (int j = 0; j < natoms * 9; j++) { atom_virial[i][j] = atom_virial_flat[i * natoms * 9 + j]; + } } }; /** @@ -1325,7 +1335,9 @@ class DeepPotModelDevi { void compute_avg(std::vector &avg, const std::vector> &xx) { assert(xx.size() == numb_models); - if (numb_models == 0) return; + if (numb_models == 0) { + return; + } avg.resize(xx[0].size()); fill(avg.begin(), avg.end(), VALUETYPE(0.)); @@ -1353,7 +1365,9 @@ class DeepPotModelDevi { const std::vector> &xx, const int &stride) { assert(xx.size() == numb_models); - if (numb_models == 0) return; + if (numb_models == 0) { + return; + } unsigned ndof = avg.size(); unsigned nloc = ndof / stride; @@ -2017,7 +2031,9 @@ void select_map(std::vector &out, const int nall1 = in.size() / stride; int nall2 = 0; for (int ii = 0; ii < nall1; ++ii) { - if (fwd_map[ii] >= 0) nall2++; + if (fwd_map[ii] >= 0) { + nall2++; + } } out.resize(nall2 * stride); DP_SelectMapInt(&in[0], &fwd_map[0], stride, nall1, nall2, &out[0]); diff --git a/source/api_c/src/c_api.cc b/source/api_c/src/c_api.cc index af6362dab6..3d8ee13754 100644 --- a/source/api_c/src/c_api.cc +++ b/source/api_c/src/c_api.cc @@ -172,11 +172,21 @@ inline void DP_DeepPotCompute_variant(DP_DeepPot* dp, DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, ae, av, 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); - if (force) std::copy(f.begin(), f.end(), force); - if (virial) std::copy(v.begin(), v.end(), virial); - if (atomic_energy) std::copy(ae.begin(), ae.end(), atomic_energy); - if (atomic_virial) std::copy(av.begin(), av.end(), atomic_virial); + if (energy) { + std::copy(e.begin(), e.end(), energy); + } + if (force) { + std::copy(f.begin(), f.end(), force); + } + if (virial) { + std::copy(v.begin(), v.end(), virial); + } + if (atomic_energy) { + std::copy(ae.begin(), ae.end(), atomic_energy); + } + if (atomic_virial) { + std::copy(av.begin(), av.end(), atomic_virial); + } } template void DP_DeepPotCompute_variant(DP_DeepPot* dp, @@ -246,11 +256,21 @@ inline void DP_DeepPotComputeNList_variant(DP_DeepPot* dp, DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, ae, av, 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); - if (force) std::copy(f.begin(), f.end(), force); - if (virial) std::copy(v.begin(), v.end(), virial); - if (atomic_energy) std::copy(ae.begin(), ae.end(), atomic_energy); - if (atomic_virial) std::copy(av.begin(), av.end(), atomic_virial); + if (energy) { + std::copy(e.begin(), e.end(), energy); + } + if (force) { + std::copy(f.begin(), f.end(), force); + } + if (virial) { + std::copy(v.begin(), v.end(), virial); + } + if (atomic_energy) { + std::copy(ae.begin(), ae.end(), atomic_energy); + } + if (atomic_virial) { + std::copy(av.begin(), av.end(), atomic_virial); + } } template void DP_DeepPotComputeNList_variant(DP_DeepPot* dp, @@ -324,11 +344,21 @@ inline void DP_DeepPotComputeMixedType_variant(DP_DeepPot* dp, dp, dp->dp.compute_mixed_type(e, f, v, ae, av, nframes, 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); - if (force) std::copy(f.begin(), f.end(), force); - if (virial) std::copy(v.begin(), v.end(), virial); - if (atomic_energy) std::copy(ae.begin(), ae.end(), atomic_energy); - if (atomic_virial) std::copy(av.begin(), av.end(), atomic_virial); + if (energy) { + std::copy(e.begin(), e.end(), energy); + } + if (force) { + std::copy(f.begin(), f.end(), force); + } + if (virial) { + std::copy(v.begin(), v.end(), virial); + } + if (atomic_energy) { + std::copy(ae.begin(), ae.end(), atomic_energy); + } + if (atomic_virial) { + std::copy(av.begin(), av.end(), atomic_virial); + } } template void DP_DeepPotComputeMixedType_variant(DP_DeepPot* dp, @@ -385,7 +415,9 @@ void DP_DeepPotModelDeviComputeNList_variant(DP_DeepPotModelDevi* dp, VALUETYPE* virial, VALUETYPE* atomic_energy, VALUETYPE* atomic_virial) { - if (nframes > 1) throw std::runtime_error("nframes > 1 not supported yet"); + if (nframes > 1) { + throw std::runtime_error("nframes > 1 not supported yet"); + } // init C++ vectors from C arrays std::vector coord_(coord, coord + natoms * 3); std::vector atype_(atype, atype + natoms); @@ -585,16 +617,26 @@ inline void DP_DeepTensorCompute_variant(DP_DeepTensor* dt, DP_REQUIRES_OK(dt, dt->dt.compute(t, f, v, at, av, 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); - if (force) std::copy(f.begin(), f.end(), force); - if (virial) std::copy(v.begin(), v.end(), virial); - if (atomic_virial) std::copy(av.begin(), av.end(), atomic_virial); + if (global_tensor) { + std::copy(t.begin(), t.end(), global_tensor); + } + if (force) { + std::copy(f.begin(), f.end(), force); + } + if (virial) { + std::copy(v.begin(), v.end(), virial); + } + if (atomic_virial) { + std::copy(av.begin(), av.end(), atomic_virial); + } // do not know the size of atomic tensor in advance... if (atomic_tensor) { *atomic_tensor = new VALUETYPE[at.size()]; std::copy(at.begin(), at.end(), *atomic_tensor); } - if (size_at) *size_at = at.size(); + if (size_at) { + *size_at = at.size(); + } } template void DP_DeepTensorCompute_variant(DP_DeepTensor* dt, @@ -648,16 +690,26 @@ inline void DP_DeepTensorComputeNList_variant(DP_DeepTensor* dt, DP_REQUIRES_OK(dt, dt->dt.compute(t, f, v, at, av, 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); - if (force) std::copy(f.begin(), f.end(), force); - if (virial) std::copy(v.begin(), v.end(), virial); - if (atomic_virial) std::copy(av.begin(), av.end(), atomic_virial); + if (global_tensor) { + std::copy(t.begin(), t.end(), global_tensor); + } + if (force) { + std::copy(f.begin(), f.end(), force); + } + if (virial) { + std::copy(v.begin(), v.end(), virial); + } + if (atomic_virial) { + std::copy(av.begin(), av.end(), atomic_virial); + } // do not know the size of atomic tensor in advance... if (atomic_tensor) { *atomic_tensor = new VALUETYPE[at.size()]; std::copy(at.begin(), at.end(), *atomic_tensor); } - if (size_at) *size_at = at.size(); + if (size_at) { + *size_at = at.size(); + } } template void DP_DeepTensorComputeNList_variant(DP_DeepTensor* dt, @@ -721,8 +773,12 @@ inline void DP_DipoleChargeModifierComputeNList_variant( DP_REQUIRES_OK(dcm, dcm->dcm.compute(df, dv, coord_, atype_, cell_, pairs_, delef_, nghost, nlist->nl)); // copy from C++ vectors to C arrays, if not NULL pointer - if (dfcorr_) std::copy(df.begin(), df.end(), dfcorr_); - if (dvcorr_) std::copy(dv.begin(), dv.end(), dvcorr_); + if (dfcorr_) { + std::copy(df.begin(), df.end(), dfcorr_); + } + if (dvcorr_) { + std::copy(dv.begin(), dv.end(), dvcorr_); + } } template void DP_DipoleChargeModifierComputeNList_variant( @@ -1316,10 +1372,18 @@ void DP_SelectByType(const int natoms, int nghost_real_; deepmd::select_by_type(fwd_map_, bkw_map_, nghost_real_, std::vector(), atype_, nghost, sel_type_); - if (fwd_map) std::copy(fwd_map_.begin(), fwd_map_.end(), fwd_map); - if (bkw_map) std::copy(bkw_map_.begin(), bkw_map_.end(), bkw_map); - if (nreal) *nreal = bkw_map_.size(); - if (nghost_real) *nghost_real = nghost_real_; + if (fwd_map) { + std::copy(fwd_map_.begin(), fwd_map_.end(), fwd_map); + } + if (bkw_map) { + std::copy(bkw_map_.begin(), bkw_map_.end(), bkw_map); + } + if (nreal) { + *nreal = bkw_map_.size(); + } + if (nghost_real) { + *nghost_real = nghost_real_; + } } void DP_SelectMapInt(const int* in, @@ -1332,7 +1396,9 @@ void DP_SelectMapInt(const int* in, std::vector fwd_map_(fwd_map, fwd_map + nall1); std::vector out_(stride * nall2); deepmd::select_map(out_, in_, fwd_map_, stride); - if (out) std::copy(out_.begin(), out_.end(), out); + if (out) { + std::copy(out_.begin(), out_.end(), out); + } } } // extern "C" diff --git a/source/api_c/tests/test_dipolecharge.cc b/source/api_c/tests/test_dipolecharge.cc index 950b103517..29cbc5f756 100644 --- a/source/api_c/tests/test_dipolecharge.cc +++ b/source/api_c/tests/test_dipolecharge.cc @@ -75,7 +75,9 @@ class TestDipoleCharge : public ::testing::Test { static bool _in_vec(const int& value, const std::vector& vec) { // naive impl. for (int ii = 0; ii < vec.size(); ++ii) { - if (value == vec[ii]) return true; + if (value == vec[ii]) { + return true; + } } return false; } diff --git a/source/api_c/tests/test_select_map.cc b/source/api_c/tests/test_select_map.cc index ee1b16c2fc..0eb44c9fd4 100644 --- a/source/api_c/tests/test_select_map.cc +++ b/source/api_c/tests/test_select_map.cc @@ -31,8 +31,12 @@ class TestSelectMap : public ::testing::Test { EXPECT_EQ(natoms, fwd_map_1.size()); EXPECT_EQ(4, expected_atype_out_1.size()); - for (int ii = 0; ii < 2; ii++) atype_out_0.push_back(0); - for (int ii = 0; ii < 4; ii++) atype_out_1.push_back(0); + for (int ii = 0; ii < 2; ii++) { + atype_out_0.push_back(0); + } + for (int ii = 0; ii < 4; ii++) { + atype_out_1.push_back(0); + } } }; diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index d8f0d8a8fe..986acb6139 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -423,10 +423,11 @@ void DeepPot::init(const std::string& model, options.config.set_intra_op_parallelism_threads(num_intra_nthreads); deepmd::load_op_library(); - if (file_content.size() == 0) + if (file_content.size() == 0) { check_status(ReadBinaryProto(Env::Default(), model, graph_def)); - else + } else { (*graph_def).ParseFromString(file_content); + } int gpu_num = -1; #if GOOGLE_CUDA || TENSORFLOW_USE_ROCM DPGetDeviceCount(gpu_num); // check current device environment @@ -471,8 +472,12 @@ void DeepPot::init(const std::string& model, } dfparam = get_scalar("fitting_attr/dfparam"); daparam = get_scalar("fitting_attr/daparam"); - if (dfparam < 0) dfparam = 0; - if (daparam < 0) daparam = 0; + if (dfparam < 0) { + dfparam = 0; + } + if (daparam < 0) { + daparam = 0; + } model_type = get_scalar("model_attr/model_type"); inited = true; @@ -1242,10 +1247,11 @@ void DeepPotModelDevi::init(const std::vector& models, options.config.set_intra_op_parallelism_threads(num_intra_nthreads); for (unsigned ii = 0; ii < numb_models; ++ii) { graph_defs[ii] = new GraphDef(); - if (file_contents.size() == 0) + if (file_contents.size() == 0) { check_status(ReadBinaryProto(Env::Default(), models[ii], graph_defs[ii])); - else + } else { (*graph_defs[ii]).ParseFromString(file_contents[ii]); + } } #if GOOGLE_CUDA || TENSORFLOW_USE_ROCM if (gpu_num > 0) { @@ -1294,8 +1300,12 @@ void DeepPotModelDevi::init(const std::vector& models, } dfparam = get_scalar("fitting_attr/dfparam"); daparam = get_scalar("fitting_attr/daparam"); - if (dfparam < 0) dfparam = 0; - if (daparam < 0) daparam = 0; + if (dfparam < 0) { + dfparam = 0; + } + if (daparam < 0) { + daparam = 0; + } model_type = get_scalar("model_attr/model_type"); // rcut = get_rcut(); // cell_size = rcut; @@ -1408,7 +1418,9 @@ void DeepPotModelDevi::compute(std::vector& all_energy, const int& ago, const std::vector& fparam, const std::vector& aparam_) { - if (numb_models == 0) return; + if (numb_models == 0) { + return; + } int nall = dcoord_.size() / 3; int nframes = 1; int nloc = nall - nghost; @@ -1504,7 +1516,9 @@ void DeepPotModelDevi::compute( const int& ago, const std::vector& fparam, const std::vector& aparam_) { - if (numb_models == 0) return; + if (numb_models == 0) { + return; + } int nframes = 1; int nall = dcoord_.size() / 3; int nloc = nall - nghost; @@ -1604,7 +1618,9 @@ template void DeepPotModelDevi::compute_avg(VALUETYPE& dener, const std::vector& all_energy) { assert(all_energy.size() == numb_models); - if (numb_models == 0) return; + if (numb_models == 0) { + return; + } dener = 0; for (unsigned ii = 0; ii < numb_models; ++ii) { @@ -1624,7 +1640,9 @@ void DeepPotModelDevi::compute_avg( std::vector& avg, const std::vector>& xx) { assert(xx.size() == numb_models); - if (numb_models == 0) return; + if (numb_models == 0) { + return; + } avg.resize(xx[0].size()); fill(avg.begin(), avg.end(), VALUETYPE(0.)); @@ -1653,7 +1671,9 @@ void DeepPotModelDevi::compute_std( const std::vector>& xx, const int& stride) { assert(xx.size() == numb_models); - if (numb_models == 0) return; + if (numb_models == 0) { + return; + } unsigned ndof = avg.size(); unsigned nloc = ndof / stride; diff --git a/source/api_cc/src/common.cc b/source/api_cc/src/common.cc index 380a2910f6..cd8db5118a 100644 --- a/source/api_cc/src/common.cc +++ b/source/api_cc/src/common.cc @@ -472,7 +472,9 @@ int deepmd::session_input_tensors( } natoms(0) = nloc; natoms(1) = nall; - for (int ii = 0; ii < ntypes; ++ii) natoms(ii + 2) = type_count[ii]; + for (int ii = 0; ii < ntypes; ++ii) { + natoms(ii + 2) = type_count[ii]; + } std::string prefix = ""; if (scope != "") { @@ -585,7 +587,9 @@ int deepmd::session_input_tensors( } } - for (int ii = 0; ii < 16; ++ii) mesh(ii) = 0; + for (int ii = 0; ii < 16; ++ii) { + mesh(ii) = 0; + } const int stride = sizeof(int*) / sizeof(int); assert(stride * sizeof(int) == sizeof(int*)); @@ -600,7 +604,9 @@ int deepmd::session_input_tensors( natoms(0) = nloc; natoms(1) = nall; - for (int ii = 0; ii < ntypes; ++ii) natoms(ii + 2) = type_count[ii]; + for (int ii = 0; ii < ntypes; ++ii) { + natoms(ii + 2) = type_count[ii]; + } std::string prefix = ""; if (scope != "") { @@ -728,7 +734,9 @@ int deepmd::session_input_tensors_mixed_type( natoms(1) = nall; natoms(2) = nall; if (ntypes > 1) { - for (int ii = 1; ii < ntypes; ++ii) natoms(ii + 2) = 0; + for (int ii = 1; ii < ntypes; ++ii) { + natoms(ii + 2) = 0; + } } std::string prefix = ""; diff --git a/source/api_cc/tests/test_dipolecharge.cc b/source/api_cc/tests/test_dipolecharge.cc index 2d568a0aa7..2b2d8aef25 100644 --- a/source/api_cc/tests/test_dipolecharge.cc +++ b/source/api_cc/tests/test_dipolecharge.cc @@ -80,7 +80,9 @@ class TestDipoleCharge : public ::testing::Test { static bool _in_vec(const int& value, const std::vector& vec) { // naive impl. for (int ii = 0; ii < vec.size(); ++ii) { - if (value == vec[ii]) return true; + if (value == vec[ii]) { + return true; + } } return false; } diff --git a/source/api_cc/tests/test_select_map.cc b/source/api_cc/tests/test_select_map.cc index 871508936c..062a5714f3 100644 --- a/source/api_cc/tests/test_select_map.cc +++ b/source/api_cc/tests/test_select_map.cc @@ -45,10 +45,18 @@ class TestSelectMap : public ::testing::Test { EXPECT_EQ(4, expected_atype_out_1.size()); EXPECT_EQ(12, expected_coord_out_1.size()); - for (int ii = 0; ii < 6; ++ii) coord_out_0.push_back(0.0); - for (int ii = 0; ii < 12; ii++) coord_out_1.push_back(0.0); - for (int ii = 0; ii < 2; ii++) atype_out_0.push_back(0); - for (int ii = 0; ii < 4; ii++) atype_out_1.push_back(0); + for (int ii = 0; ii < 6; ++ii) { + coord_out_0.push_back(0.0); + } + for (int ii = 0; ii < 12; ii++) { + coord_out_1.push_back(0.0); + } + for (int ii = 0; ii < 2; ii++) { + atype_out_0.push_back(0); + } + for (int ii = 0; ii < 4; ii++) { + atype_out_1.push_back(0); + } } }; diff --git a/source/ipi/driver.cc b/source/ipi/driver.cc index 71372387fe..aecc5f2b2f 100644 --- a/source/ipi/driver.cc +++ b/source/ipi/driver.cc @@ -32,12 +32,17 @@ const double icvt_f = 1. / cvt_f; char *trimwhitespace(char *str) { char *end; // Trim leading space - while (isspace((unsigned char)*str)) str++; - if (*str == 0) // All spaces? + while (isspace((unsigned char)*str)) { + str++; + } + if (*str == 0) { // All spaces? return str; + } // Trim trailing space end = str + strlen(str) - 1; - while (end > str && isspace((unsigned char)*end)) end--; + while (end > str && isspace((unsigned char)*end)) { + end--; + } // Write new null terminator *(end + 1) = 0; return str; @@ -52,10 +57,11 @@ void normalize_coord(std::vector &coord, region.phys2Inter(inter, &coord[3 * ii]); for (int dd = 0; dd < 3; ++dd) { inter[dd] -= int(floor(inter[dd])); - if (inter[dd] < 0) + if (inter[dd] < 0) { inter[dd] += 1.; - else if (inter[dd] >= 1) + } else if (inter[dd] >= 1) { inter[dd] -= 1.; + } } region.inter2Phys(&coord[3 * ii], inter); } @@ -132,31 +138,37 @@ int main(int argc, char *argv[]) { while (true) { readbuffer_(&socket, header, MSGLEN); std::string header_str(trimwhitespace(header)); - if (b_verb) std::cout << "# get header " << header_str << std::endl; + if (b_verb) { + std::cout << "# get header " << header_str << std::endl; + } if (header_str == "STATUS") { if (!isinit) { writebuffer_(&socket, msg_needinit, MSGLEN); - if (b_verb) + if (b_verb) { std::cout << "# send back " << "NEEDINIT" << std::endl; + } } else if (hasdata) { writebuffer_(&socket, msg_havedata, MSGLEN); - if (b_verb) + if (b_verb) { std::cout << "# send back " << "HAVEDATA" << std::endl; + } } else { writebuffer_(&socket, msg_ready, MSGLEN); - if (b_verb) + if (b_verb) { std::cout << "# send back " << "READY" << std::endl; + } } } else if (header_str == "INIT") { assert(4 == sizeof(int32_t)); readbuffer_(&socket, (char *)(&cbuf), sizeof(int32_t)); readbuffer_(&socket, initbuffer, cbuf); - if (b_verb) + if (b_verb) { std::cout << "Init sys from wrapper, using " << initbuffer << std::endl; + } } else if (header_str == "POSDATA") { assert(8 == sizeof(double)); @@ -172,9 +184,10 @@ int main(int argc, char *argv[]) { readbuffer_(&socket, (char *)(&cbuf), sizeof(int32_t)); if (natoms < 0) { natoms = cbuf; - if (b_verb) + if (b_verb) { std::cout << "# get number of atoms in system: " << natoms << std::endl; + } dcoord.resize(3 * natoms); dforce.resize(3 * natoms, 0); @@ -203,9 +216,10 @@ int main(int argc, char *argv[]) { for (int ii = 0; ii < 9; ++ii) { virial[ii] = dvirial[(ii % 3) * 3 + (ii / 3)] * icvt_ener * (1.0); } - if (b_verb) + if (b_verb) { std::cout << "# energy of sys. : " << std::scientific << std::setprecision(10) << dener << std::endl; + } writebuffer_(&socket, msg_forceready, MSGLEN); writebuffer_(&socket, (char *)(&ener), sizeof(double)); writebuffer_(&socket, (char *)(&natoms), sizeof(int32_t)); diff --git a/source/ipi/src/sockets.c b/source/ipi/src/sockets.c index 497f77fba4..732247b07d 100644 --- a/source/ipi/src/sockets.c +++ b/source/ipi/src/sockets.c @@ -79,7 +79,9 @@ ignored here for C compatibility. psock = (struct sockaddr *)&serv_addr; ssock = sizeof(serv_addr); sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd < 0) error("Error opening socket"); + if (sockfd < 0) { + error("Error opening socket"); + } server = gethostbyname(host); if (server == NULL) { @@ -92,8 +94,9 @@ ignored here for C compatibility. bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons(*port); - if (connect(sockfd, psock, ssock) < 0) + if (connect(sockfd, psock, ssock) < 0) { error("Error opening socket: wrong host address, or broken connection"); + } } else { // creates a unix socket struct sockaddr_un serv_addr; psock = (struct sockaddr *)&serv_addr; @@ -103,8 +106,9 @@ ignored here for C compatibility. serv_addr.sun_family = AF_UNIX; strcpy(serv_addr.sun_path, "/tmp/ipi_"); strcpy(serv_addr.sun_path + 9, host); - if (connect(sockfd, psock, ssock) < 0) + if (connect(sockfd, psock, ssock) < 0) { error("Error opening socket: wrong host address, or broken connection"); + } } *psockfd = sockfd; @@ -124,8 +128,9 @@ void writebuffer_(int *psockfd, char *data, int len) int sockfd = *psockfd; n = write(sockfd, data, len); - if (n < 0) + if (n < 0) { error("Error writing to socket: server has quit or connection broke"); + } } void readbuffer_(int *psockfd, char *data, int len) @@ -148,6 +153,7 @@ void readbuffer_(int *psockfd, char *data, int len) n += nr; } - if (n == 0) + if (n == 0) { error("Error reading from socket: server has quit or connection broke"); + } } diff --git a/source/lib/include/ComputeDescriptor.h b/source/lib/include/ComputeDescriptor.h index d2128217d6..baa02572b3 100644 --- a/source/lib/include/ComputeDescriptor.h +++ b/source/lib/include/ComputeDescriptor.h @@ -113,7 +113,9 @@ static void compute_dRdT(double (*dRdT)[9], for (int ii = 0; ii < 3; ++ii) { for (int jj = 0; jj < 3; ++jj) { dRdT0[ii * 3 + jj] = r1[ii] * r1[jj] / nr13; - if (ii == jj) dRdT0[ii * 3 + jj] -= 1. / nr1; + if (ii == jj) { + dRdT0[ii * 3 + jj] -= 1. / nr1; + } } } @@ -129,7 +131,9 @@ static void compute_dRdT(double (*dRdT)[9], } } double tmpy[3]; - for (int dd = 0; dd < 3; ++dd) tmpy[dd] = r2[dd] - r1dr2 / nr12 * r1[dd]; + for (int dd = 0; dd < 3; ++dd) { + tmpy[dd] = r2[dd] - r1dr2 / nr12 * r1[dd]; + } double ntmpy = sqrt(deepmd::dot3(tmpy, tmpy)); double ydRdy[3] = {0}; for (int ii = 0; ii < 3; ++ii) { @@ -148,7 +152,9 @@ static void compute_dRdT(double (*dRdT)[9], double res[3]; deepmd::cprod(dRdT0 + ii * 3, yy, dRdT2 + ii * 3); deepmd::cprod(xx, dRdT1 + ii * 3, res); - for (int dd = 0; dd < 3; ++dd) dRdT2[ii * 3 + dd] += res[dd]; + for (int dd = 0; dd < 3; ++dd) { + dRdT2[ii * 3 + dd] += res[dd]; + } } } @@ -172,7 +178,9 @@ static void compute_dRdT_1(double (*dRdT)[9], for (int ii = 0; ii < 3; ++ii) { for (int jj = 0; jj < 3; ++jj) { dRdT0[ii * 3 + jj] = -r1[ii] * r1[jj] / nr13; - if (ii == jj) dRdT0[ii * 3 + jj] += 1. / nr1; + if (ii == jj) { + dRdT0[ii * 3 + jj] += 1. / nr1; + } } } @@ -188,7 +196,9 @@ static void compute_dRdT_1(double (*dRdT)[9], } } double tmpy[3]; - for (int dd = 0; dd < 3; ++dd) tmpy[dd] = r2[dd] - r1dr2 / nr12 * r1[dd]; + for (int dd = 0; dd < 3; ++dd) { + tmpy[dd] = r2[dd] - r1dr2 / nr12 * r1[dd]; + } double ntmpy = sqrt(deepmd::dot3(tmpy, tmpy)); double ydRdy[3] = {0}; for (int ii = 0; ii < 3; ++ii) { @@ -207,7 +217,9 @@ static void compute_dRdT_1(double (*dRdT)[9], double res[3]; deepmd::cprod(dRdT0 + ii * 3, yy, dRdT2 + ii * 3); deepmd::cprod(xx, dRdT1 + ii * 3, res); - for (int dd = 0; dd < 3; ++dd) dRdT2[ii * 3 + dd] += res[dd]; + for (int dd = 0; dd < 3; ++dd) { + dRdT2[ii * 3 + dd] += res[dd]; + } } } @@ -243,7 +255,9 @@ static void compute_dRdT_2(double (*dRdT)[9], } } double tmpy[3]; - for (int dd = 0; dd < 3; ++dd) tmpy[dd] = r2[dd] - r1dr2 / nr12 * r1[dd]; + for (int dd = 0; dd < 3; ++dd) { + tmpy[dd] = r2[dd] - r1dr2 / nr12 * r1[dd]; + } double ntmpy = sqrt(deepmd::dot3(tmpy, tmpy)); double ydRdy[3] = {0}; for (int ii = 0; ii < 3; ++ii) { @@ -262,7 +276,9 @@ static void compute_dRdT_2(double (*dRdT)[9], double res[3]; deepmd::cprod(dRdT0 + ii * 3, yy, dRdT2 + ii * 3); deepmd::cprod(xx, dRdT1 + ii * 3, res); - for (int dd = 0; dd < 3; ++dd) dRdT2[ii * 3 + dd] += res[dd]; + for (int dd = 0; dd < 3; ++dd) { + dRdT2[ii * 3 + dd] += res[dd]; + } } } @@ -297,7 +313,9 @@ void compute_descriptor(std::vector &descrpt_a, fill(rij_a.begin(), rij_a.end(), 0.0); for (int ii = 0; ii < int(sec_a.size()) - 1; ++ii) { for (int jj = sec_a[ii]; jj < sec_a[ii + 1]; ++jj) { - if (fmt_nlist_a[jj] < 0) break; + if (fmt_nlist_a[jj] < 0) { + break; + } sel_a_diff[jj].resize(3); const int &j_idx = fmt_nlist_a[jj]; if (b_pbc) { @@ -306,10 +324,13 @@ void compute_descriptor(std::vector &descrpt_a, posi[i_idx * 3 + 0], posi[i_idx * 3 + 1], posi[i_idx * 3 + 2], sel_a_diff[jj][0], sel_a_diff[jj][1], sel_a_diff[jj][2]); } else { - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { sel_a_diff[jj][dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; + } + } + for (int dd = 0; dd < 3; ++dd) { + rij_a[jj * 3 + dd] = sel_a_diff[jj][dd]; } - for (int dd = 0; dd < 3; ++dd) rij_a[jj * 3 + dd] = sel_a_diff[jj][dd]; } } @@ -318,7 +339,9 @@ void compute_descriptor(std::vector &descrpt_a, fill(rij_r.begin(), rij_r.end(), 0.0); for (int ii = 0; ii < int(sec_r.size()) - 1; ++ii) { for (int jj = sec_r[ii]; jj < sec_r[ii + 1]; ++jj) { - if (fmt_nlist_r[jj] < 0) break; + if (fmt_nlist_r[jj] < 0) { + break; + } sel_r_diff[jj].resize(3); const int &j_idx = fmt_nlist_r[jj]; if (b_pbc) { @@ -327,10 +350,13 @@ void compute_descriptor(std::vector &descrpt_a, posi[i_idx * 3 + 0], posi[i_idx * 3 + 1], posi[i_idx * 3 + 2], sel_r_diff[jj][0], sel_r_diff[jj][1], sel_r_diff[jj][2]); } else { - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { sel_r_diff[jj][dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; + } + } + for (int dd = 0; dd < 3; ++dd) { + rij_r[jj * 3 + dd] = sel_r_diff[jj][dd]; } - for (int dd = 0; dd < 3; ++dd) rij_r[jj * 3 + dd] = sel_r_diff[jj][dd]; } } @@ -392,21 +418,31 @@ void compute_descriptor(std::vector &descrpt_a, yy[dd] = r2[dd]; } double norm_xx = sqrt(deepmd::dot3(xx, xx)); - for (unsigned dd = 0; dd < 3; ++dd) xx[dd] /= norm_xx; + for (unsigned dd = 0; dd < 3; ++dd) { + xx[dd] /= norm_xx; + } double dxy = deepmd::dot3(xx, yy); - for (unsigned dd = 0; dd < 3; ++dd) yy[dd] -= dxy * xx[dd]; + for (unsigned dd = 0; dd < 3; ++dd) { + yy[dd] -= dxy * xx[dd]; + } double norm_yy = sqrt(deepmd::dot3(yy, yy)); - for (unsigned dd = 0; dd < 3; ++dd) yy[dd] /= norm_yy; + for (unsigned dd = 0; dd < 3; ++dd) { + yy[dd] /= norm_yy; + } deepmd::cprod(xx, yy, zz); rot_mat.resize(9); - for (int dd = 0; dd < 9; ++dd) rot_mat[dd] = rot[dd]; + for (int dd = 0; dd < 9; ++dd) { + rot_mat[dd] = rot[dd]; + } // 1./rr, cos(theta), cos(phi), sin(phi) descrpt_a.resize(sec_a.back() * 4); fill(descrpt_a.begin(), descrpt_a.end(), 0.0); for (int ii = 0; ii < int(sec_a.size()) - 1; ++ii) { for (int jj = sec_a[ii]; jj < sec_a[ii + 1]; ++jj) { - if (fmt_nlist_a[jj] < 0) break; + if (fmt_nlist_a[jj] < 0) { + break; + } double rdiff[3]; deepmd::dotmv3(rdiff, rot, &sel_a_diff[jj][0]); double rr2 = deepmd::dot3(rdiff, rdiff); @@ -432,7 +468,9 @@ void compute_descriptor(std::vector &descrpt_a, fill(descrpt_r.begin(), descrpt_r.end(), 0.0); for (int ii = 0; ii < int(sec_r.size()) - 1; ++ii) { for (int jj = sec_r[ii]; jj < sec_r[ii + 1]; ++jj) { - if (fmt_nlist_r[jj] < 0) break; + if (fmt_nlist_r[jj] < 0) { + break; + } const double *rdiff = &sel_r_diff[jj][0]; double rr = sqrt(deepmd::dot3(rdiff, rdiff)); descrpt_r[jj] = 1. / rr; @@ -459,7 +497,9 @@ void compute_descriptor(std::vector &descrpt_a, for (int sec_iter = 0; sec_iter < int(sec_a.size()) - 1; ++sec_iter) { for (int nei_iter = sec_a[sec_iter]; nei_iter < sec_a[sec_iter + 1]; ++nei_iter) { - if (fmt_nlist_a[nei_iter] < 0) break; + if (fmt_nlist_a[nei_iter] < 0) { + break; + } // drdS, stored in tranposed form double dtrdST[4][3]; double *rr = &sel_a_diff[nei_iter][0]; @@ -514,8 +554,9 @@ void compute_descriptor(std::vector &descrpt_a, for (int ll = 0; ll < 3; ++ll) { dRdTr_1[ii][jj] += dRdT_1[jj][ii * 3 + ll] * rr[ll]; } - if (axis0_type == 0 && nei_iter == axis0_idx) + if (axis0_type == 0 && nei_iter == axis0_idx) { dRdTr_1[ii][jj] += rot[jj * 3 + ii]; + } } } // dRdTr_2 @@ -526,8 +567,9 @@ void compute_descriptor(std::vector &descrpt_a, for (int ll = 0; ll < 3; ++ll) { dRdTr_2[ii][jj] += dRdT_2[jj][ii * 3 + ll] * rr[ll]; } - if (axis1_type == 0 && nei_iter == axis1_idx) + if (axis1_type == 0 && nei_iter == axis1_idx) { dRdTr_2[ii][jj] += rot[jj * 3 + ii]; + } } } // dRdTr_k @@ -591,7 +633,9 @@ void compute_descriptor(std::vector &descrpt_a, for (int sec_iter = 0; sec_iter < int(sec_r.size()) - 1; ++sec_iter) { for (int nei_iter = sec_r[sec_iter]; nei_iter < sec_r[sec_iter + 1]; ++nei_iter) { - if (fmt_nlist_r[nei_iter] < 0) break; + if (fmt_nlist_r[nei_iter] < 0) { + break; + } const double *rr = &sel_r_diff[nei_iter][0]; double nr = sqrt(deepmd::dot3(rr, rr)); @@ -634,7 +678,9 @@ void compute_descriptor(std::vector &descrpt_a, std::vector > sel_a_diff(sec_a.back()); for (int ii = 0; ii < int(sec_a.size()) - 1; ++ii) { for (int jj = sec_a[ii]; jj < sec_a[ii + 1]; ++jj) { - if (fmt_nlist_a[jj] < 0) break; + if (fmt_nlist_a[jj] < 0) { + break; + } sel_a_diff[jj].resize(3); const int &j_idx = fmt_nlist_a[jj]; if (b_pbc) { @@ -643,15 +689,18 @@ void compute_descriptor(std::vector &descrpt_a, posi[i_idx * 3 + 0], posi[i_idx * 3 + 1], posi[i_idx * 3 + 2], sel_a_diff[jj][0], sel_a_diff[jj][1], sel_a_diff[jj][2]); } else { - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { sel_a_diff[jj][dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; + } } } } std::vector > sel_r_diff(sec_r.back()); for (int ii = 0; ii < int(sec_r.size()) - 1; ++ii) { for (int jj = sec_r[ii]; jj < sec_r[ii + 1]; ++jj) { - if (fmt_nlist_r[jj] < 0) break; + if (fmt_nlist_r[jj] < 0) { + break; + } sel_r_diff[jj].resize(3); const int &j_idx = fmt_nlist_r[jj]; if (b_pbc) { @@ -660,8 +709,9 @@ void compute_descriptor(std::vector &descrpt_a, posi[i_idx * 3 + 0], posi[i_idx * 3 + 1], posi[i_idx * 3 + 2], sel_r_diff[jj][0], sel_r_diff[jj][1], sel_r_diff[jj][2]); } else { - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { sel_r_diff[jj][dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; + } } } } @@ -691,21 +741,31 @@ void compute_descriptor(std::vector &descrpt_a, yy[dd] = r2[dd]; } double norm_xx = sqrt(deepmd::dot3(xx, xx)); - for (unsigned dd = 0; dd < 3; ++dd) xx[dd] /= norm_xx; + for (unsigned dd = 0; dd < 3; ++dd) { + xx[dd] /= norm_xx; + } double dxy = deepmd::dot3(xx, yy); - for (unsigned dd = 0; dd < 3; ++dd) yy[dd] -= dxy * xx[dd]; + for (unsigned dd = 0; dd < 3; ++dd) { + yy[dd] -= dxy * xx[dd]; + } double norm_yy = sqrt(deepmd::dot3(yy, yy)); - for (unsigned dd = 0; dd < 3; ++dd) yy[dd] /= norm_yy; + for (unsigned dd = 0; dd < 3; ++dd) { + yy[dd] /= norm_yy; + } deepmd::cprod(xx, yy, zz); rot_mat.resize(9); - for (int dd = 0; dd < 9; ++dd) rot_mat[dd] = rot[dd]; + for (int dd = 0; dd < 9; ++dd) { + rot_mat[dd] = rot[dd]; + } // 1./rr, cos(theta), cos(phi), sin(phi) descrpt_a.resize(sec_a.back() * 4); fill(descrpt_a.begin(), descrpt_a.end(), 0.0); for (int ii = 0; ii < int(sec_a.size()) - 1; ++ii) { for (int jj = sec_a[ii]; jj < sec_a[ii + 1]; ++jj) { - if (fmt_nlist_a[jj] < 0) break; + if (fmt_nlist_a[jj] < 0) { + break; + } double rdiff[3]; deepmd::dotmv3(rdiff, rot, &sel_a_diff[jj][0]); double rr2 = deepmd::dot3(rdiff, rdiff); @@ -731,7 +791,9 @@ void compute_descriptor(std::vector &descrpt_a, fill(descrpt_r.begin(), descrpt_r.end(), 0.0); for (int ii = 0; ii < int(sec_r.size()) - 1; ++ii) { for (int jj = sec_r[ii]; jj < sec_r[ii + 1]; ++jj) { - if (fmt_nlist_r[jj] < 0) break; + if (fmt_nlist_r[jj] < 0) { + break; + } double rdiff[3]; deepmd::dotmv3(rdiff, rot, &sel_r_diff[jj][0]); double rr = sqrt(deepmd::dot3(rdiff, rdiff)); @@ -775,7 +837,9 @@ void compute_descriptor_se_a_extf(std::vector &descrpt_a, fill(rij_a.begin(), rij_a.end(), 0.0); for (int ii = 0; ii < int(sec_a.size()) - 1; ++ii) { for (int jj = sec_a[ii]; jj < sec_a[ii + 1]; ++jj) { - if (fmt_nlist_a[jj] < 0) break; + if (fmt_nlist_a[jj] < 0) { + break; + } sel_a_diff[jj].resize(3); const int &j_idx = fmt_nlist_a[jj]; if (b_pbc) { @@ -784,10 +848,13 @@ void compute_descriptor_se_a_extf(std::vector &descrpt_a, posi[i_idx * 3 + 0], posi[i_idx * 3 + 1], posi[i_idx * 3 + 2], sel_a_diff[jj][0], sel_a_diff[jj][1], sel_a_diff[jj][2]); } else { - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { sel_a_diff[jj][dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; + } + } + for (int dd = 0; dd < 3; ++dd) { + rij_a[jj * 3 + dd] = sel_a_diff[jj][dd]; } - for (int dd = 0; dd < 3; ++dd) rij_a[jj * 3 + dd] = sel_a_diff[jj][dd]; } } @@ -801,7 +868,9 @@ void compute_descriptor_se_a_extf(std::vector &descrpt_a, for (int sec_iter = 0; sec_iter < int(sec_a.size()) - 1; ++sec_iter) { for (int nei_iter = sec_a[sec_iter]; nei_iter < sec_a[sec_iter + 1]; ++nei_iter) { - if (fmt_nlist_a[nei_iter] < 0) break; + if (fmt_nlist_a[nei_iter] < 0) { + break; + } const double *rr = &sel_a_diff[nei_iter][0]; // check validity of ef double nr2 = deepmd::dot3(rr, rr); @@ -909,7 +978,9 @@ void compute_descriptor_se_a_ef_para(std::vector &descrpt_a, fill(rij_a.begin(), rij_a.end(), 0.0); for (int ii = 0; ii < int(sec_a.size()) - 1; ++ii) { for (int jj = sec_a[ii]; jj < sec_a[ii + 1]; ++jj) { - if (fmt_nlist_a[jj] < 0) break; + if (fmt_nlist_a[jj] < 0) { + break; + } sel_a_diff[jj].resize(3); const int &j_idx = fmt_nlist_a[jj]; if (b_pbc) { @@ -918,10 +989,13 @@ void compute_descriptor_se_a_ef_para(std::vector &descrpt_a, posi[i_idx * 3 + 0], posi[i_idx * 3 + 1], posi[i_idx * 3 + 2], sel_a_diff[jj][0], sel_a_diff[jj][1], sel_a_diff[jj][2]); } else { - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { sel_a_diff[jj][dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; + } + } + for (int dd = 0; dd < 3; ++dd) { + rij_a[jj * 3 + dd] = sel_a_diff[jj][dd]; } - for (int dd = 0; dd < 3; ++dd) rij_a[jj * 3 + dd] = sel_a_diff[jj][dd]; } } @@ -935,7 +1009,9 @@ void compute_descriptor_se_a_ef_para(std::vector &descrpt_a, for (int sec_iter = 0; sec_iter < int(sec_a.size()) - 1; ++sec_iter) { for (int nei_iter = sec_a[sec_iter]; nei_iter < sec_a[sec_iter + 1]; ++nei_iter) { - if (fmt_nlist_a[nei_iter] < 0) break; + if (fmt_nlist_a[nei_iter] < 0) { + break; + } const double *rr = &sel_a_diff[nei_iter][0]; // check validity of ef double nr2 = deepmd::dot3(rr, rr); @@ -1039,7 +1115,9 @@ void compute_descriptor_se_a_ef_vert(std::vector &descrpt_a, fill(rij_a.begin(), rij_a.end(), 0.0); for (int ii = 0; ii < int(sec_a.size()) - 1; ++ii) { for (int jj = sec_a[ii]; jj < sec_a[ii + 1]; ++jj) { - if (fmt_nlist_a[jj] < 0) break; + if (fmt_nlist_a[jj] < 0) { + break; + } sel_a_diff[jj].resize(3); const int &j_idx = fmt_nlist_a[jj]; if (b_pbc) { @@ -1048,10 +1126,13 @@ void compute_descriptor_se_a_ef_vert(std::vector &descrpt_a, posi[i_idx * 3 + 0], posi[i_idx * 3 + 1], posi[i_idx * 3 + 2], sel_a_diff[jj][0], sel_a_diff[jj][1], sel_a_diff[jj][2]); } else { - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { sel_a_diff[jj][dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; + } + } + for (int dd = 0; dd < 3; ++dd) { + rij_a[jj * 3 + dd] = sel_a_diff[jj][dd]; } - for (int dd = 0; dd < 3; ++dd) rij_a[jj * 3 + dd] = sel_a_diff[jj][dd]; } } @@ -1065,7 +1146,9 @@ void compute_descriptor_se_a_ef_vert(std::vector &descrpt_a, for (int sec_iter = 0; sec_iter < int(sec_a.size()) - 1; ++sec_iter) { for (int nei_iter = sec_a[sec_iter]; nei_iter < sec_a[sec_iter + 1]; ++nei_iter) { - if (fmt_nlist_a[nei_iter] < 0) break; + if (fmt_nlist_a[nei_iter] < 0) { + break; + } const double *rr = &sel_a_diff[nei_iter][0]; // check validity of ef double nr2 = deepmd::dot3(rr, rr); diff --git a/source/lib/include/SimulationRegion_Impl.h b/source/lib/include/SimulationRegion_Impl.h index c6e34b27c4..96d47edc2b 100644 --- a/source/lib/include/SimulationRegion_Impl.h +++ b/source/lib/include/SimulationRegion_Impl.h @@ -199,11 +199,14 @@ inline void SimulationRegion::shiftCoord(const int *idx, template inline void SimulationRegion::apply_periodic(int dim, double *dd) const { - if (!is_periodic[dim]) return; - if (dd[dim] >= static_cast(0.5)) + if (!is_periodic[dim]) { + return; + } + if (dd[dim] >= static_cast(0.5)) { dd[dim] -= static_cast(1.); - else if (dd[dim] < -static_cast(0.5)) + } else if (dd[dim] < -static_cast(0.5)) { dd[dim] += static_cast(1.); + } } template @@ -211,7 +214,9 @@ inline void SimulationRegion::apply_periodic(int dim, double *dd, int &shift) const { shift = 0; - if (!is_periodic[dim]) return; + if (!is_periodic[dim]) { + return; + } if (dd[dim] >= static_cast(0.5)) { dd[dim] -= static_cast(1.); shift = -1; @@ -225,9 +230,13 @@ template inline void SimulationRegion::diffNearestNeighbor( const VALUETYPE *r0, const VALUETYPE *r1, VALUETYPE *phys) const { double inter[3]; - for (int dd = 0; dd < 3; ++dd) phys[dd] = r0[dd] - r1[dd]; + for (int dd = 0; dd < 3; ++dd) { + phys[dd] = r0[dd] - r1[dd]; + } SimulationRegion::phys2Inter(inter, phys); - for (int dd = 0; dd < 3; ++dd) apply_periodic(dd, inter); + for (int dd = 0; dd < 3; ++dd) { + apply_periodic(dd, inter); + } SimulationRegion::inter2Phys(phys, inter); } @@ -334,7 +343,9 @@ template inline void SimulationRegion::phys2Inter( double *i_v, const VALUETYPE *p_v_) const { double p_v[3]; - for (int dd = 0; dd < 3; ++dd) p_v[dd] = p_v_[dd]; + for (int dd = 0; dd < 3; ++dd) { + p_v[dd] = p_v_[dd]; + } tensorDotVector(i_v, rec_boxt, p_v); } @@ -343,7 +354,9 @@ inline void SimulationRegion::inter2Phys(VALUETYPE *p_v_, const double *i_v) const { double p_v[3]; tensorTransDotVector(p_v, boxt, i_v); - for (int dd = 0; dd < 3; ++dd) p_v_[dd] = p_v[dd]; + for (int dd = 0; dd < 3; ++dd) { + p_v_[dd] = p_v[dd]; + } } template diff --git a/source/lib/include/gpu_cuda.h b/source/lib/include/gpu_cuda.h index e15211ab07..541536aea6 100644 --- a/source/lib/include/gpu_cuda.h +++ b/source/lib/include/gpu_cuda.h @@ -30,9 +30,13 @@ inline void DPAssert(cudaError_t code, "`nvidia-smi`. " "The usage of GPUs is controlled by `CUDA_VISIBLE_DEVICES` " "environment variable.\n"); - if (abort) throw deepmd::deepmd_exception_oom("CUDA Assert"); + if (abort) { + throw deepmd::deepmd_exception_oom("CUDA Assert"); + } + } + if (abort) { + throw deepmd::deepmd_exception("CUDA Assert"); } - if (abort) throw deepmd::deepmd_exception("CUDA Assert"); } } @@ -58,9 +62,13 @@ inline void nborAssert(cudaError_t code, "`nvidia-smi`. " "The usage of GPUs is controlled by `CUDA_VISIBLE_DEVICES` " "environment variable.\n"); - if (abort) throw deepmd::deepmd_exception_oom("CUDA Assert"); + if (abort) { + throw deepmd::deepmd_exception_oom("CUDA Assert"); + } + } + if (abort) { + throw deepmd::deepmd_exception("CUDA Assert"); } - if (abort) throw deepmd::deepmd_exception("CUDA Assert"); } } diff --git a/source/lib/include/gpu_rocm.h b/source/lib/include/gpu_rocm.h index 7dccde6af9..ad89e1ccca 100644 --- a/source/lib/include/gpu_rocm.h +++ b/source/lib/include/gpu_rocm.h @@ -19,7 +19,9 @@ inline void DPAssert(hipError_t code, if (code != hipSuccess) { fprintf(stderr, "hip assert: %s %s %d\n", hipGetErrorString(code), file, line); - if (abort) throw deepmd::deepmd_exception("HIP Assert"); + if (abort) { + throw deepmd::deepmd_exception("HIP Assert"); + } } } @@ -32,8 +34,9 @@ inline void nborAssert(hipError_t code, if (code != hipSuccess) { fprintf(stderr, "hip assert: %s %s %d\n", "DeePMD-kit:\tillegal nbor list sorting", file, line); - if (abort) + if (abort) { throw deepmd::deepmd_exception("HIP Assert: illegal nbor list sorting"); + } } } diff --git a/source/lib/src/coord.cc b/source/lib/src/coord.cc index 8fb0ddc56a..b358781a0d 100644 --- a/source/lib/src/coord.cc +++ b/source/lib/src/coord.cc @@ -17,7 +17,9 @@ void deepmd::normalize_coord_cpu(FPTYPE* coord, convert_to_inter_cpu(ri, region, coord + 3 * ii); for (int dd = 0; dd < 3; ++dd) { ri[dd] = fmod(ri[dd], (FPTYPE)1.); - if (ri[dd] < (FPTYPE)0.) ri[dd] += (FPTYPE)1.; + if (ri[dd] < (FPTYPE)0.) { + ri[dd] += (FPTYPE)1.; + } } convert_to_phys_cpu(coord + 3 * ii, region, ri); } @@ -77,14 +79,18 @@ void deepmd::compute_cell_info( for (int dd = 0; dd < 3; ++dd) { cell_info[dd] = 0; // nat_stt cell_info[3 + dd] = to_face[dd] / rcut; // ncell - if (cell_info[3 + dd] == 0) cell_info[3 + dd] = 1; + if (cell_info[3 + dd] == 0) { + cell_info[3 + dd] = 1; + } cell_size[dd] = to_face[dd] / cell_info[3 + dd]; cell_info[12 + dd] = int(rcut / cell_size[dd]) + 1; // ngcell cell_info[6 + dd] = -cell_info[12 + dd]; // ext_stt cell_info[9 + dd] = cell_info[3 + dd] + cell_info[12 + dd]; // ext_end cell_info[15 + dd] = cell_info[12 + dd]; // cell_shift cell_info[18 + dd] = rcut / cell_size[dd]; // cell_iter - if (cell_info[18 + dd] * cell_size[dd] < rcut) cell_info[18 + dd] += 1; + if (cell_info[18 + dd] * cell_size[dd] < rcut) { + cell_info[18 + dd] += 1; + } } cell_info[21] = (cell_info[3 + 0]) * (cell_info[3 + 1]) * (cell_info[3 + 2]); // loc_cellnum diff --git a/source/lib/src/cuda/coord.cu b/source/lib/src/cuda/coord.cu index e35b3a0a7c..a9b63d836b 100644 --- a/source/lib/src/cuda/coord.cu +++ b/source/lib/src/cuda/coord.cu @@ -26,10 +26,14 @@ __device__ inline int compute_pbc_shift(int idx, int ncell) { int shift = 0; if (idx < 0) { shift = 1; - while (idx + shift * ncell < 0) shift++; + while (idx + shift * ncell < 0) { + shift++; + } } else if (idx >= ncell) { shift = -1; - while (idx + shift * ncell >= ncell) shift--; + while (idx + shift * ncell >= ncell) { + shift--; + } } return shift; } @@ -51,7 +55,9 @@ __global__ void normalize_one(FPTYPE *out_c, phys2Inter(inter, out_c + idy * 3, rec_boxt); for (int dd = 0; dd < 3; ++dd) { inter[dd] = _fmod(inter[dd], (FPTYPE)1.); - if (inter[dd] < (FPTYPE)0.) inter[dd] += (FPTYPE)1.; + if (inter[dd] < (FPTYPE)0.) { + inter[dd] += (FPTYPE)1.; + } } inter2Phys(out_c + idy * 3, inter, boxt); } @@ -86,7 +92,9 @@ __global__ void _fill_idx_cellmap(int *idx_cellmap, phys2Inter(inter, in_c + idy * 3, rec_boxt); for (int dd = 0; dd < 3; ++dd) { idx_noshift[dd] = (inter[dd] - nat_orig[dd]) / cell_size[dd]; - if (inter[dd] - nat_orig[dd] < (FPTYPE)0.) idx_noshift[dd]--; + if (inter[dd] - nat_orig[dd] < (FPTYPE)0.) { + idx_noshift[dd]--; + } if (idx_noshift[dd] < nat_stt[dd]) { idx_noshift[dd] = nat_stt[dd]; } else if (idx_noshift[dd] >= nat_end[dd]) { @@ -145,14 +153,18 @@ __global__ void _fill_total_cellnum_map(int *total_cellnum_map, shift[1] = compute_pbc_shift(idx[1], global_grid[1]); shift[2] = compute_pbc_shift(idx[2], global_grid[2]); bool loc = false; - if (shift[0] == 0 && shift[1] == 0 && shift[2] == 0) loc = true; + if (shift[0] == 0 && shift[1] == 0 && shift[2] == 0) { + loc = true; + } for (int dd = 0; dd < 3; dd++) { idx[dd] += shift[dd] * global_grid[dd]; } int orig_idy = collapse_index(idx, global_grid); mask_cellnum_map[idy] = loc_cellnum_map[orig_idy]; total_cellnum_map[idy] = mask_cellnum_map[idy]; - if (loc) mask_cellnum_map[idy] = 0; + if (loc) { + mask_cellnum_map[idy] = 0; + } cell_map[idy] = orig_idy; } } @@ -205,10 +217,11 @@ __global__ void _copy_coord(FPTYPE *out_c, int shift[3]; FPTYPE d_shift[3]; for (int ii = 0; ii < total_cellnum; ii++) { - if (idy >= sec_total_cellnum_map[ii + 1]) + if (idy >= sec_total_cellnum_map[ii + 1]) { cell_idx++; - else + } else { break; + } } for (int dd = 0; dd < 3; dd++) { shift[dd] = cell_shift_map[cell_idx * 3 + dd]; diff --git a/source/lib/src/cuda/cudart/cudart_stub.cc b/source/lib/src/cuda/cudart/cudart_stub.cc index c9a4f3f007..2a4bfdf362 100644 --- a/source/lib/src/cuda/cudart/cudart_stub.cc +++ b/source/lib/src/cuda/cudart/cudart_stub.cc @@ -105,7 +105,9 @@ extern void CUDARTAPI __cudaRegisterFunction(void **fatCubinHandle, int thread_limit, uint3 *tid, uint3 *bid, dim3 *bDim, dim3 *gDim, int *wSize); static auto func_ptr = LoadSymbol("__cudaRegisterFunction"); - if (!func_ptr) return; + if (!func_ptr) { + return; + } func_ptr(fatCubinHandle, hostFun, deviceFun, deviceName, thread_limit, tid, bid, bDim, gDim, wSize); } @@ -113,7 +115,9 @@ extern void CUDARTAPI __cudaRegisterFunction(void **fatCubinHandle, extern void CUDARTAPI __cudaUnregisterFatBinary(void **fatCubinHandle) { using FuncPtr = void(CUDARTAPI *)(void **fatCubinHandle); static auto func_ptr = LoadSymbol("__cudaUnregisterFatBinary"); - if (!func_ptr) return; + if (!func_ptr) { + return; + } func_ptr(fatCubinHandle); } @@ -129,7 +133,9 @@ extern void CUDARTAPI __cudaRegisterVar(void **fatCubinHandle, void **fatCubinHandle, char *hostVar, char *deviceAddress, const char *deviceName, int ext, size_t size, int constant, int global); static auto func_ptr = LoadSymbol("__cudaRegisterVar"); - if (!func_ptr) return; + if (!func_ptr) { + return; + } func_ptr(fatCubinHandle, hostVar, deviceAddress, deviceName, ext, size, constant, global); } @@ -137,7 +143,9 @@ extern void CUDARTAPI __cudaRegisterVar(void **fatCubinHandle, extern void **CUDARTAPI __cudaRegisterFatBinary(void *fatCubin) { using FuncPtr = void **(CUDARTAPI *)(void *fatCubin); static auto func_ptr = LoadSymbol("__cudaRegisterFatBinary"); - if (!func_ptr) return nullptr; + if (!func_ptr) { + return nullptr; + } return (void **)func_ptr(fatCubin); } @@ -148,7 +156,9 @@ extern cudaError_t CUDARTAPI __cudaPopCallConfiguration(dim3 *gridDim, using FuncPtr = cudaError_t(CUDARTAPI *)(dim3 * gridDim, dim3 * blockDim, size_t * sharedMem, void *stream); static auto func_ptr = LoadSymbol("__cudaPopCallConfiguration"); - if (!func_ptr) return GetSymbolNotFoundError(); + if (!func_ptr) { + return GetSymbolNotFoundError(); + } return func_ptr(gridDim, blockDim, sharedMem, stream); } @@ -157,14 +167,18 @@ extern __host__ __device__ unsigned CUDARTAPI __cudaPushCallConfiguration( using FuncPtr = unsigned(CUDARTAPI *)(dim3 gridDim, dim3 blockDim, size_t sharedMem, void *stream); static auto func_ptr = LoadSymbol("__cudaPushCallConfiguration"); - if (!func_ptr) return 0; + if (!func_ptr) { + return 0; + } return func_ptr(gridDim, blockDim, sharedMem, stream); } extern char CUDARTAPI __cudaInitModule(void **fatCubinHandle) { using FuncPtr = char(CUDARTAPI *)(void **fatCubinHandle); static auto func_ptr = LoadSymbol("__cudaInitModule"); - if (!func_ptr) return 0; + if (!func_ptr) { + return 0; + } return func_ptr(fatCubinHandle); } @@ -172,7 +186,9 @@ extern char CUDARTAPI __cudaInitModule(void **fatCubinHandle) { extern void CUDARTAPI __cudaRegisterFatBinaryEnd(void **fatCubinHandle) { using FuncPtr = void(CUDARTAPI *)(void **fatCubinHandle); static auto func_ptr = LoadSymbol("__cudaRegisterFatBinaryEnd"); - if (!func_ptr) return; + if (!func_ptr) { + return; + } func_ptr(fatCubinHandle); } #endif diff --git a/source/lib/src/cuda/neighbor_list.cu b/source/lib/src/cuda/neighbor_list.cu index f8a82671eb..fe148c4978 100644 --- a/source/lib/src/cuda/neighbor_list.cu +++ b/source/lib/src/cuda/neighbor_list.cu @@ -216,7 +216,9 @@ int build_nlist_gpu(InputNlist &nlist, cudaMemcpyDeviceToHost)); int max_nei = 0; for (int ii = 0; ii < nloc; ii++) { - if (numneigh_host[ii] > max_nei) max_nei = numneigh_host[ii]; + if (numneigh_host[ii] > max_nei) { + max_nei = numneigh_host[ii]; + } } *max_list_size = max_nei; delete[] numneigh_host; diff --git a/source/lib/src/cuda/prod_env_mat.cu b/source/lib/src/cuda/prod_env_mat.cu index 9a20a515c5..243b69c6b5 100644 --- a/source/lib/src/cuda/prod_env_mat.cu +++ b/source/lib/src/cuda/prod_env_mat.cu @@ -129,7 +129,9 @@ __global__ void format_nlist_fill_a(uint_64* key, uint_64* key_in = key + idx * MAX_NBOR_SIZE; FPTYPE diff[3]; const int& j_idx = nei_idx[idy]; - if (type[j_idx] < 0) return; + if (type[j_idx] < 0) { + return; + } for (int dd = 0; dd < 3; dd++) { diff[dd] = coord[j_idx * 3 + dd] - coord[idx * 3 + dd]; } @@ -151,8 +153,9 @@ __global__ void fill_nei_iter(int* nei_iter_dev, int nei_type_cur = -1, nbor_idx_cur = 0; int nei_type_pre = -1, nbor_idx_pre = 0; if (col < max_nbor_size && key_out[col] != key_out[max_nbor_size - 1]) { - if (col >= 1) + if (col >= 1) { decoding_nbor_info(nei_type_pre, nbor_idx_pre, key_out[col - 1]); + } decoding_nbor_info(nei_type_cur, nbor_idx_cur, key_out[col]); } if (nei_type_cur != nei_type_pre) { @@ -358,7 +361,9 @@ __global__ void compute_env_mat_a(FPTYPE* em, // <<>> const int_64 bid = blockIdx.x; const unsigned int tid = threadIdx.x; - if (type[bid] < 0) return; + if (type[bid] < 0) { + return; + } if (tid >= nnei) { return; } diff --git a/source/lib/src/cuda/prod_force_grad.cu b/source/lib/src/cuda/prod_force_grad.cu index b0429d1492..9589f3b498 100644 --- a/source/lib/src/cuda/prod_force_grad.cu +++ b/source/lib/src/cuda/prod_force_grad.cu @@ -44,7 +44,9 @@ __global__ void force_grad_wrt_neighbors_a(FPTYPE* grad_net, if (j_idx < 0) { return; } - if (j_idx >= nloc) j_idx = j_idx % nloc; + if (j_idx >= nloc) { + j_idx = j_idx % nloc; + } const int kk = idx / nloc; // frame index grad_net[idx * nnei * 4 + idy * 4 + idw] += dev_dot(grad + kk * nloc * 3 + j_idx * 3, @@ -69,7 +71,9 @@ __global__ void force_grad_wrt_neighbors_r(FPTYPE* grad_net, if (j_idx < 0) { return; } - if (j_idx >= nloc) j_idx = j_idx % nloc; + if (j_idx >= nloc) { + j_idx = j_idx % nloc; + } const int kk = idx / nloc; // frame index grad_net[idx * nnei + idy] += dev_dot(grad + kk * nloc * 3 + j_idx * 3, env_deriv + idx * nnei * 3 + idy * 3); diff --git a/source/lib/src/cuda/prod_virial.cu b/source/lib/src/cuda/prod_virial.cu index 7b42008e68..e01170f01c 100644 --- a/source/lib/src/cuda/prod_virial.cu +++ b/source/lib/src/cuda/prod_virial.cu @@ -21,7 +21,9 @@ __global__ void atom_virial_reduction(FPTYPE* virial, __syncthreads(); } // write result for this block to global memory - if (tid == 0) virial[bid] = data[0]; + if (tid == 0) { + virial[bid] = data[0]; + } } template diff --git a/source/lib/src/cuda/tabulate.cu b/source/lib/src/cuda/tabulate.cu index a63038f406..2df2c5c46a 100644 --- a/source/lib/src/cuda/tabulate.cu +++ b/source/lib/src/cuda/tabulate.cu @@ -110,8 +110,9 @@ __forceinline__ __device__ FPTYPE dot(FPTYPE ll[4], FPTYPE rr[4]) { template __forceinline__ __device__ void warp_reduce(FPTYPE& val) { - for (int offset = 16; offset > 0; offset >>= 1) + for (int offset = 16; offset > 0; offset >>= 1) { val += __shfl_down_sync(FULL_MASK, val, offset); + } } template @@ -164,7 +165,9 @@ __global__ void tabulate_fusion_se_a_fifth_order_polynomial( sum[kk] += (nnei - breakpoint) * em[block_idx * nnei * MTILE + ii * MTILE + kk] * res; } - if (unloop) break; + if (unloop) { + break; + } mark_table_idx = table_idx; } for (int ii = 0; ii < MTILE; ii++) { @@ -263,7 +266,9 @@ __global__ void tabulate_fusion_se_a_grad_fifth_order_polynomial( } dy_dem_x[block_idx * nnei + ii] = Csub; } - if (unloop) break; + if (unloop) { + break; + } } } @@ -289,8 +294,9 @@ __global__ void tabulate_fusion_se_a_grad_grad_fifth_order_polynomial( bool unloop = false; int breakpoint = nnei - 1; FPTYPE* iteratorC = (FPTYPE*)&_data[0]; - for (int kk = 0; kk < MTILE; kk++) + for (int kk = 0; kk < MTILE; kk++) { iteratorC[kk * last_layer_size + thread_idx] = (FPTYPE)0.; + } __syncthreads(); int mark_table_idx = -1; @@ -325,7 +331,9 @@ __global__ void tabulate_fusion_se_a_grad_grad_fifth_order_polynomial( (em[em_index] * res_grad * dz_xx + dz_dy_dem[em_index] * res); } mark_table_idx = table_idx; - if (unloop) break; + if (unloop) { + break; + } } for (int ii = 0; ii < MTILE; ii++) { dz_dy[block_idx * MTILE * last_layer_size + ii * last_layer_size + diff --git a/source/lib/src/env_mat.cc b/source/lib/src/env_mat.cc index ebd4e2c573..ceaea1a125 100644 --- a/source/lib/src/env_mat.cc +++ b/source/lib/src/env_mat.cc @@ -23,7 +23,9 @@ void env_mat_a(std::vector& descrpt_a, fill(rij_a.begin(), rij_a.end(), 0.0); for (int ii = 0; ii < int(sec_a.size()) - 1; ++ii) { for (int jj = sec_a[ii]; jj < sec_a[ii + 1]; ++jj) { - if (fmt_nlist_a[jj] < 0) break; + if (fmt_nlist_a[jj] < 0) { + break; + } sel_a_diff[jj].resize(3); const int& j_idx = fmt_nlist_a[jj]; if (b_pbc) { @@ -32,10 +34,13 @@ void env_mat_a(std::vector& descrpt_a, posi[i_idx * 3 + 0], posi[i_idx * 3 + 1], posi[i_idx * 3 + 2], sel_a_diff[jj][0], sel_a_diff[jj][1], sel_a_diff[jj][2]); } else { - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { sel_a_diff[jj][dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; + } + } + for (int dd = 0; dd < 3; ++dd) { + rij_a[jj * 3 + dd] = sel_a_diff[jj][dd]; } - for (int dd = 0; dd < 3; ++dd) rij_a[jj * 3 + dd] = sel_a_diff[jj][dd]; } } @@ -49,7 +54,9 @@ void env_mat_a(std::vector& descrpt_a, for (int sec_iter = 0; sec_iter < int(sec_a.size()) - 1; ++sec_iter) { for (int nei_iter = sec_a[sec_iter]; nei_iter < sec_a[sec_iter + 1]; ++nei_iter) { - if (fmt_nlist_a[nei_iter] < 0) break; + if (fmt_nlist_a[nei_iter] < 0) { + break; + } const double* rr = &sel_a_diff[nei_iter][0]; double nr2 = deepmd::dot3(rr, rr); double inr = 1. / sqrt(nr2); @@ -128,7 +135,9 @@ void deepmd::env_mat_a_cpu(std::vector& descrpt_a, fill(rij_a.begin(), rij_a.end(), (FPTYPE)0.0); for (int ii = 0; ii < int(sec_a.size()) - 1; ++ii) { for (int jj = sec_a[ii]; jj < sec_a[ii + 1]; ++jj) { - if (fmt_nlist_a[jj] < 0) break; + if (fmt_nlist_a[jj] < 0) { + break; + } const int& j_idx = fmt_nlist_a[jj]; for (int dd = 0; dd < 3; ++dd) { rij_a[jj * 3 + dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; @@ -145,7 +154,9 @@ void deepmd::env_mat_a_cpu(std::vector& descrpt_a, for (int sec_iter = 0; sec_iter < int(sec_a.size()) - 1; ++sec_iter) { for (int nei_iter = sec_a[sec_iter]; nei_iter < sec_a[sec_iter + 1]; ++nei_iter) { - if (fmt_nlist_a[nei_iter] < 0) break; + if (fmt_nlist_a[nei_iter] < 0) { + break; + } const FPTYPE* rr = &rij_a[nei_iter * 3]; FPTYPE nr2 = deepmd::dot3(rr, rr); FPTYPE inr = (FPTYPE)1. / sqrt(nr2); @@ -227,7 +238,9 @@ void env_mat_r(std::vector& descrpt, fill(rij.begin(), rij.end(), 0.0); for (int ii = 0; ii < int(sec.size()) - 1; ++ii) { for (int jj = sec[ii]; jj < sec[ii + 1]; ++jj) { - if (fmt_nlist[jj] < 0) break; + if (fmt_nlist[jj] < 0) { + break; + } sel_diff[jj].resize(3); const int& j_idx = fmt_nlist[jj]; if (b_pbc) { @@ -236,10 +249,13 @@ void env_mat_r(std::vector& descrpt, posi[i_idx * 3 + 0], posi[i_idx * 3 + 1], posi[i_idx * 3 + 2], sel_diff[jj][0], sel_diff[jj][1], sel_diff[jj][2]); } else { - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { sel_diff[jj][dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; + } + } + for (int dd = 0; dd < 3; ++dd) { + rij[jj * 3 + dd] = sel_diff[jj][dd]; } - for (int dd = 0; dd < 3; ++dd) rij[jj * 3 + dd] = sel_diff[jj][dd]; } } @@ -253,7 +269,9 @@ void env_mat_r(std::vector& descrpt, for (int sec_iter = 0; sec_iter < int(sec.size()) - 1; ++sec_iter) { for (int nei_iter = sec[sec_iter]; nei_iter < sec[sec_iter + 1]; ++nei_iter) { - if (fmt_nlist[nei_iter] < 0) break; + if (fmt_nlist[nei_iter] < 0) { + break; + } const double* rr = &sel_diff[nei_iter][0]; double nr2 = deepmd::dot3(rr, rr); double inr = 1. / sqrt(nr2); @@ -296,7 +314,9 @@ void deepmd::env_mat_r_cpu(std::vector& descrpt_a, fill(rij_a.begin(), rij_a.end(), (FPTYPE)0.0); for (int ii = 0; ii < int(sec.size()) - 1; ++ii) { for (int jj = sec[ii]; jj < sec[ii + 1]; ++jj) { - if (fmt_nlist[jj] < 0) break; + if (fmt_nlist[jj] < 0) { + break; + } const int& j_idx = fmt_nlist[jj]; for (int dd = 0; dd < 3; ++dd) { @@ -314,7 +334,9 @@ void deepmd::env_mat_r_cpu(std::vector& descrpt_a, for (int sec_iter = 0; sec_iter < int(sec.size()) - 1; ++sec_iter) { for (int nei_iter = sec[sec_iter]; nei_iter < sec[sec_iter + 1]; ++nei_iter) { - if (fmt_nlist[nei_iter] < 0) break; + if (fmt_nlist[nei_iter] < 0) { + break; + } const FPTYPE* rr = &rij_a[nei_iter * 3]; FPTYPE nr2 = deepmd::dot3(rr, rr); FPTYPE inr = (FPTYPE)1. / sqrt(nr2); diff --git a/source/lib/src/env_mat_nvnmd.cc b/source/lib/src/env_mat_nvnmd.cc index 5b4b03eeca..cc2aefaba1 100644 --- a/source/lib/src/env_mat_nvnmd.cc +++ b/source/lib/src/env_mat_nvnmd.cc @@ -44,7 +44,9 @@ void deepmd::env_mat_a_nvnmd_quantize_cpu(std::vector& descrpt_a, fill(rij_a.begin(), rij_a.end(), 0.0); for (int ii = 0; ii < int(sec_a.size()) - 1; ++ii) { for (int jj = sec_a[ii]; jj < sec_a[ii + 1]; ++jj) { - if (fmt_nlist_a[jj] < 0) break; + if (fmt_nlist_a[jj] < 0) { + break; + } const int& j_idx = fmt_nlist_a[jj]; for (int dd = 0; dd < 3; ++dd) { rij_a[jj * 3 + dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; @@ -63,7 +65,9 @@ void deepmd::env_mat_a_nvnmd_quantize_cpu(std::vector& descrpt_a, for (int sec_iter = 0; sec_iter < int(sec_a.size()) - 1; ++sec_iter) { for (int nei_iter = sec_a[sec_iter]; nei_iter < sec_a[sec_iter + 1]; ++nei_iter) { - if (fmt_nlist_a[nei_iter] < 0) break; + if (fmt_nlist_a[nei_iter] < 0) { + break; + } const FPTYPE* rr = &rij_a[nei_iter * 3]; // NVNMD diff --git a/source/lib/src/ewald.cc b/source/lib/src/ewald.cc index 9e9a5efc3d..04883d819f 100644 --- a/source/lib/src/ewald.cc +++ b/source/lib/src/ewald.cc @@ -38,8 +38,9 @@ VALUETYPE rec_err_esti(const VALUETYPE& test_q, for (mm[2] = -BD[2]; mm[2] <= BD[2]; ++mm[2]) { if (mm[0] >= -int(KK[0]) / 2 && mm[0] <= int(KK[0]) / 2 && mm[1] >= -int(KK[1]) / 2 && mm[1] <= int(KK[1]) / 2 && - mm[2] >= -int(KK[2]) / 2 && mm[2] <= int(KK[2]) / 2) + mm[2] >= -int(KK[2]) / 2 && mm[2] <= int(KK[2]) / 2) { continue; + } VALUETYPE rm[3] = {0, 0, 0}; for (int dd = 0; dd < 3; ++dd) { rm[0] += mm[dd] * rec_box[dd * 3 + 0]; @@ -70,10 +71,14 @@ void cmpt_k(std::vector& KK, VALUETYPE ll = sqrt(deepmd::dot3(boxt + dd * 3, boxt + dd * 3)); KK[dd] = ll / param.spacing; // KK[dd] should be large enough - if (KK[dd] * param.spacing < ll) KK[dd] += 1; + if (KK[dd] * param.spacing < ll) { + KK[dd] += 1; + } assert(KK[dd] * param.spacing >= ll); // KK[dd] should be even - if ((KK[dd] / 2) * 2 != KK[dd]) KK[dd] += 1; + if ((KK[dd] / 2) * 2 != KK[dd]) { + KK[dd] += 1; + } assert((KK[dd] / 2) * 2 == KK[dd]); } } @@ -115,7 +120,9 @@ void deepmd::ewald_recp(VALUETYPE& ener, totK *= (KK[dd] + 1); } int stride[3]; - for (int dd = 0; dd < 3; ++dd) stride[dd] = KK[dd] + 1; + for (int dd = 0; dd < 3; ++dd) { + stride[dd] = KK[dd] + 1; + } // compute the sq std::vector > thread_sqr(nthreads), @@ -141,7 +148,9 @@ void deepmd::ewald_recp(VALUETYPE& ener, mr[1] = ir[1] * mm1; int shift1 = (mm1 + KK[1] / 2) * stride[2]; for (int mm2 = -KK[2] / 2; mm2 <= KK[2] / 2; ++mm2) { - if (mm0 == 0 && mm1 == 0 && mm2 == 0) continue; + if (mm0 == 0 && mm1 == 0 && mm2 == 0) { + continue; + } int mc = shift0 + shift1 + mm2 + KK[2] / 2; mr[2] = ir[2] * mm2; VALUETYPE mdotr = 2. * M_PI * (mr[0] + mr[1] + mr[2]); @@ -190,7 +199,9 @@ void deepmd::ewald_recp(VALUETYPE& ener, // int shift1 = (mm1 + KK[1]/2) * stride[2]; // for (int mm2 = -KK[2]/2; mm2 <= KK[2]/2; ++mm2){ // int mc = shift0 + shift1 + mm2 + KK[2]/2; - if (mm0 == 0 && mm1 == 0 && mm2 == 0) continue; + if (mm0 == 0 && mm1 == 0 && mm2 == 0) { + continue; + } // \bm m and \vert m \vert^2 VALUETYPE rm[3] = {0, 0, 0}; rm[0] += mm0 * rec_box[0 * 3 + 0]; @@ -215,7 +226,9 @@ void deepmd::ewald_recp(VALUETYPE& ener, for (int dd0 = 0; dd0 < 3; ++dd0) { for (int dd1 = 0; dd1 < 3; ++dd1) { VALUETYPE tmp = vpref * rm[dd0] * rm[dd1]; - if (dd0 == dd1) tmp += 1; + if (dd0 == dd1) { + tmp += 1; + } thread_virial[thread_id][dd0 * 3 + dd1] += eincr * tmp; } } diff --git a/source/lib/src/fmt_nlist.cc b/source/lib/src/fmt_nlist.cc index 23ebf6cc58..e06c7dc479 100644 --- a/source/lib/src/fmt_nlist.cc +++ b/source/lib/src/fmt_nlist.cc @@ -63,8 +63,9 @@ int format_nlist_i_fill_a(std::vector &fmt_nei_idx_a, posi[i_idx * 3 + 1], posi[i_idx * 3 + 2], diff[0], diff[1], diff[2]); } else { - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { diff[dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; + } } double rr = sqrt(deepmd::dot3(diff, diff)); if (rr <= rcut) { @@ -114,7 +115,9 @@ int format_nlist_i_cpu(std::vector &fmt_nei_idx_a, // rcut is float in this function, so float rr is enough float diff[3]; const int &j_idx = nei_idx[kk]; - if (type[j_idx] < 0) continue; + if (type[j_idx] < 0) { + continue; + } for (int dd = 0; dd < 3; ++dd) { diff[dd] = (float)posi[j_idx * 3 + dd] - (float)posi[i_idx * 3 + dd]; } diff --git a/source/lib/src/map_aparam.cc b/source/lib/src/map_aparam.cc index e95d3cbc0a..e458c636e2 100644 --- a/source/lib/src/map_aparam.cc +++ b/source/lib/src/map_aparam.cc @@ -26,7 +26,9 @@ void deepmd::map_aparam_cpu(FPTYPE* output, // loop over neighbor atoms for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } // loop over elements of aparam for (int dd = 0; dd < numb_aparam; ++dd) { output[ii * nnei * numb_aparam + jj * numb_aparam + dd] = diff --git a/source/lib/src/neighbor_list.cc b/source/lib/src/neighbor_list.cc index 19b4908334..3954fd386a 100644 --- a/source/lib/src/neighbor_list.cc +++ b/source/lib/src/neighbor_list.cc @@ -15,8 +15,12 @@ bool is_loc(const std::vector& idx, const std::vector& nat_stt, const std::vector& nat_end) { bool ret = true; - for (int dd = 0; dd < 3; ++dd) ret = ret && idx[dd] >= nat_stt[dd]; - for (int dd = 0; dd < 3; ++dd) ret = ret && idx[dd] < nat_end[dd]; + for (int dd = 0; dd < 3; ++dd) { + ret = ret && idx[dd] >= nat_stt[dd]; + } + for (int dd = 0; dd < 3; ++dd) { + ret = ret && idx[dd] < nat_end[dd]; + } return ret; } @@ -49,14 +53,22 @@ void build_clist(std::vector >& clist, // compute region info, in terms of internal coord int nall = coord.size() / 3; std::vector ext_ncell(3); - for (int dd = 0; dd < 3; ++dd) ext_ncell[dd] = ext_end[dd] - ext_stt[dd]; + for (int dd = 0; dd < 3; ++dd) { + ext_ncell[dd] = ext_end[dd] - ext_stt[dd]; + } int ncell = ext_ncell[0] * ext_ncell[1] * ext_ncell[2]; std::vector cell_size(3); - for (int dd = 0; dd < 3; ++dd) cell_size[dd] = 1. / global_grid[dd]; + for (int dd = 0; dd < 3; ++dd) { + cell_size[dd] = 1. / global_grid[dd]; + } std::vector nat_orig(3); - for (int dd = 0; dd < 3; ++dd) nat_orig[dd] = nat_stt[dd] * cell_size[dd]; + for (int dd = 0; dd < 3; ++dd) { + nat_orig[dd] = nat_stt[dd] * cell_size[dd]; + } std::vector idx_orig_shift(3); - for (int dd = 0; dd < 3; ++dd) idx_orig_shift[dd] = nat_stt[dd] - ext_stt[dd]; + for (int dd = 0; dd < 3; ++dd) { + idx_orig_shift[dd] = nat_stt[dd] - ext_stt[dd]; + } // allocate the reserve the cell list clist.resize(ncell); @@ -73,7 +85,9 @@ void build_clist(std::vector >& clist, std::vector idx(3); for (int dd = 0; dd < 3; ++dd) { idx[dd] = (inter[dd] - nat_orig[dd]) / cell_size[dd]; - if (inter[dd] - nat_orig[dd] < 0.) idx[dd]--; + if (inter[dd] - nat_orig[dd] < 0.) { + idx[dd]--; + } if (idx[dd] < nat_stt[dd]) { if (count_warning_loc_idx_lower < MAX_WARN_IDX_OUT_OF_BOUND) { std::cerr << "# warning: loc idx out of lower bound (ignored if " @@ -101,7 +115,9 @@ void build_clist(std::vector >& clist, std::vector idx(3); for (int dd = 0; dd < 3; ++dd) { idx[dd] = (inter[dd] - nat_orig[dd]) / cell_size[dd]; - if (inter[dd] - nat_orig[dd] < 0.) idx[dd]--; + if (inter[dd] - nat_orig[dd] < 0.) { + idx[dd]--; + } if (idx[dd] < ext_stt[dd]) { if (count_warning_ghost_idx_lower < MAX_WARN_IDX_OUT_OF_BOUND && fabs((inter[dd] - nat_orig[dd]) - (ext_stt[dd] * cell_size[dd])) > @@ -139,12 +155,18 @@ void build_clist(std::vector >& clist, // compute region info, in terms of internal coord int nall = coord.size() / 3; std::vector nat_ncell(3); - for (int dd = 0; dd < 3; ++dd) nat_ncell[dd] = nat_end[dd] - nat_stt[dd]; + for (int dd = 0; dd < 3; ++dd) { + nat_ncell[dd] = nat_end[dd] - nat_stt[dd]; + } int ncell = nat_ncell[0] * nat_ncell[1] * nat_ncell[2]; std::vector cell_size(3); - for (int dd = 0; dd < 3; ++dd) cell_size[dd] = 1. / nat_end[dd]; + for (int dd = 0; dd < 3; ++dd) { + cell_size[dd] = 1. / nat_end[dd]; + } std::vector nat_orig(3); - for (int dd = 0; dd < 3; ++dd) nat_orig[dd] = nat_stt[dd] * cell_size[dd]; + for (int dd = 0; dd < 3; ++dd) { + nat_orig[dd] = nat_stt[dd] * cell_size[dd]; + } // allocate the reserve the cell list clist.resize(ncell); @@ -162,7 +184,9 @@ void build_clist(std::vector >& clist, std::vector idx(3); for (int dd = 0; dd < 3; ++dd) { idx[dd] = (inter[dd] - nat_orig[dd]) / cell_size[dd]; - if (inter[dd] - nat_orig[dd] < 0.) idx[dd]--; + if (inter[dd] - nat_orig[dd] < 0.) { + idx[dd]--; + } if (idx[dd] < nat_stt[dd]) { if (count_warning_loc_idx_lower < MAX_WARN_IDX_OUT_OF_BOUND) { std::cerr << "# warning: loc idx out of lower bound (ignored if " @@ -204,7 +228,9 @@ void build_nlist_cell(std::vector >& nlist0, // loop over t (target) cell for (unsigned jj = 0; jj < clist[tidx].size(); ++jj) { int j_idx = clist[tidx][jj]; - if (cidx == tidx && j_idx <= i_idx) continue; + if (cidx == tidx && j_idx <= i_idx) { + continue; + } double diff[3]; for (int dd0 = 0; dd0 < 3; ++dd0) { diff[dd0] = coord[i_idx * 3 + dd0] - coord[j_idx * 3 + dd0]; @@ -214,11 +240,19 @@ void build_nlist_cell(std::vector >& nlist0, } double r2 = deepmd::dot3(diff, diff); if (r2 < rc02) { - if (i_idx < nloc) nlist0[i_idx].push_back(j_idx); - if (j_idx < nloc) nlist0[j_idx].push_back(i_idx); + if (i_idx < nloc) { + nlist0[i_idx].push_back(j_idx); + } + if (j_idx < nloc) { + nlist0[j_idx].push_back(i_idx); + } } else if (r2 < rc12) { - if (i_idx < nloc) nlist1[i_idx].push_back(j_idx); - if (j_idx < nloc) nlist1[j_idx].push_back(i_idx); + if (i_idx < nloc) { + nlist1[i_idx].push_back(j_idx); + } + if (j_idx < nloc) { + nlist1[j_idx].push_back(i_idx); + } } } } @@ -239,11 +273,15 @@ void build_nlist_cell(std::vector >& nlist0, // loop over c (current) cell for (unsigned ii = 0; ii < clist0[cidx].size(); ++ii) { int i_idx = clist0[cidx][ii]; - if (i_idx >= nlist0.size()) continue; + if (i_idx >= nlist0.size()) { + continue; + } // loop over t (target) cell for (unsigned jj = 0; jj < clist1[tidx].size(); ++jj) { int j_idx = clist1[tidx][jj]; - if (cidx == tidx && j_idx == i_idx) continue; + if (cidx == tidx && j_idx == i_idx) { + continue; + } double diff[3]; for (int dd0 = 0; dd0 < 3; ++dd0) { diff[dd0] = coord[i_idx * 3 + dd0] - coord[j_idx * 3 + dd0]; @@ -288,7 +326,9 @@ void build_nlist(std::vector >& nlist0, // compute the region info int nall = coord.size() / 3; std::vector ext_ncell(3); - for (int dd = 0; dd < 3; ++dd) ext_ncell[dd] = ext_end[dd] - ext_stt[dd]; + for (int dd = 0; dd < 3; ++dd) { + ext_ncell[dd] = ext_end[dd] - ext_stt[dd]; + } // compute number of iter according to the cut-off assert(rc0 <= rc1); @@ -298,7 +338,9 @@ void build_nlist(std::vector >& nlist0, for (int dd = 0; dd < 3; ++dd) { double cell_size = to_face[dd] / nat_end[dd]; niter[dd] = rc1 / cell_size; - if (niter[dd] * cell_size < rc1) niter[dd] += 1; + if (niter[dd] * cell_size < rc1) { + niter[dd] += 1; + } assert(niter[dd] * cell_size >= rc1); } // check the validity of the iters @@ -313,7 +355,9 @@ void build_nlist(std::vector >& nlist0, for (int ii = 0; ii < nloc; ++ii) { nlist0[ii].clear(); int esti = 4. / 3. * 3.14 * (rc0 * rc0 * rc0) * density * 1.5 + 20; - if (esti < 0) esti = 10; + if (esti < 0) { + esti = 10; + } nlist0[ii].reserve(esti); } nlist1.resize(nloc); @@ -322,25 +366,32 @@ void build_nlist(std::vector >& nlist0, int esti = 4. / 3. * 3.14 * (rc1 * rc1 * rc1 - rc0 * rc0 * rc0) * density * 1.5 + 20; - if (esti < 0) esti = 10; + if (esti < 0) { + esti = 10; + } nlist1[ii].reserve(esti); } // shift of the idx origin std::vector idx_orig_shift(3); - for (int dd = 0; dd < 3; ++dd) idx_orig_shift[dd] = nat_stt[dd] - ext_stt[dd]; + for (int dd = 0; dd < 3; ++dd) { + idx_orig_shift[dd] = nat_stt[dd] - ext_stt[dd]; + } // compute the nlists double rc02 = 0; - if (rc0 > 0) rc02 = rc0 * rc0; + if (rc0 > 0) { + rc02 = rc0 * rc0; + } double rc12 = rc1 * rc1; std::vector cidx(3); for (cidx[0] = nat_stt[0]; cidx[0] < nat_end[0]; ++cidx[0]) { for (cidx[1] = nat_stt[1]; cidx[1] < nat_end[1]; ++cidx[1]) { for (cidx[2] = nat_stt[2]; cidx[2] < nat_end[2]; ++cidx[2]) { std::vector mcidx(3); - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { mcidx[dd] = cidx[dd] + idx_orig_shift[dd]; + } int clp_cidx = collapse_index(mcidx, ext_ncell); std::vector tidx(3); for (tidx[0] = cidx[0] - niter[0]; tidx[0] < cidx[0] + niter[0] + 1; @@ -350,11 +401,13 @@ void build_nlist(std::vector >& nlist0, for (tidx[2] = cidx[2] - niter[2]; tidx[2] < cidx[2] + niter[2] + 1; ++tidx[2]) { std::vector mtidx(3); - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { mtidx[dd] = tidx[dd] + idx_orig_shift[dd]; + } int clp_tidx = collapse_index(mtidx, ext_ncell); - if (is_loc(tidx, nat_stt, nat_end) && clp_tidx < clp_cidx) + if (is_loc(tidx, nat_stt, nat_end) && clp_tidx < clp_cidx) { continue; + } build_nlist_cell(nlist0, nlist1, clp_cidx, clp_tidx, clist, coord, rc02, rc12); } @@ -385,7 +438,9 @@ void build_nlist(std::vector >& nlist0, // compute the region info int nall = coord.size() / 3; std::vector nat_ncell(3); - for (int dd = 0; dd < 3; ++dd) nat_ncell[dd] = nat_end[dd] - nat_stt[dd]; + for (int dd = 0; dd < 3; ++dd) { + nat_ncell[dd] = nat_end[dd] - nat_stt[dd]; + } // compute number of iter according to the cut-off assert(rc0 <= rc1); @@ -395,7 +450,9 @@ void build_nlist(std::vector >& nlist0, for (int dd = 0; dd < 3; ++dd) { double cell_size = to_face[dd] / nat_end[dd]; niter[dd] = rc1 / cell_size; - if (niter[dd] * cell_size < rc1) niter[dd] += 1; + if (niter[dd] * cell_size < rc1) { + niter[dd] += 1; + } assert(niter[dd] * cell_size >= rc1); } // check the validity of the iters @@ -420,11 +477,15 @@ void build_nlist(std::vector >& nlist0, // physical cell size std::vector phys_cs(9); - for (int dd = 0; dd < 9; ++dd) phys_cs[dd] = region.getBoxTensor()[dd]; + for (int dd = 0; dd < 9; ++dd) { + phys_cs[dd] = region.getBoxTensor()[dd]; + } // compute the nlists double rc02 = 0; - if (rc0 > 0) rc02 = rc0 * rc0; + if (rc0 > 0) { + rc02 = rc0 * rc0; + } double rc12 = rc1 * rc1; #ifdef HALF_NEIGHBOR_LIST @@ -455,30 +516,35 @@ void build_nlist(std::vector >& nlist0, for (tidx[0] = cidx[0] - niter[0]; tidx[0] < cidx[0] + niter[0] + 1; ++tidx[0]) { shift[0] = 0; - if (tidx[0] < 0) + if (tidx[0] < 0) { shift[0] += 1; - else if (tidx[0] >= nat_ncell[0]) + } else if (tidx[0] >= nat_ncell[0]) { shift[0] -= 1; + } stidx[0] = tidx[0] + shift[0] * nat_ncell[0]; for (tidx[1] = cidx[1] - niter[1]; tidx[1] < cidx[1] + niter[1] + 1; ++tidx[1]) { shift[1] = 0; - if (tidx[1] < 0) + if (tidx[1] < 0) { shift[1] += 1; - else if (tidx[1] >= nat_ncell[1]) + } else if (tidx[1] >= nat_ncell[1]) { shift[1] -= 1; + } stidx[1] = tidx[1] + shift[1] * nat_ncell[1]; for (tidx[2] = cidx[2] - niter[2]; tidx[2] < cidx[2] + niter[2] + 1; ++tidx[2]) { shift[2] = 0; - if (tidx[2] < 0) + if (tidx[2] < 0) { shift[2] += 1; - else if (tidx[2] >= nat_ncell[2]) + } else if (tidx[2] >= nat_ncell[2]) { shift[2] -= 1; + } stidx[2] = tidx[2] + shift[2] * nat_ncell[2]; int clp_tidx = collapse_index(stidx, nat_ncell); #ifdef HALF_NEIGHBOR_LIST - if (clp_tidx < clp_cidx) continue; + if (clp_tidx < clp_cidx) { + continue; + } build_nlist_cell(nlist0, nlist1, clp_cidx, clp_tidx, clist, coord, rc02, rc12, shift, phys_cs); #else @@ -513,7 +579,9 @@ void build_nlist(std::vector >& nlist0, // compute the region info int nall = coord.size() / 3; std::vector nat_ncell(3); - for (int dd = 0; dd < 3; ++dd) nat_ncell[dd] = nat_end[dd] - nat_stt[dd]; + for (int dd = 0; dd < 3; ++dd) { + nat_ncell[dd] = nat_end[dd] - nat_stt[dd]; + } // compute number of iter according to the cut-off assert(rc0 <= rc1); @@ -523,7 +591,9 @@ void build_nlist(std::vector >& nlist0, for (int dd = 0; dd < 3; ++dd) { double cell_size = to_face[dd] / nat_end[dd]; niter[dd] = rc1 / cell_size; - if (niter[dd] * cell_size < rc1) niter[dd] += 1; + if (niter[dd] * cell_size < rc1) { + niter[dd] += 1; + } assert(niter[dd] * cell_size >= rc1); } // check the validity of the iters @@ -548,11 +618,15 @@ void build_nlist(std::vector >& nlist0, // physical cell size std::vector phys_cs(9); - for (int dd = 0; dd < 9; ++dd) phys_cs[dd] = region.getBoxTensor()[dd]; + for (int dd = 0; dd < 9; ++dd) { + phys_cs[dd] = region.getBoxTensor()[dd]; + } // compute the nlists double rc02 = 0; - if (rc0 > 0) rc02 = rc0 * rc0; + if (rc0 > 0) { + rc02 = rc0 * rc0; + } double rc12 = rc1 * rc1; std::vector cidx(3); for (cidx[0] = nat_stt[0]; cidx[0] < nat_end[0]; ++cidx[0]) { @@ -565,26 +639,29 @@ void build_nlist(std::vector >& nlist0, for (tidx[0] = cidx[0] - niter[0]; tidx[0] < cidx[0] + niter[0] + 1; ++tidx[0]) { shift[0] = 0; - if (tidx[0] < 0) + if (tidx[0] < 0) { shift[0] += 1; - else if (tidx[0] >= nat_ncell[0]) + } else if (tidx[0] >= nat_ncell[0]) { shift[0] -= 1; + } stidx[0] = tidx[0] + shift[0] * nat_ncell[0]; for (tidx[1] = cidx[1] - niter[1]; tidx[1] < cidx[1] + niter[1] + 1; ++tidx[1]) { shift[1] = 0; - if (tidx[1] < 0) + if (tidx[1] < 0) { shift[1] += 1; - else if (tidx[1] >= nat_ncell[1]) + } else if (tidx[1] >= nat_ncell[1]) { shift[1] -= 1; + } stidx[1] = tidx[1] + shift[1] * nat_ncell[1]; for (tidx[2] = cidx[2] - niter[2]; tidx[2] < cidx[2] + niter[2] + 1; ++tidx[2]) { shift[2] = 0; - if (tidx[2] < 0) + if (tidx[2] < 0) { shift[2] += 1; - else if (tidx[2] >= nat_ncell[2]) + } else if (tidx[2] >= nat_ncell[2]) { shift[2] -= 1; + } stidx[2] = tidx[2] + shift[2] * nat_ncell[2]; int clp_tidx = collapse_index(stidx, nat_ncell); build_nlist_cell(nlist0, nlist1, clp_cidx, clp_tidx, clist0, @@ -608,7 +685,9 @@ void build_nlist(std::vector >& nlist0, assert(rc0 <= rc1); double rc02 = rc0 * rc0; // negative rc0 means not applying rc0 - if (rc0 < 0) rc02 = 0; + if (rc0 < 0) { + rc02 = 0; + } double rc12 = rc1 * rc1; unsigned natoms = posi3.size() / 3; @@ -649,10 +728,14 @@ static int compute_pbc_shift(int idx, int ncell) { int shift = 0; if (idx < 0) { shift = 1; - while (idx + shift * ncell < 0) shift++; + while (idx + shift * ncell < 0) { + shift++; + } } else if (idx >= ncell) { shift = -1; - while (idx + shift * ncell >= ncell) shift--; + while (idx + shift * ncell >= ncell) { + shift--; + } } assert(idx + shift * ncell >= 0 && idx + shift * ncell < ncell); return shift; @@ -677,7 +760,9 @@ void copy_coord(std::vector& out_c, region.toFaceDistance(to_face); for (int dd = 0; dd < 3; ++dd) { ncell[dd] = to_face[dd] / rc; - if (ncell[dd] == 0) ncell[dd] = 1; + if (ncell[dd] == 0) { + ncell[dd] = 1; + } cell_size[dd] = to_face[dd] / ncell[dd]; ngcell[dd] = int(rc / cell_size[dd]) + 1; assert(cell_size[dd] * ngcell[dd] >= rc); @@ -703,7 +788,9 @@ void copy_coord(std::vector& out_c, mapping.resize(nloc); copy(in_c.begin(), in_c.end(), out_c.begin()); copy(in_t.begin(), in_t.end(), out_t.begin()); - for (int ii = 0; ii < nloc; ++ii) mapping[ii] = ii; + for (int ii = 0; ii < nloc; ++ii) { + mapping[ii] = ii; + } // push ghost std::vector ii(3), jj(3), pbc_shift(3, 0); @@ -771,7 +858,9 @@ void deepmd::convert_nlist(InputNlist& to_nlist, int deepmd::max_numneigh(const InputNlist& nlist) { int max_num = 0; for (int ii = 0; ii < nlist.inum; ++ii) { - if (nlist.numneigh[ii] > max_num) max_num = nlist.numneigh[ii]; + if (nlist.numneigh[ii] > max_num) { + max_num = nlist.numneigh[ii]; + } } return max_num; } @@ -794,7 +883,9 @@ int deepmd::build_nlist_cpu(InputNlist& nlist, nlist.ilist[ii] = ii; jlist.clear(); for (int jj = 0; jj < nall; ++jj) { - if (jj == ii) continue; + if (jj == ii) { + continue; + } FPTYPE diff[3]; for (int dd = 0; dd < 3; ++dd) { diff[dd] = c_cpy[ii * 3 + dd] - c_cpy[jj * 3 + dd]; @@ -810,7 +901,9 @@ int deepmd::build_nlist_cpu(InputNlist& nlist, } else { int list_size = jlist.size(); nlist.numneigh[ii] = list_size; - if (list_size > *max_list_size) *max_list_size = list_size; + if (list_size > *max_list_size) { + *max_list_size = list_size; + } std::copy(jlist.begin(), jlist.end(), nlist.firstneigh[ii]); } } diff --git a/source/lib/src/prod_force.cc b/source/lib/src/prod_force.cc index 8cd67d8c7a..7ddd9246e7 100644 --- a/source/lib/src/prod_force.cc +++ b/source/lib/src/prod_force.cc @@ -51,7 +51,9 @@ void deepmd::prod_force_a_cpu(FPTYPE* force, // deriv wrt neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } int aa_start, aa_end; make_index_range(aa_start, aa_end, jj, nnei); for (int aa = aa_start; aa < aa_end; ++aa) { @@ -160,7 +162,9 @@ void deepmd::prod_force_r_cpu(FPTYPE* force, for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; // if (j_idx > nloc) j_idx = j_idx % nloc; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } force[kk * nall * 3 + j_idx * 3 + 0] += net_deriv[i_idx * ndescrpt + jj] * env_deriv[i_idx * ndescrpt * 3 + jj * 3 + 0]; diff --git a/source/lib/src/prod_force_grad.cc b/source/lib/src/prod_force_grad.cc index 920601c113..c77b4e62ff 100644 --- a/source/lib/src/prod_force_grad.cc +++ b/source/lib/src/prod_force_grad.cc @@ -52,8 +52,12 @@ void deepmd::prod_force_grad_a_cpu(FPTYPE* grad_net, // loop over neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx >= nloc) j_idx = j_idx % nloc; - if (j_idx < 0) continue; + if (j_idx >= nloc) { + j_idx = j_idx % nloc; + } + if (j_idx < 0) { + continue; + } int aa_start, aa_end; make_index_range(aa_start, aa_end, jj, nnei); const int kk = i_idx / nloc; // frame index @@ -125,8 +129,12 @@ void deepmd::prod_force_grad_r_cpu(FPTYPE* grad_net, // loop over neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx >= nloc) j_idx = j_idx % nloc; - if (j_idx < 0) continue; + if (j_idx >= nloc) { + j_idx = j_idx % nloc; + } + if (j_idx < 0) { + continue; + } int kk = i_idx / nloc; // frame index for (int dd = 0; dd < 3; ++dd) { grad_net[i_idx * ndescrpt + jj] += diff --git a/source/lib/src/prod_virial.cc b/source/lib/src/prod_virial.cc index 636c45c1a8..64d1107cd6 100644 --- a/source/lib/src/prod_virial.cc +++ b/source/lib/src/prod_virial.cc @@ -45,7 +45,9 @@ void deepmd::prod_virial_a_cpu(FPTYPE* virial, // deriv wrt neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } int aa_start, aa_end; make_index_range(aa_start, aa_end, jj, nnei); for (int aa = aa_start; aa < aa_end; ++aa) { @@ -112,7 +114,9 @@ void deepmd::prod_virial_r_cpu(FPTYPE* virial, // deriv wrt neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } FPTYPE pref = -1.0 * net_deriv[i_idx * ndescrpt + jj]; for (int dd0 = 0; dd0 < 3; ++dd0) { for (int dd1 = 0; dd1 < 3; ++dd1) { diff --git a/source/lib/src/prod_virial_grad.cc b/source/lib/src/prod_virial_grad.cc index 14ba158cc1..d34186107c 100644 --- a/source/lib/src/prod_virial_grad.cc +++ b/source/lib/src/prod_virial_grad.cc @@ -42,7 +42,9 @@ void deepmd::prod_virial_grad_a_cpu(FPTYPE* grad_net, // loop over neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } int aa_start, aa_end; make_index_range(aa_start, aa_end, jj, nnei); for (int aa = aa_start; aa < aa_end; ++aa) { @@ -108,7 +110,9 @@ void deepmd::prod_virial_grad_r_cpu(FPTYPE* grad_net, // loop over neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } for (int dd0 = 0; dd0 < 3; ++dd0) { for (int dd1 = 0; dd1 < 3; ++dd1) { grad_net[i_idx * ndescrpt + jj] -= diff --git a/source/lib/src/rocm/coord.hip.cu b/source/lib/src/rocm/coord.hip.cu index 592f425195..198ef87311 100644 --- a/source/lib/src/rocm/coord.hip.cu +++ b/source/lib/src/rocm/coord.hip.cu @@ -26,10 +26,14 @@ __device__ inline int compute_pbc_shift(int idx, int ncell) { int shift = 0; if (idx < 0) { shift = 1; - while (idx + shift * ncell < 0) shift++; + while (idx + shift * ncell < 0) { + shift++; + } } else if (idx >= ncell) { shift = -1; - while (idx + shift * ncell >= ncell) shift--; + while (idx + shift * ncell >= ncell) { + shift--; + } } return shift; } @@ -51,7 +55,9 @@ __global__ void normalize_one(FPTYPE *out_c, phys2Inter(inter, out_c + idy * 3, rec_boxt); for (int dd = 0; dd < 3; ++dd) { inter[dd] = _fmod(inter[dd], (FPTYPE)1.); - if (inter[dd] < (FPTYPE)0.) inter[dd] += (FPTYPE)1.; + if (inter[dd] < (FPTYPE)0.) { + inter[dd] += (FPTYPE)1.; + } } inter2Phys(out_c + idy * 3, inter, boxt); } @@ -86,7 +92,9 @@ __global__ void _fill_idx_cellmap(int *idx_cellmap, phys2Inter(inter, in_c + idy * 3, rec_boxt); for (int dd = 0; dd < 3; ++dd) { idx_noshift[dd] = (inter[dd] - nat_orig[dd]) / cell_size[dd]; - if (inter[dd] - nat_orig[dd] < 0.) idx_noshift[dd]--; + if (inter[dd] - nat_orig[dd] < 0.) { + idx_noshift[dd]--; + } if (idx_noshift[dd] < nat_stt[dd]) { idx_noshift[dd] = nat_stt[dd]; } else if (idx_noshift[dd] >= nat_end[dd]) { @@ -145,14 +153,18 @@ __global__ void _fill_total_cellnum_map(int *total_cellnum_map, shift[1] = compute_pbc_shift(idx[1], global_grid[1]); shift[2] = compute_pbc_shift(idx[2], global_grid[2]); bool loc = false; - if (shift[0] == 0 && shift[1] == 0 && shift[2] == 0) loc = true; + if (shift[0] == 0 && shift[1] == 0 && shift[2] == 0) { + loc = true; + } for (int dd = 0; dd < 3; dd++) { idx[dd] += shift[dd] * global_grid[dd]; } int orig_idy = collapse_index(idx, global_grid); mask_cellnum_map[idy] = loc_cellnum_map[orig_idy]; total_cellnum_map[idy] = mask_cellnum_map[idy]; - if (loc) mask_cellnum_map[idy] = 0; + if (loc) { + mask_cellnum_map[idy] = 0; + } cell_map[idy] = orig_idy; } } @@ -205,10 +217,11 @@ __global__ void _copy_coord(FPTYPE *out_c, int shift[3]; FPTYPE d_shift[3]; for (int ii = 0; ii < total_cellnum; ii++) { - if (idy >= sec_total_cellnum_map[ii + 1]) + if (idy >= sec_total_cellnum_map[ii + 1]) { cell_idx++; - else + } else { break; + } } for (int dd = 0; dd < 3; dd++) { shift[dd] = cell_shift_map[cell_idx * 3 + dd]; diff --git a/source/lib/src/rocm/neighbor_list.hip.cu b/source/lib/src/rocm/neighbor_list.hip.cu index 2dd74dce43..34043233ab 100644 --- a/source/lib/src/rocm/neighbor_list.hip.cu +++ b/source/lib/src/rocm/neighbor_list.hip.cu @@ -215,7 +215,9 @@ int build_nlist_gpu_rocm(InputNlist &nlist, hipMemcpyDeviceToHost)); int max_nei = 0; for (int ii = 0; ii < nloc; ii++) { - if (numneigh_host[ii] > max_nei) max_nei = numneigh_host[ii]; + if (numneigh_host[ii] > max_nei) { + max_nei = numneigh_host[ii]; + } } *max_list_size = max_nei; delete[] numneigh_host; diff --git a/source/lib/src/rocm/prod_env_mat.hip.cu b/source/lib/src/rocm/prod_env_mat.hip.cu index abb47bcabb..c2bfbd3cac 100644 --- a/source/lib/src/rocm/prod_env_mat.hip.cu +++ b/source/lib/src/rocm/prod_env_mat.hip.cu @@ -126,7 +126,9 @@ __global__ void format_nlist_fill_a(uint_64* key, uint_64* key_in = key + idx * MAX_NBOR_SIZE; FPTYPE diff[3]; const int& j_idx = nei_idx[idy]; - if (type[j_idx] < 0) return; + if (type[j_idx] < 0) { + return; + } for (int dd = 0; dd < 3; dd++) { diff[dd] = coord[j_idx * 3 + dd] - coord[idx * 3 + dd]; } @@ -148,8 +150,9 @@ __global__ void fill_nei_iter(int* nei_iter_dev, int nei_type_cur = -1, nbor_idx_cur = 0; int nei_type_pre = -1, nbor_idx_pre = 0; if (col < max_nbor_size && key_out[col] != key_out[max_nbor_size - 1]) { - if (col >= 1) + if (col >= 1) { decoding_nbor_info(nei_type_pre, nbor_idx_pre, key_out[col - 1]); + } decoding_nbor_info(nei_type_cur, nbor_idx_cur, key_out[col]); } if (nei_type_cur != nei_type_pre) { @@ -365,7 +368,9 @@ __global__ void compute_env_mat_a(FPTYPE* em, // <<>> const int_64 bid = blockIdx.x; const unsigned int tid = threadIdx.x; - if (type[bid] < 0) return; + if (type[bid] < 0) { + return; + } if (tid >= nnei) { return; } diff --git a/source/lib/src/rocm/prod_force_grad.hip.cu b/source/lib/src/rocm/prod_force_grad.hip.cu index bb7fe7792f..e43ce37af6 100644 --- a/source/lib/src/rocm/prod_force_grad.hip.cu +++ b/source/lib/src/rocm/prod_force_grad.hip.cu @@ -44,7 +44,9 @@ __global__ void force_grad_wrt_neighbors_a(FPTYPE* grad_net, if (j_idx < 0) { return; } - if (j_idx >= nloc) j_idx = j_idx % nloc; + if (j_idx >= nloc) { + j_idx = j_idx % nloc; + } const int kk = idx / nloc; // frame index grad_net[idx * nnei * 4 + idy * 4 + idw] += dev_dot(grad + kk * nloc * 3 + j_idx * 3, @@ -69,7 +71,9 @@ __global__ void force_grad_wrt_neighbors_r(FPTYPE* grad_net, if (j_idx < 0) { return; } - if (j_idx >= nloc) j_idx = j_idx % nloc; + if (j_idx >= nloc) { + j_idx = j_idx % nloc; + } const int kk = idx / nloc; // frame index grad_net[idx * nnei + idy] += dev_dot(grad + kk * nloc * 3 + j_idx * 3, env_deriv + idx * nnei * 3 + idy * 3); diff --git a/source/lib/src/rocm/prod_virial.hip.cu b/source/lib/src/rocm/prod_virial.hip.cu index 30628c610f..dccd721df6 100644 --- a/source/lib/src/rocm/prod_virial.hip.cu +++ b/source/lib/src/rocm/prod_virial.hip.cu @@ -21,7 +21,9 @@ __global__ void atom_virial_reduction(FPTYPE* virial, __syncthreads(); } // write result for this block to global memory - if (tid == 0) virial[bid] = data[0]; + if (tid == 0) { + virial[bid] = data[0]; + } } template diff --git a/source/lib/src/rocm/tabulate.hip.cu b/source/lib/src/rocm/tabulate.hip.cu index 3f91854643..5aaf023262 100644 --- a/source/lib/src/rocm/tabulate.hip.cu +++ b/source/lib/src/rocm/tabulate.hip.cu @@ -70,8 +70,9 @@ __forceinline__ __device__ FPTYPE dot(FPTYPE ll[4], FPTYPE rr[4]) { template __forceinline__ __device__ void warp_reduce(FPTYPE& val) { - for (int offset = 32; offset > 0; offset >>= 1) + for (int offset = 32; offset > 0; offset >>= 1) { val += __shfl_down(val, offset); // ########???? + } } template @@ -96,8 +97,9 @@ __global__ void tabulate_fusion_se_a_fifth_order_polynomial( bool unloop = false; int breakpoint = nnei - 1; FPTYPE* iteratorC = (FPTYPE*)&_data[0]; - for (int kk = 0; kk < MTILE; kk++) + for (int kk = 0; kk < MTILE; kk++) { iteratorC[kk * last_layer_size + thread_idx] = (FPTYPE)0.; + } __syncthreads(); for (int ii = 0; ii < nnei; ii++) { @@ -130,7 +132,9 @@ __global__ void tabulate_fusion_se_a_fifth_order_polynomial( (nnei - breakpoint) * em[block_idx * nnei * MTILE + ii * MTILE + kk] * res; } - if (unloop) break; + if (unloop) { + break; + } } for (int ii = 0; ii < MTILE; ii++) { out[block_idx * MTILE * last_layer_size + ii * last_layer_size + @@ -236,7 +240,9 @@ __global__ void tabulate_fusion_se_a_grad_fifth_order_polynomial( } dy_dem_x[block_idx * nnei + ii + warp_idx] = Csub; } - if (unloop) break; + if (unloop) { + break; + } } } @@ -262,8 +268,9 @@ __global__ void tabulate_fusion_se_a_grad_grad_fifth_order_polynomial( bool unloop = false; int breakpoint = nnei - 1; FPTYPE* iteratorC = (FPTYPE*)&_data[0]; - for (int kk = 0; kk < MTILE; kk++) + for (int kk = 0; kk < MTILE; kk++) { iteratorC[kk * last_layer_size + thread_idx] = (FPTYPE)0.; + } __syncthreads(); for (int ii = 0; ii < nnei; ii++) { @@ -299,7 +306,9 @@ __global__ void tabulate_fusion_se_a_grad_grad_fifth_order_polynomial( (nnei - breakpoint) * (em[em_index] * res_grad * dz_xx + dz_dy_dem[em_index] * res); } - if (unloop) break; + if (unloop) { + break; + } } for (int ii = 0; ii < MTILE; ii++) { dz_dy[block_idx * MTILE * last_layer_size + ii * last_layer_size + diff --git a/source/lib/src/soft_min_switch.cc b/source/lib/src/soft_min_switch.cc index f46f9ad9f2..6bd388f601 100644 --- a/source/lib/src/soft_min_switch.cc +++ b/source/lib/src/soft_min_switch.cc @@ -31,7 +31,9 @@ void deepmd::soft_min_switch_cpu(FPTYPE* sw_value, FPTYPE bb = 0; for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } int rij_idx_shift = (i_idx * nnei + jj) * 3; FPTYPE dr[3] = {rij[rij_idx_shift + 0], rij[rij_idx_shift + 1], rij[rij_idx_shift + 2]}; @@ -49,7 +51,9 @@ void deepmd::soft_min_switch_cpu(FPTYPE* sw_value, // deriv of switch distributed as force for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } int rij_idx_shift = (ii * nnei + jj) * 3; FPTYPE dr[3] = {rij[rij_idx_shift + 0], rij[rij_idx_shift + 1], rij[rij_idx_shift + 2]}; diff --git a/source/lib/src/soft_min_switch_force.cc b/source/lib/src/soft_min_switch_force.cc index 8ae10ae11c..d9e707f7de 100644 --- a/source/lib/src/soft_min_switch_force.cc +++ b/source/lib/src/soft_min_switch_force.cc @@ -28,7 +28,9 @@ void deepmd::soft_min_switch_force_cpu(FPTYPE* force, int i_idx = ii; for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } int rij_idx_shift = (ii * nnei + jj) * 3; force[i_idx * 3 + 0] += du[i_idx] * sw_deriv[rij_idx_shift + 0]; force[i_idx * 3 + 1] += du[i_idx] * sw_deriv[rij_idx_shift + 1]; diff --git a/source/lib/src/soft_min_switch_force_grad.cc b/source/lib/src/soft_min_switch_force_grad.cc index 3976a04a57..a7c3fc0972 100644 --- a/source/lib/src/soft_min_switch_force_grad.cc +++ b/source/lib/src/soft_min_switch_force_grad.cc @@ -27,8 +27,12 @@ void deepmd::soft_min_switch_force_grad_cpu(FPTYPE* grad_net, // deriv wrt center atom for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx >= nloc) j_idx = j_idx % nloc; - if (j_idx < 0) continue; + if (j_idx >= nloc) { + j_idx = j_idx % nloc; + } + if (j_idx < 0) { + continue; + } int rij_idx_shift = (ii * nnei + jj) * 3; grad_net[i_idx] += grad[i_idx * 3 + 0] * sw_deriv[rij_idx_shift + 0]; grad_net[i_idx] += grad[i_idx * 3 + 1] * sw_deriv[rij_idx_shift + 1]; diff --git a/source/lib/src/soft_min_switch_virial.cc b/source/lib/src/soft_min_switch_virial.cc index 6b1bbe4659..417bf22b1c 100644 --- a/source/lib/src/soft_min_switch_virial.cc +++ b/source/lib/src/soft_min_switch_virial.cc @@ -32,7 +32,9 @@ void deepmd::soft_min_switch_virial_cpu(FPTYPE* virial, // loop over neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } int rij_idx_shift = (ii * nnei + jj) * 3; for (int dd0 = 0; dd0 < 3; ++dd0) { for (int dd1 = 0; dd1 < 3; ++dd1) { diff --git a/source/lib/src/soft_min_switch_virial_grad.cc b/source/lib/src/soft_min_switch_virial_grad.cc index c94332d4ca..b29fa876a2 100644 --- a/source/lib/src/soft_min_switch_virial_grad.cc +++ b/source/lib/src/soft_min_switch_virial_grad.cc @@ -27,7 +27,9 @@ void deepmd::soft_min_switch_virial_grad_cpu(FPTYPE* grad_net, // loop over neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[i_idx * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } int rij_idx_shift = (ii * nnei + jj) * 3; for (int dd0 = 0; dd0 < 3; ++dd0) { for (int dd1 = 0; dd1 < 3; ++dd1) { diff --git a/source/lib/src/tabulate.cc b/source/lib/src/tabulate.cc index b2edb30be9..87bc7401e0 100644 --- a/source/lib/src/tabulate.cc +++ b/source/lib/src/tabulate.cc @@ -146,7 +146,9 @@ void deepmd::tabulate_fusion_se_a_cpu(FPTYPE* out, var * ll[3]; } } - if (unloop) break; + if (unloop) { + break; + } } } } @@ -229,7 +231,9 @@ void deepmd::tabulate_fusion_se_a_grad_cpu(FPTYPE* dy_dem_x, } } dy_dem_x[ii * nnei + jj] = grad; - if (unloop) break; + if (unloop) { + break; + } } } } @@ -310,7 +314,9 @@ void deepmd::tabulate_fusion_se_a_grad_grad_cpu(FPTYPE* dz_dy, var * hh[3] + dz_xx * var_grad * ll[3]; } } - if (unloop) break; + if (unloop) { + break; + } } } } diff --git a/source/lib/tests/test_env_mat_a.cc b/source/lib/tests/test_env_mat_a.cc index e88639e2ea..479286f30a 100644 --- a/source/lib/tests/test_env_mat_a.cc +++ b/source/lib/tests/test_env_mat_a.cc @@ -282,7 +282,9 @@ TEST_F(TestEnvMatA, orig_cpy_num_deriv) { for (int jj = 0; jj < sec_a[2]; ++jj) { int j_idx = fmt_nlist_a[jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } for (int kk = 0; kk < 4; ++kk) { for (int dd = 0; dd < 3; ++dd) { std::vector posi_0 = posi_cpy; @@ -383,7 +385,9 @@ TEST_F(TestEnvMatA, cpu_num_deriv) { for (int jj = 0; jj < sec_a[2]; ++jj) { int j_idx = fmt_nlist_a[jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } for (int kk = 0; kk < 4; ++kk) { for (int dd = 0; dd < 3; ++dd) { std::vector posi_0 = posi_cpy; diff --git a/source/lib/tests/test_env_mat_a_mix.cc b/source/lib/tests/test_env_mat_a_mix.cc index 1ee143836c..2bb7068f75 100644 --- a/source/lib/tests/test_env_mat_a_mix.cc +++ b/source/lib/tests/test_env_mat_a_mix.cc @@ -310,7 +310,9 @@ TEST_F(TestEnvMatAMix, orig_cpy_num_deriv) { for (int jj = 0; jj < sec_a.back(); ++jj) { int j_idx = fmt_nlist_a[jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } for (int kk = 0; kk < 4; ++kk) { for (int dd = 0; dd < 3; ++dd) { std::vector posi_0 = posi_cpy; @@ -411,7 +413,9 @@ TEST_F(TestEnvMatAMix, cpu_num_deriv) { for (int jj = 0; jj < sec_a.back(); ++jj) { int j_idx = fmt_nlist_a[jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } for (int kk = 0; kk < 4; ++kk) { for (int dd = 0; dd < 3; ++dd) { std::vector posi_0 = posi_cpy; diff --git a/source/lib/tests/test_env_mat_r.cc b/source/lib/tests/test_env_mat_r.cc index 8a503c8c37..b9d826fa06 100644 --- a/source/lib/tests/test_env_mat_r.cc +++ b/source/lib/tests/test_env_mat_r.cc @@ -152,7 +152,9 @@ TEST_F(TestEnvMatR, orig_cpy_num_deriv) { for (int jj = 0; jj < sec_a[2]; ++jj) { int j_idx = fmt_nlist_a[jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } for (int dd = 0; dd < 3; ++dd) { std::vector posi_0 = posi_cpy; std::vector posi_1 = posi_cpy; @@ -239,7 +241,9 @@ TEST_F(TestEnvMatR, cpu_num_deriv) { for (int jj = 0; jj < sec_a[2]; ++jj) { int j_idx = fmt_nlist_a[jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } for (int dd = 0; dd < 3; ++dd) { std::vector posi_0 = posi_cpy; std::vector posi_1 = posi_cpy; diff --git a/source/lib/tests/test_soft_min_switch.cc b/source/lib/tests/test_soft_min_switch.cc index c87c086bb6..b3ed9cb0b7 100644 --- a/source/lib/tests/test_soft_min_switch.cc +++ b/source/lib/tests/test_soft_min_switch.cc @@ -119,7 +119,9 @@ TEST_F(TestSoftMinSwitch, cpu_num_deriv) { int i_idx = ii; for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist[ii * nnei + jj]; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } for (int dd = 0; dd < 3; ++dd) { std::vector posi_0 = posi_cpy; std::vector posi_1 = posi_cpy; diff --git a/source/lmp/compute_deeptensor_atom.cpp b/source/lmp/compute_deeptensor_atom.cpp index 89eb6fb38e..0060bfa56a 100644 --- a/source/lmp/compute_deeptensor_atom.cpp +++ b/source/lmp/compute_deeptensor_atom.cpp @@ -25,7 +25,9 @@ using namespace LAMMPS_NS; ComputeDeeptensorAtom::ComputeDeeptensorAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), dp(lmp), tensor(nullptr) { - if (narg < 4) error->all(FLERR, "Illegal compute deeptensor/atom command"); + if (narg < 4) { + error->all(FLERR, "Illegal compute deeptensor/atom command"); + } // parse args std::string model_file = std::string(arg[3]); diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 43d870180d..400328ce0d 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -62,14 +62,17 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg) "Illegal pair_style command\nwrong number of parameters\n"); } if (string(arg[iarg]) == string("model")) { - if (iarg + 1 > narg) error->all(FLERR, "Illegal fix adapt command"); + if (iarg + 1 > narg) { + error->all(FLERR, "Illegal fix adapt command"); + } model = string(arg[iarg + 1]); iarg += 2; } else if (string(arg[iarg]) == string("efield")) { - if (iarg + 3 > narg) + if (iarg + 3 > narg) { error->all(FLERR, "Illegal fix adapt command, efield should be provided 3 " "float numbers"); + } efield[0] = atof(arg[iarg + 1]); efield[1] = atof(arg[iarg + 2]); efield[2] = atof(arg[iarg + 3]); diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index ccf95c0984..b5878c208e 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -79,13 +79,14 @@ static int stringCmp(const void *a, const void *b) { char *n = (char *)b; int i, sum = 0; - for (i = 0; i < MPI_MAX_PROCESSOR_NAME; i++) - if (m[i] == n[i]) + for (i = 0; i < MPI_MAX_PROCESSOR_NAME; i++) { + if (m[i] == n[i]) { continue; - else { + } else { sum = m[i] - n[i]; break; } + } return sum; } @@ -109,9 +110,10 @@ int PairDeepMD::get_node_rank() { strcpy(host_names[rank], host_name); - for (n = 0; n < nprocs; n++) + for (n = 0; n < nprocs; n++) { MPI_Bcast(&(host_names[n]), MPI_MAX_PROCESSOR_NAME, MPI_CHAR, n, MPI_COMM_WORLD); + } qsort(host_names, nprocs, sizeof(char[MPI_MAX_PROCESSOR_NAME]), stringCmp); color = 0; @@ -172,13 +174,19 @@ static void ana_st(double &max, double &sum, const vector &vec, const int &nloc) { - if (nloc == 0) return; + if (nloc == 0) { + return; + } max = vec[0]; min = vec[0]; sum = vec[0]; for (unsigned ii = 1; ii < nloc; ++ii) { - if (vec[ii] > max) max = vec[ii]; - if (vec[ii] < min) min = vec[ii]; + if (vec[ii] > max) { + max = vec[ii]; + } + if (vec[ii] < min) { + min = vec[ii]; + } sum += vec[ii]; } } @@ -240,14 +248,16 @@ void PairDeepMD::make_ttm_fparam(vector &fparam) { double total_Te = 0; // loop over grids to get average electron temperature - for (int ixnode = 0; ixnode < nxnodes; ixnode++) - for (int iynode = 0; iynode < nynodes; iynode++) + for (int ixnode = 0; ixnode < nxnodes; ixnode++) { + for (int iynode = 0; iynode < nynodes; iynode++) { for (int iznode = 0; iznode < nznodes; iznode++) { if (T_electron[ixnode][iynode][iznode] != 0) { numb_effective_nodes += 1; total_Te += T_electron[ixnode][iynode][iznode]; } } + } + } fparam[0] = total_Te / numb_effective_nodes; } @@ -287,12 +297,24 @@ void PairDeepMD::make_ttm_aparam(vector &daparam) { int ixnode = static_cast(xscale * nxnodes); int iynode = static_cast(yscale * nynodes); int iznode = static_cast(zscale * nznodes); - while (ixnode > nxnodes - 1) ixnode -= nxnodes; - while (iynode > nynodes - 1) iynode -= nynodes; - while (iznode > nznodes - 1) iznode -= nznodes; - while (ixnode < 0) ixnode += nxnodes; - while (iynode < 0) iynode += nynodes; - while (iznode < 0) iznode += nznodes; + while (ixnode > nxnodes - 1) { + ixnode -= nxnodes; + } + while (iynode > nynodes - 1) { + iynode -= nynodes; + } + while (iznode > nznodes - 1) { + iznode -= nznodes; + } + while (ixnode < 0) { + ixnode += nxnodes; + } + while (iynode < 0) { + iynode += nynodes; + } + while (iznode < 0) { + iznode += nznodes; + } daparam[ii] = T_electron[ixnode][iynode][iznode]; } } @@ -310,7 +332,9 @@ PairDeepMD::PairDeepMD(LAMMPS *lmp) : Pair(lmp) { - if (lmp->citeme) lmp->citeme->add(cite_user_deepmd_package); + if (lmp->citeme) { + lmp->citeme->add(cite_user_deepmd_package); + } if (strcmp(update->unit_style, "metal") != 0) { error->all( FLERR, @@ -386,12 +410,17 @@ PairDeepMD::~PairDeepMD() { } void PairDeepMD::compute(int eflag, int vflag) { - if (numb_models == 0) return; - if (eflag || vflag) ev_setup(eflag, vflag); - if (vflag_atom) + if (numb_models == 0) { + return; + } + if (eflag || vflag) { + ev_setup(eflag, vflag); + } + if (vflag_atom) { error->all(FLERR, "6-element atomic virial is not supported. Use compute " "centroid/stress/atom command for 9-element atomic virial."); + } bool do_ghost = true; double **x = atom->x; @@ -537,7 +566,9 @@ void PairDeepMD::compute(int eflag, int vflag) { } } if (eflag_atom) { - for (int ii = 0; ii < nlocal; ++ii) eatom[ii] += deatom[ii]; + for (int ii = 0; ii < nlocal; ++ii) { + eatom[ii] += deatom[ii]; + } } // Added by Davide Tisi 2020 // interface the atomic virial computed by DeepMD @@ -587,7 +618,9 @@ void PairDeepMD::compute(int eflag, int vflag) { deatom = all_atom_energy[0]; dvatom = all_atom_virial[0]; if (eflag_atom) { - for (int ii = 0; ii < nlocal; ++ii) eatom[ii] += deatom[ii]; + for (int ii = 0; ii < nlocal; ++ii) { + eatom[ii] += deatom[ii]; + } } // Added by Davide Tisi 2020 // interface the atomic virial computed by DeepMD @@ -693,8 +726,9 @@ void PairDeepMD::compute(int eflag, int vflag) { } MPI_Gather(&nlocal, 1, MPI_INT, counts, 1, MPI_INT, 0, world); displacements[0] = 0; - for (int ii = 0; ii < nprocs - 1; ii++) + for (int ii = 0; ii < nprocs - 1; ii++) { displacements[ii + 1] = displacements[ii] + counts[ii]; + } MPI_Gatherv(tagsend, nlocal, MPI_LMP_TAGINT, tagrecv, counts, displacements, MPI_LMP_TAGINT, 0, world); MPI_Gatherv(stdfsend, nlocal, MPI_DOUBLE, stdfrecv, counts, @@ -759,7 +793,9 @@ void PairDeepMD::compute(int eflag, int vflag) { } // accumulate energy and virial - if (eflag) eng_vdwl += scale[1][1] * dener; + if (eflag) { + eng_vdwl += scale[1][1] * dener; + } if (vflag) { virial[0] += 1.0 * dvirial[0] * scale[1][1]; virial[1] += 1.0 * dvirial[4] * scale[1][1]; @@ -785,9 +821,13 @@ void PairDeepMD::allocate() { } } for (int i = 1; i <= numb_types; ++i) { - if (i > n) continue; + if (i > n) { + continue; + } for (int j = i; j <= numb_types; ++j) { - if (j > n) continue; + if (j > n) { + continue; + } setflag[i][j] = 1; scale[i][j] = 1; } @@ -817,7 +857,9 @@ static bool is_key(const string &input) { } void PairDeepMD::settings(int narg, char **arg) { - if (narg <= 0) error->all(FLERR, "Illegal pair_style command"); + if (narg <= 0) { + error->all(FLERR, "Illegal pair_style command"); + } vector models; int iarg = 0; @@ -875,11 +917,15 @@ void PairDeepMD::settings(int narg, char **arg) { "Illegal pair_style command\nwrong number of parameters\n"); } if (string(arg[iarg]) == string("out_freq")) { - if (iarg + 1 >= narg) error->all(FLERR, "Illegal out_freq, not provided"); + if (iarg + 1 >= narg) { + error->all(FLERR, "Illegal out_freq, not provided"); + } out_freq = atoi(arg[iarg + 1]); iarg += 2; } else if (string(arg[iarg]) == string("out_file")) { - if (iarg + 1 >= narg) error->all(FLERR, "Illegal out_file, not provided"); + if (iarg + 1 >= narg) { + error->all(FLERR, "Illegal out_file, not provided"); + } out_file = string(arg[iarg + 1]); iarg += 2; } else if (string(arg[iarg]) == string("fparam")) { @@ -964,7 +1010,9 @@ void PairDeepMD::settings(int narg, char **arg) { } } - if (out_freq < 0) error->all(FLERR, "Illegal out_freq, should be >= 0"); + if (out_freq < 0) { + error->all(FLERR, "Illegal out_freq, should be >= 0"); + } if (do_ttm && aparam.size() > 0) { error->all(FLERR, "aparam and ttm should NOT be set simultaneously"); } @@ -1159,7 +1207,9 @@ double PairDeepMD::init_one(int i, int j) { error->warning(FLERR, warning_msg); } - if (setflag[i][j] == 0) scale[i][j] = 1.0; + if (setflag[i][j] == 0) { + scale[i][j] = 1.0; + } scale[j][i] = scale[i][j]; return cutoff; @@ -1245,10 +1295,11 @@ void PairDeepMD::extend(int &extend_inum, std::map::iterator iter = loc_type_count.begin(); for (int i = 0; i < nloc; i++) { iter = loc_type_count.find(atype[i]); - if (iter != loc_type_count.end()) + if (iter != loc_type_count.end()) { iter->second += 1; - else + } else { loc_type_count.insert(pair(atype[i], 1)); + } } assert(numb_types_real - 1 == loc_type_count.rbegin()->first); int nloc_virt = 0; @@ -1260,10 +1311,11 @@ void PairDeepMD::extend(int &extend_inum, std::map ghost_type_count; for (int i = nloc; i < nall; i++) { iter = ghost_type_count.find(atype[i]); - if (iter != ghost_type_count.end()) + if (iter != ghost_type_count.end()) { iter->second += 1; - else + } else { ghost_type_count.insert(pair(atype[i], 1)); + } } int nghost_virt = 0; for (int i = 0; i < numb_types_spin; i++) { diff --git a/source/lmp/pppm_dplr.cpp b/source/lmp/pppm_dplr.cpp index 892688b340..20af43fad4 100644 --- a/source/lmp/pppm_dplr.cpp +++ b/source/lmp/pppm_dplr.cpp @@ -50,8 +50,9 @@ PPPMDPLR::PPPMDPLR(LAMMPS *lmp) void PPPMDPLR::init() { // DPLR PPPM requires newton on, b/c it computes forces on ghost atoms - if (force->newton == 0) + if (force->newton == 0) { error->all(FLERR, "Kspace style pppm/dplr requires newton on"); + } PPPM::init(); @@ -73,7 +74,9 @@ void PPPMDPLR::compute(int eflag, int vflag) { ev_init(eflag, vflag); - if (evflag_atom && !peratom_allocate_flag) allocate_peratom(); + if (evflag_atom && !peratom_allocate_flag) { + allocate_peratom(); + } // if atom count has changed, update qsum and qsqsum @@ -84,13 +87,15 @@ void PPPMDPLR::compute(int eflag, int vflag) { // return if there are no charges - if (qsqsum == 0.0) return; + if (qsqsum == 0.0) { + return; + } // convert atoms from box to lamda coords - if (triclinic == 0) + if (triclinic == 0) { boxlo = domain->boxlo; - else { + } else { boxlo = domain->boxlo_lamda; domain->x2lamda(atom->nlocal); } @@ -191,7 +196,9 @@ void PPPMDPLR::compute(int eflag, int vflag) { // extra per-atom energy/virial communication - if (evflag_atom) fieldforce_peratom(); + if (evflag_atom) { + fieldforce_peratom(); + } // sum global energy across procs and add in volume-dependent term @@ -214,7 +221,9 @@ void PPPMDPLR::compute(int eflag, int vflag) { if (vflag_global) { double virial_all[6]; MPI_Allreduce(virial, virial_all, 6, MPI_DOUBLE, MPI_SUM, world); - for (i = 0; i < 6; i++) virial[i] = 0.5 * qscale * volume * virial_all[i]; + for (i = 0; i < 6; i++) { + virial[i] = 0.5 * qscale * volume * virial_all[i]; + } } // per-atom energy/virial @@ -225,7 +234,9 @@ void PPPMDPLR::compute(int eflag, int vflag) { double *q = atom->q; int nlocal = atom->nlocal; int ntotal = nlocal; - if (tip4pflag) ntotal += atom->nghost; + if (tip4pflag) { + ntotal += atom->nghost; + } if (eflag_atom) { for (i = 0; i < nlocal; i++) { @@ -234,22 +245,31 @@ void PPPMDPLR::compute(int eflag, int vflag) { MY_PI2 * q[i] * qsum / (g_ewald * g_ewald * volume); eatom[i] *= qscale; } - for (i = nlocal; i < ntotal; i++) eatom[i] *= 0.5 * qscale; + for (i = nlocal; i < ntotal; i++) { + eatom[i] *= 0.5 * qscale; + } } if (vflag_atom) { - for (i = 0; i < ntotal; i++) - for (j = 0; j < 6; j++) vatom[i][j] *= 0.5 * qscale; + for (i = 0; i < ntotal; i++) { + for (j = 0; j < 6; j++) { + vatom[i][j] *= 0.5 * qscale; + } + } } } // 2d slab correction - if (slabflag == 1) slabcorr(); + if (slabflag == 1) { + slabcorr(); + } // convert atoms back from lamda to box coords - if (triclinic) domain->lamda2x(atom->nlocal); + if (triclinic) { + domain->lamda2x(atom->nlocal); + } } /* ---------------------------------------------------------------------- @@ -310,7 +330,9 @@ void PPPMDPLR::fieldforce_ik() { const double qfactor = qqrd2e * scale * q[i]; fele[i * 3 + 0] += qfactor * ekx; fele[i * 3 + 1] += qfactor * eky; - if (slabflag != 2) fele[i * 3 + 2] += qfactor * ekz; + if (slabflag != 2) { + fele[i * 3 + 2] += qfactor * ekz; + } } } @@ -400,6 +422,8 @@ void PPPMDPLR::fieldforce_ad() { sf = sf_coeff[4] * sin(2 * MY_PI * s3); sf += sf_coeff[5] * sin(4 * MY_PI * s3); sf *= 2 * q[i] * q[i]; - if (slabflag != 2) fele[i * 3 + 2] += qfactor * (ekz * q[i] - sf); + if (slabflag != 2) { + fele[i * 3 + 2] += qfactor * (ekz * q[i] - sf); + } } } diff --git a/source/md/include/common.h b/source/md/include/common.h index c58b3fa2b3..0c342b8cbd 100644 --- a/source/md/include/common.h +++ b/source/md/include/common.h @@ -28,10 +28,11 @@ void normalize_coord(std::vector& coord, double inter[3]; region.phys2Inter(inter, phys); for (int dd = 0; dd < 3; ++dd) { - if (inter[dd] < 0) + if (inter[dd] < 0) { inter[dd] += 1.; - else if (inter[dd] >= 1) + } else if (inter[dd] >= 1) { inter[dd] -= 1.; + } } region.inter2Phys(phys, inter); for (int dd = 0; dd < 3; ++dd) { diff --git a/source/md/mdnn.cc b/source/md/mdnn.cc index 1ebb7753f8..25587bee7e 100644 --- a/source/md/mdnn.cc +++ b/source/md/mdnn.cc @@ -150,11 +150,15 @@ int main(int argc, char* argv[]) { // compute force at step 0 nnp.compute(dener, dforce, dvirial, dcoord, dtype, dbox); // change virial to gromacs convention - for (int ii = 0; ii < 9; ++ii) dvirial[ii] *= -0.5; + for (int ii = 0; ii < 9; ++ii) { + dvirial[ii] *= -0.5; + } st.record(dener, dvirial, dveloc, dmass, region); ofstream efout(ener_file); ofstream pforce; - if (print_f) pforce.open("force.out"); + if (print_f) { + pforce.open("force.out"); + } st.print_head(efout); st.print(efout, 0, 0); @@ -166,7 +170,9 @@ int main(int argc, char* argv[]) { normalize_coord(dcoord, region); nnp.compute(dener, dforce, dvirial, dae, dav, dcoord, dtype, dbox); // change virial to gromacs convention - for (int ii = 0; ii < 9; ++ii) dvirial[ii] *= -0.5; + for (int ii = 0; ii < 9; ++ii) { + dvirial[ii] *= -0.5; + } inte.stepVeloc(dveloc, dforce, dmass, 0.5 * dt, freez); if ((ii + 1) % nener == 0) { st.record(dener, dvirial, dveloc, dmass, region); diff --git a/source/md/src/AdWeight.cc b/source/md/src/AdWeight.cc index c2562a0c0c..a7759d740a 100644 --- a/source/md/src/AdWeight.cc +++ b/source/md/src/AdWeight.cc @@ -131,7 +131,9 @@ void AdWeight::force_intpl(vector& of, for (int ii = 0; ii < nall; ++ii) { for (int dd = 0; dd < 3; ++dd) { double pref = (1 - weight[ii]); - if (fabs(pref) < protect_level) pref = protect_level; + if (fabs(pref) < protect_level) { + pref = protect_level; + } of[ii * 3 + dd] += pref * ff_bd_force[ii * 3 + dd]; // if (fabs(ff_bd_force[ii*3+dd]) > 1e6) { // cout << " ii " << ii diff --git a/source/md/src/Convert.cc b/source/md/src/Convert.cc index d40e710084..dbced7f6f4 100644 --- a/source/md/src/Convert.cc +++ b/source/md/src/Convert.cc @@ -24,7 +24,9 @@ Convert::Convert(const vector& atomname, sorting[ii] = pair >( atype[ii], pair(ii, amass[ii])); } - if (sort_) sort(sorting.begin(), sorting.end()); + if (sort_) { + sort(sorting.begin(), sorting.end()); + } idx_map_nnp2gro.resize(natoms); idx_map_gro2nnp.resize(natoms); for (unsigned ii = 0; ii < idx_map_nnp2gro.size(); ++ii) { diff --git a/source/md/src/GroFileManager.cc b/source/md/src/GroFileManager.cc index 0cf33bb54a..d81e48c200 100644 --- a/source/md/src/GroFileManager.cc +++ b/source/md/src/GroFileManager.cc @@ -88,10 +88,11 @@ bool GroFileManager::writePotenFile(const double &rmin, double upper = rcut + 1; double nx; - if (int(upper / interval) != upper / interval) + if (int(upper / interval) != upper / interval) { nx = int(upper / interval) + 1; - else + } else { nx = int(upper / interval); + } upper = interval * nx; int i = 0; diff --git a/source/md/src/HarmonicBond.cc b/source/md/src/HarmonicBond.cc index 010513adc0..99efb0e9b9 100644 --- a/source/md/src/HarmonicBond.cc +++ b/source/md/src/HarmonicBond.cc @@ -33,8 +33,12 @@ void HarmonicBond::compute(VALUETYPE& ener, VALUETYPE r1 = sqrt(r2); VALUETYPE ae, af; hb_inner(ae, af, r1); - for (int dd = 0; dd < 3; ++dd) force[ii * 3 + dd] += af * diff[dd]; - for (int dd = 0; dd < 3; ++dd) force[jj * 3 + dd] -= af * diff[dd]; + for (int dd = 0; dd < 3; ++dd) { + force[ii * 3 + dd] += af * diff[dd]; + } + for (int dd = 0; dd < 3; ++dd) { + force[jj * 3 + dd] -= af * diff[dd]; + } ener += ae; for (int dd0 = 0; dd0 < 3; ++dd0) { for (int dd1 = 0; dd1 < 3; ++dd1) { diff --git a/source/md/src/Interpolation.cpp b/source/md/src/Interpolation.cpp index 40377a292e..25fd0108e1 100644 --- a/source/md/src/Interpolation.cpp +++ b/source/md/src/Interpolation.cpp @@ -346,7 +346,9 @@ bool Interpolation::splinePeriodic(const std::vector& x, bool tag = solverForSplinePeriodic(lambda.begin(), lambda.end(), mu.begin(), mu.end()); - if (!tag) return false; + if (!tag) { + return false; + } ps.get_x() = x; ps.get_p().clear(); @@ -448,7 +450,9 @@ bool Interpolation::spline(const std::vector::const_iterator xbegin, PiecewisePoly& ps) { int xsize = 0; std::vector::const_iterator itmp = xbegin; - while (itmp++ != xend) ++xsize; + while (itmp++ != xend) { + ++xsize; + } std::vector lambda(xsize); std::vector mu(xsize); diff --git a/source/md/src/LJInter.cc b/source/md/src/LJInter.cc index 024af5cb26..f1e4a6a5c5 100644 --- a/source/md/src/LJInter.cc +++ b/source/md/src/LJInter.cc @@ -36,15 +36,21 @@ void LJInter::compute(VALUETYPE& ener, for (unsigned ii = 0; ii < nlist.size(); ++ii) { for (unsigned _ = 0; _ < nlist[ii].size(); ++_) { int jj = nlist[ii][_]; - if (jj < ii) continue; + if (jj < ii) { + continue; + } VALUETYPE diff[3]; region.diffNearestNeighbor(&coord[ii * 3], &coord[jj * 3], diff); VALUETYPE r2 = diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]; if (r2 < rc2) { VALUETYPE ae, af; lj_inner(ae, af, r2); - for (int dd = 0; dd < 3; ++dd) force[ii * 3 + dd] += af * diff[dd]; - for (int dd = 0; dd < 3; ++dd) force[jj * 3 + dd] -= af * diff[dd]; + for (int dd = 0; dd < 3; ++dd) { + force[ii * 3 + dd] += af * diff[dd]; + } + for (int dd = 0; dd < 3; ++dd) { + force[jj * 3 + dd] -= af * diff[dd]; + } ener += ae; for (int dd0 = 0; dd0 < 3; ++dd0) { for (int dd1 = 0; dd1 < 3; ++dd1) { diff --git a/source/md/src/MaxShift.cc b/source/md/src/MaxShift.cc index 3cab8bc59d..6eba961fe6 100644 --- a/source/md/src/MaxShift.cc +++ b/source/md/src/MaxShift.cc @@ -22,7 +22,9 @@ MaxShift::max_shift2(const vector& coord, VALUETYPE diff[3]; region.diffNearestNeighbor(&coord[ii * 3], &record[ii * 3], diff); VALUETYPE r2 = diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]; - if (r2 > maxv) maxv = r2; + if (r2 > maxv) { + maxv = r2; + } } return maxv; diff --git a/source/md/src/Poly.cpp b/source/md/src/Poly.cpp index e3a3a4a060..6b496ec4b6 100644 --- a/source/md/src/Poly.cpp +++ b/source/md/src/Poly.cpp @@ -1,11 +1,15 @@ #include "Poly.h" bool PiecewisePoly::valid() const { - if (x.size() != p.size() + 1) return false; + if (x.size() != p.size() + 1) { + return false; + } std::vector::const_iterator i = x.begin(); std::vector::const_iterator j = x.begin(); for (++j; j != x.end(); ++i, ++j) { - if (*i > *j) return false; + if (*i > *j) { + return false; + } } return true; } @@ -60,8 +64,12 @@ double PiecewisePoly::value_periodic(const double& xx_) const { double PiecewisePoly::value(const double& xx, unsigned& begin, unsigned& end) const { - if (end <= begin) return 0; - if (end - begin == 1) return p[begin].value(xx); + if (end <= begin) { + return 0; + } + if (end - begin == 1) { + return p[begin].value(xx); + } unsigned mid = (begin + end) / 2; while (end - begin > 1) { if (xx < x[mid]) { diff --git a/source/md/src/RandomGenerator_MT19937.cc b/source/md/src/RandomGenerator_MT19937.cc index 59d6a092f8..87fc69660c 100644 --- a/source/md/src/RandomGenerator_MT19937.cc +++ b/source/md/src/RandomGenerator_MT19937.cc @@ -92,7 +92,9 @@ void RandomGenerator_MT19937::init_by_array(unsigned long init_key[], mt[0] = mt[N - 1]; i = 1; } - if (j >= key_length) j = 0; + if (j >= key_length) { + j = 0; + } } for (k = N - 1; k; k--) { mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1566083941UL)) - @@ -117,8 +119,9 @@ unsigned long RandomGenerator_MT19937::genrand_int32(void) { if (mti >= N) { /* generate N words at one time */ int kk; - if (mti == N + 1) /* if init_genrand() has not been called, */ + if (mti == N + 1) { /* if init_genrand() has not been called, */ init_genrand(5489UL); /* a default initial seed is used */ + } for (kk = 0; kk < N - M; kk++) { y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK); diff --git a/source/md/src/StringSplit.cpp b/source/md/src/StringSplit.cpp index 6a7f7f62ad..dfd10c930e 100644 --- a/source/md/src/StringSplit.cpp +++ b/source/md/src/StringSplit.cpp @@ -33,5 +33,7 @@ void StringOperation::split(const std::string& in, out.push_back(token); s.erase(0, pos + len); } - if (!s.empty()) out.push_back(s); + if (!s.empty()) { + out.push_back(s); + } } diff --git a/source/md/src/TF.cc b/source/md/src/TF.cc index 24b5927702..13921e0ef6 100644 --- a/source/md/src/TF.cc +++ b/source/md/src/TF.cc @@ -27,10 +27,11 @@ TF::meas(const VALUETYPE& xx) const { ff = 0; } else { int posi = int(xx / hh); - if (posi < 0) + if (posi < 0) { posi = 0; - else if (posi >= data.size() - 1) + } else if (posi >= data.size() - 1) { posi = data.size() - 2; + } Poly p; Interpolation::pieceLinearInterpol(posi * hh, (posi + 1) * hh, data[posi], data[posi + 1], p); diff --git a/source/md/src/Tabulated.cc b/source/md/src/Tabulated.cc index 297d0614ab..a6f728aa24 100644 --- a/source/md/src/Tabulated.cc +++ b/source/md/src/Tabulated.cc @@ -104,15 +104,21 @@ void Tabulated::compute(VALUETYPE &ener, for (unsigned ii = 0; ii < nlist.size(); ++ii) { for (unsigned _ = 0; _ < nlist[ii].size(); ++_) { int jj = nlist[ii][_]; - if (jj < ii) continue; + if (jj < ii) { + continue; + } VALUETYPE diff[3]; region.diffNearestNeighbor(&coord[ii * 3], &coord[jj * 3], diff); VALUETYPE r2 = diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]; if (r2 < rc2) { VALUETYPE ae, af; tb_inner(ae, af, r2); - for (int dd = 0; dd < 3; ++dd) force[ii * 3 + dd] += af * diff[dd]; - for (int dd = 0; dd < 3; ++dd) force[jj * 3 + dd] -= af * diff[dd]; + for (int dd = 0; dd < 3; ++dd) { + force[ii * 3 + dd] += af * diff[dd]; + } + for (int dd = 0; dd < 3; ++dd) { + force[jj * 3 + dd] -= af * diff[dd]; + } ener += ae; for (int dd0 = 0; dd0 < 3; ++dd0) { for (int dd1 = 0; dd1 < 3; ++dd1) { @@ -135,7 +141,9 @@ void Tabulated::compute(VALUETYPE &ener, for (unsigned ii = 0; ii < nlist.size(); ++ii) { for (unsigned _ = 0; _ < nlist[ii].size(); ++_) { int jj = nlist[ii][_]; - if (jj < ii) continue; + if (jj < ii) { + continue; + } VALUETYPE diff[3]; region.diffNearestNeighbor(&coord[ii * 3], &coord[jj * 3], diff); VALUETYPE r2 = diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]; @@ -148,8 +156,12 @@ void Tabulated::compute(VALUETYPE &ener, ae *= qiqj; af *= qiqj; } - for (int dd = 0; dd < 3; ++dd) force[ii * 3 + dd] += af * diff[dd]; - for (int dd = 0; dd < 3; ++dd) force[jj * 3 + dd] -= af * diff[dd]; + for (int dd = 0; dd < 3; ++dd) { + force[ii * 3 + dd] += af * diff[dd]; + } + for (int dd = 0; dd < 3; ++dd) { + force[jj * 3 + dd] -= af * diff[dd]; + } ener += ae; for (int dd0 = 0; dd0 < 3; ++dd0) { for (int dd1 = 0; dd1 < 3; ++dd1) { diff --git a/source/md/src/Trajectory.cc b/source/md/src/Trajectory.cc index 673f6ebaad..cb1c31a540 100644 --- a/source/md/src/Trajectory.cc +++ b/source/md/src/Trajectory.cc @@ -53,7 +53,9 @@ void XtcSaver::save(const int &step, tmpBox[dd][dd] = box[3 * dd + dd]; } for (int ii = 0; ii < frame.size(); ++ii) { - for (int dd = 0; dd < 3; ++dd) xx[ii][dd] = frame[ii][dd]; + for (int dd = 0; dd < 3; ++dd) { + xx[ii][dd] = frame[ii][dd]; + } } write_xtc(xd, natoms, step, time, tmpBox, xx, prec); } @@ -114,7 +116,9 @@ void TrrSaver::save(const int &step, } } for (int ii = 0; ii < ixx.size(); ++ii) { - for (int dd = 0; dd < 3; ++dd) xx[ii][dd] = ixx[ii][dd]; + for (int dd = 0; dd < 3; ++dd) { + xx[ii][dd] = ixx[ii][dd]; + } } for (int ii = 0; ii < natoms; ++ii) { for (int dd = 0; dd < 3; ++dd) { @@ -123,10 +127,14 @@ void TrrSaver::save(const int &step, } } for (int ii = 0; ii < ivv.size(); ++ii) { - for (int dd = 0; dd < 3; ++dd) vv[ii][dd] = ivv[ii][dd]; + for (int dd = 0; dd < 3; ++dd) { + vv[ii][dd] = ivv[ii][dd]; + } } for (int ii = 0; ii < iff.size(); ++ii) { - for (int dd = 0; dd < 3; ++dd) ff[ii][dd] = iff[ii][dd]; + for (int dd = 0; dd < 3; ++dd) { + ff[ii][dd] = iff[ii][dd]; + } } write_trr(xd, natoms, step, time, lambda, tmpBox, xx, vv, ff); } diff --git a/source/md/src/XyzFileManager.cc b/source/md/src/XyzFileManager.cc index b1d8fc1e9d..61828117d7 100644 --- a/source/md/src/XyzFileManager.cc +++ b/source/md/src/XyzFileManager.cc @@ -92,10 +92,13 @@ void XyzFileManager::getBoxSize(const string& file, vector& boxsize) { boxsize.resize(9); fill(boxsize.begin(), boxsize.end(), 0.); if (words.size() == 3) { - for (int ii = 0; ii < 3; ++ii) + for (int ii = 0; ii < 3; ++ii) { boxsize[3 * ii + ii] = atof(words[ii].c_str()); + } } else if (words.size() == 9) { - for (int ii = 0; ii < 9; ++ii) boxsize[ii] = atof(words[ii].c_str()); + for (int ii = 0; ii < 9; ++ii) { + boxsize[ii] = atof(words[ii].c_str()); + } } else { cerr << "XyzFileManager::getBoxSize: wrong format, line has " << words.size() << " words" << endl; diff --git a/source/md/src/ZM.cc b/source/md/src/ZM.cc index 61537629c3..9c06e3e434 100644 --- a/source/md/src/ZM.cc +++ b/source/md/src/ZM.cc @@ -66,8 +66,12 @@ void ZM::exclude(VALUETYPE& ener, ae *= qiqj; af *= qiqj; } - for (int dd = 0; dd < 3; ++dd) force[ii * 3 + dd] -= af * diff[dd]; - for (int dd = 0; dd < 3; ++dd) force[jj * 3 + dd] += af * diff[dd]; + for (int dd = 0; dd < 3; ++dd) { + force[ii * 3 + dd] -= af * diff[dd]; + } + for (int dd = 0; dd < 3; ++dd) { + force[jj * 3 + dd] += af * diff[dd]; + } ener -= ae; for (int dd0 = 0; dd0 < 3; ++dd0) { for (int dd1 = 0; dd1 < 3; ++dd1) { diff --git a/source/md/src/ZMFunctions.cpp b/source/md/src/ZMFunctions.cpp index 28f68887dd..8f881dca3b 100644 --- a/source/md/src/ZMFunctions.cpp +++ b/source/md/src/ZMFunctions.cpp @@ -169,7 +169,9 @@ void ZeroMultipole::Potential::reinit(const int& ll_, } double ZeroMultipole::Potential::pot(const double& rr) { - if (rr > rc) return 0.; + if (rr > rc) { + return 0.; + } double tmp0 = funcV(alpha, rr); // double tmp0 = 0.; double tmp1 = coeff.back(); @@ -184,7 +186,9 @@ double ZeroMultipole::Potential::ulpot(const double& rr) { } double ZeroMultipole::Potential::mpotp(const double& rr) { - if (rr > rc) return 0.; + if (rr > rc) { + return 0.; + } double tmp0 = -funcD1V(alpha, rr); double tmp1 = 2 * ll * coeff[ll]; for (int ii = ll - 1; ii >= 1; --ii) { diff --git a/source/op/descrpt.cc b/source/op/descrpt.cc index 5560849e2a..0cc6109aae 100644 --- a/source/op/descrpt.cc +++ b/source/op/descrpt.cc @@ -221,10 +221,11 @@ class DescrptOp : public OpKernel { compute_t inter[3]; region.phys2Inter(inter, &d_coord3[3 * ii]); for (int dd = 0; dd < 3; ++dd) { - if (inter[dd] < 0) + if (inter[dd] < 0) { inter[dd] += 1.; - else if (inter[dd] >= 1) + } else if (inter[dd] >= 1) { inter[dd] -= 1.; + } } region.inter2Phys(&d_coord3[3 * ii], inter); } @@ -232,7 +233,9 @@ class DescrptOp : public OpKernel { // set type std::vector d_type(nall); - for (int ii = 0; ii < nall; ++ii) d_type[ii] = type(kk, ii); + for (int ii = 0; ii < nall; ++ii) { + d_type[ii] = type(kk, ii); + } // build nlist std::vector > d_nlist_a; @@ -262,8 +265,9 @@ class DescrptOp : public OpKernel { std::vector ext_stt = {mesh(7 - 1), mesh(8 - 1), mesh(9 - 1)}; std::vector ext_end = {mesh(10 - 1), mesh(11 - 1), mesh(12 - 1)}; std::vector global_grid(3); - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { global_grid[dd] = nat_end[dd] - nat_stt[dd]; + } ::build_nlist(d_nlist_a, d_nlist_r, d_coord3, nloc, rcut_a, rcut_r, nat_stt, nat_end, ext_stt, ext_end, region, global_grid); } else if (nei_mode == 1) { @@ -493,15 +497,21 @@ class DescrptOp : public OpKernel { int excl_type = -(*(info_i + 1) + 1); int ntypes = sel_a.size(); for (unsigned ii = 0; ii < ntypes; ++ii) { - if (ii == excl_type) continue; + if (ii == excl_type) { + continue; + } compute_t diff[3]; int list_idx, jd; // push axis candidates into sort_info for (int count = 0; count < 3; ++count) { list_idx = sec_a[ii] + count; - if (list_idx >= sec_a[ii + 1]) continue; + if (list_idx >= sec_a[ii + 1]) { + continue; + } jd = nlist_a[list_idx]; - if (jd < 0) continue; + if (jd < 0) { + continue; + } if (b_pbc) { region.diffNearestNeighbor(coord3[3 * id + 0], coord3[3 * id + 1], coord3[3 * id + 2], coord3[3 * jd + 0], @@ -524,15 +534,21 @@ class DescrptOp : public OpKernel { int excl_type = -*(info_i + 1); int ntypes = sel_r.size(); for (unsigned ii = 0; ii < ntypes; ++ii) { - if (ii == excl_type) continue; + if (ii == excl_type) { + continue; + } compute_t diff[3]; int list_idx, jd; // push axis candidates for sort_info for (int count = 0; count < 3; ++count) { list_idx = sec_r[ii] + count; - if (list_idx >= sec_r[ii + 1]) continue; + if (list_idx >= sec_r[ii + 1]) { + continue; + } jd = nlist_r[list_idx]; - if (jd < 0) continue; + if (jd < 0) { + continue; + } if (b_pbc) { region.diffNearestNeighbor(coord3[3 * id + 0], coord3[3 * id + 1], coord3[3 * id + 2], coord3[3 * jd + 0], diff --git a/source/op/descrpt_se_a_ef.cc b/source/op/descrpt_se_a_ef.cc index a7f22ee4a7..77e92b4b8b 100644 --- a/source/op/descrpt_se_a_ef.cc +++ b/source/op/descrpt_se_a_ef.cc @@ -228,10 +228,11 @@ class DescrptSeAEfOp : public OpKernel { compute_t inter[3]; region.phys2Inter(inter, &d_coord3[3 * ii]); for (int dd = 0; dd < 3; ++dd) { - if (inter[dd] < 0) + if (inter[dd] < 0) { inter[dd] += 1.; - else if (inter[dd] >= 1) + } else if (inter[dd] >= 1) { inter[dd] -= 1.; + } } region.inter2Phys(&d_coord3[3 * ii], inter); } @@ -247,7 +248,9 @@ class DescrptSeAEfOp : public OpKernel { // set type std::vector d_type(nall); - for (int ii = 0; ii < nall; ++ii) d_type[ii] = type(kk, ii); + for (int ii = 0; ii < nall; ++ii) { + d_type[ii] = type(kk, ii); + } // build nlist std::vector > d_nlist_a; @@ -279,8 +282,9 @@ class DescrptSeAEfOp : public OpKernel { std::vector ext_stt = {mesh(7 - 1), mesh(8 - 1), mesh(9 - 1)}; std::vector ext_end = {mesh(10 - 1), mesh(11 - 1), mesh(12 - 1)}; std::vector global_grid(3); - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { global_grid[dd] = nat_end[dd] - nat_stt[dd]; + } ::build_nlist(d_nlist_a, d_nlist_r, d_coord3, nloc, rcut_a, rcut_r, nat_stt, nat_end, ext_stt, ext_end, region, global_grid); } else if (nei_mode == 1) { diff --git a/source/op/descrpt_se_a_ef_para.cc b/source/op/descrpt_se_a_ef_para.cc index 254b54eb23..67d3a17c21 100644 --- a/source/op/descrpt_se_a_ef_para.cc +++ b/source/op/descrpt_se_a_ef_para.cc @@ -228,10 +228,11 @@ class DescrptSeAEfParaOp : public OpKernel { compute_t inter[3]; region.phys2Inter(inter, &d_coord3[3 * ii]); for (int dd = 0; dd < 3; ++dd) { - if (inter[dd] < 0) + if (inter[dd] < 0) { inter[dd] += 1.; - else if (inter[dd] >= 1) + } else if (inter[dd] >= 1) { inter[dd] -= 1.; + } } region.inter2Phys(&d_coord3[3 * ii], inter); } @@ -247,7 +248,9 @@ class DescrptSeAEfParaOp : public OpKernel { // set type std::vector d_type(nall); - for (int ii = 0; ii < nall; ++ii) d_type[ii] = type(kk, ii); + for (int ii = 0; ii < nall; ++ii) { + d_type[ii] = type(kk, ii); + } // build nlist std::vector > d_nlist_a; @@ -279,8 +282,9 @@ class DescrptSeAEfParaOp : public OpKernel { std::vector ext_stt = {mesh(7 - 1), mesh(8 - 1), mesh(9 - 1)}; std::vector ext_end = {mesh(10 - 1), mesh(11 - 1), mesh(12 - 1)}; std::vector global_grid(3); - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { global_grid[dd] = nat_end[dd] - nat_stt[dd]; + } ::build_nlist(d_nlist_a, d_nlist_r, d_coord3, nloc, rcut_a, rcut_r, nat_stt, nat_end, ext_stt, ext_end, region, global_grid); } else if (nei_mode == 1) { diff --git a/source/op/descrpt_se_a_ef_vert.cc b/source/op/descrpt_se_a_ef_vert.cc index 1be705ea77..77a3a9cf41 100644 --- a/source/op/descrpt_se_a_ef_vert.cc +++ b/source/op/descrpt_se_a_ef_vert.cc @@ -228,10 +228,11 @@ class DescrptSeAEfVertOp : public OpKernel { compute_t inter[3]; region.phys2Inter(inter, &d_coord3[3 * ii]); for (int dd = 0; dd < 3; ++dd) { - if (inter[dd] < 0) + if (inter[dd] < 0) { inter[dd] += 1.; - else if (inter[dd] >= 1) + } else if (inter[dd] >= 1) { inter[dd] -= 1.; + } } region.inter2Phys(&d_coord3[3 * ii], inter); } @@ -247,7 +248,9 @@ class DescrptSeAEfVertOp : public OpKernel { // set type std::vector d_type(nall); - for (int ii = 0; ii < nall; ++ii) d_type[ii] = type(kk, ii); + for (int ii = 0; ii < nall; ++ii) { + d_type[ii] = type(kk, ii); + } // build nlist std::vector > d_nlist_a; @@ -279,8 +282,9 @@ class DescrptSeAEfVertOp : public OpKernel { std::vector ext_stt = {mesh(7 - 1), mesh(8 - 1), mesh(9 - 1)}; std::vector ext_end = {mesh(10 - 1), mesh(11 - 1), mesh(12 - 1)}; std::vector global_grid(3); - for (int dd = 0; dd < 3; ++dd) + for (int dd = 0; dd < 3; ++dd) { global_grid[dd] = nat_end[dd] - nat_stt[dd]; + } ::build_nlist(d_nlist_a, d_nlist_r, d_coord3, nloc, rcut_a, rcut_r, nat_stt, nat_end, ext_stt, ext_end, region, global_grid); } else if (nei_mode == 1) { diff --git a/source/op/ewald_recp.cc b/source/op/ewald_recp.cc index cbf93f5916..43a56b24cc 100644 --- a/source/op/ewald_recp.cc +++ b/source/op/ewald_recp.cc @@ -106,17 +106,20 @@ class EwaldRecpOp : public OpKernel { FPTYPE inter[3]; convert_to_inter_cpu(inter, region, &coord(coord_iter + ii * 3)); for (int dd = 0; dd < 3; ++dd) { - if (inter[dd] < 0) + if (inter[dd] < 0) { inter[dd] += 1.; - else if (inter[dd] >= 1) + } else if (inter[dd] >= 1) { inter[dd] -= 1.; + } } convert_to_phys_cpu(&d_coord3[ii * 3], region, inter); } // set charge std::vector d_charge(nloc); - for (int ii = 0; ii < nloc; ++ii) d_charge[ii] = charge(charge_iter + ii); + for (int ii = 0; ii < nloc; ++ii) { + d_charge[ii] = charge(charge_iter + ii); + } // prepare outputs std::vectors FPTYPE d_ener; diff --git a/source/op/matmul_flt_nvnmd.cc b/source/op/matmul_flt_nvnmd.cc index 354afbbdb2..f840966265 100644 --- a/source/op/matmul_flt_nvnmd.cc +++ b/source/op/matmul_flt_nvnmd.cc @@ -130,7 +130,9 @@ class MatmulFltNvnmdOp : public OpKernel { // find x max exponnet if ((normx & 0x0f) == 0) { // normalize x[:,:] find_max_expo(expo_max1, (FPTYPE *)&x[hh * N * M], N * M); - for (ii = 0; ii < N; ii++) expo_max1s[ii] = expo_max1; + for (ii = 0; ii < N; ii++) { + expo_max1s[ii] = expo_max1; + } } else { // normalize x[ii,:] for (ii = 0; ii < N; ii++) { @@ -142,7 +144,9 @@ class MatmulFltNvnmdOp : public OpKernel { // find w max exponnet if ((normw & 0x0f) == 0) { // normalize w[:,:] find_max_expo(expo_max2, (FPTYPE *)&w[hh * M * K], M * K); - for (kk = 0; kk < K; kk++) expo_max2s[kk] = expo_max2; + for (kk = 0; kk < K; kk++) { + expo_max2s[kk] = expo_max2; + } } else { // normalize w[:,kk] for (kk = 0; kk < K; kk++) { diff --git a/source/op/neighbor_stat.cc b/source/op/neighbor_stat.cc index ba067786f9..08c36327b7 100644 --- a/source/op/neighbor_stat.cc +++ b/source/op/neighbor_stat.cc @@ -119,10 +119,11 @@ class NeighborStatOp : public OpKernel { compute_t inter[3]; region.phys2Inter(inter, &d_coord3[3 * ii]); for (int dd = 0; dd < 3; ++dd) { - if (inter[dd] < 0) + if (inter[dd] < 0) { inter[dd] += 1.; - else if (inter[dd] >= 1) + } else if (inter[dd] >= 1) { inter[dd] -= 1.; + } } region.inter2Phys(&d_coord3[3 * ii], inter); } @@ -130,7 +131,9 @@ class NeighborStatOp : public OpKernel { // set type std::vector d_type(nall); - for (int ii = 0; ii < nall; ++ii) d_type[ii] = type[ii]; + for (int ii = 0; ii < nall; ++ii) { + d_type[ii] = type[ii]; + } // build nlist std::vector > d_nlist_a; @@ -180,10 +183,14 @@ class NeighborStatOp : public OpKernel { #pragma omp parallel for for (int ii = 0; ii < nloc; ii++) { - if (d_type[ii] < 0) continue; // virtual atom + if (d_type[ii] < 0) { + continue; // virtual atom + } for (int jj = 0; jj < d_nlist_r[ii].size(); jj++) { int type = d_type[d_nlist_r[ii][jj]]; - if (type < 0) continue; // virtual atom + if (type < 0) { + continue; // virtual atom + } max_nbor_size[ii * ntypes + type] += 1; compute_t rij[3] = { d_coord3[d_nlist_r[ii][jj] * 3 + 0] - d_coord3[ii * 3 + 0], diff --git a/source/op/optimizer/parallel.cc b/source/op/optimizer/parallel.cc index f3a052ba90..f0beb6c204 100644 --- a/source/op/optimizer/parallel.cc +++ b/source/op/optimizer/parallel.cc @@ -59,12 +59,16 @@ Status ParallelProdForce(RemapperContext *ctx, std::vector *invalidated_nodes, std::vector *nodes_to_delete) { // skip on GPUs - if (GetNumAvailableGPUs() > 0) return Status(); + if (GetNumAvailableGPUs() > 0) { + return Status(); + } const NodeDef *ori_node = ctx->graph_view.GetNode(node_index)->node(); auto &src_attr = ori_node->attr(); TF_INT64 tot = GetNThreads(); - if (tot <= 1) return Status(); + if (tot <= 1) { + return Status(); + } NodeDef sum_node; sum_node.set_name(ori_node->name()); @@ -83,7 +87,9 @@ Status ParallelProdForce(RemapperContext *ctx, sub_node.set_op("ParallelProdForceSeA"); sub_node.set_device(ori_node->device()); // copy input - for (int jj = 0; jj < 4; ++jj) sub_node.add_input(ori_node->input(jj)); + for (int jj = 0; jj < 4; ++jj) { + sub_node.add_input(ori_node->input(jj)); + } // set frac auto *sub_attr = sub_node.mutable_attr(); (*sub_attr)["T"] = src_attr.at("T"); diff --git a/source/op/prod_env_mat_multi_device.cc b/source/op/prod_env_mat_multi_device.cc index 9a516dde35..d9e762d4b3 100644 --- a/source/op/prod_env_mat_multi_device.cc +++ b/source/op/prod_env_mat_multi_device.cc @@ -601,7 +601,9 @@ class ProdEnvMatAOp : public OpKernel { gpu_inlist, array_int, array_longlong, max_nbor_size, avg, std, nloc, frame_nall, rcut_r, rcut_r_smth, sec_a); - if (b_nlist_map) _map_nlist_gpu(nlist, idx_mapping, nloc, nnei); + if (b_nlist_map) { + _map_nlist_gpu(nlist, idx_mapping, nloc, nnei); + } deepmd::delete_device_memory(firstneigh); #endif // GOOGLE_CUDA @@ -644,7 +646,9 @@ class ProdEnvMatAOp : public OpKernel { gpu_inlist, array_int, array_longlong, max_nbor_size, avg, std, nloc, frame_nall, rcut_r, rcut_r_smth, sec_a); - if (b_nlist_map) _map_nlist_gpu_rocm(nlist, idx_mapping, nloc, nnei); + if (b_nlist_map) { + _map_nlist_gpu_rocm(nlist, idx_mapping, nloc, nnei); + } deepmd::delete_device_memory(firstneigh); #endif // TENSORFLOW_USE_ROCM } else if (device == "CPU") { @@ -668,7 +672,9 @@ class ProdEnvMatAOp : public OpKernel { inlist, max_nbor_size, avg, std, nloc, frame_nall, rcut_r, rcut_r_smth, sec_a); // do nlist mapping if coords were copied - if (b_nlist_map) _map_nlist_cpu(nlist, &idx_mapping[0], nloc, nnei); + if (b_nlist_map) { + _map_nlist_cpu(nlist, &idx_mapping[0], nloc, nnei); + } } } } @@ -883,7 +889,9 @@ class ProdEnvMatROp : public OpKernel { gpu_inlist, array_int, array_longlong, max_nbor_size, avg, std, nloc, frame_nall, rcut, rcut_smth, sec); - if (b_nlist_map) _map_nlist_gpu(nlist, idx_mapping, nloc, nnei); + if (b_nlist_map) { + _map_nlist_gpu(nlist, idx_mapping, nloc, nnei); + } deepmd::delete_device_memory(firstneigh); #endif // GOOGLE_CUDA @@ -926,7 +934,9 @@ class ProdEnvMatROp : public OpKernel { gpu_inlist, array_int, array_longlong, max_nbor_size, avg, std, nloc, frame_nall, rcut, rcut_smth, sec); - if (b_nlist_map) _map_nlist_gpu_rocm(nlist, idx_mapping, nloc, nnei); + if (b_nlist_map) { + _map_nlist_gpu_rocm(nlist, idx_mapping, nloc, nnei); + } deepmd::delete_device_memory(firstneigh); #endif // TENSORFLOW_USE_ROCM } else if (device == "CPU") { @@ -949,7 +959,9 @@ class ProdEnvMatROp : public OpKernel { deepmd::prod_env_mat_r_cpu(em, em_deriv, rij, nlist, coord, type, inlist, max_nbor_size, avg, std, nloc, frame_nall, rcut, rcut_smth, sec); - if (b_nlist_map) _map_nlist_cpu(nlist, &idx_mapping[0], nloc, nnei); + if (b_nlist_map) { + _map_nlist_cpu(nlist, &idx_mapping[0], nloc, nnei); + } } } } diff --git a/source/op/prod_env_mat_multi_device_nvnmd.cc b/source/op/prod_env_mat_multi_device_nvnmd.cc index cfccd6605a..eea1e83f46 100644 --- a/source/op/prod_env_mat_multi_device_nvnmd.cc +++ b/source/op/prod_env_mat_multi_device_nvnmd.cc @@ -448,7 +448,9 @@ class ProdEnvMatANvnmdQuantizeOp : public OpKernel { em, em_deriv, rij, nlist, coord, type, inlist, max_nbor_size, avg, std, nloc, frame_nall, rcut_r, rcut_r_smth, sec_a); // do nlist mapping if coords were copied - if (b_nlist_map) _map_nlist_cpu(nlist, &idx_mapping[0], nloc, nnei); + if (b_nlist_map) { + _map_nlist_cpu(nlist, &idx_mapping[0], nloc, nnei); + } } } } diff --git a/source/op/prod_force.cc b/source/op/prod_force.cc index 591a56ffda..e67647e96e 100644 --- a/source/op/prod_force.cc +++ b/source/op/prod_force.cc @@ -132,14 +132,20 @@ class ProdForceOp : public OpKernel { int axis1_type = axis(axis_iter + i_idx * 4 + 2); int axis_0 = axis(axis_iter + i_idx * 4 + 1); int axis_1 = axis(axis_iter + i_idx * 4 + 3); - if (axis0_type == 1) axis_0 += n_a_sel; - if (axis1_type == 1) axis_1 += n_a_sel; + if (axis0_type == 1) { + axis_0 += n_a_sel; + } + if (axis1_type == 1) { + axis_1 += n_a_sel; + } // deriv wrt neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist(nlist_iter + i_idx * nnei + jj); // if (j_idx > nloc) j_idx = j_idx % nloc; - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } if (jj == axis_0) { for (int aa = 0; aa < ndescrpt; ++aa) { force(force_iter + j_idx * 3 + 0) -= diff --git a/source/op/prod_force_grad.cc b/source/op/prod_force_grad.cc index 5e63ff2308..712bb7b1d9 100644 --- a/source/op/prod_force_grad.cc +++ b/source/op/prod_force_grad.cc @@ -141,14 +141,22 @@ class ProdForceGradOp : public OpKernel { int axis1_type = axis(axis_iter + i_idx * 4 + 2); int axis_0 = axis(axis_iter + i_idx * 4 + 1); int axis_1 = axis(axis_iter + i_idx * 4 + 3); - if (axis0_type == 1) axis_0 += n_a_sel; - if (axis1_type == 1) axis_1 += n_a_sel; + if (axis0_type == 1) { + axis_0 += n_a_sel; + } + if (axis1_type == 1) { + axis_1 += n_a_sel; + } // loop over neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist(nlist_iter + i_idx * nnei + jj); - if (j_idx > nloc) j_idx = j_idx % nloc; - if (j_idx < 0) continue; + if (j_idx > nloc) { + j_idx = j_idx % nloc; + } + if (j_idx < 0) { + continue; + } if (jj == axis_0) { for (int aa = 0; aa < ndescrpt; ++aa) { for (int dd = 0; dd < 3; ++dd) { diff --git a/source/op/prod_force_multi_device.cc b/source/op/prod_force_multi_device.cc index 8ba62882cf..c3b2222962 100644 --- a/source/op/prod_force_multi_device.cc +++ b/source/op/prod_force_multi_device.cc @@ -49,12 +49,15 @@ template class ProdForceSeAOp : public OpKernel { public: explicit ProdForceSeAOp(OpKernelConstruction* context) : OpKernel(context) { - if (context->HasAttr("parallel")) + if (context->HasAttr("parallel")) { OP_REQUIRES_OK(context, context->GetAttr("parallel", ¶llel)); - if (context->HasAttr("start_frac")) + } + if (context->HasAttr("start_frac")) { OP_REQUIRES_OK(context, context->GetAttr("start_frac", &start_frac)); - if (context->HasAttr("end_frac")) + } + if (context->HasAttr("end_frac")) { OP_REQUIRES_OK(context, context->GetAttr("end_frac", &end_frac)); + } } void Compute(OpKernelContext* context) override { @@ -124,9 +127,10 @@ class ProdForceSeAOp : public OpKernel { int start_index = 0, end_index = nloc, nloc_loc = nloc; if (parallel) { - if (device != "CPU") + if (device != "CPU") { throw deepmd::deepmd_exception( "Auto parallelization for ProdForceA is not supported on GPUs!"); + } // we split in_deriv, net_deriv, and nlist along nloc // compute start and end index along nloc // frac belongs to [0, 1] diff --git a/source/op/prod_virial.cc b/source/op/prod_virial.cc index 8769ccf8f1..fb278bcd40 100644 --- a/source/op/prod_virial.cc +++ b/source/op/prod_virial.cc @@ -136,13 +136,19 @@ class ProdVirialOp : public OpKernel { int axis1_type = axis(axis_iter + i_idx * 4 + 2); int axis_0 = axis(axis_iter + i_idx * 4 + 1); int axis_1 = axis(axis_iter + i_idx * 4 + 3); - if (axis0_type == 1) axis_0 += n_a_sel; - if (axis1_type == 1) axis_1 += n_a_sel; + if (axis0_type == 1) { + axis_0 += n_a_sel; + } + if (axis1_type == 1) { + axis_1 += n_a_sel; + } // deriv wrt neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist(nlist_iter + i_idx * nnei + jj); - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } if (jj == axis_0) { for (int aa = 0; aa < ndescrpt; ++aa) { FPTYPE pref = -1.0 * net_deriv(net_iter + i_idx * ndescrpt + aa); diff --git a/source/op/prod_virial_grad.cc b/source/op/prod_virial_grad.cc index e7683111b2..495abd1a10 100644 --- a/source/op/prod_virial_grad.cc +++ b/source/op/prod_virial_grad.cc @@ -143,13 +143,19 @@ class ProdVirialGradOp : public OpKernel { int axis1_type = axis(axis_iter + i_idx * 4 + 2); int axis_0 = axis(axis_iter + i_idx * 4 + 1); int axis_1 = axis(axis_iter + i_idx * 4 + 3); - if (axis0_type == 1) axis_0 += n_a_sel; - if (axis1_type == 1) axis_1 += n_a_sel; + if (axis0_type == 1) { + axis_0 += n_a_sel; + } + if (axis1_type == 1) { + axis_1 += n_a_sel; + } // loop over neighbors for (int jj = 0; jj < nnei; ++jj) { int j_idx = nlist(nlist_iter + i_idx * nnei + jj); - if (j_idx < 0) continue; + if (j_idx < 0) { + continue; + } if (jj == axis_0) { for (int aa = 0; aa < ndescrpt; ++aa) { for (int dd0 = 0; dd0 < 3; ++dd0) { diff --git a/source/op/quantize_nvnmd.cc b/source/op/quantize_nvnmd.cc index 505bdb51ba..048cba6581 100644 --- a/source/op/quantize_nvnmd.cc +++ b/source/op/quantize_nvnmd.cc @@ -113,14 +113,15 @@ class QuantizeNvnmdOp : public OpKernel { else { prec = 1 << this->nbit1; - if (this->isround) + if (this->isround) { for (ii = 0; ii < N; ii++) { y[ii] = round(x[ii] * prec) / prec; } - else + } else { for (ii = 0; ii < N; ii++) { y[ii] = floor(x[ii] * prec) / prec; } + } } } // Compute