diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6d7a629ac6..e1f42fd120 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,7 +29,7 @@ repos: exclude: ^source/3rdparty - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.12.10 + rev: v0.12.11 hooks: - id: ruff args: ["--fix"] @@ -60,7 +60,7 @@ repos: - id: blacken-docs # C++ - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v20.1.8 + rev: v21.1.0 hooks: - id: clang-format exclude: ^(source/3rdparty|source/lib/src/gpu/cudart/.+\.inc|.+\.ipynb$|.+\.json$) diff --git a/source/api_c/include/deepmd.hpp b/source/api_c/include/deepmd.hpp index 8a3656bfc2..afa62403e7 100644 --- a/source/api_c/include/deepmd.hpp +++ b/source/api_c/include/deepmd.hpp @@ -26,7 +26,7 @@ namespace hpp { struct deepmd_exception : public std::runtime_error { public: deepmd_exception() : runtime_error("DeePMD-kit C API Error!") {}; - deepmd_exception(const std::string &msg) + deepmd_exception(const std::string& msg) : runtime_error(std::string("DeePMD-kit C API Error: ") + msg) {}; }; } // namespace hpp @@ -36,7 +36,7 @@ struct deepmd_exception : public std::runtime_error { * @brief Check if any exceptions throw in the C++ API. Throw if possible. */ #define DP_CHECK_OK(check_func, dp) \ - const char *err_msg = check_func(dp); \ + const char* err_msg = check_func(dp); \ if (std::strlen(err_msg)) { \ std::string err_msg_str = std::string(err_msg); \ DP_DeleteChar(err_msg); \ @@ -45,173 +45,173 @@ struct deepmd_exception : public std::runtime_error { DP_DeleteChar(err_msg); template -inline void _DP_DeepPotCompute(DP_DeepPot *dp, +inline void _DP_DeepPotCompute(DP_DeepPot* dp, const int nframes, const int natom, - const FPTYPE *coord, - const int *atype, - const FPTYPE *cell, - const FPTYPE *fparam, - const FPTYPE *aparam, - double *energy, - FPTYPE *force, - FPTYPE *virial, - FPTYPE *atomic_energy, - FPTYPE *atomic_virial); + const FPTYPE* coord, + const int* atype, + const FPTYPE* cell, + const FPTYPE* fparam, + const FPTYPE* aparam, + double* energy, + FPTYPE* force, + FPTYPE* virial, + FPTYPE* atomic_energy, + FPTYPE* atomic_virial); template <> -inline void _DP_DeepPotCompute(DP_DeepPot *dp, +inline void _DP_DeepPotCompute(DP_DeepPot* dp, const int nframes, const int natom, - const double *coord, - const int *atype, - const double *cell, - const double *fparam, - const double *aparam, - double *energy, - double *force, - double *virial, - double *atomic_energy, - double *atomic_virial) { + const double* coord, + const int* atype, + const double* cell, + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* virial, + double* atomic_energy, + double* atomic_virial) { DP_DeepPotCompute2(dp, nframes, natom, coord, atype, cell, fparam, aparam, energy, force, virial, atomic_energy, atomic_virial); } template <> -inline void _DP_DeepPotCompute(DP_DeepPot *dp, +inline void _DP_DeepPotCompute(DP_DeepPot* dp, const int nframes, const int natom, - const float *coord, - const int *atype, - const float *cell, - const float *fparam, - const float *aparam, - double *energy, - float *force, - float *virial, - float *atomic_energy, - float *atomic_virial) { + const float* coord, + const int* atype, + const float* cell, + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* virial, + float* atomic_energy, + float* atomic_virial) { DP_DeepPotComputef2(dp, nframes, natom, coord, atype, cell, fparam, aparam, energy, force, virial, atomic_energy, atomic_virial); } // support spin template -inline void _DP_DeepSpinCompute(DP_DeepSpin *dp, +inline void _DP_DeepSpinCompute(DP_DeepSpin* dp, const int nframes, const int natom, - const FPTYPE *coord, - const FPTYPE *spin, - const int *atype, - const FPTYPE *cell, - const FPTYPE *fparam, - const FPTYPE *aparam, - double *energy, - FPTYPE *force, - FPTYPE *force_mag, - FPTYPE *virial, - FPTYPE *atomic_energy, - FPTYPE *atomic_virial); + const FPTYPE* coord, + const FPTYPE* spin, + const int* atype, + const FPTYPE* cell, + const FPTYPE* fparam, + const FPTYPE* aparam, + double* energy, + FPTYPE* force, + FPTYPE* force_mag, + FPTYPE* virial, + FPTYPE* atomic_energy, + FPTYPE* atomic_virial); template <> -inline void _DP_DeepSpinCompute(DP_DeepSpin *dp, +inline void _DP_DeepSpinCompute(DP_DeepSpin* dp, const int nframes, const int natom, - const double *coord, - const double *spin, - const int *atype, - const double *cell, - const double *fparam, - const double *aparam, - double *energy, - double *force, - double *force_mag, - double *virial, - double *atomic_energy, - double *atomic_virial) { + const double* coord, + const double* spin, + const int* atype, + const double* cell, + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* force_mag, + double* virial, + double* atomic_energy, + double* atomic_virial) { DP_DeepSpinCompute2(dp, nframes, natom, coord, spin, atype, cell, fparam, aparam, energy, force, force_mag, virial, atomic_energy, atomic_virial); } template <> -inline void _DP_DeepSpinCompute(DP_DeepSpin *dp, +inline void _DP_DeepSpinCompute(DP_DeepSpin* dp, const int nframes, const int natom, - const float *coord, - const float *spin, - const int *atype, - const float *cell, - const float *fparam, - const float *aparam, - double *energy, - float *force, - float *force_mag, - float *virial, - float *atomic_energy, - float *atomic_virial) { + const float* coord, + const float* spin, + const int* atype, + const float* cell, + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* force_mag, + float* virial, + float* atomic_energy, + float* atomic_virial) { DP_DeepSpinComputef2(dp, nframes, natom, coord, spin, atype, cell, fparam, aparam, energy, force, force_mag, virial, atomic_energy, atomic_virial); } template -inline void _DP_DeepPotComputeNList(DP_DeepPot *dp, +inline void _DP_DeepPotComputeNList(DP_DeepPot* dp, const int nframes, const int natom, - const FPTYPE *coord, - const int *atype, - const FPTYPE *cell, + const FPTYPE* coord, + const int* atype, + const FPTYPE* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const FPTYPE *fparam, - const FPTYPE *aparam, - double *energy, - FPTYPE *force, - FPTYPE *virial, - FPTYPE *atomic_energy, - FPTYPE *atomic_virial); + const FPTYPE* fparam, + const FPTYPE* aparam, + double* energy, + FPTYPE* force, + FPTYPE* virial, + FPTYPE* atomic_energy, + FPTYPE* atomic_virial); template <> -inline void _DP_DeepPotComputeNList(DP_DeepPot *dp, +inline void _DP_DeepPotComputeNList(DP_DeepPot* dp, const int nframes, const int natom, - const double *coord, - const int *atype, - const double *cell, + const double* coord, + const int* atype, + const double* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const double *fparam, - const double *aparam, - double *energy, - double *force, - double *virial, - double *atomic_energy, - double *atomic_virial) { + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* virial, + double* atomic_energy, + double* atomic_virial) { DP_DeepPotComputeNList2(dp, nframes, natom, coord, atype, cell, nghost, nlist, ago, fparam, aparam, energy, force, virial, atomic_energy, atomic_virial); } template <> -inline void _DP_DeepPotComputeNList(DP_DeepPot *dp, +inline void _DP_DeepPotComputeNList(DP_DeepPot* dp, const int nframes, const int natom, - const float *coord, - const int *atype, - const float *cell, + const float* coord, + const int* atype, + const float* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const float *fparam, - const float *aparam, - double *energy, - float *force, - float *virial, - float *atomic_energy, - float *atomic_virial) { + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* virial, + float* atomic_energy, + float* atomic_virial) { DP_DeepPotComputeNListf2(dp, nframes, natom, coord, atype, cell, nghost, nlist, ago, fparam, aparam, energy, force, virial, atomic_energy, atomic_virial); @@ -219,550 +219,550 @@ inline void _DP_DeepPotComputeNList(DP_DeepPot *dp, // support spin template -inline void _DP_DeepSpinComputeNList(DP_DeepSpin *dp, +inline void _DP_DeepSpinComputeNList(DP_DeepSpin* dp, const int nframes, const int natom, - const FPTYPE *coord, - const FPTYPE *spin, - const int *atype, - const FPTYPE *cell, + const FPTYPE* coord, + const FPTYPE* spin, + const int* atype, + const FPTYPE* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const FPTYPE *fparam, - const FPTYPE *aparam, - double *energy, - FPTYPE *force, - FPTYPE *force_mag, - FPTYPE *virial, - FPTYPE *atomic_energy, - FPTYPE *atomic_virial); + const FPTYPE* fparam, + const FPTYPE* aparam, + double* energy, + FPTYPE* force, + FPTYPE* force_mag, + FPTYPE* virial, + FPTYPE* atomic_energy, + FPTYPE* atomic_virial); template <> -inline void _DP_DeepSpinComputeNList(DP_DeepSpin *dp, +inline void _DP_DeepSpinComputeNList(DP_DeepSpin* dp, const int nframes, const int natom, - const double *coord, - const double *spin, - const int *atype, - const double *cell, + const double* coord, + const double* spin, + const int* atype, + const double* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const double *fparam, - const double *aparam, - double *energy, - double *force, - double *force_mag, - double *virial, - double *atomic_energy, - double *atomic_virial) { + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* force_mag, + double* virial, + double* atomic_energy, + double* atomic_virial) { DP_DeepSpinComputeNList2(dp, nframes, natom, coord, spin, atype, cell, nghost, nlist, ago, fparam, aparam, energy, force, force_mag, virial, atomic_energy, atomic_virial); } template <> -inline void _DP_DeepSpinComputeNList(DP_DeepSpin *dp, +inline void _DP_DeepSpinComputeNList(DP_DeepSpin* dp, const int nframes, const int natom, - const float *coord, - const float *spin, - const int *atype, - const float *cell, + const float* coord, + const float* spin, + const int* atype, + const float* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const float *fparam, - const float *aparam, - double *energy, - float *force, - float *force_mag, - float *virial, - float *atomic_energy, - float *atomic_virial) { + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* force_mag, + float* virial, + float* atomic_energy, + float* atomic_virial) { DP_DeepSpinComputeNListf2(dp, nframes, natom, coord, spin, atype, cell, nghost, nlist, ago, fparam, aparam, energy, force, force_mag, virial, atomic_energy, atomic_virial); } template -inline void _DP_DeepPotComputeMixedType(DP_DeepPot *dp, +inline void _DP_DeepPotComputeMixedType(DP_DeepPot* dp, const int nframes, const int natom, - const FPTYPE *coord, - const int *atype, - const FPTYPE *cell, - const FPTYPE *fparam, - const FPTYPE *aparam, - double *energy, - FPTYPE *force, - FPTYPE *virial, - FPTYPE *atomic_energy, - FPTYPE *atomic_virial); + const FPTYPE* coord, + const int* atype, + const FPTYPE* cell, + const FPTYPE* fparam, + const FPTYPE* aparam, + double* energy, + FPTYPE* force, + FPTYPE* virial, + FPTYPE* atomic_energy, + FPTYPE* atomic_virial); template <> -inline void _DP_DeepPotComputeMixedType(DP_DeepPot *dp, +inline void _DP_DeepPotComputeMixedType(DP_DeepPot* dp, const int nframes, const int natom, - const double *coord, - const int *atype, - const double *cell, - const double *fparam, - const double *aparam, - double *energy, - double *force, - double *virial, - double *atomic_energy, - double *atomic_virial) { + const double* coord, + const int* atype, + const double* cell, + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* virial, + double* atomic_energy, + double* atomic_virial) { DP_DeepPotComputeMixedType(dp, nframes, natom, coord, atype, cell, fparam, aparam, energy, force, virial, atomic_energy, atomic_virial); } template <> -inline void _DP_DeepPotComputeMixedType(DP_DeepPot *dp, +inline void _DP_DeepPotComputeMixedType(DP_DeepPot* dp, const int nframes, const int natom, - const float *coord, - const int *atype, - const float *cell, - const float *fparam, - const float *aparam, - double *energy, - float *force, - float *virial, - float *atomic_energy, - float *atomic_virial) { + const float* coord, + const int* atype, + const float* cell, + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* virial, + float* atomic_energy, + float* atomic_virial) { DP_DeepPotComputeMixedTypef(dp, nframes, natom, coord, atype, cell, fparam, aparam, energy, force, virial, atomic_energy, atomic_virial); } template -inline void _DP_DeepPotModelDeviCompute(DP_DeepPotModelDevi *dp, +inline void _DP_DeepPotModelDeviCompute(DP_DeepPotModelDevi* dp, const int natom, - const FPTYPE *coord, - const int *atype, - const FPTYPE *cell, - const FPTYPE *fparam, - const FPTYPE *aparam, - double *energy, - FPTYPE *force, - FPTYPE *virial, - FPTYPE *atomic_energy, - FPTYPE *atomic_virial); + const FPTYPE* coord, + const int* atype, + const FPTYPE* cell, + const FPTYPE* fparam, + const FPTYPE* aparam, + double* energy, + FPTYPE* force, + FPTYPE* virial, + FPTYPE* atomic_energy, + FPTYPE* atomic_virial); template <> -inline void _DP_DeepPotModelDeviCompute(DP_DeepPotModelDevi *dp, +inline void _DP_DeepPotModelDeviCompute(DP_DeepPotModelDevi* dp, const int natom, - const double *coord, - const int *atype, - const double *cell, - const double *fparam, - const double *aparam, - double *energy, - double *force, - double *virial, - double *atomic_energy, - double *atomic_virial) { + const double* coord, + const int* atype, + const double* cell, + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* virial, + double* atomic_energy, + double* atomic_virial) { DP_DeepPotModelDeviCompute2(dp, 1, natom, coord, atype, cell, fparam, aparam, energy, force, virial, atomic_energy, atomic_virial); } template <> -inline void _DP_DeepPotModelDeviCompute(DP_DeepPotModelDevi *dp, +inline void _DP_DeepPotModelDeviCompute(DP_DeepPotModelDevi* dp, const int natom, - const float *coord, - const int *atype, - const float *cell, - const float *fparam, - const float *aparam, - double *energy, - float *force, - float *virial, - float *atomic_energy, - float *atomic_virial) { + const float* coord, + const int* atype, + const float* cell, + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* virial, + float* atomic_energy, + float* atomic_virial) { DP_DeepPotModelDeviComputef2(dp, 1, natom, coord, atype, cell, fparam, aparam, energy, force, virial, atomic_energy, atomic_virial); } template -inline void _DP_DeepSpinModelDeviCompute(DP_DeepSpinModelDevi *dp, +inline void _DP_DeepSpinModelDeviCompute(DP_DeepSpinModelDevi* dp, const int natom, - const FPTYPE *coord, - const FPTYPE *spin, - const int *atype, - const FPTYPE *cell, - const FPTYPE *fparam, - const FPTYPE *aparam, - double *energy, - FPTYPE *force, - FPTYPE *force_mag, - FPTYPE *virial, - FPTYPE *atomic_energy, - FPTYPE *atomic_virial); + const FPTYPE* coord, + const FPTYPE* spin, + const int* atype, + const FPTYPE* cell, + const FPTYPE* fparam, + const FPTYPE* aparam, + double* energy, + FPTYPE* force, + FPTYPE* force_mag, + FPTYPE* virial, + FPTYPE* atomic_energy, + FPTYPE* atomic_virial); template <> -inline void _DP_DeepSpinModelDeviCompute(DP_DeepSpinModelDevi *dp, +inline void _DP_DeepSpinModelDeviCompute(DP_DeepSpinModelDevi* dp, const int natom, - const double *coord, - const double *spin, - const int *atype, - const double *cell, - const double *fparam, - const double *aparam, - double *energy, - double *force, - double *force_mag, - double *virial, - double *atomic_energy, - double *atomic_virial) { + const double* coord, + const double* spin, + const int* atype, + const double* cell, + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* force_mag, + double* virial, + double* atomic_energy, + double* atomic_virial) { DP_DeepSpinModelDeviCompute2(dp, 1, natom, coord, spin, atype, cell, fparam, aparam, energy, force, force_mag, virial, atomic_energy, atomic_virial); } template <> -inline void _DP_DeepSpinModelDeviCompute(DP_DeepSpinModelDevi *dp, +inline void _DP_DeepSpinModelDeviCompute(DP_DeepSpinModelDevi* dp, const int natom, - const float *coord, - const float *spin, - const int *atype, - const float *cell, - const float *fparam, - const float *aparam, - double *energy, - float *force, - float *force_mag, - float *virial, - float *atomic_energy, - float *atomic_virial) { + const float* coord, + const float* spin, + const int* atype, + const float* cell, + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* force_mag, + float* virial, + float* atomic_energy, + float* atomic_virial) { DP_DeepSpinModelDeviComputef2(dp, 1, natom, coord, spin, atype, cell, fparam, aparam, energy, force, force_mag, virial, atomic_energy, atomic_virial); } template -inline void _DP_DeepPotModelDeviComputeNList(DP_DeepPotModelDevi *dp, +inline void _DP_DeepPotModelDeviComputeNList(DP_DeepPotModelDevi* dp, const int natom, - const FPTYPE *coord, - const int *atype, - const FPTYPE *cell, + const FPTYPE* coord, + const int* atype, + const FPTYPE* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const FPTYPE *fparam, - const FPTYPE *aparam, - double *energy, - FPTYPE *force, - FPTYPE *virial, - FPTYPE *atomic_energy, - FPTYPE *atomic_virial); + const FPTYPE* fparam, + const FPTYPE* aparam, + double* energy, + FPTYPE* force, + FPTYPE* virial, + FPTYPE* atomic_energy, + FPTYPE* atomic_virial); template <> -inline void _DP_DeepPotModelDeviComputeNList(DP_DeepPotModelDevi *dp, +inline void _DP_DeepPotModelDeviComputeNList(DP_DeepPotModelDevi* dp, const int natom, - const double *coord, - const int *atype, - const double *cell, + const double* coord, + const int* atype, + const double* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const double *fparam, - const double *aparam, - double *energy, - double *force, - double *virial, - double *atomic_energy, - double *atomic_virial) { + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* virial, + double* atomic_energy, + double* atomic_virial) { DP_DeepPotModelDeviComputeNList2(dp, 1, natom, coord, atype, cell, nghost, nlist, ago, fparam, aparam, energy, force, virial, atomic_energy, atomic_virial); } template <> -inline void _DP_DeepPotModelDeviComputeNList(DP_DeepPotModelDevi *dp, +inline void _DP_DeepPotModelDeviComputeNList(DP_DeepPotModelDevi* dp, const int natom, - const float *coord, - const int *atype, - const float *cell, + const float* coord, + const int* atype, + const float* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const float *fparam, - const float *aparam, - double *energy, - float *force, - float *virial, - float *atomic_energy, - float *atomic_virial) { + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* virial, + float* atomic_energy, + float* atomic_virial) { DP_DeepPotModelDeviComputeNListf2(dp, 1, natom, coord, atype, cell, nghost, nlist, ago, fparam, aparam, energy, force, virial, atomic_energy, atomic_virial); } template -inline void _DP_DeepSpinModelDeviComputeNList(DP_DeepSpinModelDevi *dp, +inline void _DP_DeepSpinModelDeviComputeNList(DP_DeepSpinModelDevi* dp, const int natom, - const FPTYPE *coord, - const FPTYPE *spin, - const int *atype, - const FPTYPE *cell, + const FPTYPE* coord, + const FPTYPE* spin, + const int* atype, + const FPTYPE* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const FPTYPE *fparam, - const FPTYPE *aparam, - double *energy, - FPTYPE *force, - FPTYPE *force_mag, - FPTYPE *virial, - FPTYPE *atomic_energy, - FPTYPE *atomic_virial); + const FPTYPE* fparam, + const FPTYPE* aparam, + double* energy, + FPTYPE* force, + FPTYPE* force_mag, + FPTYPE* virial, + FPTYPE* atomic_energy, + FPTYPE* atomic_virial); template <> -inline void _DP_DeepSpinModelDeviComputeNList(DP_DeepSpinModelDevi *dp, +inline void _DP_DeepSpinModelDeviComputeNList(DP_DeepSpinModelDevi* dp, const int natom, - const double *coord, - const double *spin, - const int *atype, - const double *cell, + const double* coord, + const double* spin, + const int* atype, + const double* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const double *fparam, - const double *aparam, - double *energy, - double *force, - double *force_mag, - double *virial, - double *atomic_energy, - double *atomic_virial) { + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* force_mag, + double* virial, + double* atomic_energy, + double* atomic_virial) { DP_DeepSpinModelDeviComputeNList2( dp, 1, natom, coord, spin, atype, cell, nghost, nlist, ago, fparam, aparam, energy, force, force_mag, virial, atomic_energy, atomic_virial); } template <> -inline void _DP_DeepSpinModelDeviComputeNList(DP_DeepSpinModelDevi *dp, +inline void _DP_DeepSpinModelDeviComputeNList(DP_DeepSpinModelDevi* dp, const int natom, - const float *coord, - const float *spin, - const int *atype, - const float *cell, + const float* coord, + const float* spin, + const int* atype, + const float* cell, const int nghost, - const DP_Nlist *nlist, + const DP_Nlist* nlist, const int ago, - const float *fparam, - const float *aparam, - double *energy, - float *force, - float *force_mag, - float *virial, - float *atomic_energy, - float *atomic_virial) { + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* force_mag, + float* virial, + float* atomic_energy, + float* atomic_virial) { DP_DeepSpinModelDeviComputeNListf2( dp, 1, natom, coord, spin, atype, cell, nghost, nlist, ago, fparam, aparam, energy, force, force_mag, virial, atomic_energy, atomic_virial); } template -inline void _DP_DeepTensorComputeTensor(DP_DeepTensor *dt, +inline void _DP_DeepTensorComputeTensor(DP_DeepTensor* dt, const int natom, - const FPTYPE *coord, - const int *atype, - const FPTYPE *cell, - FPTYPE **tensor, - int *size); + const FPTYPE* coord, + const int* atype, + const FPTYPE* cell, + FPTYPE** tensor, + int* size); template <> -inline void _DP_DeepTensorComputeTensor(DP_DeepTensor *dt, +inline void _DP_DeepTensorComputeTensor(DP_DeepTensor* dt, const int natom, - const double *coord, - const int *atype, - const double *cell, - double **tensor, - int *size) { + const double* coord, + const int* atype, + const double* cell, + double** tensor, + int* size) { DP_DeepTensorComputeTensor(dt, natom, coord, atype, cell, tensor, size); } template <> -inline void _DP_DeepTensorComputeTensor(DP_DeepTensor *dt, +inline void _DP_DeepTensorComputeTensor(DP_DeepTensor* dt, const int natom, - const float *coord, - const int *atype, - const float *cell, - float **tensor, - int *size) { + const float* coord, + const int* atype, + const float* cell, + float** tensor, + int* size) { DP_DeepTensorComputeTensorf(dt, natom, coord, atype, cell, tensor, size); } template -inline void _DP_DeepTensorComputeTensorNList(DP_DeepTensor *dt, +inline void _DP_DeepTensorComputeTensorNList(DP_DeepTensor* dt, const int natom, - const FPTYPE *coord, - const int *atype, - const FPTYPE *cell, + const FPTYPE* coord, + const int* atype, + const FPTYPE* cell, const int nghost, - const DP_Nlist *nlist, - FPTYPE **tensor, - int *size); + const DP_Nlist* nlist, + FPTYPE** tensor, + int* size); template <> -inline void _DP_DeepTensorComputeTensorNList(DP_DeepTensor *dt, +inline void _DP_DeepTensorComputeTensorNList(DP_DeepTensor* dt, const int natom, - const double *coord, - const int *atype, - const double *cell, + const double* coord, + const int* atype, + const double* cell, const int nghost, - const DP_Nlist *nlist, - double **tensor, - int *size) { + const DP_Nlist* nlist, + double** tensor, + int* size) { DP_DeepTensorComputeTensorNList(dt, natom, coord, atype, cell, nghost, nlist, tensor, size); } template <> -inline void _DP_DeepTensorComputeTensorNList(DP_DeepTensor *dt, +inline void _DP_DeepTensorComputeTensorNList(DP_DeepTensor* dt, const int natom, - const float *coord, - const int *atype, - const float *cell, + const float* coord, + const int* atype, + const float* cell, const int nghost, - const DP_Nlist *nlist, - float **tensor, - int *size) { + const DP_Nlist* nlist, + float** tensor, + int* size) { DP_DeepTensorComputeTensorNListf(dt, natom, coord, atype, cell, nghost, nlist, tensor, size); } template -inline void _DP_DeepTensorCompute(DP_DeepTensor *dt, +inline void _DP_DeepTensorCompute(DP_DeepTensor* dt, const int natom, - const FPTYPE *coord, - const int *atype, - const FPTYPE *cell, - FPTYPE *global_tensor, - FPTYPE *force, - FPTYPE *virial, - FPTYPE **atomic_energy, - FPTYPE *atomic_virial, - int *size_at); + const FPTYPE* coord, + const int* atype, + const FPTYPE* cell, + FPTYPE* global_tensor, + FPTYPE* force, + FPTYPE* virial, + FPTYPE** atomic_energy, + FPTYPE* atomic_virial, + int* size_at); template <> -inline void _DP_DeepTensorCompute(DP_DeepTensor *dt, +inline void _DP_DeepTensorCompute(DP_DeepTensor* dt, const int natom, - const double *coord, - const int *atype, - const double *cell, - double *global_tensor, - double *force, - double *virial, - double **atomic_tensor, - double *atomic_virial, - int *size_at) { + const double* coord, + const int* atype, + const double* cell, + double* global_tensor, + double* force, + double* virial, + double** atomic_tensor, + double* atomic_virial, + int* size_at) { DP_DeepTensorCompute(dt, natom, coord, atype, cell, global_tensor, force, virial, atomic_tensor, atomic_virial, size_at); } template <> -inline void _DP_DeepTensorCompute(DP_DeepTensor *dt, +inline void _DP_DeepTensorCompute(DP_DeepTensor* dt, const int natom, - const float *coord, - const int *atype, - const float *cell, - float *global_tensor, - float *force, - float *virial, - float **atomic_tensor, - float *atomic_virial, - int *size_at) { + const float* coord, + const int* atype, + const float* cell, + float* global_tensor, + float* force, + float* virial, + float** atomic_tensor, + float* atomic_virial, + int* size_at) { DP_DeepTensorComputef(dt, natom, coord, atype, cell, global_tensor, force, virial, atomic_tensor, atomic_virial, size_at); } template -inline void _DP_DeepTensorComputeNList(DP_DeepTensor *dt, +inline void _DP_DeepTensorComputeNList(DP_DeepTensor* dt, const int natom, - const FPTYPE *coord, - const int *atype, - const FPTYPE *cell, + const FPTYPE* coord, + const int* atype, + const FPTYPE* cell, const int nghost, - const DP_Nlist *nlist, - FPTYPE *global_tensor, - FPTYPE *force, - FPTYPE *virial, - FPTYPE **atomic_energy, - FPTYPE *atomic_virial, - int *size_at); + const DP_Nlist* nlist, + FPTYPE* global_tensor, + FPTYPE* force, + FPTYPE* virial, + FPTYPE** atomic_energy, + FPTYPE* atomic_virial, + int* size_at); template <> -inline void _DP_DeepTensorComputeNList(DP_DeepTensor *dt, +inline void _DP_DeepTensorComputeNList(DP_DeepTensor* dt, const int natom, - const double *coord, - const int *atype, - const double *cell, + const double* coord, + const int* atype, + const double* cell, const int nghost, - const DP_Nlist *nlist, - double *global_tensor, - double *force, - double *virial, - double **atomic_tensor, - double *atomic_virial, - int *size_at) { + const DP_Nlist* nlist, + double* global_tensor, + double* force, + double* virial, + double** atomic_tensor, + double* atomic_virial, + int* size_at) { DP_DeepTensorComputeNList(dt, natom, coord, atype, cell, nghost, nlist, global_tensor, force, virial, atomic_tensor, atomic_virial, size_at); } template <> -inline void _DP_DeepTensorComputeNList(DP_DeepTensor *dt, +inline void _DP_DeepTensorComputeNList(DP_DeepTensor* dt, const int natom, - const float *coord, - const int *atype, - const float *cell, + const float* coord, + const int* atype, + const float* cell, const int nghost, - const DP_Nlist *nlist, - float *global_tensor, - float *force, - float *virial, - float **atomic_tensor, - float *atomic_virial, - int *size_at) { + const DP_Nlist* nlist, + float* global_tensor, + float* force, + float* virial, + float** atomic_tensor, + float* atomic_virial, + int* size_at) { DP_DeepTensorComputeNListf(dt, natom, coord, atype, cell, nghost, nlist, global_tensor, force, virial, atomic_tensor, atomic_virial, size_at); } template -inline void _DP_DipoleChargeModifierComputeNList(DP_DipoleChargeModifier *dcm, +inline void _DP_DipoleChargeModifierComputeNList(DP_DipoleChargeModifier* dcm, const int natom, - const FPTYPE *coord, - const int *atype, - const FPTYPE *cell, - const int *pairs, + const FPTYPE* coord, + const int* atype, + const FPTYPE* cell, + const int* pairs, const int npairs, - const FPTYPE *delef_, + const FPTYPE* delef_, const int nghost, - const DP_Nlist *nlist, - FPTYPE *dfcorr_, - FPTYPE *dvcorr_); + const DP_Nlist* nlist, + FPTYPE* dfcorr_, + FPTYPE* dvcorr_); template <> inline void _DP_DipoleChargeModifierComputeNList( - DP_DipoleChargeModifier *dcm, + DP_DipoleChargeModifier* dcm, const int natom, - const double *coord, - const int *atype, - const double *cell, - const int *pairs, + const double* coord, + const int* atype, + const double* cell, + const int* pairs, const int npairs, - const double *delef_, + const double* delef_, const int nghost, - const DP_Nlist *nlist, - double *dfcorr_, - double *dvcorr_) { + const DP_Nlist* nlist, + double* dfcorr_, + double* dvcorr_) { DP_DipoleChargeModifierComputeNList(dcm, natom, coord, atype, cell, pairs, npairs, delef_, nghost, nlist, dfcorr_, dvcorr_); @@ -770,30 +770,30 @@ inline void _DP_DipoleChargeModifierComputeNList( template <> inline void _DP_DipoleChargeModifierComputeNList( - DP_DipoleChargeModifier *dcm, + DP_DipoleChargeModifier* dcm, const int natom, - const float *coord, - const int *atype, - const float *cell, - const int *pairs, + const float* coord, + const int* atype, + const float* cell, + const int* pairs, const int npairs, - const float *delef_, + const float* delef_, const int nghost, - const DP_Nlist *nlist, - float *dfcorr_, - float *dvcorr_) { + const DP_Nlist* nlist, + float* dfcorr_, + float* dvcorr_) { DP_DipoleChargeModifierComputeNListf(dcm, natom, coord, atype, cell, pairs, npairs, delef_, nghost, nlist, dfcorr_, dvcorr_); } -inline double *_DP_Get_Energy_Pointer(std::vector &vec, +inline double* _DP_Get_Energy_Pointer(std::vector& vec, const int nframes) { vec.resize(nframes); return &vec[0]; } -inline double *_DP_Get_Energy_Pointer(double &vec, const int nframes) { +inline double* _DP_Get_Energy_Pointer(double& vec, const int nframes) { assert(nframes == 1); return &vec; } @@ -812,7 +812,7 @@ struct InputNlist { nl(DP_NewNlist(0, nullptr, nullptr, nullptr)) { DP_CHECK_OK(DP_NlistCheckOK, nl); }; - InputNlist(int inum_, int *ilist_, int *numneigh_, int **firstneigh_) + InputNlist(int inum_, int* ilist_, int* numneigh_, int** firstneigh_) : inum(inum_), ilist(ilist_), numneigh(numneigh_), @@ -821,17 +821,17 @@ struct InputNlist { DP_CHECK_OK(DP_NlistCheckOK, nl); }; InputNlist(int inum_, - int *ilist_, - int *numneigh_, - int **firstneigh_, + int* ilist_, + int* numneigh_, + int** firstneigh_, int nswap, - int *sendnum, - int *recvnum, - int *firstrecv, - int **sendlist, - int *sendproc, - int *recvproc, - void *world) + int* sendnum, + int* recvnum, + int* firstrecv, + int** sendlist, + int* sendproc, + int* recvproc, + void* world) : inum(inum_), ilist(ilist_), numneigh(numneigh_), @@ -850,15 +850,15 @@ struct InputNlist { world)) {}; ~InputNlist() { DP_DeleteNlist(nl); }; /// @brief C API neighbor list. - DP_Nlist *nl; + DP_Nlist* nl; /// @brief Number of core region atoms int inum; /// @brief Array stores the core region atom's index - int *ilist; + int* ilist; /// @brief Array stores the core region atom's neighbor atom number - int *numneigh; + int* numneigh; /// @brief Array stores the core region atom's neighbor index - int **firstneigh; + int** firstneigh; /** * @brief Set mask for this neighbor list. */ @@ -867,7 +867,7 @@ struct InputNlist { * @brief Set mapping for this neighbor list. * @param mapping mapping from all atoms to real atoms, in size nall. */ - void set_mapping(int *mapping) { DP_NlistSetMapping(nl, mapping); }; + void set_mapping(int* mapping) { DP_NlistSetMapping(nl, mapping); }; }; /** @@ -884,8 +884,8 @@ void inline convert_pbtxt_to_pb(std::string fn_pb_txt, std::string fn_pb) { * @param[in] from_nlist 2D int vector. The first axis represents the centeral * atoms and the second axis represents the neighbor atoms. */ -void inline convert_nlist(InputNlist &to_nlist, - std::vector> &from_nlist) { +void inline convert_nlist(InputNlist& to_nlist, + std::vector>& from_nlist) { to_nlist.inum = from_nlist.size(); for (int ii = 0; ii < to_nlist.inum; ++ii) { to_nlist.ilist[ii] = ii; @@ -936,8 +936,8 @@ class DeepBaseModel { * @brief Get the type map (element name of the atom types) of this model. * @param[out] type_map The type map of this model. **/ - void get_type_map(std::string &type_map) { - const char *type_map_c = DP_DeepBaseModelGetTypeMap(dpbase); + void get_type_map(std::string& type_map) { + const char* type_map_c = DP_DeepBaseModelGetTypeMap(dpbase); type_map.assign(type_map_c); DP_DeleteChar(type_map_c); }; @@ -946,7 +946,7 @@ class DeepBaseModel { * information. * @param[in] pre The prefix to each line. */ - void print_summary(const std::string &pre) const { + void print_summary(const std::string& pre) const { DP_PrintSummary(pre.c_str()); } /** @@ -967,15 +967,15 @@ class DeepBaseModel { } protected: - DP_DeepBaseModel *dpbase; + DP_DeepBaseModel* dpbase; int dfparam; int daparam; bool aparam_nall; template - void validate_fparam_aparam(const int &nframes, - const int &nloc, - const std::vector &fparam, - const std::vector &aparam) const { + void validate_fparam_aparam(const int& nframes, + const int& nloc, + const std::vector& fparam, + const std::vector& aparam) const { if (fparam.size() != dfparam && fparam.size() != static_cast(nframes) * dfparam) { throw deepmd::hpp::deepmd_exception( @@ -991,10 +991,10 @@ class DeepBaseModel { } } template - void tile_fparam_aparam(std::vector &out_param, - const int &nframes, - const int &dparam, - const std::vector ¶m) const { + void tile_fparam_aparam(std::vector& out_param, + const int& nframes, + const int& dparam, + const std::vector& param) const { if (param.size() == dparam) { out_param.resize(static_cast(nframes) * dparam); for (int ii = 0; ii < nframes; ++ii) { @@ -1023,9 +1023,9 @@ class DeepPot : public DeepBaseModel { * @param[in] gpu_rank The GPU rank. * @param[in] file_content The content of the frozen model file. **/ - DeepPot(const std::string &model, - const int &gpu_rank = 0, - const std::string &file_content = "") + DeepPot(const std::string& model, + const int& gpu_rank = 0, + const std::string& file_content = "") : dp(nullptr) { try { init(model, gpu_rank, file_content); @@ -1043,9 +1043,9 @@ class DeepPot : public DeepBaseModel { * @param[in] gpu_rank The GPU rank. * @param[in] file_content The content of the frozen model file. **/ - void init(const std::string &model, - const int &gpu_rank = 0, - const std::string &file_content = "") { + void init(const std::string& model, + const int& gpu_rank = 0, + const std::string& file_content = "") { if (dp) { std::cerr << "WARNING: deepmd-kit should not be initialized twice, do " "nothing at the second call of initializer" @@ -1058,7 +1058,7 @@ class DeepPot : public DeepBaseModel { dfparam = DP_DeepPotGetDimFParam(dp); daparam = DP_DeepPotGetDimAParam(dp); aparam_nall = DP_DeepPotIsAParamNAll(dp); - dpbase = (DP_DeepBaseModel *)dp; + dpbase = (DP_DeepBaseModel*)dp; }; /** @@ -1083,34 +1083,34 @@ class DeepPot : public DeepBaseModel { **/ template void compute( - ENERGYVTYPE &ener, - std::vector &force, - std::vector &virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + ENERGYVTYPE& ener, + std::vector& force, + std::vector& virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1; assert(nframes * natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == nframes * 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; - double *ener_ = _DP_Get_Energy_Pointer(ener, nframes); + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; + double* ener_ = _DP_Get_Energy_Pointer(ener, nframes); force.resize(static_cast(nframes) * natoms * 3); virial.resize(static_cast(nframes) * 9); - VALUETYPE *force_ = &force[0]; - VALUETYPE *virial_ = &virial[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* virial_ = &virial[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, natoms, fparam, aparam); tile_fparam_aparam(fparam_, nframes, dfparam, fparam); tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepPotCompute(dp, nframes, natoms, coord_, atype_, box_, fparam__, aparam__, ener_, force_, virial_, @@ -1142,41 +1142,41 @@ class DeepPot : public DeepBaseModel { **/ template void compute( - ENERGYVTYPE &ener, - std::vector &force, - std::vector &virial, - std::vector &atom_energy, - std::vector &atom_virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + ENERGYVTYPE& ener, + std::vector& force, + std::vector& virial, + std::vector& atom_energy, + std::vector& atom_virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1; assert(nframes * natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == nframes * 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; - double *ener_ = _DP_Get_Energy_Pointer(ener, nframes); + double* ener_ = _DP_Get_Energy_Pointer(ener, nframes); force.resize(static_cast(nframes) * natoms * 3); virial.resize(static_cast(nframes) * 9); atom_energy.resize(static_cast(nframes) * natoms); atom_virial.resize(static_cast(nframes) * natoms * 9); - VALUETYPE *force_ = &force[0]; - VALUETYPE *virial_ = &virial[0]; - VALUETYPE *atomic_ener_ = &atom_energy[0]; - VALUETYPE *atomic_virial_ = &atom_virial[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* virial_ = &virial[0]; + VALUETYPE* atomic_ener_ = &atom_energy[0]; + VALUETYPE* atomic_virial_ = &atom_virial[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, natoms, fparam, aparam); tile_fparam_aparam(fparam_, nframes, dfparam, fparam); tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepPotCompute(dp, nframes, natoms, coord_, atype_, box_, fparam__, aparam__, ener_, force_, virial_, @@ -1210,31 +1210,31 @@ class DeepPot : public DeepBaseModel { **/ template void compute( - ENERGYVTYPE &ener, - std::vector &force, - std::vector &virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, + ENERGYVTYPE& ener, + std::vector& force, + std::vector& virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &lmp_list, - const int &ago, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1; assert(nframes * natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == nframes * 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; - double *ener_ = _DP_Get_Energy_Pointer(ener, nframes); + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; + double* ener_ = _DP_Get_Energy_Pointer(ener, nframes); force.resize(static_cast(nframes) * natoms * 3); virial.resize(static_cast(nframes) * 9); - VALUETYPE *force_ = &force[0]; - VALUETYPE *virial_ = &virial[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* virial_ = &virial[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, (aparam_nall ? natoms : (natoms - nghost)), fparam, aparam); @@ -1242,8 +1242,8 @@ class DeepPot : public DeepBaseModel { tile_fparam_aparam(aparam_, nframes, (aparam_nall ? natoms : (natoms - nghost)) * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepPotComputeNList( dp, nframes, natoms, coord_, atype_, box_, nghost, lmp_list.nl, ago, @@ -1278,38 +1278,38 @@ class DeepPot : public DeepBaseModel { **/ template void compute( - ENERGYVTYPE &ener, - std::vector &force, - std::vector &virial, - std::vector &atom_energy, - std::vector &atom_virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, + ENERGYVTYPE& ener, + std::vector& force, + std::vector& virial, + std::vector& atom_energy, + std::vector& atom_virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &lmp_list, - const int &ago, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1; assert(nframes * natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == nframes * 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; - double *ener_ = _DP_Get_Energy_Pointer(ener, nframes); + double* ener_ = _DP_Get_Energy_Pointer(ener, nframes); force.resize(static_cast(nframes) * natoms * 3); virial.resize(static_cast(nframes) * 9); atom_energy.resize(static_cast(nframes) * natoms); atom_virial.resize(static_cast(nframes) * natoms * 9); - VALUETYPE *force_ = &force[0]; - VALUETYPE *virial_ = &virial[0]; - VALUETYPE *atomic_ener_ = &atom_energy[0]; - VALUETYPE *atomic_virial_ = &atom_virial[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* virial_ = &virial[0]; + VALUETYPE* atomic_ener_ = &atom_energy[0]; + VALUETYPE* atomic_virial_ = &atom_virial[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, (aparam_nall ? natoms : (natoms - nghost)), fparam, aparam); @@ -1317,8 +1317,8 @@ class DeepPot : public DeepBaseModel { tile_fparam_aparam(aparam_, nframes, (aparam_nall ? natoms : (natoms - nghost)) * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepPotComputeNList(dp, nframes, natoms, coord_, atype_, box_, nghost, lmp_list.nl, ago, fparam__, @@ -1349,34 +1349,34 @@ class DeepPot : public DeepBaseModel { **/ template void compute_mixed_type( - ENERGYVTYPE &ener, - std::vector &force, - std::vector &virial, - const int &nframes, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + ENERGYVTYPE& ener, + std::vector& force, + std::vector& virial, + const int& nframes, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size() / nframes; assert(nframes * natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == nframes * 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; - double *ener_ = _DP_Get_Energy_Pointer(ener, nframes); + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; + double* ener_ = _DP_Get_Energy_Pointer(ener, nframes); force.resize(static_cast(nframes) * natoms * 3); virial.resize(static_cast(nframes) * 9); - VALUETYPE *force_ = &force[0]; - VALUETYPE *virial_ = &virial[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* virial_ = &virial[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, natoms, fparam, aparam); tile_fparam_aparam(fparam_, nframes, dfparam, fparam); tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepPotComputeMixedType(dp, nframes, natoms, coord_, atype_, box_, fparam__, aparam__, ener_, @@ -1408,41 +1408,41 @@ class DeepPot : public DeepBaseModel { **/ template void compute_mixed_type( - ENERGYVTYPE &ener, - std::vector &force, - std::vector &virial, - std::vector &atom_energy, - std::vector &atom_virial, - const int &nframes, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + ENERGYVTYPE& ener, + std::vector& force, + std::vector& virial, + std::vector& atom_energy, + std::vector& atom_virial, + const int& nframes, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size() / nframes; assert(nframes * natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == nframes * 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; - double *ener_ = _DP_Get_Energy_Pointer(ener, nframes); + double* ener_ = _DP_Get_Energy_Pointer(ener, nframes); force.resize(static_cast(nframes) * natoms * 3); virial.resize(static_cast(nframes) * 9); atom_energy.resize(static_cast(nframes) * natoms); atom_virial.resize(static_cast(nframes) * natoms * 9); - VALUETYPE *force_ = &force[0]; - VALUETYPE *virial_ = &virial[0]; - VALUETYPE *atomic_ener_ = &atom_energy[0]; - VALUETYPE *atomic_virial_ = &atom_virial[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* virial_ = &virial[0]; + VALUETYPE* atomic_ener_ = &atom_energy[0]; + VALUETYPE* atomic_virial_ = &atom_virial[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, natoms, fparam, aparam); tile_fparam_aparam(fparam_, nframes, dfparam, fparam); tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepPotComputeMixedType( dp, nframes, natoms, coord_, atype_, box_, fparam__, aparam__, ener_, @@ -1451,7 +1451,7 @@ class DeepPot : public DeepBaseModel { }; private: - DP_DeepPot *dp; + DP_DeepPot* dp; }; class DeepSpin : public DeepBaseModel { @@ -1467,9 +1467,9 @@ class DeepSpin : public DeepBaseModel { * @param[in] gpu_rank The GPU rank. * @param[in] file_content The content of the frozen model file. **/ - DeepSpin(const std::string &model, - const int &gpu_rank = 0, - const std::string &file_content = "") + DeepSpin(const std::string& model, + const int& gpu_rank = 0, + const std::string& file_content = "") : dp(nullptr) { try { init(model, gpu_rank, file_content); @@ -1487,9 +1487,9 @@ class DeepSpin : public DeepBaseModel { * @param[in] gpu_rank The GPU rank. * @param[in] file_content The content of the frozen model file. **/ - void init(const std::string &model, - const int &gpu_rank = 0, - const std::string &file_content = "") { + void init(const std::string& model, + const int& gpu_rank = 0, + const std::string& file_content = "") { if (dp) { std::cerr << "WARNING: deepmd-kit should not be initialized twice, do " "nothing at the second call of initializer" @@ -1502,7 +1502,7 @@ class DeepSpin : public DeepBaseModel { dfparam = DP_DeepSpinGetDimFParam(dp); daparam = DP_DeepSpinGetDimAParam(dp); aparam_nall = DP_DeepSpinIsAParamNAll(dp); - dpbase = (DP_DeepBaseModel *)dp; + dpbase = (DP_DeepBaseModel*)dp; }; /** @@ -1531,39 +1531,39 @@ class DeepSpin : public DeepBaseModel { **/ template void compute( - ENERGYVTYPE &ener, - std::vector &force, - std::vector &force_mag, - std::vector &virial, - const std::vector &coord, - const std::vector &spin, - const std::vector &atype, - const std::vector &box, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + ENERGYVTYPE& ener, + std::vector& force, + std::vector& force_mag, + std::vector& virial, + const std::vector& coord, + const std::vector& spin, + const std::vector& atype, + const std::vector& box, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1; assert(nframes * natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == nframes * 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *spin_ = &spin[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; - double *ener_ = _DP_Get_Energy_Pointer(ener, nframes); + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* spin_ = &spin[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; + double* ener_ = _DP_Get_Energy_Pointer(ener, nframes); force.resize(static_cast(nframes) * natoms * 3); force_mag.resize(static_cast(nframes) * natoms * 3); virial.resize(static_cast(nframes) * 9); - VALUETYPE *force_ = &force[0]; - VALUETYPE *force_mag_ = &force_mag[0]; - VALUETYPE *virial_ = &virial[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* force_mag_ = &force_mag[0]; + VALUETYPE* virial_ = &virial[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, natoms, fparam, aparam); tile_fparam_aparam(fparam_, nframes, dfparam, fparam); tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepSpinCompute(dp, nframes, natoms, coord_, spin_, atype_, box_, fparam__, aparam__, ener_, force_, @@ -1599,46 +1599,46 @@ class DeepSpin : public DeepBaseModel { **/ template void compute( - ENERGYVTYPE &ener, - std::vector &force, - std::vector &force_mag, - std::vector &virial, - std::vector &atom_energy, - std::vector &atom_virial, - const std::vector &coord, - const std::vector &spin, - const std::vector &atype, - const std::vector &box, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + ENERGYVTYPE& ener, + std::vector& force, + std::vector& force_mag, + std::vector& virial, + std::vector& atom_energy, + std::vector& atom_virial, + const std::vector& coord, + const std::vector& spin, + const std::vector& atype, + const std::vector& box, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1; assert(nframes * natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == nframes * 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *spin_ = &spin[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* spin_ = &spin[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; - double *ener_ = _DP_Get_Energy_Pointer(ener, nframes); + double* ener_ = _DP_Get_Energy_Pointer(ener, nframes); force.resize(static_cast(nframes) * natoms * 3); force_mag.resize(static_cast(nframes) * natoms * 3); virial.resize(static_cast(nframes) * 9); atom_energy.resize(static_cast(nframes) * natoms); atom_virial.resize(static_cast(nframes) * natoms * 9); - VALUETYPE *force_ = &force[0]; - VALUETYPE *force_mag_ = &force_mag[0]; - VALUETYPE *virial_ = &virial[0]; - VALUETYPE *atomic_ener_ = &atom_energy[0]; - VALUETYPE *atomic_virial_ = &atom_virial[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* force_mag_ = &force_mag[0]; + VALUETYPE* virial_ = &virial[0]; + VALUETYPE* atomic_ener_ = &atom_energy[0]; + VALUETYPE* atomic_virial_ = &atom_virial[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, natoms, fparam, aparam); tile_fparam_aparam(fparam_, nframes, dfparam, fparam); tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepSpinCompute( dp, nframes, natoms, coord_, spin_, atype_, box_, fparam__, aparam__, @@ -1675,36 +1675,36 @@ class DeepSpin : public DeepBaseModel { **/ template void compute( - ENERGYVTYPE &ener, - std::vector &force, - std::vector &force_mag, - std::vector &virial, - const std::vector &coord, - const std::vector &spin, - const std::vector &atype, - const std::vector &box, + ENERGYVTYPE& ener, + std::vector& force, + std::vector& force_mag, + std::vector& virial, + const std::vector& coord, + const std::vector& spin, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &lmp_list, - const int &ago, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1; assert(nframes * natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == nframes * 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *spin_ = &spin[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; - double *ener_ = _DP_Get_Energy_Pointer(ener, nframes); + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* spin_ = &spin[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; + double* ener_ = _DP_Get_Energy_Pointer(ener, nframes); force.resize(static_cast(nframes) * natoms * 3); force_mag.resize(static_cast(nframes) * natoms * 3); virial.resize(static_cast(nframes) * 9); - VALUETYPE *force_ = &force[0]; - VALUETYPE *force_mag_ = &force_mag[0]; - VALUETYPE *virial_ = &virial[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* force_mag_ = &force_mag[0]; + VALUETYPE* virial_ = &virial[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, (aparam_nall ? natoms : (natoms - nghost)), fparam, aparam); @@ -1712,8 +1712,8 @@ class DeepSpin : public DeepBaseModel { tile_fparam_aparam(aparam_, nframes, (aparam_nall ? natoms : (natoms - nghost)) * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepSpinComputeNList(dp, nframes, natoms, coord_, spin_, atype_, box_, nghost, lmp_list.nl, ago, fparam__, aparam__, ener_, force_, @@ -1752,42 +1752,42 @@ class DeepSpin : public DeepBaseModel { **/ template void compute( - ENERGYVTYPE &ener, - std::vector &force, - std::vector &force_mag, - std::vector &virial, - std::vector &atom_energy, - std::vector &atom_virial, - const std::vector &coord, - const std::vector &spin, - const std::vector &atype, - const std::vector &box, + ENERGYVTYPE& ener, + std::vector& force, + std::vector& force_mag, + std::vector& virial, + std::vector& atom_energy, + std::vector& atom_virial, + const std::vector& coord, + const std::vector& spin, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &lmp_list, - const int &ago, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1; assert(nframes * natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == nframes * 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *spin_ = &spin[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; - double *ener_ = _DP_Get_Energy_Pointer(ener, nframes); + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* spin_ = &spin[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; + double* ener_ = _DP_Get_Energy_Pointer(ener, nframes); force.resize(static_cast(nframes) * natoms * 3); force_mag.resize(static_cast(nframes) * natoms * 3); virial.resize(static_cast(nframes) * 9); atom_energy.resize(static_cast(nframes) * natoms); atom_virial.resize(static_cast(nframes) * natoms * 9); - VALUETYPE *force_ = &force[0]; - VALUETYPE *force_mag_ = &force_mag[0]; - VALUETYPE *virial_ = &virial[0]; - VALUETYPE *atomic_ener_ = &atom_energy[0]; - VALUETYPE *atomic_virial_ = &atom_virial[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* force_mag_ = &force_mag[0]; + VALUETYPE* virial_ = &virial[0]; + VALUETYPE* atomic_ener_ = &atom_energy[0]; + VALUETYPE* atomic_virial_ = &atom_virial[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, (aparam_nall ? natoms : (natoms - nghost)), fparam, aparam); @@ -1795,8 +1795,8 @@ class DeepSpin : public DeepBaseModel { tile_fparam_aparam(aparam_, nframes, (aparam_nall ? natoms : (natoms - nghost)) * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepSpinComputeNList( dp, nframes, natoms, coord_, spin_, atype_, box_, nghost, lmp_list.nl, ago, fparam__, aparam__, ener_, force_, force_mag_, virial_, @@ -1805,7 +1805,7 @@ class DeepSpin : public DeepBaseModel { }; private: - DP_DeepSpin *dp; + DP_DeepSpin* dp; }; /** @@ -1865,8 +1865,8 @@ class DeepBaseModelDevi { * @param[in] xx The vectors of all models. **/ template - void compute_avg(std::vector &avg, - const std::vector> &xx) { + void compute_avg(std::vector& avg, + const std::vector>& xx) { assert(xx.size() == numb_models); if (numb_models == 0) { return; @@ -1893,10 +1893,10 @@ class DeepBaseModelDevi { * @param[in] stride The stride to compute the deviation. **/ template - void compute_std(std::vector &std, - const std::vector &avg, - const std::vector> &xx, - const int &stride) { + void compute_std(std::vector& std, + const std::vector& avg, + const std::vector>& xx, + const int& stride) { assert(xx.size() == numb_models); if (numb_models == 0) { return; @@ -1911,8 +1911,8 @@ class DeepBaseModelDevi { for (unsigned ii = 0; ii < numb_models; ++ii) { for (unsigned jj = 0; jj < nloc; ++jj) { - const VALUETYPE *tmp_f = &(xx[ii][static_cast(jj) * stride]); - const VALUETYPE *tmp_avg = &(avg[static_cast(jj) * stride]); + const VALUETYPE* tmp_f = &(xx[ii][static_cast(jj) * stride]); + const VALUETYPE* tmp_avg = &(avg[static_cast(jj) * stride]); for (unsigned dd = 0; dd < stride; ++dd) { VALUETYPE vdiff = tmp_f[dd] - tmp_avg[dd]; std[jj] += vdiff * vdiff; @@ -1932,16 +1932,16 @@ class DeepBaseModelDevi { * @param[in] stride The stride to compute the deviation. **/ template - void compute_relative_std(std::vector &std, - const std::vector &avg, + void compute_relative_std(std::vector& std, + const std::vector& avg, const VALUETYPE eps, - const int &stride) { + const int& stride) { unsigned ndof = avg.size(); unsigned nloc = std.size(); assert(nloc * stride == ndof); for (unsigned ii = 0; ii < nloc; ++ii) { - const VALUETYPE *tmp_avg = &(avg[static_cast(ii) * stride]); + const VALUETYPE* tmp_avg = &(avg[static_cast(ii) * stride]); VALUETYPE f_norm = 0.0; for (unsigned dd = 0; dd < stride; ++dd) { f_norm += tmp_avg[dd] * tmp_avg[dd]; @@ -1957,9 +1957,9 @@ class DeepBaseModelDevi { * @param[in] xx The vectors of all forces. **/ template - void compute_std_f(std::vector &std, - const std::vector &avg, - const std::vector> &xx) { + void compute_std_f(std::vector& std, + const std::vector& avg, + const std::vector>& xx) { compute_std(std, avg, xx, 3); }; /** @@ -1969,23 +1969,23 @@ class DeepBaseModelDevi { * @param[in] eps The level parameter for computing the deviation. **/ template - void compute_relative_std_f(std::vector &std, - const std::vector &avg, + void compute_relative_std_f(std::vector& std, + const std::vector& avg, const VALUETYPE eps) { compute_relative_std(std, avg, eps, 3); }; protected: - DP_DeepBaseModelDevi *dpbase; + DP_DeepBaseModelDevi* dpbase; int numb_models; int dfparam; int daparam; bool aparam_nall; template - void validate_fparam_aparam(const int &nframes, - const int &nloc, - const std::vector &fparam, - const std::vector &aparam) const { + void validate_fparam_aparam(const int& nframes, + const int& nloc, + const std::vector& fparam, + const std::vector& aparam) const { if (fparam.size() != dfparam && fparam.size() != static_cast(nframes) * dfparam) { throw deepmd::hpp::deepmd_exception( @@ -2001,10 +2001,10 @@ class DeepBaseModelDevi { } } template - void tile_fparam_aparam(std::vector &out_param, - const int &nframes, - const int &dparam, - const std::vector ¶m) const { + void tile_fparam_aparam(std::vector& out_param, + const int& nframes, + const int& dparam, + const std::vector& param) const { if (param.size() == dparam) { out_param.resize(static_cast(nframes) * dparam); for (int ii = 0; ii < nframes; ++ii) { @@ -2031,7 +2031,7 @@ class DeepPotModelDevi : public DeepBaseModelDevi { * @brief DP model deviation constructor with initialization. * @param[in] models The names of the frozen model file. **/ - DeepPotModelDevi(const std::vector &models) : dp(nullptr) { + DeepPotModelDevi(const std::vector& models) : dp(nullptr) { try { init(models); } catch (...) { @@ -2048,9 +2048,9 @@ class DeepPotModelDevi : public DeepBaseModelDevi { * @param[in] gpu_rank The GPU rank. * @param[in] file_content The content of the frozen model file. **/ - void init(const std::vector &models, - const int &gpu_rank = 0, - const std::vector &file_content = + void init(const std::vector& models, + const int& gpu_rank = 0, + const std::vector& file_content = std::vector()) { if (dp) { std::cerr << "WARNING: deepmd-kit should not be initialized twice, do " @@ -2058,17 +2058,17 @@ class DeepPotModelDevi : public DeepBaseModelDevi { << std::endl; return; } - std::vector cstrings; + std::vector cstrings; cstrings.reserve(models.size()); - for (std::string const &str : models) { + for (std::string const& str : models) { cstrings.push_back(str.data()); } - std::vector c_file_contents; + std::vector c_file_contents; std::vector size_file_contents; c_file_contents.reserve(file_content.size()); size_file_contents.reserve(file_content.size()); - for (std::string const &str : file_content) { + for (std::string const& str : file_content) { c_file_contents.push_back(str.data()); size_file_contents.push_back(str.size()); } @@ -2081,7 +2081,7 @@ class DeepPotModelDevi : public DeepBaseModelDevi { dfparam = DP_DeepPotModelDeviGetDimFParam(dp); daparam = DP_DeepPotModelDeviGetDimAParam(dp); aparam_nall = DP_DeepPotModelDeviIsAParamNAll(dp); - dpbase = (DP_DeepBaseModelDevi *)dp; + dpbase = (DP_DeepBaseModelDevi*)dp; }; /** @@ -2106,23 +2106,23 @@ class DeepPotModelDevi : public DeepBaseModelDevi { **/ template void compute( - std::vector &ener, - std::vector> &force, - std::vector> &virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + std::vector& ener, + std::vector>& force, + std::vector>& virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = 1; assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; // memory will be continuous for std::vector but not // std::vector @@ -2130,15 +2130,15 @@ class DeepPotModelDevi : public DeepBaseModelDevi { std::vector force_flat(static_cast(numb_models) * natoms * 3); std::vector virial_flat(numb_models * 9); - double *ener_ = &energy_flat[0]; - VALUETYPE *force_ = &force_flat[0]; - VALUETYPE *virial_ = &virial_flat[0]; + double* ener_ = &energy_flat[0]; + VALUETYPE* force_ = &force_flat[0]; + VALUETYPE* virial_ = &virial_flat[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, natoms, fparam, aparam); tile_fparam_aparam(fparam_, nframes, dfparam, fparam); tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepPotModelDeviCompute(dp, natoms, coord_, atype_, box_, fparam__, aparam__, ener_, force_, @@ -2185,25 +2185,25 @@ class DeepPotModelDevi : public DeepBaseModelDevi { **/ template void compute( - std::vector &ener, - std::vector> &force, - std::vector> &virial, - std::vector> &atom_energy, - std::vector> &atom_virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + std::vector& ener, + std::vector>& force, + std::vector>& virial, + std::vector>& atom_energy, + std::vector>& atom_virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = 1; assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; std::vector energy_flat(numb_models); std::vector force_flat(static_cast(numb_models) * @@ -2213,17 +2213,17 @@ class DeepPotModelDevi : public DeepBaseModelDevi { natoms); std::vector atom_virial_flat(static_cast(numb_models) * natoms * 9); - double *ener_ = &energy_flat[0]; - VALUETYPE *force_ = &force_flat[0]; - VALUETYPE *virial_ = &virial_flat[0]; - VALUETYPE *atomic_ener_ = &atom_energy_flat[0]; - VALUETYPE *atomic_virial_ = &atom_virial_flat[0]; + double* ener_ = &energy_flat[0]; + VALUETYPE* force_ = &force_flat[0]; + VALUETYPE* virial_ = &virial_flat[0]; + VALUETYPE* atomic_ener_ = &atom_energy_flat[0]; + VALUETYPE* atomic_virial_ = &atom_virial_flat[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, natoms, fparam, aparam); tile_fparam_aparam(fparam_, nframes, dfparam, fparam); tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepPotModelDeviCompute( dp, natoms, coord_, atype_, box_, fparam__, aparam__, ener_, force_, @@ -2282,26 +2282,26 @@ class DeepPotModelDevi : public DeepBaseModelDevi { **/ template void compute( - std::vector &ener, - std::vector> &force, - std::vector> &virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, + std::vector& ener, + std::vector>& force, + std::vector>& virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &lmp_list, - const int &ago, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = 1; assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; // memory will be continuous for std::vector but not // std::vector @@ -2309,9 +2309,9 @@ class DeepPotModelDevi : public DeepBaseModelDevi { std::vector force_flat(static_cast(numb_models) * natoms * 3); std::vector virial_flat(numb_models * 9); - double *ener_ = &energy_flat[0]; - VALUETYPE *force_ = &force_flat[0]; - VALUETYPE *virial_ = &virial_flat[0]; + double* ener_ = &energy_flat[0]; + VALUETYPE* force_ = &force_flat[0]; + VALUETYPE* virial_ = &virial_flat[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, (aparam_nall ? natoms : (natoms - nghost)), fparam, aparam); @@ -2319,8 +2319,8 @@ class DeepPotModelDevi : public DeepBaseModelDevi { tile_fparam_aparam(aparam_, nframes, (aparam_nall ? natoms : (natoms - nghost)) * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepPotModelDeviComputeNList( dp, natoms, coord_, atype_, box_, nghost, lmp_list.nl, ago, fparam__, @@ -2370,28 +2370,28 @@ class DeepPotModelDevi : public DeepBaseModelDevi { **/ template void compute( - std::vector &ener, - std::vector> &force, - std::vector> &virial, - std::vector> &atom_energy, - std::vector> &atom_virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, + std::vector& ener, + std::vector>& force, + std::vector>& virial, + std::vector>& atom_energy, + std::vector>& atom_virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &lmp_list, - const int &ago, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = 1; assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; std::vector energy_flat(numb_models); std::vector force_flat(static_cast(numb_models) * @@ -2401,11 +2401,11 @@ class DeepPotModelDevi : public DeepBaseModelDevi { natoms); std::vector atom_virial_flat(static_cast(numb_models) * natoms * 9); - double *ener_ = &energy_flat[0]; - VALUETYPE *force_ = &force_flat[0]; - VALUETYPE *virial_ = &virial_flat[0]; - VALUETYPE *atomic_ener_ = &atom_energy_flat[0]; - VALUETYPE *atomic_virial_ = &atom_virial_flat[0]; + double* ener_ = &energy_flat[0]; + VALUETYPE* force_ = &force_flat[0]; + VALUETYPE* virial_ = &virial_flat[0]; + VALUETYPE* atomic_ener_ = &atom_energy_flat[0]; + VALUETYPE* atomic_virial_ = &atom_virial_flat[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, (aparam_nall ? natoms : (natoms - nghost)), fparam, aparam); @@ -2413,8 +2413,8 @@ class DeepPotModelDevi : public DeepBaseModelDevi { tile_fparam_aparam(aparam_, nframes, (aparam_nall ? natoms : (natoms - nghost)) * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepPotModelDeviComputeNList( dp, natoms, coord_, atype_, box_, nghost, lmp_list.nl, ago, fparam__, @@ -2449,7 +2449,7 @@ class DeepPotModelDevi : public DeepBaseModelDevi { }; private: - DP_DeepPotModelDevi *dp; + DP_DeepPotModelDevi* dp; }; class DeepSpinModelDevi : public DeepBaseModelDevi { @@ -2463,7 +2463,7 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { * @brief DP model deviation constructor with initialization. * @param[in] models The names of the frozen model file. **/ - DeepSpinModelDevi(const std::vector &models) : dp(nullptr) { + DeepSpinModelDevi(const std::vector& models) : dp(nullptr) { try { init(models); } catch (...) { @@ -2480,9 +2480,9 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { * @param[in] gpu_rank The GPU rank. * @param[in] file_content The content of the frozen model file. **/ - void init(const std::vector &models, - const int &gpu_rank = 0, - const std::vector &file_content = + void init(const std::vector& models, + const int& gpu_rank = 0, + const std::vector& file_content = std::vector()) { if (dp) { std::cerr << "WARNING: deepmd-kit should not be initialized twice, do " @@ -2490,17 +2490,17 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { << std::endl; return; } - std::vector cstrings; + std::vector cstrings; cstrings.reserve(models.size()); - for (std::string const &str : models) { + for (std::string const& str : models) { cstrings.push_back(str.data()); } - std::vector c_file_contents; + std::vector c_file_contents; std::vector size_file_contents; c_file_contents.reserve(file_content.size()); size_file_contents.reserve(file_content.size()); - for (std::string const &str : file_content) { + for (std::string const& str : file_content) { c_file_contents.push_back(str.data()); size_file_contents.push_back(str.size()); } @@ -2513,7 +2513,7 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { dfparam = DP_DeepSpinModelDeviGetDimFParam(dp); daparam = DP_DeepSpinModelDeviGetDimAParam(dp); aparam_nall = DP_DeepSpinModelDeviIsAParamNAll(dp); - dpbase = (DP_DeepBaseModelDevi *)dp; + dpbase = (DP_DeepBaseModelDevi*)dp; }; /** @@ -2541,26 +2541,26 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { **/ template void compute( - std::vector &ener, - std::vector> &force, - std::vector> &force_mag, - std::vector> &virial, - const std::vector &coord, - const std::vector &spin, - const std::vector &atype, - const std::vector &box, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + std::vector& ener, + std::vector>& force, + std::vector>& force_mag, + std::vector>& virial, + const std::vector& coord, + const std::vector& spin, + const std::vector& atype, + const std::vector& box, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = 1; assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *spin_ = &spin[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* spin_ = &spin[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; // memory will be continuous for std::vector but not // std::vector @@ -2570,16 +2570,16 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { std::vector force_mag_flat(static_cast(numb_models) * natoms * 3); std::vector virial_flat(numb_models * 9); - double *ener_ = &energy_flat[0]; - VALUETYPE *force_ = &force_flat[0]; - VALUETYPE *force_mag_ = &force_mag_flat[0]; - VALUETYPE *virial_ = &virial_flat[0]; + double* ener_ = &energy_flat[0]; + VALUETYPE* force_ = &force_flat[0]; + VALUETYPE* force_mag_ = &force_mag_flat[0]; + VALUETYPE* virial_ = &virial_flat[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, natoms, fparam, aparam); tile_fparam_aparam(fparam_, nframes, dfparam, fparam); tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepSpinModelDeviCompute( dp, natoms, coord_, spin_, atype_, box_, fparam__, aparam__, ener_, @@ -2634,28 +2634,28 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { **/ template void compute( - std::vector &ener, - std::vector> &force, - std::vector> &force_mag, - std::vector> &virial, - std::vector> &atom_energy, - std::vector> &atom_virial, - const std::vector &coord, - const std::vector &spin, - const std::vector &atype, - const std::vector &box, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + std::vector& ener, + std::vector>& force, + std::vector>& force_mag, + std::vector>& virial, + std::vector>& atom_energy, + std::vector>& atom_virial, + const std::vector& coord, + const std::vector& spin, + const std::vector& atype, + const std::vector& box, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = 1; assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *spin_ = &spin[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* spin_ = &spin[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; std::vector energy_flat(numb_models); std::vector force_flat(static_cast(numb_models) * @@ -2667,18 +2667,18 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { natoms); std::vector atom_virial_flat(static_cast(numb_models) * natoms * 9); - double *ener_ = &energy_flat[0]; - VALUETYPE *force_ = &force_flat[0]; - VALUETYPE *force_mag_ = &force_mag_flat[0]; - VALUETYPE *virial_ = &virial_flat[0]; - VALUETYPE *atomic_ener_ = &atom_energy_flat[0]; - VALUETYPE *atomic_virial_ = &atom_virial_flat[0]; + double* ener_ = &energy_flat[0]; + VALUETYPE* force_ = &force_flat[0]; + VALUETYPE* force_mag_ = &force_mag_flat[0]; + VALUETYPE* virial_ = &virial_flat[0]; + VALUETYPE* atomic_ener_ = &atom_energy_flat[0]; + VALUETYPE* atomic_virial_ = &atom_virial_flat[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, natoms, fparam, aparam); tile_fparam_aparam(fparam_, nframes, dfparam, fparam); tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepSpinModelDeviCompute( dp, natoms, coord_, spin_, atype_, box_, fparam__, aparam__, ener_, @@ -2745,29 +2745,29 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { **/ template void compute( - std::vector &ener, - std::vector> &force, - std::vector> &force_mag, - std::vector> &virial, - const std::vector &coord, - const std::vector &spin, - const std::vector &atype, - const std::vector &box, + std::vector& ener, + std::vector>& force, + std::vector>& force_mag, + std::vector>& virial, + const std::vector& coord, + const std::vector& spin, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &lmp_list, - const int &ago, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = 1; assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *spin_ = &spin[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* spin_ = &spin[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; // memory will be continous for std::vector but not std::vector std::vector energy_flat(numb_models); std::vector force_flat(static_cast(numb_models) * @@ -2775,10 +2775,10 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { std::vector force_mag_flat(static_cast(numb_models) * natoms * 3); std::vector virial_flat(numb_models * 9); - double *ener_ = &energy_flat[0]; - VALUETYPE *force_ = &force_flat[0]; - VALUETYPE *force_mag_ = &force_mag_flat[0]; - VALUETYPE *virial_ = &virial_flat[0]; + double* ener_ = &energy_flat[0]; + VALUETYPE* force_ = &force_flat[0]; + VALUETYPE* force_mag_ = &force_mag_flat[0]; + VALUETYPE* virial_ = &virial_flat[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, (aparam_nall ? natoms : (natoms - nghost)), fparam, aparam); @@ -2786,8 +2786,8 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { tile_fparam_aparam(aparam_, nframes, (aparam_nall ? natoms : (natoms - nghost)) * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepSpinModelDeviComputeNList( dp, natoms, coord_, spin_, atype_, box_, nghost, lmp_list.nl, ago, fparam__, aparam__, ener_, force_, force_mag_, virial_, nullptr, @@ -2845,31 +2845,31 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { **/ template void compute( - std::vector &ener, - std::vector> &force, - std::vector> &force_mag, - std::vector> &virial, - std::vector> &atom_energy, - std::vector> &atom_virial, - const std::vector &coord, - const std::vector &spin, - const std::vector &atype, - const std::vector &box, + std::vector& ener, + std::vector>& force, + std::vector>& force_mag, + std::vector>& virial, + std::vector>& atom_energy, + std::vector>& atom_virial, + const std::vector& coord, + const std::vector& spin, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &lmp_list, - const int &ago, - const std::vector &fparam = std::vector(), - const std::vector &aparam = std::vector()) { + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam = std::vector(), + const std::vector& aparam = std::vector()) { unsigned int natoms = atype.size(); unsigned int nframes = 1; assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *spin_ = &spin[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* spin_ = &spin[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; std::vector energy_flat(numb_models); std::vector force_flat(static_cast(numb_models) * natoms * 3); @@ -2880,12 +2880,12 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { natoms); std::vector atom_virial_flat(static_cast(numb_models) * natoms * 9); - double *ener_ = &energy_flat[0]; - VALUETYPE *force_ = &force_flat[0]; - VALUETYPE *force_mag_ = &force_mag_flat[0]; - VALUETYPE *virial_ = &virial_flat[0]; - VALUETYPE *atomic_ener_ = &atom_energy_flat[0]; - VALUETYPE *atomic_virial_ = &atom_virial_flat[0]; + double* ener_ = &energy_flat[0]; + VALUETYPE* force_ = &force_flat[0]; + VALUETYPE* force_mag_ = &force_mag_flat[0]; + VALUETYPE* virial_ = &virial_flat[0]; + VALUETYPE* atomic_ener_ = &atom_energy_flat[0]; + VALUETYPE* atomic_virial_ = &atom_virial_flat[0]; std::vector fparam_, aparam_; validate_fparam_aparam(nframes, (aparam_nall ? natoms : (natoms - nghost)), fparam, aparam); @@ -2893,8 +2893,8 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { tile_fparam_aparam(aparam_, nframes, (aparam_nall ? natoms : (natoms - nghost)) * daparam, aparam); - const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; - const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; + const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; + const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; _DP_DeepSpinModelDeviComputeNList( dp, natoms, coord_, spin_, atype_, box_, nghost, lmp_list.nl, ago, fparam__, aparam__, ener_, force_, force_mag_, virial_, atomic_ener_, @@ -2933,7 +2933,7 @@ class DeepSpinModelDevi : public DeepBaseModelDevi { }; private: - DP_DeepSpinModelDevi *dp; + DP_DeepSpinModelDevi* dp; }; /** @@ -2950,9 +2950,9 @@ class DeepTensor { * @brief DeepTensor constructor with initialization. * @param[in] model The name of the frozen model file. **/ - DeepTensor(const std::string &model, - const int &gpu_rank = 0, - const std::string &name_scope = "") + DeepTensor(const std::string& model, + const int& gpu_rank = 0, + const std::string& name_scope = "") : dt(nullptr) { try { init(model, gpu_rank, name_scope); @@ -2968,9 +2968,9 @@ class DeepTensor { * @brief Initialize the DeepTensor. * @param[in] model The name of the frozen model file. **/ - void init(const std::string &model, - const int &gpu_rank = 0, - const std::string &name_scope = "") { + void init(const std::string& model, + const int& gpu_rank = 0, + const std::string& name_scope = "") { if (dt) { std::cerr << "WARNING: deepmd-kit should not be initialized twice, do " "nothing at the second call of initializer" @@ -2993,23 +2993,23 @@ class DeepTensor { *x 9 (PBC) or empty (no PBC). **/ template - void compute(std::vector &tensor, - const std::vector &coord, - const std::vector &atype, - const std::vector &box) { + void compute(std::vector& tensor, + const std::vector& coord, + const std::vector& atype, + const std::vector& box) { unsigned int natoms = atype.size(); assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; - VALUETYPE *tensor_; - VALUETYPE **p_tensor = &tensor_; + VALUETYPE* tensor_; + VALUETYPE** p_tensor = &tensor_; int size; - int *p_size = &size; + int* p_size = &size; _DP_DeepTensorComputeTensor(dt, natoms, coord_, atype_, box_, p_tensor, p_size); @@ -3033,25 +3033,25 @@ class DeepTensor { * @param[in] nlist The neighbor list. **/ template - void compute(std::vector &tensor, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, + void compute(std::vector& tensor, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &lmp_list) { + const InputNlist& lmp_list) { unsigned int natoms = atype.size(); assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; - VALUETYPE *tensor_; - VALUETYPE **p_tensor = &tensor_; + VALUETYPE* tensor_; + VALUETYPE** p_tensor = &tensor_; int size; - int *p_size = &size; + int* p_size = &size; _DP_DeepTensorComputeTensorNList(dt, natoms, coord_, atype_, box_, nghost, lmp_list.nl, @@ -3076,26 +3076,26 @@ class DeepTensor { *x 9 (PBC) or empty (no PBC). **/ template - void compute(std::vector &global_tensor, - std::vector &force, - std::vector &virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box) { + void compute(std::vector& global_tensor, + std::vector& force, + std::vector& virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box) { unsigned int natoms = atype.size(); assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; global_tensor.resize(odim); force.resize(static_cast(odim) * natoms * 3); virial.resize(static_cast(odim) * 9); - VALUETYPE *global_tensor_ = &global_tensor[0]; - VALUETYPE *force_ = &force[0]; - VALUETYPE *virial_ = &virial[0]; + VALUETYPE* global_tensor_ = &global_tensor[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* virial_ = &virial[0]; _DP_DeepTensorCompute(dt, natoms, coord_, atype_, box_, global_tensor_, force_, virial_, nullptr, @@ -3117,36 +3117,36 @@ class DeepTensor { *x 9 (PBC) or empty (no PBC). **/ template - void compute(std::vector &global_tensor, - std::vector &force, - std::vector &virial, - std::vector &atom_tensor, - std::vector &atom_virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box) { + void compute(std::vector& global_tensor, + std::vector& force, + std::vector& virial, + std::vector& atom_tensor, + std::vector& atom_virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box) { unsigned int natoms = atype.size(); assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; global_tensor.resize(odim); force.resize(static_cast(odim) * natoms * 3); virial.resize(static_cast(odim) * 9); atom_virial.resize(static_cast(odim) * natoms * 9); - VALUETYPE *global_tensor_ = &global_tensor[0]; - VALUETYPE *force_ = &force[0]; - VALUETYPE *virial_ = &virial[0]; - VALUETYPE *atomic_virial_ = &atom_virial[0]; + VALUETYPE* global_tensor_ = &global_tensor[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* virial_ = &virial[0]; + VALUETYPE* atomic_virial_ = &atom_virial[0]; - VALUETYPE *atomic_tensor_; - VALUETYPE **p_atomic_tensor = &atomic_tensor_; + VALUETYPE* atomic_tensor_; + VALUETYPE** p_atomic_tensor = &atomic_tensor_; int size_at; - int *p_size_at = &size_at; + int* p_size_at = &size_at; _DP_DeepTensorCompute( dt, natoms, coord_, atype_, box_, global_tensor_, force_, virial_, @@ -3173,28 +3173,28 @@ class DeepTensor { * @param[in] nlist The neighbor list. **/ template - void compute(std::vector &global_tensor, - std::vector &force, - std::vector &virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, + void compute(std::vector& global_tensor, + std::vector& force, + std::vector& virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &lmp_list) { + const InputNlist& lmp_list) { unsigned int natoms = atype.size(); assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; global_tensor.resize(odim); force.resize(static_cast(odim) * natoms * 3); virial.resize(static_cast(odim) * 9); - VALUETYPE *global_tensor_ = &global_tensor[0]; - VALUETYPE *force_ = &force[0]; - VALUETYPE *virial_ = &virial[0]; + VALUETYPE* global_tensor_ = &global_tensor[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* virial_ = &virial[0]; _DP_DeepTensorComputeNList( dt, natoms, coord_, atype_, box_, nghost, lmp_list.nl, global_tensor_, @@ -3218,38 +3218,38 @@ class DeepTensor { * @param[in] nlist The neighbor list. **/ template - void compute(std::vector &global_tensor, - std::vector &force, - std::vector &virial, - std::vector &atom_tensor, - std::vector &atom_virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, + void compute(std::vector& global_tensor, + std::vector& force, + std::vector& virial, + std::vector& atom_tensor, + std::vector& atom_virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &lmp_list) { + const InputNlist& lmp_list) { unsigned int natoms = atype.size(); assert(natoms * 3 == coord.size()); if (!box.empty()) { assert(box.size() == 9); } - const VALUETYPE *coord_ = &coord[0]; - const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr; - const int *atype_ = &atype[0]; + const VALUETYPE* coord_ = &coord[0]; + const VALUETYPE* box_ = !box.empty() ? &box[0] : nullptr; + const int* atype_ = &atype[0]; global_tensor.resize(odim); force.resize(static_cast(odim) * natoms * 3); virial.resize(static_cast(odim) * 9); atom_virial.resize(static_cast(odim) * natoms * 9); - VALUETYPE *global_tensor_ = &global_tensor[0]; - VALUETYPE *force_ = &force[0]; - VALUETYPE *virial_ = &virial[0]; - VALUETYPE *atomic_virial_ = &atom_virial[0]; + VALUETYPE* global_tensor_ = &global_tensor[0]; + VALUETYPE* force_ = &force[0]; + VALUETYPE* virial_ = &virial[0]; + VALUETYPE* atomic_virial_ = &atom_virial[0]; - VALUETYPE *atomic_tensor_; - VALUETYPE **p_atomic_tensor = &atomic_tensor_; + VALUETYPE* atomic_tensor_; + VALUETYPE** p_atomic_tensor = &atomic_tensor_; int size_at; - int *p_size_at = &size_at; + int* p_size_at = &size_at; _DP_DeepTensorComputeNList( dt, natoms, coord_, atype_, box_, nghost, lmp_list.nl, global_tensor_, @@ -3286,7 +3286,7 @@ class DeepTensor { } std::vector sel_types() const { - int *sel_types_arr = DP_DeepTensorGetSelTypes(dt); + int* sel_types_arr = DP_DeepTensorGetSelTypes(dt); std::vector sel_types_vec = std::vector(sel_types_arr, sel_types_arr + nsel_types); return sel_types_vec; @@ -3296,21 +3296,21 @@ class DeepTensor { * information. * @param[in] pre The prefix to each line. */ - void print_summary(const std::string &pre) const { + void print_summary(const std::string& pre) const { DP_PrintSummary(pre.c_str()); } /** * @brief Get the type map (element name of the atom types) of this model. * @param[out] type_map The type map of this model. **/ - void get_type_map(std::string &type_map) { - const char *type_map_c = DP_DeepTensorGetTypeMap(dt); + void get_type_map(std::string& type_map) { + const char* type_map_c = DP_DeepTensorGetTypeMap(dt); type_map.assign(type_map_c); DP_DeleteChar(type_map_c); }; private: - DP_DeepTensor *dt; + DP_DeepTensor* dt; int odim; int nsel_types; }; @@ -3328,9 +3328,9 @@ class DipoleChargeModifier { * @param[in] gpu_rank The rank of the GPU to be used. * @param[in] name_scope The name scope of the model. **/ - DipoleChargeModifier(const std::string &model, - const int &gpu_rank = 0, - const std::string &name_scope = "") + DipoleChargeModifier(const std::string& model, + const int& gpu_rank = 0, + const std::string& name_scope = "") : dcm(nullptr) { try { init(model, gpu_rank, name_scope); @@ -3348,9 +3348,9 @@ class DipoleChargeModifier { * @param[in] gpu_rank The rank of the GPU to be used. * @param[in] name_scope The name scope of the model. **/ - void init(const std::string &model, - const int &gpu_rank = 0, - const std::string &name_scope = "") { + void init(const std::string& model, + const int& gpu_rank = 0, + const std::string& name_scope = "") { if (dcm) { std::cerr << "WARNING: deepmd-kit should not be initialized twice, do " "nothing at the second call of initializer" @@ -3379,31 +3379,31 @@ class DipoleChargeModifier { * @param[in] lmp_list The neighbor list. **/ template - void compute(std::vector &dfcorr_, - std::vector &dvcorr_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, - const std::vector> &pairs, - const std::vector &delef_, + void compute(std::vector& dfcorr_, + std::vector& dvcorr_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector>& pairs, + const std::vector& delef_, const int nghost, - const InputNlist &lmp_list) { + const InputNlist& lmp_list) { unsigned int natoms = datype_.size(); assert(natoms * 3 == dcoord_.size()); if (!dbox.empty()) { assert(dbox.size() == 9); } - const VALUETYPE *dcoord = &dcoord_[0]; - const VALUETYPE *dbox_ = !dbox.empty() ? &dbox[0] : nullptr; - const int *datype = &datype_[0]; + const VALUETYPE* dcoord = &dcoord_[0]; + const VALUETYPE* dbox_ = !dbox.empty() ? &dbox[0] : nullptr; + const int* datype = &datype_[0]; const int npairs = pairs.size(); - const int *dpairs = reinterpret_cast(&pairs[0]); - const VALUETYPE *delef = &delef_[0]; + const int* dpairs = reinterpret_cast(&pairs[0]); + const VALUETYPE* delef = &delef_[0]; dfcorr_.resize(static_cast(natoms) * 3); dvcorr_.resize(9); - VALUETYPE *dfcorr = &dfcorr_[0]; - VALUETYPE *dvcorr = &dvcorr_[0]; + VALUETYPE* dfcorr = &dfcorr_[0]; + VALUETYPE* dvcorr = &dvcorr_[0]; _DP_DipoleChargeModifierComputeNList( dcm, natoms, dcoord, datype, dbox_, dpairs, npairs, delef, nghost, @@ -3428,7 +3428,7 @@ class DipoleChargeModifier { }; std::vector sel_types() const { - int *sel_types_arr = DP_DipoleChargeModifierGetSelTypes(dcm); + int* sel_types_arr = DP_DipoleChargeModifierGetSelTypes(dcm); std::vector sel_types_vec = std::vector(sel_types_arr, sel_types_arr + nsel_types); return sel_types_vec; @@ -3439,12 +3439,12 @@ class DipoleChargeModifier { * information. * @param[in] pre The prefix to each line. */ - void print_summary(const std::string &pre) const { + void print_summary(const std::string& pre) const { DP_PrintSummary(pre.c_str()); } private: - DP_DipoleChargeModifier *dcm; + DP_DipoleChargeModifier* dcm; int nsel_types; }; @@ -3453,9 +3453,9 @@ class DipoleChargeModifier { * @param[in] model Path to the model. * @param[out] file_content Content of the model file. **/ -void inline read_file_to_string(std::string model, std::string &file_content) { +void inline read_file_to_string(std::string model, std::string& file_content) { int size; - const char *c_file_content = DP_ReadFileToChar2(model.c_str(), &size); + const char* c_file_content = DP_ReadFileToChar2(model.c_str(), &size); if (size < 0) { // negative size indicates error std::string error_message = std::string(c_file_content, -size); @@ -3478,13 +3478,13 @@ void inline read_file_to_string(std::string model, std::string &file_content) { * @param[in] sel_type_ The selected atom types. */ template -void select_by_type(std::vector &fwd_map, - std::vector &bkw_map, - int &nghost_real, - const std::vector &dcoord_, - const std::vector &datype_, - const int &nghost, - const std::vector &sel_type_) { +void select_by_type(std::vector& fwd_map, + std::vector& bkw_map, + int& nghost_real, + const std::vector& dcoord_, + const std::vector& datype_, + const int& nghost, + const std::vector& sel_type_) { const int natoms = datype_.size(); const int nsel_type = sel_type_.size(); fwd_map.resize(natoms); @@ -3505,10 +3505,10 @@ void select_by_type(std::vector &fwd_map, * @param[in] stride The stride of the input vector. */ template -void select_map(std::vector &out, - const std::vector &in, - const std::vector &fwd_map, - const int &stride) { +void select_map(std::vector& out, + const std::vector& in, + const std::vector& fwd_map, + const int& stride) { static_assert(std::is_same(), "only support int"); const int nall1 = in.size() / stride; int nall2 = 0; diff --git a/source/api_c/tests/test_deepmd_exception.cc b/source/api_c/tests/test_deepmd_exception.cc index f9f2984588..96f6942a65 100644 --- a/source/api_c/tests/test_deepmd_exception.cc +++ b/source/api_c/tests/test_deepmd_exception.cc @@ -16,7 +16,7 @@ TEST(TestDeepmdException, deepmdexception) { std::string expected_error_message = "DeePMD-kit C API Error: unittest"; try { throw deepmd::hpp::deepmd_exception("unittest"); - } catch (deepmd::hpp::deepmd_exception &ex) { + } catch (deepmd::hpp::deepmd_exception& ex) { EXPECT_STREQ(expected_error_message.c_str(), ex.what()); } } diff --git a/source/api_c/tests/test_utils.h b/source/api_c/tests/test_utils.h index 5167732bc8..59c764409a 100644 --- a/source/api_c/tests/test_utils.h +++ b/source/api_c/tests/test_utils.h @@ -14,7 +14,7 @@ typedef testing::Types ValueTypes; template inline void _fold_back(typename std::vector::iterator out, const typename std::vector::const_iterator in, - const std::vector &mapping, + const std::vector& mapping, const int nloc, const int nall, const int ndim, @@ -35,9 +35,9 @@ inline void _fold_back(typename std::vector::iterator out, } template -inline void _fold_back(std::vector &out, - const std::vector &in, - const std::vector &mapping, +inline void _fold_back(std::vector& out, + const std::vector& in, + const std::vector& mapping, const int nloc, const int nall, const int ndim, @@ -48,14 +48,14 @@ inline void _fold_back(std::vector &out, } template -inline void _build_nlist(std::vector> &nlist_data, - std::vector &coord_cpy, - std::vector &atype_cpy, - std::vector &mapping, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, - const float &rc) { +inline void _build_nlist(std::vector>& nlist_data, + std::vector& coord_cpy, + std::vector& atype_cpy, + std::vector& mapping, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, + const float& rc) { // convert VALUETYPE to double, it looks like copy_coord only accepts double std::vector coord_cpy_; std::vector coord_(coord.begin(), coord.end()); @@ -90,13 +90,13 @@ class EnergyModelTest { double level = std::is_same::value ? 1e-6 : 1e-2; // expected? public: - virtual void compute(double &ener, - std::vector &force, - std::vector &virial, - const std::vector &coord, - const std::vector &box) = 0; - void test_f(const std::vector &coord, - const std::vector &box) { + virtual void compute(double& ener, + std::vector& force, + std::vector& virial, + const std::vector& coord, + const std::vector& box) = 0; + void test_f(const std::vector& coord, + const std::vector& box) { int ndof = coord.size(); double ener; std::vector force, virial; @@ -114,8 +114,8 @@ class EnergyModelTest { EXPECT_LT(fabs(num - ana), level); } } - void test_v(const std::vector &coord, - const std::vector &box) { + void test_v(const std::vector& coord, + const std::vector& box) { std::vector num_diff(9); double ener; std::vector force, virial; diff --git a/source/api_cc/src/DeepTensor.cc b/source/api_cc/src/DeepTensor.cc index a9031472e6..02ec164be7 100644 --- a/source/api_cc/src/DeepTensor.cc +++ b/source/api_cc/src/DeepTensor.cc @@ -12,18 +12,18 @@ using namespace deepmd; DeepTensor::DeepTensor() : inited(false) {} -DeepTensor::DeepTensor(const std::string &model, - const int &gpu_rank, - const std::string &name_scope_) +DeepTensor::DeepTensor(const std::string& model, + const int& gpu_rank, + const std::string& name_scope_) : inited(false) { init(model, gpu_rank, name_scope_); } DeepTensor::~DeepTensor() {} -void DeepTensor::init(const std::string &model, - const int &gpu_rank, - const std::string &name_scope_) { +void DeepTensor::init(const std::string& model, + const int& gpu_rank, + const std::string& name_scope_) { if (inited) { std::cerr << "WARNING: deepmd-kit should not be initialized twice, do " "nothing at the second call of initializer" @@ -47,183 +47,183 @@ void DeepTensor::init(const std::string &model, inited = true; } -void DeepTensor::print_summary(const std::string &pre) const { +void DeepTensor::print_summary(const std::string& pre) const { deepmd::print_summary(pre); } template -void DeepTensor::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox) { +void DeepTensor::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox) { std::vector force_, virial_, datom_tensor_, datom_virial_; dt->computew(dtensor_, force_, virial_, datom_tensor_, datom_virial_, dcoord_, datype_, dbox, false); } -template void DeepTensor::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); +template void DeepTensor::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); -template void DeepTensor::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); +template void DeepTensor::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); template -void DeepTensor::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +void DeepTensor::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list) { + const InputNlist& lmp_list) { std::vector force_, virial_, datom_tensor_, datom_virial_; dt->computew(dtensor_, force_, virial_, datom_tensor_, datom_virial_, dcoord_, datype_, dbox, nghost, lmp_list, false); } -template void DeepTensor::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +template void DeepTensor::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list); + const InputNlist& lmp_list); -template void DeepTensor::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +template void DeepTensor::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list); + const InputNlist& lmp_list); template -void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox) { +void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox) { std::vector datom_tensor_, datom_virial_; dt->computew(dglobal_tensor_, dforce_, dvirial_, datom_tensor_, datom_virial_, dcoord_, datype_, dbox, true); } -template void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); +template void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); -template void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); +template void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); template -void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list) { + const InputNlist& lmp_list) { std::vector datom_tensor_, datom_virial_; dt->computew(dglobal_tensor_, dforce_, dvirial_, datom_tensor_, datom_virial_, dcoord_, datype_, dbox, nghost, lmp_list, true); } -template void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +template void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list); - -template void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, + const InputNlist& lmp_list); + +template void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list); + const InputNlist& lmp_list); template -void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox) { +void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox) { dt->computew(dglobal_tensor_, dforce_, dvirial_, datom_tensor_, datom_virial_, dcoord_, datype_, dbox, true); } -template void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); - -template void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); +template void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); + +template void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); template -void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list) { + const InputNlist& lmp_list) { dt->computew(dglobal_tensor_, dforce_, dvirial_, datom_tensor_, datom_virial_, dcoord_, datype_, dbox, nghost, lmp_list, true); } -template void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +template void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list); - -template void DeepTensor::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, + const InputNlist& lmp_list); + +template void DeepTensor::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list); + const InputNlist& lmp_list); -void DeepTensor::get_type_map(std::string &type_map) { +void DeepTensor::get_type_map(std::string& type_map) { dt->get_type_map(type_map); } @@ -231,7 +231,7 @@ double DeepTensor::cutoff() const { return dt->cutoff(); } int DeepTensor::output_dim() const { return dt->output_dim(); } -const std::vector &DeepTensor::sel_types() const { +const std::vector& DeepTensor::sel_types() const { return dt->sel_types(); } diff --git a/source/api_cc/src/DeepTensorTF.cc b/source/api_cc/src/DeepTensorTF.cc index 1081473f25..d17c248f7e 100644 --- a/source/api_cc/src/DeepTensorTF.cc +++ b/source/api_cc/src/DeepTensorTF.cc @@ -7,9 +7,9 @@ using namespace tensorflow; DeepTensorTF::DeepTensorTF() : inited(false), graph_def(new GraphDef()) {} -DeepTensorTF::DeepTensorTF(const std::string &model, - const int &gpu_rank, - const std::string &name_scope_) +DeepTensorTF::DeepTensorTF(const std::string& model, + const int& gpu_rank, + const std::string& name_scope_) : inited(false), name_scope(name_scope_), graph_def(new GraphDef()) { try { init(model, gpu_rank, name_scope_); @@ -22,9 +22,9 @@ DeepTensorTF::DeepTensorTF(const std::string &model, DeepTensorTF::~DeepTensorTF() { delete graph_def; } -void DeepTensorTF::init(const std::string &model, - const int &gpu_rank, - const std::string &name_scope_) { +void DeepTensorTF::init(const std::string& model, + const int& gpu_rank, + const std::string& name_scope_) { if (inited) { std::cerr << "WARNING: deepmd-kit should not be initialized twice, do " "nothing at the second call of initializer" @@ -59,7 +59,7 @@ void DeepTensorTF::init(const std::string &model, deepmd::check_status(session->Create(*graph_def)); try { model_version = get_scalar("model_attr/model_version"); - } catch (deepmd::tf_exception &e) { + } catch (deepmd::tf_exception& e) { // no model version defined in old models model_version = "0.0"; } @@ -85,23 +85,23 @@ void DeepTensorTF::init(const std::string &model, } template -VT DeepTensorTF::get_scalar(const std::string &name) const { +VT DeepTensorTF::get_scalar(const std::string& name) const { return session_get_scalar(session, name, name_scope); } template -void DeepTensorTF::get_vector(std::vector &vec, - const std::string &name) const { +void DeepTensorTF::get_vector(std::vector& vec, + const std::string& name) const { session_get_vector(vec, session, name, name_scope); } template void DeepTensorTF::run_model( - std::vector &d_tensor_, - Session *session, - const std::vector> &input_tensors, - const AtomMap &atommap, - const std::vector &sel_fwd, + std::vector& d_tensor_, + Session* session, + const std::vector>& input_tensors, + const AtomMap& atommap, + const std::vector& sel_fwd, const int nghost) { unsigned nloc = atommap.get_type().size(); unsigned nall = nloc + nghost; @@ -139,46 +139,46 @@ void DeepTensorTF::run_model( } template void DeepTensorTF::run_model( - std::vector &d_tensor_, - Session *session, - const std::vector> &input_tensors, - const AtomMap &atommap, - const std::vector &sel_fwd, + std::vector& d_tensor_, + Session* session, + const std::vector>& input_tensors, + const AtomMap& atommap, + const std::vector& sel_fwd, const int nghost); template void DeepTensorTF::run_model( - std::vector &d_tensor_, - Session *session, - const std::vector> &input_tensors, - const AtomMap &atommap, - const std::vector &sel_fwd, + std::vector& d_tensor_, + Session* session, + const std::vector>& input_tensors, + const AtomMap& atommap, + const std::vector& sel_fwd, const int nghost); template void DeepTensorTF::run_model( - std::vector &d_tensor_, - Session *session, - const std::vector> &input_tensors, - const AtomMap &atommap, - const std::vector &sel_fwd, + std::vector& d_tensor_, + Session* session, + const std::vector>& input_tensors, + const AtomMap& atommap, + const std::vector& sel_fwd, const int nghost); template void DeepTensorTF::run_model( - std::vector &d_tensor_, - Session *session, - const std::vector> &input_tensors, - const AtomMap &atommap, - const std::vector &sel_fwd, + std::vector& d_tensor_, + Session* session, + const std::vector>& input_tensors, + const AtomMap& atommap, + const std::vector& sel_fwd, const int nghost); template void DeepTensorTF::run_model( - std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - tensorflow::Session *session, - const std::vector> - &input_tensors, - const AtomMap &atommap, - const std::vector &sel_fwd, + std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + tensorflow::Session* session, + const std::vector>& + input_tensors, + const AtomMap& atommap, + const std::vector& sel_fwd, const int nghost) { unsigned nloc = atommap.get_type().size(); unsigned nall = nloc + nghost; @@ -282,61 +282,61 @@ void DeepTensorTF::run_model( } template void DeepTensorTF::run_model( - std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - tensorflow::Session *session, - const std::vector> - &input_tensors, - const AtomMap &atommap, - const std::vector &sel_fwd, + std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + tensorflow::Session* session, + const std::vector>& + input_tensors, + const AtomMap& atommap, + const std::vector& sel_fwd, const int nghost); template void DeepTensorTF::run_model( - std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - tensorflow::Session *session, - const std::vector> - &input_tensors, - const AtomMap &atommap, - const std::vector &sel_fwd, + std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + tensorflow::Session* session, + const std::vector>& + input_tensors, + const AtomMap& atommap, + const std::vector& sel_fwd, const int nghost); template void DeepTensorTF::run_model( - std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - tensorflow::Session *session, - const std::vector> - &input_tensors, - const AtomMap &atommap, - const std::vector &sel_fwd, + std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + tensorflow::Session* session, + const std::vector>& + input_tensors, + const AtomMap& atommap, + const std::vector& sel_fwd, const int nghost); template void DeepTensorTF::run_model( - std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - tensorflow::Session *session, - const std::vector> - &input_tensors, - const AtomMap &atommap, - const std::vector &sel_fwd, + std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + tensorflow::Session* session, + const std::vector>& + input_tensors, + const AtomMap& atommap, + const std::vector& sel_fwd, const int nghost); template -void DeepTensorTF::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox) { +void DeepTensorTF::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox) { int nall = datype_.size(); std::vector dcoord, aparam, aparam_; std::vector datype, fwd_map, bkw_map; @@ -347,23 +347,23 @@ void DeepTensorTF::compute(std::vector &dtensor_, compute_inner(dtensor_, dcoord, datype, dbox); } -template void DeepTensorTF::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); +template void DeepTensorTF::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); -template void DeepTensorTF::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); +template void DeepTensorTF::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); template -void DeepTensorTF::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +void DeepTensorTF::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list) { + const InputNlist& lmp_list) { int nall = datype_.size(); std::vector dcoord, dforce, datom_virial, aparam, aparam_; std::vector datype, fwd_map, bkw_map; @@ -380,29 +380,29 @@ void DeepTensorTF::compute(std::vector &dtensor_, compute_inner(dtensor_, dcoord, datype, dbox, nghost_real, nlist); } -template void DeepTensorTF::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +template void DeepTensorTF::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list); + const InputNlist& lmp_list); -template void DeepTensorTF::compute(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +template void DeepTensorTF::compute(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list); + const InputNlist& lmp_list); template -void DeepTensorTF::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox) { +void DeepTensorTF::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox) { int nall = datype_.size(); std::vector dcoord, dforce, datom_virial, aparam, aparam_; std::vector datype, fwd_map, bkw_map; @@ -434,35 +434,35 @@ void DeepTensorTF::compute(std::vector &dglobal_tensor_, } template void DeepTensorTF::compute( - std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); - -template void DeepTensorTF::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); + std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); + +template void DeepTensorTF::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); template -void DeepTensorTF::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +void DeepTensorTF::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list) { + const InputNlist& lmp_list) { int nall = datype_.size(); std::vector dcoord, dforce, datom_virial, aparam, aparam_; std::vector datype, fwd_map, bkw_map; @@ -493,33 +493,33 @@ void DeepTensorTF::compute(std::vector &dglobal_tensor_, } template void DeepTensorTF::compute( - std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, + std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list); - -template void DeepTensorTF::compute(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, + const InputNlist& lmp_list); + +template void DeepTensorTF::compute(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &lmp_list); + const InputNlist& lmp_list); template -void DeepTensorTF::compute_inner(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox) { +void DeepTensorTF::compute_inner(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox) { int nall = dcoord_.size() / 3; int nloc = nall; AtomMap atommap(datype_.begin(), datype_.begin() + nloc); @@ -550,24 +550,24 @@ void DeepTensorTF::compute_inner(std::vector &dtensor_, } template void DeepTensorTF::compute_inner( - std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); + std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); template void DeepTensorTF::compute_inner( - std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); + std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); template -void DeepTensorTF::compute_inner(std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +void DeepTensorTF::compute_inner(std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &nlist_) { + const InputNlist& nlist_) { int nall = dcoord_.size() / 3; int nloc = nall - nghost; AtomMap atommap(datype_.begin(), datype_.begin() + nloc); @@ -608,30 +608,30 @@ void DeepTensorTF::compute_inner(std::vector &dtensor_, } template void DeepTensorTF::compute_inner( - std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, + std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &nlist_); + const InputNlist& nlist_); template void DeepTensorTF::compute_inner( - std::vector &dtensor_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, + std::vector& dtensor_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &nlist_); + const InputNlist& nlist_); template -void DeepTensorTF::compute_inner(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox) { +void DeepTensorTF::compute_inner(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox) { int nall = dcoord_.size() / 3; int nloc = nall; AtomMap atommap(datype_.begin(), datype_.begin() + nloc); @@ -664,36 +664,36 @@ void DeepTensorTF::compute_inner(std::vector &dglobal_tensor_, } template void DeepTensorTF::compute_inner( - std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); + std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); template void DeepTensorTF::compute_inner( - std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox); + std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox); template -void DeepTensorTF::compute_inner(std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, +void DeepTensorTF::compute_inner(std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &nlist_) { + const InputNlist& nlist_) { int nall = dcoord_.size() / 3; int nloc = nall - nghost; AtomMap atommap(datype_.begin(), datype_.begin() + nloc); @@ -736,41 +736,41 @@ void DeepTensorTF::compute_inner(std::vector &dglobal_tensor_, } template void DeepTensorTF::compute_inner( - std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, + std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &nlist_); + const InputNlist& nlist_); template void DeepTensorTF::compute_inner( - std::vector &dglobal_tensor_, - std::vector &dforce_, - std::vector &dvirial_, - std::vector &datom_tensor_, - std::vector &datom_virial_, - const std::vector &dcoord_, - const std::vector &datype_, - const std::vector &dbox, + std::vector& dglobal_tensor_, + std::vector& dforce_, + std::vector& dvirial_, + std::vector& datom_tensor_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, const int nghost, - const InputNlist &nlist_); + const InputNlist& nlist_); -void DeepTensorTF::get_type_map(std::string &type_map) { +void DeepTensorTF::get_type_map(std::string& type_map) { type_map = get_scalar("model_attr/tmap"); } -void DeepTensorTF::computew(std::vector &global_tensor, - std::vector &force, - std::vector &virial, - std::vector &atom_tensor, - std::vector &atom_virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, +void DeepTensorTF::computew(std::vector& global_tensor, + std::vector& force, + std::vector& virial, + std::vector& atom_tensor, + std::vector& atom_virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, const bool request_deriv) { if (request_deriv) { compute(global_tensor, force, virial, atom_tensor, atom_virial, coord, @@ -783,14 +783,14 @@ void DeepTensorTF::computew(std::vector &global_tensor, atom_virial.clear(); } } -void DeepTensorTF::computew(std::vector &global_tensor, - std::vector &force, - std::vector &virial, - std::vector &atom_tensor, - std::vector &atom_virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, +void DeepTensorTF::computew(std::vector& global_tensor, + std::vector& force, + std::vector& virial, + std::vector& atom_tensor, + std::vector& atom_virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, const bool request_deriv) { if (request_deriv) { compute(global_tensor, force, virial, atom_tensor, atom_virial, coord, @@ -804,16 +804,16 @@ void DeepTensorTF::computew(std::vector &global_tensor, } } -void DeepTensorTF::computew(std::vector &global_tensor, - std::vector &force, - std::vector &virial, - std::vector &atom_tensor, - std::vector &atom_virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, +void DeepTensorTF::computew(std::vector& global_tensor, + std::vector& force, + std::vector& virial, + std::vector& atom_tensor, + std::vector& atom_virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &inlist, + const InputNlist& inlist, const bool request_deriv) { if (request_deriv) { compute(global_tensor, force, virial, atom_tensor, atom_virial, coord, @@ -826,16 +826,16 @@ void DeepTensorTF::computew(std::vector &global_tensor, atom_virial.clear(); } } -void DeepTensorTF::computew(std::vector &global_tensor, - std::vector &force, - std::vector &virial, - std::vector &atom_tensor, - std::vector &atom_virial, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, +void DeepTensorTF::computew(std::vector& global_tensor, + std::vector& force, + std::vector& virial, + std::vector& atom_tensor, + std::vector& atom_virial, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, const int nghost, - const InputNlist &inlist, + const InputNlist& inlist, const bool request_deriv) { if (request_deriv) { compute(global_tensor, force, virial, atom_tensor, atom_virial, coord, diff --git a/source/api_cc/tests/test_deepmd_exception.cc b/source/api_cc/tests/test_deepmd_exception.cc index 77e399d722..c28c0f0069 100644 --- a/source/api_cc/tests/test_deepmd_exception.cc +++ b/source/api_cc/tests/test_deepmd_exception.cc @@ -18,7 +18,7 @@ TEST(TestDeepmdException, deepmdexception) { std::string expected_error_message = "DeePMD-kit Error: unittest"; try { throw deepmd::deepmd_exception("unittest"); - } catch (deepmd::deepmd_exception &ex) { + } catch (deepmd::deepmd_exception& ex) { EXPECT_STREQ(expected_error_message.c_str(), ex.what()); } } diff --git a/source/api_cc/tests/test_utils.h b/source/api_cc/tests/test_utils.h index d06823b4e0..64d8a37ef5 100644 --- a/source/api_cc/tests/test_utils.h +++ b/source/api_cc/tests/test_utils.h @@ -14,7 +14,7 @@ typedef testing::Types ValueTypes; template inline void _fold_back(typename std::vector::iterator out, const typename std::vector::const_iterator in, - const std::vector &mapping, + const std::vector& mapping, const int nloc, const int nall, const int ndim, @@ -35,9 +35,9 @@ inline void _fold_back(typename std::vector::iterator out, } template -inline void _fold_back(std::vector &out, - const std::vector &in, - const std::vector &mapping, +inline void _fold_back(std::vector& out, + const std::vector& in, + const std::vector& mapping, const int nloc, const int nall, const int ndim, @@ -48,14 +48,14 @@ inline void _fold_back(std::vector &out, } template -inline void _build_nlist(std::vector> &nlist_data, - std::vector &coord_cpy, - std::vector &atype_cpy, - std::vector &mapping, - const std::vector &coord, - const std::vector &atype, - const std::vector &box, - const float &rc) { +inline void _build_nlist(std::vector>& nlist_data, + std::vector& coord_cpy, + std::vector& atype_cpy, + std::vector& mapping, + const std::vector& coord, + const std::vector& atype, + const std::vector& box, + const float& rc) { // convert VALUETYPE to double, it looks like copy_coord only accepts double std::vector coord_cpy_; std::vector coord_(coord.begin(), coord.end()); @@ -90,13 +90,13 @@ class EnergyModelTest { double level = std::is_same::value ? 1e-6 : 1e-2; // expected? public: - virtual void compute(double &ener, - std::vector &force, - std::vector &virial, - const std::vector &coord, - const std::vector &box) = 0; - void test_f(const std::vector &coord, - const std::vector &box) { + virtual void compute(double& ener, + std::vector& force, + std::vector& virial, + const std::vector& coord, + const std::vector& box) = 0; + void test_f(const std::vector& coord, + const std::vector& box) { int ndof = coord.size(); double ener; std::vector force, virial; @@ -114,8 +114,8 @@ class EnergyModelTest { EXPECT_LT(fabs(num - ana), level); } } - void test_v(const std::vector &coord, - const std::vector &box) { + void test_v(const std::vector& coord, + const std::vector& box) { std::vector num_diff(9); double ener; std::vector force, virial; diff --git a/source/ipi/driver.cc b/source/ipi/driver.cc index 9a91a27ad3..879e19c46f 100644 --- a/source/ipi/driver.cc +++ b/source/ipi/driver.cc @@ -29,8 +29,8 @@ const double icvt_ener = 1. / cvt_ener; const double cvt_f = cvt_ener / cvt_len; const double icvt_f = 1. / cvt_f; -char *trimwhitespace(char *str) { - char *end; +char* trimwhitespace(char* str) { + char* end; // Trim leading space while (isspace((unsigned char)*str)) { str++; @@ -48,7 +48,7 @@ char *trimwhitespace(char *str) { return str; } -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { if (argc == 1) { std::cerr << "usage " << std::endl; std::cerr << argv[0] << " input_script " << std::endl; @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) { } int port = jdata["port"]; std::string host_str = jdata["host"]; - const char *host = host_str.c_str(); + const char* host = host_str.c_str(); std::string graph_file = jdata["graph_file"]; std::string coord_file = jdata["coord_file"]; std::map name_type_map = jdata["atom_type"]; @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) { std::vector dcoord_tmp; std::vector dtype = cvt.get_type(); std::vector dbox(9, 0); - double *msg_buff = NULL; + double* msg_buff = NULL; double ener; double virial[9]; char msg_needinit[] = "NEEDINIT "; @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) { } } else if (header_str == "INIT") { assert(4 == sizeof(int32_t)); - readbuffer_(&socket, (char *)(&cbuf), sizeof(int32_t)); + readbuffer_(&socket, (char*)(&cbuf), sizeof(int32_t)); readbuffer_(&socket, initbuffer, cbuf); if (b_verb) { std::cout << "Init sys from wrapper, using " << initbuffer << std::endl; @@ -153,14 +153,14 @@ int main(int argc, char *argv[]) { assert(8 == sizeof(double)); // get box - readbuffer_(&socket, (char *)(cell_h), 9 * sizeof(double)); - readbuffer_(&socket, (char *)(cell_ih), 9 * sizeof(double)); + readbuffer_(&socket, (char*)(cell_h), 9 * sizeof(double)); + readbuffer_(&socket, (char*)(cell_ih), 9 * sizeof(double)); for (int dd = 0; dd < 9; ++dd) { dbox[dd] = cell_h[(dd % 3) * 3 + (dd / 3)] * cvt_len; } // get number of atoms - readbuffer_(&socket, (char *)(&cbuf), sizeof(int32_t)); + readbuffer_(&socket, (char*)(&cbuf), sizeof(int32_t)); if (natoms < 0) { natoms = cbuf; if (b_verb) { @@ -176,7 +176,7 @@ int main(int argc, char *argv[]) { } // get coord - readbuffer_(&socket, (char *)(msg_buff), natoms * 3 * sizeof(double)); + readbuffer_(&socket, (char*)(msg_buff), natoms * 3 * sizeof(double)); for (int ii = 0; ii < natoms * 3; ++ii) { dcoord_tmp[ii] = msg_buff[ii] * cvt_len; } @@ -199,12 +199,12 @@ int main(int argc, char *argv[]) { << std::setprecision(10) << dener << std::endl; } writebuffer_(&socket, msg_forceready, MSGLEN); - writebuffer_(&socket, (char *)(&ener), sizeof(double)); - writebuffer_(&socket, (char *)(&natoms), sizeof(int32_t)); - writebuffer_(&socket, (char *)(msg_buff), 3 * natoms * sizeof(double)); - writebuffer_(&socket, (char *)(virial), 9 * sizeof(double)); + writebuffer_(&socket, (char*)(&ener), sizeof(double)); + writebuffer_(&socket, (char*)(&natoms), sizeof(int32_t)); + writebuffer_(&socket, (char*)(msg_buff), 3 * natoms * sizeof(double)); + writebuffer_(&socket, (char*)(virial), 9 * sizeof(double)); cbuf = 7; - writebuffer_(&socket, (char *)(&cbuf), sizeof(int32_t)); + writebuffer_(&socket, (char*)(&cbuf), sizeof(int32_t)); writebuffer_(&socket, msg_nothing, 7); hasdata = false; } else { diff --git a/source/ipi/include/sockets.h b/source/ipi/include/sockets.h index 08f24c68ed..150b7c1a69 100644 --- a/source/ipi/include/sockets.h +++ b/source/ipi/include/sockets.h @@ -15,7 +15,7 @@ extern "C" { #endif -void error(const char *msg); +void error(const char* msg); /* Opens a socket. Note that fortran passes an extra argument for the string length, but this is @@ -29,7 +29,7 @@ void error(const char *msg); recommended. host: The name of the host server. */ -void open_socket_(int *psockfd, int *inet, int *port, const char *host); +void open_socket_(int* psockfd, int* inet, int* port, const char* host); /* Writes to a socket. Args: @@ -37,7 +37,7 @@ void open_socket_(int *psockfd, int *inet, int *port, const char *host); data: The data to be written to the socket. plen: The length of the data in bytes. */ -void writebuffer_(int *psockfd, char *data, int len); +void writebuffer_(int* psockfd, char* data, int len); /* Reads from a socket. Args: @@ -45,7 +45,7 @@ void writebuffer_(int *psockfd, char *data, int len); data: The storage array for data read from the socket. plen: The length of the data in bytes. */ -void readbuffer_(int *psockfd, char *data, int len); +void readbuffer_(int* psockfd, char* data, int len); #ifdef __cplusplus } diff --git a/source/ipi/src/sockets.c b/source/ipi/src/sockets.c index d9a2b8a865..1d45849f1a 100644 --- a/source/ipi/src/sockets.c +++ b/source/ipi/src/sockets.c @@ -45,14 +45,14 @@ Can be linked to a FORTRAN code that does not support sockets natively. #include #include -void error(const char *msg) +void error(const char* msg) // Prints an error message and then exits. { perror(msg); exit(-1); } -void open_socket_(int *psockfd, int *inet, int *port, const char *host) +void open_socket_(int* psockfd, int* inet, int* port, const char* host) /* Opens a socket. Note that fortran passes an extra argument for the string length, but this is @@ -70,14 +70,14 @@ ignored here for C compatibility. { int sockfd, portno, n; - struct hostent *server; + struct hostent* server; - struct sockaddr *psock; + struct sockaddr* psock; int ssock; if (*inet > 0) { // creates an internet socket struct sockaddr_in serv_addr; - psock = (struct sockaddr *)&serv_addr; + psock = (struct sockaddr*)&serv_addr; ssock = sizeof(serv_addr); sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { @@ -90,9 +90,9 @@ ignored here for C compatibility. exit(-1); } - bzero((char *)&serv_addr, sizeof(serv_addr)); + bzero((char*)&serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; - bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, + 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) { @@ -100,10 +100,10 @@ ignored here for C compatibility. } } else { // creates a unix socket struct sockaddr_un serv_addr; - psock = (struct sockaddr *)&serv_addr; + psock = (struct sockaddr*)&serv_addr; ssock = sizeof(serv_addr); sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - bzero((char *)&serv_addr, sizeof(serv_addr)); + bzero((char*)&serv_addr, sizeof(serv_addr)); serv_addr.sun_family = AF_UNIX; strcpy(serv_addr.sun_path, "/tmp/ipi_"); strcpy(serv_addr.sun_path + 9, host); @@ -115,7 +115,7 @@ ignored here for C compatibility. *psockfd = sockfd; } -void writebuffer_(int *psockfd, char *data, int len) +void writebuffer_(int* psockfd, char* data, int len) /* Writes to a socket. Args: @@ -134,7 +134,7 @@ void writebuffer_(int *psockfd, char *data, int len) } } -void readbuffer_(int *psockfd, char *data, int len) +void readbuffer_(int* psockfd, char* data, int len) /* Reads from a socket. Args: diff --git a/source/lib/include/ComputeDescriptor.h b/source/lib/include/ComputeDescriptor.h index 733cb1ee0c..edede310b6 100644 --- a/source/lib/include/ComputeDescriptor.h +++ b/source/lib/include/ComputeDescriptor.h @@ -9,100 +9,100 @@ #include "switcher.h" #include "utilities.h" -inline void compute_descriptor(std::vector &descrpt_a, - std::vector &descrpt_r, - std::vector &rot_mat, - const std::vector &posi, - const int &ntypes, - const std::vector &type, - const SimulationRegion ®ion, - const bool &b_pbc, - const int &i_idx, - const std::vector &fmt_nlist_a, - const std::vector &fmt_nlist_r, - const std::vector &sec_a, - const std::vector &sec_r, +inline void compute_descriptor(std::vector& descrpt_a, + std::vector& descrpt_r, + std::vector& rot_mat, + const std::vector& posi, + const int& ntypes, + const std::vector& type, + const SimulationRegion& region, + const bool& b_pbc, + const int& i_idx, + const std::vector& fmt_nlist_a, + const std::vector& fmt_nlist_r, + const std::vector& sec_a, + const std::vector& sec_r, const int axis0_type, const int axis0_idx, const int axis1_type, const int axis1_idx); -inline void compute_descriptor(std::vector &descrpt_a, - std::vector &descrpt_a_deriv, - std::vector &descrpt_r, - std::vector &descrpt_r_deriv, - std::vector &rij_a, - std::vector &rij_r, - std::vector &rot_mat, - const std::vector &posi, - const int &ntypes, - const std::vector &type, - const SimulationRegion ®ion, - const bool &b_pbc, - const int &i_idx, - const std::vector &fmt_nlist_a, - const std::vector &fmt_nlist_r, - const std::vector &sec_a, - const std::vector &sec_r, +inline void compute_descriptor(std::vector& descrpt_a, + std::vector& descrpt_a_deriv, + std::vector& descrpt_r, + std::vector& descrpt_r_deriv, + std::vector& rij_a, + std::vector& rij_r, + std::vector& rot_mat, + const std::vector& posi, + const int& ntypes, + const std::vector& type, + const SimulationRegion& region, + const bool& b_pbc, + const int& i_idx, + const std::vector& fmt_nlist_a, + const std::vector& fmt_nlist_r, + const std::vector& sec_a, + const std::vector& sec_r, const int axis0_type, const int axis0_idx, const int axis1_type, const int axis1_idx); -inline void compute_descriptor_se_a_extf(std::vector &descrpt_a, - std::vector &descrpt_a_deriv, - std::vector &rij_a, - const std::vector &posi, - const int &ntypes, - const std::vector &type, - const SimulationRegion ®ion, - const bool &b_pbc, - const std::vector &efield, - const int &i_idx, - const std::vector &fmt_nlist_a, - const std::vector &sec_a, - const double &rmin, - const double &rmax); +inline void compute_descriptor_se_a_extf(std::vector& descrpt_a, + std::vector& descrpt_a_deriv, + std::vector& rij_a, + const std::vector& posi, + const int& ntypes, + const std::vector& type, + const SimulationRegion& region, + const bool& b_pbc, + const std::vector& efield, + const int& i_idx, + const std::vector& fmt_nlist_a, + const std::vector& sec_a, + const double& rmin, + const double& rmax); inline void compute_descriptor_se_a_ef_para( - std::vector &descrpt_a, - std::vector &descrpt_a_deriv, - std::vector &rij_a, - const std::vector &posi, - const int &ntypes, - const std::vector &type, - const SimulationRegion ®ion, - const bool &b_pbc, - const std::vector &efield, - const int &i_idx, - const std::vector &fmt_nlist_a, - const std::vector &sec_a, - const double &rmin, - const double &rmax); + std::vector& descrpt_a, + std::vector& descrpt_a_deriv, + std::vector& rij_a, + const std::vector& posi, + const int& ntypes, + const std::vector& type, + const SimulationRegion& region, + const bool& b_pbc, + const std::vector& efield, + const int& i_idx, + const std::vector& fmt_nlist_a, + const std::vector& sec_a, + const double& rmin, + const double& rmax); inline void compute_descriptor_se_a_ef_vert( - std::vector &descrpt_a, - std::vector &descrpt_a_deriv, - std::vector &rij_a, - const std::vector &posi, - const int &ntypes, - const std::vector &type, - const SimulationRegion ®ion, - const bool &b_pbc, - const std::vector &efield, - const int &i_idx, - const std::vector &fmt_nlist_a, - const std::vector &sec_a, - const double &rmin, - const double &rmax); + std::vector& descrpt_a, + std::vector& descrpt_a_deriv, + std::vector& rij_a, + const std::vector& posi, + const int& ntypes, + const std::vector& type, + const SimulationRegion& region, + const bool& b_pbc, + const std::vector& efield, + const int& i_idx, + const std::vector& fmt_nlist_a, + const std::vector& sec_a, + const double& rmin, + const double& rmax); static void compute_dRdT(double (*dRdT)[9], - const double *r1, - const double *r2, - const double *rot) { - double *dRdT0 = dRdT[0]; - double *dRdT1 = dRdT[1]; - double *dRdT2 = dRdT[2]; - const double *xx = rot; - const double *yy = rot + 3; + const double* r1, + const double* r2, + const double* rot) { + double* dRdT0 = dRdT[0]; + double* dRdT1 = dRdT[1]; + double* dRdT2 = dRdT[2]; + const double* xx = rot; + const double* yy = rot + 3; double nr1 = sqrt(deepmd::dot3(r1, r1)); double nr12 = nr1 * nr1; @@ -160,14 +160,14 @@ static void compute_dRdT(double (*dRdT)[9], } static void compute_dRdT_1(double (*dRdT)[9], - const double *r1, - const double *r2, - const double *rot) { - double *dRdT0 = dRdT[0]; - double *dRdT1 = dRdT[1]; - double *dRdT2 = dRdT[2]; - const double *xx = rot; - const double *yy = rot + 3; + const double* r1, + const double* r2, + const double* rot) { + double* dRdT0 = dRdT[0]; + double* dRdT1 = dRdT[1]; + double* dRdT2 = dRdT[2]; + const double* xx = rot; + const double* yy = rot + 3; double nr1 = sqrt(deepmd::dot3(r1, r1)); double nr12 = nr1 * nr1; @@ -225,14 +225,14 @@ static void compute_dRdT_1(double (*dRdT)[9], } static void compute_dRdT_2(double (*dRdT)[9], - const double *r1, - const double *r2, - const double *rot) { - double *dRdT0 = dRdT[0]; - double *dRdT1 = dRdT[1]; - double *dRdT2 = dRdT[2]; - const double *xx = rot; - const double *yy = rot + 3; + const double* r1, + const double* r2, + const double* rot) { + double* dRdT0 = dRdT[0]; + double* dRdT1 = dRdT[1]; + double* dRdT2 = dRdT[2]; + const double* xx = rot; + const double* yy = rot + 3; double nr1 = sqrt(deepmd::dot3(r1, r1)); double nr12 = nr1 * nr1; @@ -287,23 +287,23 @@ static void compute_dRdT_2(double (*dRdT)[9], // n_sel_r_nei x 12 // (1./rr, cos_theta, cos_phi, sin_phi) x 4 x (x, y, z) + //(1./rr) x 4 x (x, y, z) -void compute_descriptor(std::vector &descrpt_a, - std::vector &descrpt_a_deriv, - std::vector &descrpt_r, - std::vector &descrpt_r_deriv, - std::vector &rij_a, - std::vector &rij_r, - std::vector &rot_mat, - const std::vector &posi, - const int &ntypes, - const std::vector &type, - const SimulationRegion ®ion, - const bool &b_pbc, - const int &i_idx, - const std::vector &fmt_nlist_a, - const std::vector &fmt_nlist_r, - const std::vector &sec_a, - const std::vector &sec_r, +void compute_descriptor(std::vector& descrpt_a, + std::vector& descrpt_a_deriv, + std::vector& descrpt_r, + std::vector& descrpt_r_deriv, + std::vector& rij_a, + std::vector& rij_r, + std::vector& rot_mat, + const std::vector& posi, + const int& ntypes, + const std::vector& type, + const SimulationRegion& region, + const bool& b_pbc, + const int& i_idx, + const std::vector& fmt_nlist_a, + const std::vector& fmt_nlist_r, + const std::vector& sec_a, + const std::vector& sec_r, const int axis0_type, const int axis0_idx, const int axis1_type, @@ -318,7 +318,7 @@ void compute_descriptor(std::vector &descrpt_a, break; } sel_a_diff[jj].resize(3); - const int &j_idx = fmt_nlist_a[jj]; + const int& j_idx = fmt_nlist_a[jj]; if (b_pbc) { region.diffNearestNeighbor( posi[j_idx * 3 + 0], posi[j_idx * 3 + 1], posi[j_idx * 3 + 2], @@ -344,7 +344,7 @@ void compute_descriptor(std::vector &descrpt_a, break; } sel_r_diff[jj].resize(3); - const int &j_idx = fmt_nlist_r[jj]; + const int& j_idx = fmt_nlist_r[jj]; if (b_pbc) { region.diffNearestNeighbor( posi[j_idx * 3 + 0], posi[j_idx * 3 + 1], posi[j_idx * 3 + 2], @@ -411,9 +411,9 @@ void compute_descriptor(std::vector &descrpt_a, // rotation matrix double rot[9]; - double *xx = rot; - double *yy = rot + 3; - double *zz = rot + 6; + double* xx = rot; + double* yy = rot + 3; + double* zz = rot + 6; for (unsigned dd = 0; dd < 3; ++dd) { xx[dd] = r1[dd]; yy[dd] = r2[dd]; @@ -472,7 +472,7 @@ void compute_descriptor(std::vector &descrpt_a, if (fmt_nlist_r[jj] < 0) { break; } - const double *rdiff = &sel_r_diff[jj][0]; + const double* rdiff = &sel_r_diff[jj][0]; double rr = sqrt(deepmd::dot3(rdiff, rdiff)); descrpt_r[jj] = 1. / rr; } @@ -503,7 +503,7 @@ void compute_descriptor(std::vector &descrpt_a, } // drdS, stored in transposed form double dtrdST[4][3]; - double *rr = &sel_a_diff[nei_iter][0]; + double* rr = &sel_a_diff[nei_iter][0]; double tr[3]; deepmd::dotmv3(tr, rot, rr); double nr2 = deepmd::dot3(tr, tr); @@ -638,7 +638,7 @@ void compute_descriptor(std::vector &descrpt_a, break; } - const double *rr = &sel_r_diff[nei_iter][0]; + const double* rr = &sel_r_diff[nei_iter][0]; double nr = sqrt(deepmd::dot3(rr, rr)); double nr3 = nr * nr * nr; int idx = nei_iter * 12; @@ -658,19 +658,19 @@ void compute_descriptor(std::vector &descrpt_a, } } -void compute_descriptor(std::vector &descrpt_a, - std::vector &descrpt_r, - std::vector &rot_mat, - const std::vector &posi, - const int &ntypes, - const std::vector &type, - const SimulationRegion ®ion, - const bool &b_pbc, - const int &i_idx, - const std::vector &fmt_nlist_a, - const std::vector &fmt_nlist_r, - const std::vector &sec_a, - const std::vector &sec_r, +void compute_descriptor(std::vector& descrpt_a, + std::vector& descrpt_r, + std::vector& rot_mat, + const std::vector& posi, + const int& ntypes, + const std::vector& type, + const SimulationRegion& region, + const bool& b_pbc, + const int& i_idx, + const std::vector& fmt_nlist_a, + const std::vector& fmt_nlist_r, + const std::vector& sec_a, + const std::vector& sec_r, const int axis0_type, const int axis0_idx, const int axis1_type, @@ -683,7 +683,7 @@ void compute_descriptor(std::vector &descrpt_a, break; } sel_a_diff[jj].resize(3); - const int &j_idx = fmt_nlist_a[jj]; + const int& j_idx = fmt_nlist_a[jj]; if (b_pbc) { region.diffNearestNeighbor( posi[j_idx * 3 + 0], posi[j_idx * 3 + 1], posi[j_idx * 3 + 2], @@ -703,7 +703,7 @@ void compute_descriptor(std::vector &descrpt_a, break; } sel_r_diff[jj].resize(3); - const int &j_idx = fmt_nlist_r[jj]; + const int& j_idx = fmt_nlist_r[jj]; if (b_pbc) { region.diffNearestNeighbor( posi[j_idx * 3 + 0], posi[j_idx * 3 + 1], posi[j_idx * 3 + 2], @@ -734,9 +734,9 @@ void compute_descriptor(std::vector &descrpt_a, // rotation matrix double rot[9]; - double *xx = rot; - double *yy = rot + 3; - double *zz = rot + 6; + double* xx = rot; + double* yy = rot + 3; + double* zz = rot + 6; for (unsigned dd = 0; dd < 3; ++dd) { xx[dd] = r1[dd]; yy[dd] = r2[dd]; @@ -805,21 +805,21 @@ void compute_descriptor(std::vector &descrpt_a, // output deriv size: n_sel_a_nei x 4 x 12 // (1./rr, cos_theta, cos_phi, sin_phi) x 4 x (x, y, z) -void compute_descriptor_se_a_extf(std::vector &descrpt_a, - std::vector &descrpt_a_deriv, - std::vector &rij_a, - const std::vector &posi, - const int &ntypes, - const std::vector &type, - const SimulationRegion ®ion, - const bool &b_pbc, - const std::vector &efield, - const int &i_idx, - const std::vector &fmt_nlist_a, - const std::vector &sec_a, - const double &rmin, - const double &rmax) { - const double *ef_ = &efield[i_idx * 3 + 0]; +void compute_descriptor_se_a_extf(std::vector& descrpt_a, + std::vector& descrpt_a_deriv, + std::vector& rij_a, + const std::vector& posi, + const int& ntypes, + const std::vector& type, + const SimulationRegion& region, + const bool& b_pbc, + const std::vector& efield, + const int& i_idx, + const std::vector& fmt_nlist_a, + const std::vector& sec_a, + const double& rmin, + const double& rmax) { + const double* ef_ = &efield[i_idx * 3 + 0]; double ef[3] = {0.}; if (std::isnan(ef_[0]) || std::isnan(ef_[1]) || std::isnan(ef_[2])) { ef[0] = 1.; @@ -842,7 +842,7 @@ void compute_descriptor_se_a_extf(std::vector &descrpt_a, break; } sel_a_diff[jj].resize(3); - const int &j_idx = fmt_nlist_a[jj]; + const int& j_idx = fmt_nlist_a[jj]; if (b_pbc) { region.diffNearestNeighbor( posi[j_idx * 3 + 0], posi[j_idx * 3 + 1], posi[j_idx * 3 + 2], @@ -872,7 +872,7 @@ void compute_descriptor_se_a_extf(std::vector &descrpt_a, if (fmt_nlist_a[nei_iter] < 0) { break; } - const double *rr = &sel_a_diff[nei_iter][0]; + const double* rr = &sel_a_diff[nei_iter][0]; // check validity of ef double nr2 = deepmd::dot3(rr, rr); double inr = 1. / sqrt(nr2); @@ -946,21 +946,21 @@ void compute_descriptor_se_a_extf(std::vector &descrpt_a, // output deriv size: n_sel_a_nei x 4 x 12 // (1./rr, cos_theta, cos_phi, sin_phi) x 4 x (x, y, z) -void compute_descriptor_se_a_ef_para(std::vector &descrpt_a, - std::vector &descrpt_a_deriv, - std::vector &rij_a, - const std::vector &posi, - const int &ntypes, - const std::vector &type, - const SimulationRegion ®ion, - const bool &b_pbc, - const std::vector &efield, - const int &i_idx, - const std::vector &fmt_nlist_a, - const std::vector &sec_a, - const double &rmin, - const double &rmax) { - const double *ef_ = &efield[i_idx * 3 + 0]; +void compute_descriptor_se_a_ef_para(std::vector& descrpt_a, + std::vector& descrpt_a_deriv, + std::vector& rij_a, + const std::vector& posi, + const int& ntypes, + const std::vector& type, + const SimulationRegion& region, + const bool& b_pbc, + const std::vector& efield, + const int& i_idx, + const std::vector& fmt_nlist_a, + const std::vector& sec_a, + const double& rmin, + const double& rmax) { + const double* ef_ = &efield[i_idx * 3 + 0]; double ef[3] = {0.}; if (std::isnan(ef_[0]) || std::isnan(ef_[1]) || std::isnan(ef_[2])) { ef[0] = 1.; @@ -983,7 +983,7 @@ void compute_descriptor_se_a_ef_para(std::vector &descrpt_a, break; } sel_a_diff[jj].resize(3); - const int &j_idx = fmt_nlist_a[jj]; + const int& j_idx = fmt_nlist_a[jj]; if (b_pbc) { region.diffNearestNeighbor( posi[j_idx * 3 + 0], posi[j_idx * 3 + 1], posi[j_idx * 3 + 2], @@ -1013,7 +1013,7 @@ void compute_descriptor_se_a_ef_para(std::vector &descrpt_a, if (fmt_nlist_a[nei_iter] < 0) { break; } - const double *rr = &sel_a_diff[nei_iter][0]; + const double* rr = &sel_a_diff[nei_iter][0]; // check validity of ef double nr2 = deepmd::dot3(rr, rr); double inr = 1. / sqrt(nr2); @@ -1083,21 +1083,21 @@ void compute_descriptor_se_a_ef_para(std::vector &descrpt_a, // output deriv size: n_sel_a_nei x 4 x 12 // (1./rr, cos_theta, cos_phi, sin_phi) x 4 x (x, y, z) -void compute_descriptor_se_a_ef_vert(std::vector &descrpt_a, - std::vector &descrpt_a_deriv, - std::vector &rij_a, - const std::vector &posi, - const int &ntypes, - const std::vector &type, - const SimulationRegion ®ion, - const bool &b_pbc, - const std::vector &efield, - const int &i_idx, - const std::vector &fmt_nlist_a, - const std::vector &sec_a, - const double &rmin, - const double &rmax) { - const double *ef_ = &efield[i_idx * 3 + 0]; +void compute_descriptor_se_a_ef_vert(std::vector& descrpt_a, + std::vector& descrpt_a_deriv, + std::vector& rij_a, + const std::vector& posi, + const int& ntypes, + const std::vector& type, + const SimulationRegion& region, + const bool& b_pbc, + const std::vector& efield, + const int& i_idx, + const std::vector& fmt_nlist_a, + const std::vector& sec_a, + const double& rmin, + const double& rmax) { + const double* ef_ = &efield[i_idx * 3 + 0]; double ef[3] = {0.}; if (std::isnan(ef_[0]) || std::isnan(ef_[1]) || std::isnan(ef_[2])) { ef[0] = 1.; @@ -1120,7 +1120,7 @@ void compute_descriptor_se_a_ef_vert(std::vector &descrpt_a, break; } sel_a_diff[jj].resize(3); - const int &j_idx = fmt_nlist_a[jj]; + const int& j_idx = fmt_nlist_a[jj]; if (b_pbc) { region.diffNearestNeighbor( posi[j_idx * 3 + 0], posi[j_idx * 3 + 1], posi[j_idx * 3 + 2], @@ -1150,7 +1150,7 @@ void compute_descriptor_se_a_ef_vert(std::vector &descrpt_a, if (fmt_nlist_a[nei_iter] < 0) { break; } - const double *rr = &sel_a_diff[nei_iter][0]; + const double* rr = &sel_a_diff[nei_iter][0]; // check validity of ef double nr2 = deepmd::dot3(rr, rr); double inr = 1. / sqrt(nr2); diff --git a/source/lib/include/SimulationRegion.h b/source/lib/include/SimulationRegion.h index 7cc853d25b..377a115dc0 100644 --- a/source/lib/include/SimulationRegion.h +++ b/source/lib/include/SimulationRegion.h @@ -13,82 +13,82 @@ class SimulationRegion { const static int SPACENDIM = MOASPNDIM; public: - void reinitBox(const double *boxv); - void affineTransform(const double *affine_map); - void reinitOrigin(const double *orig); - void reinitOrigin(const std::vector &orig); + void reinitBox(const double* boxv); + void affineTransform(const double* affine_map); + void reinitOrigin(const double* orig); + void reinitOrigin(const std::vector& orig); void backup(); void recover(); public: SimulationRegion(); ~SimulationRegion(); - double *getBoxTensor() { return boxt; }; - const double *getBoxTensor() const { return boxt; }; - double *getRecBoxTensor() { return rec_boxt; } - const double *getRecBoxTensor() const { return rec_boxt; } - double *getBoxOrigin() { return origin; } - const double *getBoxOrigin() const { return origin; } + double* getBoxTensor() { return boxt; }; + const double* getBoxTensor() const { return boxt; }; + double* getRecBoxTensor() { return rec_boxt; } + const double* getRecBoxTensor() const { return rec_boxt; } + double* getBoxOrigin() { return origin; } + const double* getBoxOrigin() const { return origin; } double getVolume() const { return volume; } public: - void toFaceDistance(double *dd) const; + void toFaceDistance(double* dd) const; public: - void phys2Inter(double *i_v, const VALUETYPE *p_v) const; - void inter2Phys(VALUETYPE *p_v, const double *i_v) const; + void phys2Inter(double* i_v, const VALUETYPE* p_v) const; + void inter2Phys(VALUETYPE* p_v, const double* i_v) const; public: bool isPeriodic(const int dim) const { return is_periodic[dim]; } - static int compactIndex(const int *idx); - double *getShiftVec(const int index = 0); - const double *getShiftVec(const int index = 0) const; - int getShiftIndex(const int *idx) const; + static int compactIndex(const int* idx); + double* getShiftVec(const int index = 0); + const double* getShiftVec(const int index = 0) const; + int getShiftIndex(const int* idx) const; int getNullShiftIndex() const; - void shiftCoord(const int *idx, - VALUETYPE &x, - VALUETYPE &y, - VALUETYPE &z) const; + void shiftCoord(const int* idx, + VALUETYPE& x, + VALUETYPE& y, + VALUETYPE& z) const; static int getNumbShiftVec() { return shift_info_size; } static int getShiftVecTotalSize() { return shift_vec_size; } public: - void diffNearestNeighbor(const VALUETYPE *r0, - const VALUETYPE *r1, - VALUETYPE *phys) const; + void diffNearestNeighbor(const VALUETYPE* r0, + const VALUETYPE* r1, + VALUETYPE* phys) const; virtual void diffNearestNeighbor(const VALUETYPE x0, const VALUETYPE y0, const VALUETYPE z0, const VALUETYPE x1, const VALUETYPE y1, const VALUETYPE z1, - VALUETYPE &dx, - VALUETYPE &dy, - VALUETYPE &dz) const; + VALUETYPE& dx, + VALUETYPE& dy, + VALUETYPE& dz) const; virtual void diffNearestNeighbor(const VALUETYPE x0, const VALUETYPE y0, const VALUETYPE z0, const VALUETYPE x1, const VALUETYPE y1, const VALUETYPE z1, - VALUETYPE &dx, - VALUETYPE &dy, - VALUETYPE &dz, - int &shift_x, - int &shift_y, - int &shift_z) const; + VALUETYPE& dx, + VALUETYPE& dy, + VALUETYPE& dz, + int& shift_x, + int& shift_y, + int& shift_z) const; virtual void diffNearestNeighbor(const VALUETYPE x0, const VALUETYPE y0, const VALUETYPE z0, const VALUETYPE x1, const VALUETYPE y1, const VALUETYPE z1, - VALUETYPE &dx, - VALUETYPE &dy, - VALUETYPE &dz, - VALUETYPE &shift_x, - VALUETYPE &shift_y, - VALUETYPE &shift_z) const; + VALUETYPE& dx, + VALUETYPE& dy, + VALUETYPE& dz, + VALUETYPE& shift_x, + VALUETYPE& shift_y, + VALUETYPE& shift_z) const; private: void computeVolume(); @@ -118,25 +118,25 @@ class SimulationRegion { static int index3to1(const int tx, const int ty, const int tz) { return (NBOX_ZZ * (NBOX_YY * (tx + DBOX_XX) + ty + DBOX_YY) + tz + DBOX_ZZ); } - double *getInterShiftVec(const int index = 0); - const double *getInterShiftVec(const int index = 0) const; + double* getInterShiftVec(const int index = 0); + const double* getInterShiftVec(const int index = 0) const; private: - void copy(double *o_v, const double *i_v) const; - void naiveTensorDotVector(double *out, - const double *i_t, - const double *i_v) const; - void naiveTensorTransDotVector(double *out, - const double *i_t, - const double *i_v) const; - void tensorDotVector(double *out, const double *i_t, const double *i_v) const; - void tensorTransDotVector(double *out, - const double *i_t, - const double *i_v) const; - void getFromRestart(double *my_boxv, double *my_orig, bool *period) const; - void defaultInitBox(double *my_boxv, double *my_orig, bool *period) const; - void apply_periodic(int dim, double *dd) const; - void apply_periodic(int dim, double *dd, int &shift) const; + void copy(double* o_v, const double* i_v) const; + void naiveTensorDotVector(double* out, + const double* i_t, + const double* i_v) const; + void naiveTensorTransDotVector(double* out, + const double* i_t, + const double* i_v) const; + void tensorDotVector(double* out, const double* i_t, const double* i_v) const; + void tensorTransDotVector(double* out, + const double* i_t, + const double* i_v) const; + void getFromRestart(double* my_boxv, double* my_orig, bool* period) const; + void defaultInitBox(double* my_boxv, double* my_orig, bool* period) const; + void apply_periodic(int dim, double* dd) const; + void apply_periodic(int dim, double* dd, int& shift) const; private: std::fstream fp; diff --git a/source/lib/include/SimulationRegion_Impl.h b/source/lib/include/SimulationRegion_Impl.h index cab06087e3..7b4c3dbb4d 100644 --- a/source/lib/include/SimulationRegion_Impl.h +++ b/source/lib/include/SimulationRegion_Impl.h @@ -23,9 +23,9 @@ SimulationRegion::SimulationRegion() { } template -void SimulationRegion::defaultInitBox(double *my_boxv, - double *my_orig, - bool *period) const { +void SimulationRegion::defaultInitBox(double* my_boxv, + double* my_orig, + bool* period) const { // by default is a 1,1,1 logical box for (int ii = 0; ii < SPACENDIM; ++ii) { for (int jj = 0; jj < SPACENDIM; ++jj) { @@ -55,7 +55,7 @@ void SimulationRegion::recover() { } template -inline void SimulationRegion::reinitBox(const double *boxv_) { +inline void SimulationRegion::reinitBox(const double* boxv_) { for (int ii = 0; ii < SPACENDIM * SPACENDIM; ++ii) { boxt[ii] = boxv_[ii]; } @@ -66,7 +66,7 @@ inline void SimulationRegion::reinitBox(const double *boxv_) { template inline void SimulationRegion::affineTransform( - const double *affine_map) { + const double* affine_map) { tensorDotVector(boxt + SPACENDIM * 0, affine_map, boxt + SPACENDIM * 0); tensorDotVector(boxt + SPACENDIM * 1, affine_map, boxt + SPACENDIM * 1); tensorDotVector(boxt + SPACENDIM * 2, affine_map, boxt + SPACENDIM * 2); @@ -76,7 +76,7 @@ inline void SimulationRegion::affineTransform( } template -inline void SimulationRegion::reinitOrigin(const double *orig) { +inline void SimulationRegion::reinitOrigin(const double* orig) { for (int ii = 0; ii < SPACENDIM; ++ii) { origin[ii] = orig[ii]; } @@ -84,7 +84,7 @@ inline void SimulationRegion::reinitOrigin(const double *orig) { template inline void SimulationRegion::reinitOrigin( - const std::vector &orig) { + const std::vector& orig) { for (int ii = 0; ii < SPACENDIM; ++ii) { origin[ii] = orig[ii]; } @@ -93,14 +93,14 @@ inline void SimulationRegion::reinitOrigin( template void SimulationRegion::computeShiftVec() { int tmp_idx[3]; - int &ii(tmp_idx[0]); - int &jj(tmp_idx[1]); - int &kk(tmp_idx[2]); + int& ii(tmp_idx[0]); + int& jj(tmp_idx[1]); + int& kk(tmp_idx[2]); for (ii = -DBOX_XX; ii <= DBOX_XX; ++ii) { for (jj = -DBOX_YY; jj <= DBOX_YY; ++jj) { for (kk = -DBOX_ZZ; kk <= DBOX_ZZ; ++kk) { - double *posi = getShiftVec(getShiftIndex(tmp_idx)); - double *inter_posi = getInterShiftVec(getShiftIndex(tmp_idx)); + double* posi = getShiftVec(getShiftIndex(tmp_idx)); + double* inter_posi = getInterShiftVec(getShiftIndex(tmp_idx)); inter_posi[0] = ii; inter_posi[1] = jj; inter_posi[2] = kk; @@ -112,29 +112,29 @@ void SimulationRegion::computeShiftVec() { } template -inline double *SimulationRegion::getShiftVec(const int index) { +inline double* SimulationRegion::getShiftVec(const int index) { return shift_vec + SPACENDIM * index; } template -inline const double *SimulationRegion::getShiftVec( +inline const double* SimulationRegion::getShiftVec( const int index) const { return shift_vec + SPACENDIM * index; } template -inline double *SimulationRegion::getInterShiftVec(const int index) { +inline double* SimulationRegion::getInterShiftVec(const int index) { return inter_shift_vec + SPACENDIM * index; } template -inline const double *SimulationRegion::getInterShiftVec( +inline const double* SimulationRegion::getInterShiftVec( const int index) const { return inter_shift_vec + SPACENDIM * index; } template -inline int SimulationRegion::getShiftIndex(const int *idx) const { +inline int SimulationRegion::getShiftIndex(const int* idx) const { return index3to1(idx[0], idx[1], idx[2]); } @@ -144,16 +144,16 @@ inline int SimulationRegion::getNullShiftIndex() const { } template -inline int SimulationRegion::compactIndex(const int *idx) { +inline int SimulationRegion::compactIndex(const int* idx) { return index3to1(idx[0], idx[1], idx[2]); } template -inline void SimulationRegion::shiftCoord(const int *idx, - VALUETYPE &x, - VALUETYPE &y, - VALUETYPE &z) const { - const double *shift = getShiftVec(getShiftIndex(idx)); +inline void SimulationRegion::shiftCoord(const int* idx, + VALUETYPE& x, + VALUETYPE& y, + VALUETYPE& z) const { + const double* shift = getShiftVec(getShiftIndex(idx)); x += shift[0]; y += shift[1]; z += shift[2]; @@ -199,7 +199,7 @@ inline void SimulationRegion::shiftCoord(const int *idx, template inline void SimulationRegion::apply_periodic(int dim, - double *dd) const { + double* dd) const { if (!is_periodic[dim]) { return; } @@ -212,8 +212,8 @@ inline void SimulationRegion::apply_periodic(int dim, template inline void SimulationRegion::apply_periodic(int dim, - double *dd, - int &shift) const { + double* dd, + int& shift) const { shift = 0; if (!is_periodic[dim]) { return; @@ -229,7 +229,7 @@ inline void SimulationRegion::apply_periodic(int dim, template inline void SimulationRegion::diffNearestNeighbor( - const VALUETYPE *r0, const VALUETYPE *r1, VALUETYPE *phys) const { + 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]; @@ -249,9 +249,9 @@ inline void SimulationRegion::diffNearestNeighbor( const VALUETYPE x1, const VALUETYPE y1, const VALUETYPE z1, - VALUETYPE &dx, - VALUETYPE &dy, - VALUETYPE &dz) const { + VALUETYPE& dx, + VALUETYPE& dy, + VALUETYPE& dz) const { // diffNearestNeighbor (0, x0, x1, dx); // diffNearestNeighbor (1, y0, y1, dy); // diffNearestNeighbor (2, z0, z1, dz); @@ -278,12 +278,12 @@ inline void SimulationRegion::diffNearestNeighbor( const VALUETYPE x1, const VALUETYPE y1, const VALUETYPE z1, - VALUETYPE &dx, - VALUETYPE &dy, - VALUETYPE &dz, - int &shift_x, - int &shift_y, - int &shift_z) const { + VALUETYPE& dx, + VALUETYPE& dy, + VALUETYPE& dz, + int& shift_x, + int& shift_y, + int& shift_z) const { // diffNearestNeighbor (0, x0, x1, dx, shift_x); // diffNearestNeighbor (1, y0, y1, dy, shift_y); // diffNearestNeighbor (2, z0, z1, dz, shift_z); @@ -310,12 +310,12 @@ inline void SimulationRegion::diffNearestNeighbor( const VALUETYPE x1, const VALUETYPE y1, const VALUETYPE z1, - VALUETYPE &dx, - VALUETYPE &dy, - VALUETYPE &dz, - VALUETYPE &shift_x, - VALUETYPE &shift_y, - VALUETYPE &shift_z) const { + VALUETYPE& dx, + VALUETYPE& dy, + VALUETYPE& dz, + VALUETYPE& shift_x, + VALUETYPE& shift_y, + VALUETYPE& shift_z) const { // diffNearestNeighbor (0, x0, x1, dx, shift_x); // diffNearestNeighbor (1, y0, y1, dy, shift_y); // diffNearestNeighbor (2, z0, z1, dz, shift_z); @@ -333,7 +333,7 @@ inline void SimulationRegion::diffNearestNeighbor( dx = phys[0]; dy = phys[1]; dz = phys[2]; - const double *tmp_shift( + const double* tmp_shift( getShiftVec(index3to1(i_shift_x, i_shift_y, i_shift_z))); shift_x = tmp_shift[0]; shift_y = tmp_shift[1]; @@ -342,7 +342,7 @@ inline void SimulationRegion::diffNearestNeighbor( template inline void SimulationRegion::phys2Inter( - double *i_v, const VALUETYPE *p_v_) const { + 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]; @@ -351,8 +351,8 @@ inline void SimulationRegion::phys2Inter( } template -inline void SimulationRegion::inter2Phys(VALUETYPE *p_v_, - const double *i_v) const { +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) { @@ -361,7 +361,7 @@ inline void SimulationRegion::inter2Phys(VALUETYPE *p_v_, } template -inline void SimulationRegion::toFaceDistance(double *dd) const { +inline void SimulationRegion::toFaceDistance(double* dd) const { double tmp[3]; deepmd::cprod(boxt + 3, boxt + 6, tmp); dd[0] = volume * deepmd::invsqrt(deepmd::dot3(tmp, tmp)); @@ -374,8 +374,8 @@ inline void SimulationRegion::toFaceDistance(double *dd) const { // static int tmp_count = 0; template -inline void SimulationRegion::copy(double *o_v, - const double *i_v) const { +inline void SimulationRegion::copy(double* o_v, + const double* i_v) const { #ifdef DEBUG_CHECK_ASSERTIONS assert(o_v != i_v); #endif @@ -386,7 +386,7 @@ inline void SimulationRegion::copy(double *o_v, template inline void SimulationRegion::naiveTensorDotVector( - double *o_v, const double *i_t, const double *i_v) const { + double* o_v, const double* i_t, const double* i_v) const { o_v[0] = i_v[0] * i_t[0 * 3 + 0] + i_v[1] * i_t[0 * 3 + 1] + i_v[2] * i_t[0 * 3 + 2]; o_v[1] = i_v[0] * i_t[1 * 3 + 0] + i_v[1] * i_t[1 * 3 + 1] + @@ -397,7 +397,7 @@ inline void SimulationRegion::naiveTensorDotVector( template inline void SimulationRegion::naiveTensorTransDotVector( - double *o_v, const double *i_t, const double *i_v) const { + double* o_v, const double* i_t, const double* i_v) const { o_v[0] = i_v[0] * i_t[0 * 3 + 0] + i_v[1] * i_t[1 * 3 + 0] + i_v[2] * i_t[2 * 3 + 0]; o_v[1] = i_v[0] * i_t[0 * 3 + 1] + i_v[1] * i_t[1 * 3 + 1] + @@ -408,7 +408,7 @@ inline void SimulationRegion::naiveTensorTransDotVector( template inline void SimulationRegion::tensorDotVector( - double *o_v, const double *i_t, const double *i_v) const { + double* o_v, const double* i_t, const double* i_v) const { // the compiler will auto-matically optimize the following code away... // const double * tmp_v (i_v); // if (o_v == i_v){ @@ -421,7 +421,7 @@ inline void SimulationRegion::tensorDotVector( template inline void SimulationRegion::tensorTransDotVector( - double *o_v, const double *i_t, const double *i_v) const { + double* o_v, const double* i_t, const double* i_v) const { naiveTensorTransDotVector(o_v, i_t, i_v); } diff --git a/source/lib/include/env_mat_nvnmd.h b/source/lib/include/env_mat_nvnmd.h index d3c18270cf..ce391a9563 100644 --- a/source/lib/include/env_mat_nvnmd.h +++ b/source/lib/include/env_mat_nvnmd.h @@ -28,16 +28,16 @@ date: 2021-12-6 namespace deepmd { template -void env_mat_a_nvnmd_quantize_cpu(std::vector &descrpt_a, - std::vector &descrpt_a_deriv, - std::vector &rij_a, - const std::vector &posi, - const std::vector &type, - const int &i_idx, - const std::vector &fmt_nlist, - const std::vector &sec, - const float &rmin, - const float &rmax); +void env_mat_a_nvnmd_quantize_cpu(std::vector& descrpt_a, + std::vector& descrpt_a_deriv, + std::vector& rij_a, + const std::vector& posi, + const std::vector& type, + const int& i_idx, + const std::vector& fmt_nlist, + const std::vector& sec, + const float& rmin, + const float& rmax); } union U_Flt64_Int64 { @@ -59,7 +59,7 @@ union U_Flt64_Int64 { split double into sign, expo, and frac */ template // float and double -void split_flt(T x, int64_t &sign, int64_t &expo, int64_t &mant) { +void split_flt(T x, int64_t& sign, int64_t& expo, int64_t& mant) { U_Flt64_Int64 ufi; ufi.nflt = x; sign = (ufi.nint >> 63) & 0x01; @@ -71,7 +71,7 @@ void split_flt(T x, int64_t &sign, int64_t &expo, int64_t &mant) { find the max exponent for float array x */ template // float and double -void find_max_expo(int64_t &max_expo, T *x, int64_t M) { +void find_max_expo(int64_t& max_expo, T* x, int64_t M) { int ii, jj, kk; U_Flt64_Int64 ufi; int64_t expo; @@ -87,7 +87,7 @@ void find_max_expo(int64_t &max_expo, T *x, int64_t M) { find the max exponent for float array x */ template // float and double -void find_max_expo(int64_t &max_expo, T *x, int64_t N, int64_t M) { +void find_max_expo(int64_t& max_expo, T* x, int64_t N, int64_t M) { int ii, jj, kk; U_Flt64_Int64 ufi; int64_t expo; @@ -103,7 +103,7 @@ void find_max_expo(int64_t &max_expo, T *x, int64_t N, int64_t M) { dot multiply */ template // float and double -void dotmul_flt_nvnmd(T &y, T *x1, T *x2, int64_t M) { +void dotmul_flt_nvnmd(T& y, T* x1, T* x2, int64_t M) { int ii, jj, kk; U_Flt64_Int64 ufi; // @@ -146,7 +146,7 @@ void dotmul_flt_nvnmd(T &y, T *x1, T *x2, int64_t M) { multiply */ template // float and double -void mul_flt_nvnmd(T &y, T x1, T x2) { +void mul_flt_nvnmd(T& y, T x1, T x2) { U_Flt64_Int64 ufi1, ufi2, ufi3; ufi1.nflt = x1; ufi1.nint &= FLT_MASK; @@ -161,7 +161,7 @@ void mul_flt_nvnmd(T &y, T x1, T x2) { add */ template // float and double -void add_flt_nvnmd(T &y, T x1, T x2) { +void add_flt_nvnmd(T& y, T x1, T x2) { U_Flt64_Int64 ufi1, ufi2, ufi3; int64_t sign1, sign2, sign3; int64_t expo1, expo2, expo3; diff --git a/source/lib/include/gpu_cuda.h b/source/lib/include/gpu_cuda.h index 9504a95b7a..8fc7781f4c 100644 --- a/source/lib/include/gpu_cuda.h +++ b/source/lib/include/gpu_cuda.h @@ -23,7 +23,7 @@ DPAssert((res), __FILE__, __LINE__); \ } inline void DPAssert(cudaError_t code, - const char *file, + const char* file, int line, bool abort = true) { if (code != cudaSuccess) { @@ -61,21 +61,21 @@ inline void DPAssert(cudaError_t code, nborAssert((res), __FILE__, __LINE__); \ } inline void nborAssert(cudaError_t code, - const char *file, + const char* file, int line, bool abort = true) { if (code != cudaSuccess) { std::string error_msg = "DeePMD-kit: Illegal nbor list sorting: "; try { DPAssert(code, file, line, true); - } catch (deepmd::deepmd_exception_oom &e) { + } catch (deepmd::deepmd_exception_oom& e) { error_msg += e.what(); if (abort) { throw deepmd::deepmd_exception_oom(error_msg); } else { fprintf(stderr, "%s\n", error_msg.c_str()); } - } catch (deepmd::deepmd_exception &e) { + } catch (deepmd::deepmd_exception& e) { error_msg += e.what(); if (abort) { throw deepmd::deepmd_exception(error_msg); @@ -87,8 +87,8 @@ inline void nborAssert(cudaError_t code, } #if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 600 -static __inline__ __device__ double atomicAdd(double *address, double val) { - unsigned long long int *address_as_ull = (unsigned long long int *)address; +static __inline__ __device__ double atomicAdd(double* address, double val) { + unsigned long long int* address_as_ull = (unsigned long long int*)address; unsigned long long int old = *address_as_ull, assumed; do { assumed = old; @@ -103,68 +103,68 @@ static __inline__ __device__ double atomicAdd(double *address, double val) { namespace deepmd { -inline void DPGetDeviceCount(int &gpu_num) { cudaGetDeviceCount(&gpu_num); } +inline void DPGetDeviceCount(int& gpu_num) { cudaGetDeviceCount(&gpu_num); } inline cudaError_t DPSetDevice(int rank) { return cudaSetDevice(rank); } template -void memcpy_host_to_device(FPTYPE *device, const std::vector &host) { +void memcpy_host_to_device(FPTYPE* device, const std::vector& host) { DPErrcheck(cudaMemcpy(device, &host[0], sizeof(FPTYPE) * host.size(), cudaMemcpyHostToDevice)); } template -void memcpy_host_to_device(FPTYPE *device, const FPTYPE *host, const int size) { +void memcpy_host_to_device(FPTYPE* device, const FPTYPE* host, const int size) { DPErrcheck( cudaMemcpy(device, host, sizeof(FPTYPE) * size, cudaMemcpyHostToDevice)); } template -void memcpy_device_to_host(const FPTYPE *device, std::vector &host) { +void memcpy_device_to_host(const FPTYPE* device, std::vector& host) { DPErrcheck(cudaMemcpy(&host[0], device, sizeof(FPTYPE) * host.size(), cudaMemcpyDeviceToHost)); } template -void memcpy_device_to_host(const FPTYPE *device, FPTYPE *host, const int size) { +void memcpy_device_to_host(const FPTYPE* device, FPTYPE* host, const int size) { DPErrcheck( cudaMemcpy(host, device, sizeof(FPTYPE) * size, cudaMemcpyDeviceToHost)); } template -void malloc_device_memory(FPTYPE *&device, const std::vector &host) { - DPErrcheck(cudaMalloc((void **)&device, sizeof(FPTYPE) * host.size())); +void malloc_device_memory(FPTYPE*& device, const std::vector& host) { + DPErrcheck(cudaMalloc((void**)&device, sizeof(FPTYPE) * host.size())); } template -void malloc_device_memory(FPTYPE *&device, const int size) { - DPErrcheck(cudaMalloc((void **)&device, sizeof(FPTYPE) * size)); +void malloc_device_memory(FPTYPE*& device, const int size) { + DPErrcheck(cudaMalloc((void**)&device, sizeof(FPTYPE) * size)); } template -void malloc_device_memory_sync(FPTYPE *&device, - const std::vector &host) { - DPErrcheck(cudaMalloc((void **)&device, sizeof(FPTYPE) * host.size())); +void malloc_device_memory_sync(FPTYPE*& device, + const std::vector& host) { + DPErrcheck(cudaMalloc((void**)&device, sizeof(FPTYPE) * host.size())); memcpy_host_to_device(device, host); } template -void malloc_device_memory_sync(FPTYPE *&device, - const FPTYPE *host, +void malloc_device_memory_sync(FPTYPE*& device, + const FPTYPE* host, const int size) { - DPErrcheck(cudaMalloc((void **)&device, sizeof(FPTYPE) * size)); + DPErrcheck(cudaMalloc((void**)&device, sizeof(FPTYPE) * size)); memcpy_host_to_device(device, host, size); } template -void delete_device_memory(FPTYPE *&device) { +void delete_device_memory(FPTYPE*& device) { if (device != NULL) { DPErrcheck(cudaFree(device)); } } template -void memset_device_memory(FPTYPE *device, const int var, const int size) { +void memset_device_memory(FPTYPE* device, const int var, const int size) { DPErrcheck(cudaMemset(device, var, sizeof(FPTYPE) * size)); } } // end of namespace deepmd diff --git a/source/lib/include/gpu_rocm.h b/source/lib/include/gpu_rocm.h index abb7ddfa62..c522c6aed4 100644 --- a/source/lib/include/gpu_rocm.h +++ b/source/lib/include/gpu_rocm.h @@ -25,7 +25,7 @@ DPAssert((res), __FILE__, __LINE__); \ } inline void DPAssert(hipError_t code, - const char *file, + const char* file, int line, bool abort = true) { if (code != hipSuccess) { @@ -46,14 +46,14 @@ inline void DPAssert(hipError_t code, nborAssert((res), __FILE__, __LINE__); \ } inline void nborAssert(hipError_t code, - const char *file, + const char* file, int line, bool abort = true) { if (code != hipSuccess) { std::string error_msg = "DeePMD-kit: Illegal nbor list sorting: "; try { DPAssert(code, file, line, true); - } catch (deepmd::deepmd_exception &e) { + } catch (deepmd::deepmd_exception& e) { error_msg += e.what(); if (abort) { throw deepmd::deepmd_exception(error_msg); @@ -65,65 +65,65 @@ inline void nborAssert(hipError_t code, } namespace deepmd { -inline void DPGetDeviceCount(int &gpu_num) { hipGetDeviceCount(&gpu_num); } +inline void DPGetDeviceCount(int& gpu_num) { hipGetDeviceCount(&gpu_num); } inline hipError_t DPSetDevice(int rank) { return hipSetDevice(rank); } template -void memcpy_host_to_device(FPTYPE *device, std::vector &host) { +void memcpy_host_to_device(FPTYPE* device, std::vector& host) { DPErrcheck(hipMemcpy(device, &host[0], sizeof(FPTYPE) * host.size(), hipMemcpyHostToDevice)); } template -void memcpy_host_to_device(FPTYPE *device, const FPTYPE *host, const int size) { +void memcpy_host_to_device(FPTYPE* device, const FPTYPE* host, const int size) { DPErrcheck( hipMemcpy(device, host, sizeof(FPTYPE) * size, hipMemcpyHostToDevice)); } template -void memcpy_device_to_host(const FPTYPE *device, std::vector &host) { +void memcpy_device_to_host(const FPTYPE* device, std::vector& host) { DPErrcheck(hipMemcpy(&host[0], device, sizeof(FPTYPE) * host.size(), hipMemcpyDeviceToHost)); } template -void memcpy_device_to_host(const FPTYPE *device, FPTYPE *host, const int size) { +void memcpy_device_to_host(const FPTYPE* device, FPTYPE* host, const int size) { DPErrcheck( hipMemcpy(host, device, sizeof(FPTYPE) * size, hipMemcpyDeviceToHost)); } template -void malloc_device_memory(FPTYPE *&device, std::vector &host) { - DPErrcheck(hipMalloc((void **)&device, sizeof(FPTYPE) * host.size())); +void malloc_device_memory(FPTYPE*& device, std::vector& host) { + DPErrcheck(hipMalloc((void**)&device, sizeof(FPTYPE) * host.size())); } template -void malloc_device_memory(FPTYPE *&device, const int size) { - DPErrcheck(hipMalloc((void **)&device, sizeof(FPTYPE) * size)); +void malloc_device_memory(FPTYPE*& device, const int size) { + DPErrcheck(hipMalloc((void**)&device, sizeof(FPTYPE) * size)); } template -void malloc_device_memory_sync(FPTYPE *&device, std::vector &host) { - DPErrcheck(hipMalloc((void **)&device, sizeof(FPTYPE) * host.size())); +void malloc_device_memory_sync(FPTYPE*& device, std::vector& host) { + DPErrcheck(hipMalloc((void**)&device, sizeof(FPTYPE) * host.size())); memcpy_host_to_device(device, host); } template -void malloc_device_memory_sync(FPTYPE *&device, - const FPTYPE *host, +void malloc_device_memory_sync(FPTYPE*& device, + const FPTYPE* host, const int size) { - DPErrcheck(hipMalloc((void **)&device, sizeof(FPTYPE) * size)); + DPErrcheck(hipMalloc((void**)&device, sizeof(FPTYPE) * size)); memcpy_host_to_device(device, host, size); } template -void delete_device_memory(FPTYPE *&device) { +void delete_device_memory(FPTYPE*& device) { if (device != NULL) { DPErrcheck(hipFree(device)); } } template -void memset_device_memory(FPTYPE *device, const int var, const int size) { +void memset_device_memory(FPTYPE* device, const int var, const int size) { DPErrcheck(hipMemset(device, var, sizeof(FPTYPE) * size)); } } // namespace deepmd diff --git a/source/lib/include/pairwise.h b/source/lib/include/pairwise.h index bbb4119e59..f711bd6f88 100644 --- a/source/lib/include/pairwise.h +++ b/source/lib/include/pairwise.h @@ -10,8 +10,8 @@ namespace deepmd { * @param[in] idxs The indexes of the fragment that each atom belongs to. -1 * will be ignored. */ -void group_atoms_cpu(std::vector> &fragments, - const std::vector &idxs); +void group_atoms_cpu(std::vector>& fragments, + const std::vector& idxs); /** * DPRc pairwise map. * @@ -30,15 +30,15 @@ void group_atoms_cpu(std::vector> &fragments, * @param[in] nloc The number of local atoms. * @param[in] nall The number of all atoms, including local and ghost atoms. */ -void dprc_pairwise_map_cpu(std::vector &forward_qm_map, - std::vector &backward_qm_map, - std::vector &forward_qmmm_map, - std::vector &backward_qmmm_map, - int &nloc_qm, - int &nloc_qmmm, - int &nall_qm, - int &nall_qmmm, - const std::vector> &fragments, +void dprc_pairwise_map_cpu(std::vector& forward_qm_map, + std::vector& backward_qm_map, + std::vector& forward_qmmm_map, + std::vector& backward_qmmm_map, + int& nloc_qm, + int& nloc_qmmm, + int& nall_qm, + int& nall_qmmm, + const std::vector>& fragments, const int nloc, const int nall); } // namespace deepmd diff --git a/source/lib/include/prod_env_mat.h b/source/lib/include/prod_env_mat.h index 60da638d68..d8ca4d1861 100644 --- a/source/lib/include/prod_env_mat.h +++ b/source/lib/include/prod_env_mat.h @@ -8,34 +8,34 @@ namespace deepmd { template -void prod_env_mat_a_cpu(FPTYPE *em, - FPTYPE *em_deriv, - FPTYPE *rij, - int *nlist, - const FPTYPE *coord, - const int *type, - const InputNlist &inlist, +void prod_env_mat_a_cpu(FPTYPE* em, + FPTYPE* em_deriv, + FPTYPE* rij, + int* nlist, + const FPTYPE* coord, + const int* type, + const InputNlist& inlist, const int max_nbor_size, - const FPTYPE *avg, - const FPTYPE *std, + const FPTYPE* avg, + const FPTYPE* std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec, - const int *f_type = NULL); + const int* f_type = NULL); template -void prod_env_mat_r_cpu(FPTYPE *em, - FPTYPE *em_deriv, - FPTYPE *rij, - int *nlist, - const FPTYPE *coord, - const int *type, - const InputNlist &inlist, +void prod_env_mat_r_cpu(FPTYPE* em, + FPTYPE* em_deriv, + FPTYPE* rij, + int* nlist, + const FPTYPE* coord, + const int* type, + const InputNlist& inlist, const int max_nbor_size, - const FPTYPE *avg, - const FPTYPE *std, + const FPTYPE* avg, + const FPTYPE* std, const int nloc, const int nall, const float rcut, @@ -44,49 +44,49 @@ void prod_env_mat_r_cpu(FPTYPE *em, #if GOOGLE_CUDA || TENSORFLOW_USE_ROCM template -void prod_env_mat_a_gpu(FPTYPE *em, - FPTYPE *em_deriv, - FPTYPE *rij, - int *nlist, - const FPTYPE *coord, - const int *type, - const InputNlist &gpu_inlist, - int *array_int, - unsigned long long *array_longlong, +void prod_env_mat_a_gpu(FPTYPE* em, + FPTYPE* em_deriv, + FPTYPE* rij, + int* nlist, + const FPTYPE* coord, + const int* type, + const InputNlist& gpu_inlist, + int* array_int, + unsigned long long* array_longlong, const int max_nbor_size, - const FPTYPE *avg, - const FPTYPE *std, + const FPTYPE* avg, + const FPTYPE* std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec, - const int *f_type = NULL); + const int* f_type = NULL); template -void prod_env_mat_r_gpu(FPTYPE *em, - FPTYPE *em_deriv, - FPTYPE *rij, - int *nlist, - const FPTYPE *coord, - const int *type, - const InputNlist &gpu_inlist, - int *array_int, - unsigned long long *array_longlong, +void prod_env_mat_r_gpu(FPTYPE* em, + FPTYPE* em_deriv, + FPTYPE* rij, + int* nlist, + const FPTYPE* coord, + const int* type, + const InputNlist& gpu_inlist, + int* array_int, + unsigned long long* array_longlong, const int max_nbor_size, - const FPTYPE *avg, - const FPTYPE *std, + const FPTYPE* avg, + const FPTYPE* std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec); -void env_mat_nbor_update(InputNlist &inlist, - InputNlist &gpu_inlist, - int &max_nbor_size, - int *&nbor_list_dev, - const int *mesh, +void env_mat_nbor_update(InputNlist& inlist, + InputNlist& gpu_inlist, + int& max_nbor_size, + int*& nbor_list_dev, + const int* mesh, const int size); #endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM diff --git a/source/lib/include/region.cuh b/source/lib/include/region.cuh index 0feafad49e..6dc71861f1 100644 --- a/source/lib/include/region.cuh +++ b/source/lib/include/region.cuh @@ -1,9 +1,9 @@ #pragma once template -__device__ inline void tensorDotVector(FPTYPE *o_v, - const FPTYPE *i_v, - const FPTYPE *i_t) { +__device__ inline void tensorDotVector(FPTYPE* o_v, + const FPTYPE* i_v, + const FPTYPE* i_t) { o_v[0] = i_v[0] * i_t[0 * 3 + 0] + i_v[1] * i_t[0 * 3 + 1] + i_v[2] * i_t[0 * 3 + 2]; o_v[1] = i_v[0] * i_t[1 * 3 + 0] + i_v[1] * i_t[1 * 3 + 1] + @@ -12,9 +12,9 @@ __device__ inline void tensorDotVector(FPTYPE *o_v, i_v[2] * i_t[2 * 3 + 2]; } template -__device__ inline void tensorTransDotVector(FPTYPE *o_v, - const FPTYPE *i_v, - const FPTYPE *i_t) { +__device__ inline void tensorTransDotVector(FPTYPE* o_v, + const FPTYPE* i_v, + const FPTYPE* i_t) { o_v[0] = i_v[0] * i_t[0 * 3 + 0] + i_v[1] * i_t[1 * 3 + 0] + i_v[2] * i_t[2 * 3 + 0]; o_v[1] = i_v[0] * i_t[0 * 3 + 1] + i_v[1] * i_t[1 * 3 + 1] + @@ -23,19 +23,19 @@ __device__ inline void tensorTransDotVector(FPTYPE *o_v, i_v[2] * i_t[2 * 3 + 2]; } template -__device__ inline void phys2Inter(FPTYPE *inter, - const FPTYPE *phys, - const FPTYPE *rec_boxt) { +__device__ inline void phys2Inter(FPTYPE* inter, + const FPTYPE* phys, + const FPTYPE* rec_boxt) { tensorDotVector(inter, phys, rec_boxt); } template -__device__ inline void inter2Phys(FPTYPE *phys, - const FPTYPE *inter, - const FPTYPE *boxt) { +__device__ inline void inter2Phys(FPTYPE* phys, + const FPTYPE* inter, + const FPTYPE* boxt) { tensorTransDotVector(phys, inter, boxt); } template -__device__ inline FPTYPE compute_volume(const FPTYPE *boxt) { +__device__ inline FPTYPE compute_volume(const FPTYPE* boxt) { FPTYPE volume = boxt[0 * 3 + 0] * (boxt[1 * 3 + 1] * boxt[2 * 3 + 2] - boxt[2 * 3 + 1] * boxt[1 * 3 + 2]) - boxt[0 * 3 + 1] * (boxt[1 * 3 + 0] * boxt[2 * 3 + 2] - diff --git a/source/lib/src/fmt_nlist.cc b/source/lib/src/fmt_nlist.cc index 2bf3e78e99..3965585cf8 100644 --- a/source/lib/src/fmt_nlist.cc +++ b/source/lib/src/fmt_nlist.cc @@ -18,26 +18,26 @@ struct NeighborInfo { int index; NeighborInfo() : type(0), dist(0), index(0) {} NeighborInfo(int tt, FPTYPE dd, int ii) : type(tt), dist(dd), index(ii) {} - bool operator<(const NeighborInfo &b) const { + bool operator<(const NeighborInfo& b) const { return (type < b.type || (type == b.type && (dist < b.dist || (dist == b.dist && index < b.index)))); } }; -int format_nlist_i_fill_a(std::vector &fmt_nei_idx_a, - std::vector &fmt_nei_idx_r, - const std::vector &posi, - const int &ntypes, - const std::vector &type, - const SimulationRegion ®ion, - const bool &b_pbc, - const int &i_idx, - const std::vector &nei_idx_a, - const std::vector &nei_idx_r, - const double &rcut, - const std::vector &sec_a, - const std::vector &sec_r) { +int format_nlist_i_fill_a(std::vector& fmt_nei_idx_a, + std::vector& fmt_nei_idx_r, + const std::vector& posi, + const int& ntypes, + const std::vector& type, + const SimulationRegion& region, + const bool& b_pbc, + const int& i_idx, + const std::vector& nei_idx_a, + const std::vector& nei_idx_r, + const double& rcut, + const std::vector& sec_a, + const std::vector& sec_r) { #ifdef DEBUG assert(sec_a.size() == ntypes + 1); assert(sec_r.size() == ntypes + 1); @@ -57,7 +57,7 @@ int format_nlist_i_fill_a(std::vector &fmt_nei_idx_a, sel_nei.reserve(nei_idx_a.size() + nei_idx_r.size()); for (unsigned kk = 0; kk < nei_idx.size(); ++kk) { double diff[3]; - const int &j_idx = nei_idx[kk]; + const int& j_idx = nei_idx[kk]; if (b_pbc) { region.diffNearestNeighbor(posi[j_idx * 3 + 0], posi[j_idx * 3 + 1], posi[j_idx * 3 + 2], posi[i_idx * 3 + 0], @@ -78,7 +78,7 @@ int format_nlist_i_fill_a(std::vector &fmt_nei_idx_a, std::vector nei_iter = sec_a; int overflowed = -1; for (unsigned kk = 0; kk < sel_nei.size(); ++kk) { - const int &nei_type = sel_nei[kk].type; + const int& nei_type = sel_nei[kk].type; if (nei_iter[nei_type] >= sec_a[nei_type + 1]) { int r_idx_iter = (nei_iter[nei_type]++) - sec_a[nei_type + 1] + sec_r[nei_type]; @@ -96,13 +96,13 @@ int format_nlist_i_fill_a(std::vector &fmt_nei_idx_a, } template -int format_nlist_i_cpu(std::vector &fmt_nei_idx_a, - const std::vector &posi, - const std::vector &type, - const int &i_idx, - const std::vector &nei_idx_a, - const float &rcut, - const std::vector &sec_a) { +int format_nlist_i_cpu(std::vector& fmt_nei_idx_a, + const std::vector& posi, + const std::vector& type, + const int& i_idx, + const std::vector& nei_idx_a, + const float& rcut, + const std::vector& sec_a) { fmt_nei_idx_a.resize(sec_a.back()); fill(fmt_nei_idx_a.begin(), fmt_nei_idx_a.end(), -1); @@ -115,7 +115,7 @@ int format_nlist_i_cpu(std::vector &fmt_nei_idx_a, for (unsigned kk = 0; kk < nei_idx.size(); ++kk) { // rcut is float in this function, so float rr is enough float diff[3]; - const int &j_idx = nei_idx[kk]; + const int& j_idx = nei_idx[kk]; if (type[j_idx] < 0) { continue; } @@ -132,7 +132,7 @@ int format_nlist_i_cpu(std::vector &fmt_nei_idx_a, std::vector nei_iter = sec_a; int overflowed = -1; for (unsigned kk = 0; kk < sel_nei.size(); ++kk) { - const int &nei_type = sel_nei[kk].type; + const int& nei_type = sel_nei[kk].type; if (nei_iter[nei_type] < sec_a[nei_type + 1]) { fmt_nei_idx_a[nei_iter[nei_type]++] = sel_nei[kk].index; } else { @@ -143,10 +143,10 @@ int format_nlist_i_cpu(std::vector &fmt_nei_idx_a, } template -void deepmd::format_nlist_cpu(int *nlist, - const InputNlist &in_nlist, - const FPTYPE *coord, - const int *type, +void deepmd::format_nlist_cpu(int* nlist, + const InputNlist& in_nlist, + const FPTYPE* coord, + const int* type, const int nloc, const int nall, const float rcut, @@ -165,7 +165,7 @@ void deepmd::format_nlist_cpu(int *nlist, std::copy(in_nlist.firstneigh[ii], in_nlist.firstneigh[ii] + i_num, ilist.begin()); format_nlist_i_cpu(fmt_ilist, posi_, type_, i_idx, ilist, rcut, sec); - int *cur_nlist = nlist + i_idx * nnei; + int* cur_nlist = nlist + i_idx * nnei; if (fmt_ilist.size() != nnei) { std::cerr << "FATAL: formatted nlist of i have length " << fmt_ilist.size() << " which does not match " << nnei @@ -176,37 +176,37 @@ void deepmd::format_nlist_cpu(int *nlist, } } -template int format_nlist_i_cpu(std::vector &fmt_nei_idx_a, - const std::vector &posi, - const std::vector &type, - const int &i_idx, - const std::vector &nei_idx_a, - const float &rcut, - const std::vector &sec_a); - -template int format_nlist_i_cpu(std::vector &fmt_nei_idx_a, - const std::vector &posi, - const std::vector &type, - const int &i_idx, - const std::vector &nei_idx_a, - const float &rcut, - const std::vector &sec_a); +template int format_nlist_i_cpu(std::vector& fmt_nei_idx_a, + const std::vector& posi, + const std::vector& type, + const int& i_idx, + const std::vector& nei_idx_a, + const float& rcut, + const std::vector& sec_a); + +template int format_nlist_i_cpu(std::vector& fmt_nei_idx_a, + const std::vector& posi, + const std::vector& type, + const int& i_idx, + const std::vector& nei_idx_a, + const float& rcut, + const std::vector& sec_a); template void deepmd::format_nlist_cpu( - int *nlist, - const deepmd::InputNlist &in_nlist, - const double *coord, - const int *type, + int* nlist, + const deepmd::InputNlist& in_nlist, + const double* coord, + const int* type, const int nloc, const int nall, const float rcut, const std::vector sec); template void deepmd::format_nlist_cpu( - int *nlist, - const deepmd::InputNlist &in_nlist, - const float *coord, - const int *type, + int* nlist, + const deepmd::InputNlist& in_nlist, + const float* coord, + const int* type, const int nloc, const int nall, const float rcut, diff --git a/source/lib/src/gpu/coord.cu b/source/lib/src/gpu/coord.cu index 52ec9ff09d..5030f67caf 100644 --- a/source/lib/src/gpu/coord.cu +++ b/source/lib/src/gpu/coord.cu @@ -2,22 +2,22 @@ #include "device.h" #include "region.cuh" -__device__ inline int collapse_index(const int *idx, const int *size) { +__device__ inline int collapse_index(const int* idx, const int* size) { return (idx[0] * size[1] + idx[1]) * size[2] + idx[2]; } __device__ inline void index_recover(const int in_idx, - const int *size, - int *idx) { + const int* size, + int* idx) { idx[2] = in_idx % size[2]; idx[1] = int(in_idx / size[2]) % size[1]; idx[0] = int(int(in_idx / size[2]) / size[1]); } -__device__ inline void idx_addshift(int *idx, const int *shift) { +__device__ inline void idx_addshift(int* idx, const int* shift) { for (int dd = 0; dd < 3; dd++) { idx[dd] += shift[dd]; } } -__device__ inline void idx_unshift(int *idx, const int *shift) { +__device__ inline void idx_unshift(int* idx, const int* shift) { for (int dd = 0; dd < 3; dd++) { idx[dd] -= shift[dd]; } @@ -42,9 +42,9 @@ __device__ inline double _fmod(double x, double y) { return fmod(x, y); } __device__ inline float _fmod(float x, float y) { return fmodf(x, y); } template -__global__ void normalize_one(FPTYPE *out_c, - const FPTYPE *boxt, - const FPTYPE *rec_boxt, +__global__ void normalize_one(FPTYPE* out_c, + const FPTYPE* boxt, + const FPTYPE* rec_boxt, const int nall) { // <<>> int idy = blockIdx.x * blockDim.x + threadIdx.x; @@ -63,14 +63,14 @@ __global__ void normalize_one(FPTYPE *out_c, } template -__global__ void _fill_idx_cellmap(int *idx_cellmap, - int *idx_cellmap_noshift, - const FPTYPE *in_c, - const FPTYPE *rec_boxt, - const int *nat_stt, - const int *nat_end, - const int *ext_stt, - const int *ext_end, +__global__ void _fill_idx_cellmap(int* idx_cellmap, + int* idx_cellmap_noshift, + const FPTYPE* in_c, + const FPTYPE* rec_boxt, + const int* nat_stt, + const int* nat_end, + const int* ext_stt, + const int* ext_end, const int nloc) { int idy = blockIdx.x * blockDim.x + threadIdx.x; int ext_ncell[3]; @@ -107,9 +107,9 @@ __global__ void _fill_idx_cellmap(int *idx_cellmap, } } -__global__ void _fill_loc_cellnum_map(int *temp_idx_order, - int *loc_cellnum_map, - const int *idx_cellmap_noshift, +__global__ void _fill_loc_cellnum_map(int* temp_idx_order, + int* loc_cellnum_map, + const int* idx_cellmap_noshift, const int nloc, const int loc_cellnum) { int idy = blockIdx.x * blockDim.x + threadIdx.x; @@ -125,15 +125,15 @@ __global__ void _fill_loc_cellnum_map(int *temp_idx_order, } } -__global__ void _fill_total_cellnum_map(int *total_cellnum_map, - int *mask_cellnum_map, - int *cell_map, - int *cell_shift_map, - const int *nat_stt, - const int *nat_end, - const int *ext_stt, - const int *ext_end, - const int *loc_cellnum_map, +__global__ void _fill_total_cellnum_map(int* total_cellnum_map, + int* mask_cellnum_map, + int* cell_map, + int* cell_shift_map, + const int* nat_stt, + const int* nat_end, + const int* ext_stt, + const int* ext_end, + const int* loc_cellnum_map, const int total_cellnum) { int idy = blockIdx.x * blockDim.x + threadIdx.x; int ext_ncell[3]; @@ -145,7 +145,7 @@ __global__ void _fill_total_cellnum_map(int *total_cellnum_map, idx_orig_shift[dd] = nat_stt[dd] - ext_stt[dd]; } if (idy < total_cellnum) { - int *shift = cell_shift_map + idy * 3; + int* shift = cell_shift_map + idy * 3; int idx[3]; index_recover(idy, ext_ncell, idx); idx_unshift(idx, idx_orig_shift); @@ -169,36 +169,36 @@ __global__ void _fill_total_cellnum_map(int *total_cellnum_map, } } -__global__ void _build_loc_clist(int *clist, - const int *idx_cellmap, - const int *idx_order, - const int *sec_num_map, +__global__ void _build_loc_clist(int* clist, + const int* idx_cellmap, + const int* idx_order, + const int* sec_num_map, const int nloc) { int idy = blockIdx.x * blockDim.x + threadIdx.x; if (idy >= nloc) { return; } int cell_idx = idx_cellmap[idy]; - int *clist_row = clist + sec_num_map[cell_idx]; + int* clist_row = clist + sec_num_map[cell_idx]; clist_row[idx_order[idy]] = idy; } template -__global__ void _copy_coord(FPTYPE *out_c, - int *out_t, - int *mapping, - const FPTYPE *in_c, - const int *in_t, - const int *cell_map, - const int *cell_shift_map, - const int *sec_loc_cellnum_map, - const int *sec_total_cellnum_map, - const int *loc_clist, +__global__ void _copy_coord(FPTYPE* out_c, + int* out_t, + int* mapping, + const FPTYPE* in_c, + const int* in_t, + const int* cell_map, + const int* cell_shift_map, + const int* sec_loc_cellnum_map, + const int* sec_total_cellnum_map, + const int* loc_clist, const int nloc, const int nall, const int total_cellnum, - const FPTYPE *boxt, - const FPTYPE *rec_boxt) { + const FPTYPE* boxt, + const FPTYPE* rec_boxt) { int idy = blockIdx.x * blockDim.x + threadIdx.x; if (idy >= nall) { return; @@ -241,26 +241,26 @@ __global__ void _copy_coord(FPTYPE *out_c, } template -void compute_int_data(int *int_data, - const FPTYPE *in_c, - const int *cell_info, - const deepmd::Region ®ion, +void compute_int_data(int* int_data, + const FPTYPE* in_c, + const int* cell_info, + const deepmd::Region& region, const int nloc, const int loc_cellnum, const int total_cellnum) { - int *idx_cellmap = int_data; - int *idx_cellmap_noshift = idx_cellmap + nloc; - int *temp_idx_order = idx_cellmap_noshift + nloc; - int *loc_cellnum_map = temp_idx_order + nloc; - int *total_cellnum_map = loc_cellnum_map + loc_cellnum; - int *mask_cellnum_map = total_cellnum_map + total_cellnum; - int *cell_map = mask_cellnum_map + total_cellnum; - int *cell_shift_map = cell_map + total_cellnum; - const int *nat_stt = cell_info; - const int *nat_end = cell_info + 3; - const int *ext_stt = cell_info + 6; - const int *ext_end = cell_info + 9; - const FPTYPE *rec_boxt = region.rec_boxt; + int* idx_cellmap = int_data; + int* idx_cellmap_noshift = idx_cellmap + nloc; + int* temp_idx_order = idx_cellmap_noshift + nloc; + int* loc_cellnum_map = temp_idx_order + nloc; + int* total_cellnum_map = loc_cellnum_map + loc_cellnum; + int* mask_cellnum_map = total_cellnum_map + total_cellnum; + int* cell_map = mask_cellnum_map + total_cellnum; + int* cell_shift_map = cell_map + total_cellnum; + const int* nat_stt = cell_info; + const int* nat_end = cell_info + 3; + const int* ext_stt = cell_info + 6; + const int* ext_end = cell_info + 9; + const FPTYPE* rec_boxt = region.rec_boxt; const int nblock_loc = (nloc + TPB - 1) / TPB; _fill_idx_cellmap<<>>(idx_cellmap, idx_cellmap_noshift, in_c, @@ -283,17 +283,17 @@ void compute_int_data(int *int_data, DPErrcheck(gpuDeviceSynchronize()); } -void build_loc_clist(int *int_data, +void build_loc_clist(int* int_data, const int nloc, const int loc_cellnum, const int total_cellnum) { const int nblock = (nloc + TPB - 1) / TPB; - const int *idx_cellmap_noshift = int_data + nloc; - const int *temp_idx_order = idx_cellmap_noshift + nloc; - const int *sec_loc_cellnum_map = temp_idx_order + nloc + loc_cellnum + + const int* idx_cellmap_noshift = int_data + nloc; + const int* temp_idx_order = idx_cellmap_noshift + nloc; + const int* sec_loc_cellnum_map = temp_idx_order + nloc + loc_cellnum + 2 * total_cellnum + total_cellnum + 3 * total_cellnum; - int *loc_clist = int_data + nloc * 3 + loc_cellnum + total_cellnum * 3 + + int* loc_clist = int_data + nloc * 3 + loc_cellnum + total_cellnum * 3 + total_cellnum * 3 + loc_cellnum + 1 + total_cellnum + 1; _build_loc_clist<<>>(loc_clist, idx_cellmap_noshift, temp_idx_order, sec_loc_cellnum_map, nloc); @@ -302,26 +302,26 @@ void build_loc_clist(int *int_data, } template -void copy_coord(FPTYPE *out_c, - int *out_t, - int *mapping, - const int *int_data, - const FPTYPE *in_c, - const int *in_t, +void copy_coord(FPTYPE* out_c, + int* out_t, + int* mapping, + const int* int_data, + const FPTYPE* in_c, + const int* in_t, const int nloc, const int nall, const int loc_cellnum, const int total_cellnum, - const deepmd::Region ®ion) { + const deepmd::Region& region) { const int nblock = (nall + TPB - 1) / TPB; - const int *cell_map = int_data + 3 * nloc + loc_cellnum + 2 * total_cellnum; - const int *cell_shift_map = cell_map + total_cellnum; - const int *sec_loc_cellnum_map = cell_shift_map + 3 * total_cellnum; - const int *sec_total_cellnum_map = sec_loc_cellnum_map + loc_cellnum + 1; - const int *loc_clist = sec_total_cellnum_map + total_cellnum + 1; + const int* cell_map = int_data + 3 * nloc + loc_cellnum + 2 * total_cellnum; + const int* cell_shift_map = cell_map + total_cellnum; + const int* sec_loc_cellnum_map = cell_shift_map + 3 * total_cellnum; + const int* sec_total_cellnum_map = sec_loc_cellnum_map + loc_cellnum + 1; + const int* loc_clist = sec_total_cellnum_map + total_cellnum + 1; - const FPTYPE *boxt = region.boxt; - const FPTYPE *rec_boxt = region.rec_boxt; + const FPTYPE* boxt = region.boxt; + const FPTYPE* rec_boxt = region.rec_boxt; _copy_coord<<>>(out_c, out_t, mapping, in_c, in_t, cell_map, cell_shift_map, sec_loc_cellnum_map, sec_total_cellnum_map, loc_clist, nloc, nall, @@ -332,13 +332,13 @@ void copy_coord(FPTYPE *out_c, namespace deepmd { template -void normalize_coord_gpu(FPTYPE *coord, +void normalize_coord_gpu(FPTYPE* coord, const int natom, - const Region ®ion) { + const Region& region) { DPErrcheck(gpuGetLastError()); DPErrcheck(gpuDeviceSynchronize()); - const FPTYPE *boxt = region.boxt; - const FPTYPE *rec_boxt = region.rec_boxt; + const FPTYPE* boxt = region.boxt; + const FPTYPE* rec_boxt = region.rec_boxt; const int nblock = (natom + TPB - 1) / TPB; normalize_one<<>>(coord, boxt, rec_boxt, natom); DPErrcheck(gpuGetLastError()); @@ -349,35 +349,35 @@ void normalize_coord_gpu(FPTYPE *coord, // memory):idx_map,idx_map_noshift,temp_idx_order,loc_cellnum_map,total_cellnum_map,mask_cellnum_map, // cell_map,cell_shift_map,sec_loc_cellnum_map,sec_total_cellnum_map,loc_clist template -int copy_coord_gpu(FPTYPE *out_c, - int *out_t, - int *mapping, - int *nall, - int *int_data, - const FPTYPE *in_c, - const int *in_t, - const int &nloc, - const int &mem_nall, - const int &loc_cellnum, - const int &total_cellnum, - const int *cell_info, - const Region ®ion) { +int copy_coord_gpu(FPTYPE* out_c, + int* out_t, + int* mapping, + int* nall, + int* int_data, + const FPTYPE* in_c, + const int* in_t, + const int& nloc, + const int& mem_nall, + const int& loc_cellnum, + const int& total_cellnum, + const int* cell_info, + const Region& region) { DPErrcheck(gpuGetLastError()); DPErrcheck(gpuDeviceSynchronize()); compute_int_data(int_data, in_c, cell_info, region, nloc, loc_cellnum, total_cellnum); - int *int_data_cpu = new int + int* int_data_cpu = new int [loc_cellnum + 2 * total_cellnum + loc_cellnum + 1 + total_cellnum + 1]; // loc_cellnum_map,total_cellnum_map,mask_cellnum_map,sec_loc_cellnum_map,sec_total_cellnum_map DPErrcheck(gpuMemcpy(int_data_cpu, int_data + 3 * nloc, sizeof(int) * (loc_cellnum + 2 * total_cellnum), gpuMemcpyDeviceToHost)); DPErrcheck(gpuGetLastError()); - int *loc_cellnum_map = int_data_cpu; - int *total_cellnum_map = loc_cellnum_map + loc_cellnum; - int *mask_cellnum_map = total_cellnum_map + total_cellnum; - int *sec_loc_cellnum_map = mask_cellnum_map + total_cellnum; - int *sec_total_cellnum_map = sec_loc_cellnum_map + loc_cellnum + 1; + int* loc_cellnum_map = int_data_cpu; + int* total_cellnum_map = loc_cellnum_map + loc_cellnum; + int* mask_cellnum_map = total_cellnum_map + total_cellnum; + int* sec_loc_cellnum_map = mask_cellnum_map + total_cellnum; + int* sec_total_cellnum_map = sec_loc_cellnum_map + loc_cellnum + 1; sec_loc_cellnum_map[0] = 0; sec_total_cellnum_map[0] = nloc; int max_cell = 0; @@ -412,36 +412,36 @@ int copy_coord_gpu(FPTYPE *out_c, return 0; } -template void normalize_coord_gpu(float *coord, +template void normalize_coord_gpu(float* coord, const int natom, - const Region ®ion); -template void normalize_coord_gpu(double *coord, + const Region& region); +template void normalize_coord_gpu(double* coord, const int natom, - const Region ®ion); -template int copy_coord_gpu(float *out_c, - int *out_t, - int *mapping, - int *nall, - int *int_data, - const float *in_c, - const int *in_t, - const int &nloc, - const int &mem_nall, - const int &loc_cellnum, - const int &total_cellnum, - const int *cell_info, - const Region ®ion); -template int copy_coord_gpu(double *out_c, - int *out_t, - int *mapping, - int *nall, - int *int_data, - const double *in_c, - const int *in_t, - const int &nloc, - const int &mem_nall, - const int &loc_cellnum, - const int &total_cellnum, - const int *cell_info, - const Region ®ion); + const Region& region); +template int copy_coord_gpu(float* out_c, + int* out_t, + int* mapping, + int* nall, + int* int_data, + const float* in_c, + const int* in_t, + const int& nloc, + const int& mem_nall, + const int& loc_cellnum, + const int& total_cellnum, + const int* cell_info, + const Region& region); +template int copy_coord_gpu(double* out_c, + int* out_t, + int* mapping, + int* nall, + int* int_data, + const double* in_c, + const int* in_t, + const int& nloc, + const int& mem_nall, + const int& loc_cellnum, + const int& total_cellnum, + const int* cell_info, + const Region& region); } // namespace deepmd diff --git a/source/lib/src/gpu/cudart/cudart_stub.cc b/source/lib/src/gpu/cudart/cudart_stub.cc index cfbabd6f5e..222cdeb942 100644 --- a/source/lib/src/gpu/cudart/cudart_stub.cc +++ b/source/lib/src/gpu/cudart/cudart_stub.cc @@ -16,12 +16,12 @@ static cudaError_t DP_CudartGetSymbolNotFoundError() { return cudaErrorSharedObjectSymbolNotFound; } -void *DP_cudart_dlopen(char *libname) { - static auto handle = [](std::string libname) -> void * { +void* DP_cudart_dlopen(char* libname) { + static auto handle = [](std::string libname) -> void* { #if defined(_WIN32) - void *dso_handle = LoadLibrary(libname.c_str()); + void* dso_handle = LoadLibrary(libname.c_str()); #else - void *dso_handle = dlopen(libname.c_str(), RTLD_NOW | RTLD_LOCAL); + void* dso_handle = dlopen(libname.c_str(), RTLD_NOW | RTLD_LOCAL); #endif if (!dso_handle) { std::cerr << "DeePMD-kit: Cannot find " << libname << std::endl; @@ -37,15 +37,15 @@ void *DP_cudart_dlopen(char *libname) { return handle; } -void *DP_cudart_dlsym(void *handle, const char *sym_name) { +void* DP_cudart_dlsym(void* handle, const char* sym_name) { // check if the handle is nullptr, if so, return a function that // returns cudaErrorSharedObjectSymbolNotFound if (!handle) { - return reinterpret_cast(&DP_CudartGetSymbolNotFoundError); + return reinterpret_cast(&DP_CudartGetSymbolNotFoundError); } - void *symbol = dlsym(handle, sym_name); + void* symbol = dlsym(handle, sym_name); if (!symbol) { - return reinterpret_cast(&DP_CudartGetSymbolNotFoundError); + return reinterpret_cast(&DP_CudartGetSymbolNotFoundError); } return symbol; }; diff --git a/source/lib/src/gpu/neighbor_list.cu b/source/lib/src/gpu/neighbor_list.cu index fc4e784915..70bc406f5a 100644 --- a/source/lib/src/gpu/neighbor_list.cu +++ b/source/lib/src/gpu/neighbor_list.cu @@ -28,9 +28,9 @@ struct parallel_prefix_scan_op { }; template -__global__ void parallel_prefix_scan(int *numneigh, - int *nei_order, - const int *temp_nlist, +__global__ void parallel_prefix_scan(int* numneigh, + int* nei_order, + const int* temp_nlist, const int mem_size, const int nloc, const int nall) { @@ -67,14 +67,14 @@ __global__ void parallel_prefix_scan(int *numneigh, } template -__device__ inline FPTYPE dev_dot(FPTYPE *arr1, FPTYPE *arr2) { +__device__ inline FPTYPE dev_dot(FPTYPE* arr1, FPTYPE* arr2) { return arr1[0] * arr2[0] + arr1[1] * arr2[1] + arr1[2] * arr2[2]; } template -__global__ void build_nlist(int *ilist, - int *temp_nlist, - const FPTYPE *c_cpy, +__global__ void build_nlist(int* ilist, + int* temp_nlist, + const FPTYPE* c_cpy, const FPTYPE rcut2, const int nloc, const int nall, @@ -82,12 +82,12 @@ __global__ void build_nlist(int *ilist, const unsigned int atom_idx = blockIdx.x; const unsigned int neighbor_idx = blockIdx.y * blockDim.y + threadIdx.y; if (neighbor_idx < nall) { - int *neighbor_row = temp_nlist + atom_idx * mem_size; + int* neighbor_row = temp_nlist + atom_idx * mem_size; if (neighbor_idx == atom_idx) { ilist[atom_idx] = atom_idx; } else { - const FPTYPE *ccoord = c_cpy + atom_idx * 3; - const FPTYPE *ncoord = c_cpy + neighbor_idx * 3; + const FPTYPE* ccoord = c_cpy + atom_idx * 3; + const FPTYPE* ncoord = c_cpy + neighbor_idx * 3; FPTYPE diff[3]; for (int kk = 0; kk < 3; kk++) { diff[kk] = ccoord[kk] - ncoord[kk]; @@ -100,16 +100,16 @@ __global__ void build_nlist(int *ilist, } } -__global__ void fill_nlist(int **firstneigh, - const int *temp_nlist, - const int *nei_order, +__global__ void fill_nlist(int** firstneigh, + const int* temp_nlist, + const int* nei_order, const int mem_size, const int nall) { const unsigned int atom_idx = blockIdx.x; const unsigned int neighbor_idx = blockIdx.y * blockDim.y + threadIdx.y; if (neighbor_idx < nall) { - const int *in_row = temp_nlist + atom_idx * mem_size; - int *out_row = firstneigh[atom_idx]; + const int* in_row = temp_nlist + atom_idx * mem_size; + int* out_row = firstneigh[atom_idx]; int nei = in_row[neighbor_idx]; if (nei != -1) { out_row[nei_order[atom_idx * mem_size + neighbor_idx]] = nei; @@ -117,8 +117,8 @@ __global__ void fill_nlist(int **firstneigh, } } -__global__ void map_nlist(int *nlist, - const int *nlist_map, +__global__ void map_nlist(int* nlist, + const int* nlist_map, const int nloc, const int nnei) { int atom_idx = blockIdx.x; @@ -133,11 +133,11 @@ __global__ void map_nlist(int *nlist, } } -__global__ void map_nei_info(int *nlist, - int *ntype, - bool *nmask, - const int *type, - const int *nlist_map, +__global__ void map_nei_info(int* nlist, + int* ntype, + bool* nmask, + const int* type, + const int* nlist_map, const int nloc, const int nnei, const int ntypes) { @@ -159,10 +159,10 @@ __global__ void map_nei_info(int *nlist, } } -__global__ void map_nei_info_noconvert(int *nlist, - int *ntype, - bool *nmask, - const int *type, +__global__ void map_nei_info_noconvert(int* nlist, + int* ntype, + bool* nmask, + const int* type, const int nloc, const int nnei, const int ntypes) { @@ -183,26 +183,26 @@ __global__ void map_nei_info_noconvert(int *nlist, namespace deepmd { template -int build_nlist_gpu(InputNlist &nlist, - int *max_list_size, - int *nlist_data, - const FPTYPE *c_cpy, - const int &nloc, - const int &nall, - const int &mem_size, - const float &rcut) { +int build_nlist_gpu(InputNlist& nlist, + int* max_list_size, + int* nlist_data, + const FPTYPE* c_cpy, + const int& nloc, + const int& nall, + const int& mem_size, + const float& rcut) { if (mem_size < nall) { return 1; } DPErrcheck(gpuGetLastError()); DPErrcheck(gpuDeviceSynchronize()); const int nblock = (nall + TPB - 1) / TPB; - int *ilist = nlist.ilist; - int *numneigh = nlist.numneigh; - int **firstneigh = nlist.firstneigh; + int* ilist = nlist.ilist; + int* numneigh = nlist.numneigh; + int** firstneigh = nlist.firstneigh; DPErrcheck(gpuMemset(nlist_data, -1, sizeof(int) * 2 * nloc * mem_size)); - int *temp_nlist = nlist_data; // nloc*mem_size - int *nei_order = temp_nlist + nloc * mem_size; + int* temp_nlist = nlist_data; // nloc*mem_size + int* nei_order = temp_nlist + nloc * mem_size; nlist.inum = nloc; FPTYPE rcut2 = rcut * rcut; @@ -220,7 +220,7 @@ int build_nlist_gpu(InputNlist &nlist, mem_size, nall); DPErrcheck(gpuGetLastError()); DPErrcheck(gpuDeviceSynchronize()); - int *numneigh_host = new int[nloc]; + int* numneigh_host = new int[nloc]; DPErrcheck(gpuMemcpy(numneigh_host, numneigh, sizeof(int) * nloc, gpuMemcpyDeviceToHost)); int max_nei = 0; @@ -234,8 +234,8 @@ int build_nlist_gpu(InputNlist &nlist, return 0; } -void use_nlist_map(int *nlist, - const int *nlist_map, +void use_nlist_map(int* nlist, + const int* nlist_map, const int nloc, const int nnei) { DPErrcheck(gpuGetLastError()); @@ -248,11 +248,11 @@ void use_nlist_map(int *nlist, DPErrcheck(gpuDeviceSynchronize()); } -void use_nei_info_gpu(int *nlist, - int *ntype, - bool *nmask, - const int *type, - const int *nlist_map, +void use_nei_info_gpu(int* nlist, + int* ntype, + bool* nmask, + const int* type, + const int* nlist_map, const int nloc, const int nnei, const int ntypes, @@ -275,25 +275,25 @@ void use_nei_info_gpu(int *nlist, DPErrcheck(gpuDeviceSynchronize()); } -template int build_nlist_gpu(InputNlist &nlist, - int *max_list_size, - int *nlist_data, - const float *c_cpy, - const int &nloc, - const int &nall, - const int &mem_size, - const float &rcut); -template int build_nlist_gpu(InputNlist &nlist, - int *max_list_size, - int *nlist_data, - const double *c_cpy, - const int &nloc, - const int &nall, - const int &mem_size, - const float &rcut); +template int build_nlist_gpu(InputNlist& nlist, + int* max_list_size, + int* nlist_data, + const float* c_cpy, + const int& nloc, + const int& nall, + const int& mem_size, + const float& rcut); +template int build_nlist_gpu(InputNlist& nlist, + int* max_list_size, + int* nlist_data, + const double* c_cpy, + const int& nloc, + const int& nall, + const int& mem_size, + const float& rcut); -__global__ void map_filter_ftype(int *ftype_out, - const int *ftype_in, +__global__ void map_filter_ftype(int* ftype_out, + const int* ftype_in, const int nloc) { int ii = blockIdx.x * blockDim.x + threadIdx.x; if (ii < nloc) { @@ -301,7 +301,7 @@ __global__ void map_filter_ftype(int *ftype_out, } } -void filter_ftype_gpu(int *ftype_out, const int *ftype_in, const int nloc) { +void filter_ftype_gpu(int* ftype_out, const int* ftype_in, const int nloc) { DPErrcheck(gpuGetLastError()); DPErrcheck(gpuDeviceSynchronize()); int nblock = (nloc + TPB - 1) / TPB; diff --git a/source/lib/src/gpu/region.cu b/source/lib/src/gpu/region.cu index 849eecfc3e..45fb8a2802 100644 --- a/source/lib/src/gpu/region.cu +++ b/source/lib/src/gpu/region.cu @@ -3,30 +3,30 @@ #include "region.h" template -__global__ void _phys2Inter(FPTYPE *inter, - const FPTYPE *phys, - const FPTYPE *rec_boxt) { +__global__ void _phys2Inter(FPTYPE* inter, + const FPTYPE* phys, + const FPTYPE* rec_boxt) { phys2Inter(inter, phys, rec_boxt); } template -__global__ void _inter2Phys(FPTYPE *phys, - const FPTYPE *inter, - const FPTYPE *boxt) { +__global__ void _inter2Phys(FPTYPE* phys, + const FPTYPE* inter, + const FPTYPE* boxt) { inter2Phys(phys, inter, boxt); } template -__global__ void _compute_volume(FPTYPE *volume, const FPTYPE *boxt) { +__global__ void _compute_volume(FPTYPE* volume, const FPTYPE* boxt) { volume[0] = compute_volume(boxt); } namespace deepmd { // only for unittest template -void convert_to_inter_gpu(FPTYPE *ri, - const Region ®ion, - const FPTYPE *rp) { +void convert_to_inter_gpu(FPTYPE* ri, + const Region& region, + const FPTYPE* rp) { DPErrcheck(gpuGetLastError()); DPErrcheck(gpuDeviceSynchronize()); _phys2Inter<<<1, 1>>>(ri, rp, region.rec_boxt); @@ -35,9 +35,9 @@ void convert_to_inter_gpu(FPTYPE *ri, } template -void convert_to_phys_gpu(FPTYPE *rp, - const Region ®ion, - const FPTYPE *ri) { +void convert_to_phys_gpu(FPTYPE* rp, + const Region& region, + const FPTYPE* ri) { DPErrcheck(gpuGetLastError()); DPErrcheck(gpuDeviceSynchronize()); _inter2Phys<<<1, 1>>>(rp, ri, region.boxt); @@ -46,7 +46,7 @@ void convert_to_phys_gpu(FPTYPE *rp, } template -void volume_gpu(FPTYPE *volume, const Region ®ion) { +void volume_gpu(FPTYPE* volume, const Region& region) { DPErrcheck(gpuGetLastError()); DPErrcheck(gpuDeviceSynchronize()); _compute_volume<<<1, 1>>>(volume, region.boxt); @@ -54,18 +54,18 @@ void volume_gpu(FPTYPE *volume, const Region ®ion) { DPErrcheck(gpuDeviceSynchronize()); } -template void convert_to_inter_gpu(float *ri, - const Region ®ion, - const float *rp); -template void convert_to_inter_gpu(double *ri, - const Region ®ion, - const double *rp); -template void convert_to_phys_gpu(float *rp, - const Region ®ion, - const float *ri); -template void convert_to_phys_gpu(double *rp, - const Region ®ion, - const double *ri); -template void volume_gpu(float *volume, const Region ®ion); -template void volume_gpu(double *volume, const Region ®ion); +template void convert_to_inter_gpu(float* ri, + const Region& region, + const float* rp); +template void convert_to_inter_gpu(double* ri, + const Region& region, + const double* rp); +template void convert_to_phys_gpu(float* rp, + const Region& region, + const float* ri); +template void convert_to_phys_gpu(double* rp, + const Region& region, + const double* ri); +template void volume_gpu(float* volume, const Region& region); +template void volume_gpu(double* volume, const Region& region); } // namespace deepmd diff --git a/source/lib/src/pairwise.cc b/source/lib/src/pairwise.cc index f5b21d9856..b4a68b00b7 100644 --- a/source/lib/src/pairwise.cc +++ b/source/lib/src/pairwise.cc @@ -8,7 +8,7 @@ #include "errors.h" template -std::vector sort_indexes(const std::vector &v) { +std::vector sort_indexes(const std::vector& v) { // https://stackoverflow.com/a/12399290/9567349 // by Lukasz Wiklendt under CC BY-SA 4.0 std::vector idx(v.size()); @@ -18,8 +18,8 @@ std::vector sort_indexes(const std::vector &v) { return idx; } -void deepmd::group_atoms_cpu(std::vector> &fragments, - const std::vector &idxs) { +void deepmd::group_atoms_cpu(std::vector>& fragments, + const std::vector& idxs) { int natoms = idxs.size(); // sort idxs std::vector idxs_idx = sort_indexes(idxs); @@ -41,15 +41,15 @@ void deepmd::group_atoms_cpu(std::vector> &fragments, } void deepmd::dprc_pairwise_map_cpu( - std::vector &forward_qm_map, - std::vector &backward_qm_map, - std::vector &forward_qmmm_map, - std::vector &backward_qmmm_map, - int &nloc_qm, - int &nloc_qmmm, - int &nall_qm, - int &nall_qmmm, - const std::vector> &fragments, + std::vector& forward_qm_map, + std::vector& backward_qm_map, + std::vector& forward_qmmm_map, + std::vector& backward_qmmm_map, + int& nloc_qm, + int& nloc_qmmm, + int& nall_qm, + int& nall_qmmm, + const std::vector>& fragments, const int nloc, const int nall) { int nfragments = fragments.size(); diff --git a/source/lib/src/prod_env_mat.cc b/source/lib/src/prod_env_mat.cc index 81984c78e4..302fac4bc9 100644 --- a/source/lib/src/prod_env_mat.cc +++ b/source/lib/src/prod_env_mat.cc @@ -12,22 +12,22 @@ using namespace deepmd; template -void deepmd::prod_env_mat_a_cpu(FPTYPE *em, - FPTYPE *em_deriv, - FPTYPE *rij, - int *nlist, - const FPTYPE *coord, - const int *type, - const InputNlist &inlist, +void deepmd::prod_env_mat_a_cpu(FPTYPE* em, + FPTYPE* em_deriv, + FPTYPE* rij, + int* nlist, + const FPTYPE* coord, + const int* type, + const InputNlist& inlist, const int max_nbor_size, - const FPTYPE *avg, - const FPTYPE *std, + const FPTYPE* avg, + const FPTYPE* std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec, - const int *f_type) { + const int* f_type) { if (f_type == NULL) { f_type = type; } @@ -108,16 +108,16 @@ void deepmd::prod_env_mat_a_cpu(FPTYPE *em, } template -void deepmd::prod_env_mat_r_cpu(FPTYPE *em, - FPTYPE *em_deriv, - FPTYPE *rij, - int *nlist, - const FPTYPE *coord, - const int *type, - const InputNlist &inlist, +void deepmd::prod_env_mat_r_cpu(FPTYPE* em, + FPTYPE* em_deriv, + FPTYPE* rij, + int* nlist, + const FPTYPE* coord, + const int* type, + const InputNlist& inlist, const int max_nbor_size, - const FPTYPE *avg, - const FPTYPE *std, + const FPTYPE* avg, + const FPTYPE* std, const int nloc, const int nall, const float rcut, @@ -191,66 +191,66 @@ void deepmd::prod_env_mat_r_cpu(FPTYPE *em, } } -template void deepmd::prod_env_mat_a_cpu(double *em, - double *em_deriv, - double *rij, - int *nlist, - const double *coord, - const int *type, - const InputNlist &inlist, +template void deepmd::prod_env_mat_a_cpu(double* em, + double* em_deriv, + double* rij, + int* nlist, + const double* coord, + const int* type, + const InputNlist& inlist, const int max_nbor_size, - const double *avg, - const double *std, + const double* avg, + const double* std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec, - const int *f_type); + const int* f_type); -template void deepmd::prod_env_mat_a_cpu(float *em, - float *em_deriv, - float *rij, - int *nlist, - const float *coord, - const int *type, - const InputNlist &inlist, +template void deepmd::prod_env_mat_a_cpu(float* em, + float* em_deriv, + float* rij, + int* nlist, + const float* coord, + const int* type, + const InputNlist& inlist, const int max_nbor_size, - const float *avg, - const float *std, + const float* avg, + const float* std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec, - const int *f_type); + const int* f_type); -template void deepmd::prod_env_mat_r_cpu(double *em, - double *em_deriv, - double *rij, - int *nlist, - const double *coord, - const int *type, - const InputNlist &inlist, +template void deepmd::prod_env_mat_r_cpu(double* em, + double* em_deriv, + double* rij, + int* nlist, + const double* coord, + const int* type, + const InputNlist& inlist, const int max_nbor_size, - const double *avg, - const double *std, + const double* avg, + const double* std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec); -template void deepmd::prod_env_mat_r_cpu(float *em, - float *em_deriv, - float *rij, - int *nlist, - const float *coord, - const int *type, - const InputNlist &inlist, +template void deepmd::prod_env_mat_r_cpu(float* em, + float* em_deriv, + float* rij, + int* nlist, + const float* coord, + const int* type, + const InputNlist& inlist, const int max_nbor_size, - const float *avg, - const float *std, + const float* avg, + const float* std, const int nloc, const int nall, const float rcut, @@ -258,17 +258,17 @@ template void deepmd::prod_env_mat_r_cpu(float *em, const std::vector sec); #if GOOGLE_CUDA || TENSORFLOW_USE_ROCM -void deepmd::env_mat_nbor_update(InputNlist &inlist, - InputNlist &gpu_inlist, - int &max_nbor_size, - int *&nbor_list_dev, - const int *mesh, +void deepmd::env_mat_nbor_update(InputNlist& inlist, + InputNlist& gpu_inlist, + int& max_nbor_size, + int*& nbor_list_dev, + const int* mesh, const int size) { - int *mesh_host = new int[size]; + int* mesh_host = new int[size]; memcpy_device_to_host(mesh, mesh_host, size); - memcpy(&inlist.ilist, 4 + mesh_host, sizeof(int *)); - memcpy(&inlist.numneigh, 8 + mesh_host, sizeof(int *)); - memcpy(&inlist.firstneigh, 12 + mesh_host, sizeof(int **)); + memcpy(&inlist.ilist, 4 + mesh_host, sizeof(int*)); + memcpy(&inlist.numneigh, 8 + mesh_host, sizeof(int*)); + memcpy(&inlist.firstneigh, 12 + mesh_host, sizeof(int**)); const int ago = mesh_host[0]; if (ago == 0 || gpu_inlist.inum < inlist.inum) { const int inum = inlist.inum; @@ -306,7 +306,7 @@ void deepmd::env_mat_nbor_update(InputNlist &inlist, // copy nbor list from host to the device std::vector nbor_list_host(static_cast(inum) * max_nbor_size, 0); - int **_firstneigh = (int **)malloc(sizeof(int *) * inum); + int** _firstneigh = (int**)malloc(sizeof(int*) * inum); for (int ii = 0; ii < inum; ii++) { _firstneigh[ii] = nbor_list_dev + ii * max_nbor_size; for (int jj = 0; jj < inlist.numneigh[ii]; jj++) { diff --git a/source/lib/src/prod_env_mat_nvnmd.cc b/source/lib/src/prod_env_mat_nvnmd.cc index d7d98b71d5..a8bf5ce29e 100644 --- a/source/lib/src/prod_env_mat_nvnmd.cc +++ b/source/lib/src/prod_env_mat_nvnmd.cc @@ -43,22 +43,22 @@ using namespace deepmd; */ template -void deepmd::prod_env_mat_a_nvnmd_quantize_cpu(FPTYPE *em, - FPTYPE *em_deriv, - FPTYPE *rij, - int *nlist, - const FPTYPE *coord, - const int *type, - const InputNlist &inlist, +void deepmd::prod_env_mat_a_nvnmd_quantize_cpu(FPTYPE* em, + FPTYPE* em_deriv, + FPTYPE* rij, + int* nlist, + const FPTYPE* coord, + const int* type, + const InputNlist& inlist, const int max_nbor_size, - const FPTYPE *avg, - const FPTYPE *std, + const FPTYPE* avg, + const FPTYPE* std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec, - const int *f_type) { + const int* f_type) { if (f_type == NULL) { f_type = type; } @@ -143,40 +143,40 @@ void deepmd::prod_env_mat_a_nvnmd_quantize_cpu(FPTYPE *em, } template void deepmd::prod_env_mat_a_nvnmd_quantize_cpu( - double *em, - double *em_deriv, - double *rij, - int *nlist, - const double *coord, - const int *type, - const InputNlist &inlist, + double* em, + double* em_deriv, + double* rij, + int* nlist, + const double* coord, + const int* type, + const InputNlist& inlist, const int max_nbor_size, - const double *avg, - const double *std, + const double* avg, + const double* std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec, - const int *f_type); + const int* f_type); template void deepmd::prod_env_mat_a_nvnmd_quantize_cpu( - float *em, - float *em_deriv, - float *rij, - int *nlist, - const float *coord, - const int *type, - const InputNlist &inlist, + float* em, + float* em_deriv, + float* rij, + int* nlist, + const float* coord, + const int* type, + const InputNlist& inlist, const int max_nbor_size, - const float *avg, - const float *std, + const float* avg, + const float* std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec, - const int *f_type); + const int* f_type); #if GOOGLE_CUDA || TENSORFLOW_USE_ROCM // UNDEFINE diff --git a/source/lib/tests/test_env_mat_a.cc b/source/lib/tests/test_env_mat_a.cc index d041d1a0a1..3c309ca9ae 100644 --- a/source/lib/tests/test_env_mat_a.cc +++ b/source/lib/tests/test_env_mat_a.cc @@ -500,7 +500,7 @@ TEST_F(TestEnvMatA, prod_cpu) { } } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); deepmd::convert_nlist(inlist, nlist_a_cpy); @@ -536,7 +536,7 @@ TEST_F(TestEnvMatA, prod_cpu_equal_cpu) { } } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_a_cpy); std::vector em(static_cast(nloc) * ndescrpt), @@ -612,7 +612,7 @@ TEST_F(TestEnvMatA, prod_gpu) { max_nbor_size = 4096; } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; convert_nlist(inlist, nlist_a_cpy); @@ -626,7 +626,7 @@ TEST_F(TestEnvMatA, prod_gpu) { double *posi_cpy_dev = NULL, *avg_dev = NULL, *std_dev = NULL; int *atype_cpy_dev = NULL, *nlist_dev = NULL, *array_int_dev = NULL, *memory_dev = NULL; - uint_64 *array_longlong_dev = NULL; + uint_64* array_longlong_dev = NULL; deepmd::malloc_device_memory_sync(em_dev, em); deepmd::malloc_device_memory_sync(em_deriv_dev, em_deriv); deepmd::malloc_device_memory_sync(rij_dev, rij); @@ -690,7 +690,7 @@ TEST_F(TestEnvMatA, prod_gpu_equal_cpu) { max_nbor_size = 4096; } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; convert_nlist(inlist, nlist_a_cpy); @@ -704,7 +704,7 @@ TEST_F(TestEnvMatA, prod_gpu_equal_cpu) { double *posi_cpy_dev = NULL, *avg_dev = NULL, *std_dev = NULL; int *atype_cpy_dev = NULL, *nlist_dev = NULL, *array_int_dev = NULL, *memory_dev = NULL; - uint_64 *array_longlong_dev = NULL; + uint_64* array_longlong_dev = NULL; deepmd::malloc_device_memory_sync(em_dev, em); deepmd::malloc_device_memory_sync(em_deriv_dev, em_deriv); deepmd::malloc_device_memory_sync(rij_dev, rij); diff --git a/source/lib/tests/test_env_mat_a_mix.cc b/source/lib/tests/test_env_mat_a_mix.cc index d7e6cc88eb..e96311dafd 100644 --- a/source/lib/tests/test_env_mat_a_mix.cc +++ b/source/lib/tests/test_env_mat_a_mix.cc @@ -528,7 +528,7 @@ TEST_F(TestEnvMatAMix, prod_cpu) { } } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); deepmd::convert_nlist(inlist, nlist_a_cpy); @@ -537,7 +537,7 @@ TEST_F(TestEnvMatAMix, prod_cpu) { rij(static_cast(nloc) * nnei * 3); std::vector nlist(static_cast(nloc) * nnei); std::vector ntype(static_cast(nloc) * nnei); - bool *nmask = new bool[static_cast(nloc) * nnei]; + bool* nmask = new bool[static_cast(nloc) * nnei]; memset(nmask, 0, sizeof(bool) * nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); @@ -573,7 +573,7 @@ TEST_F(TestEnvMatAMix, prod_cpu_equal_cpu) { } } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_a_cpy); std::vector em(static_cast(nloc) * ndescrpt), @@ -650,7 +650,7 @@ TEST_F(TestEnvMatAMix, prod_gpu) { max_nbor_size = 4096; } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; convert_nlist(inlist, nlist_a_cpy); @@ -659,18 +659,18 @@ TEST_F(TestEnvMatAMix, prod_gpu) { rij(static_cast(nloc) * nnei * 3, 0.0); std::vector nlist(static_cast(nloc) * nnei, 0); std::vector ntype(static_cast(nloc) * nnei, 0); - bool *nmask = new bool[static_cast(nloc) * nnei]; + bool* nmask = new bool[static_cast(nloc) * nnei]; memset(nmask, 0, sizeof(bool) * nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); double *em_dev = NULL, *em_deriv_dev = NULL, *rij_dev = NULL; - bool *nmask_dev = NULL; + bool* nmask_dev = NULL; double *posi_cpy_dev = NULL, *avg_dev = NULL, *std_dev = NULL; int *f_atype_cpy_dev = NULL, *atype_dev = NULL, *nlist_dev = NULL, *ntype_dev = NULL, *mapping_dev = NULL, *array_int_dev = NULL, *memory_dev = NULL; - uint_64 *array_longlong_dev = NULL; + uint_64* array_longlong_dev = NULL; deepmd::malloc_device_memory_sync(em_dev, em); deepmd::malloc_device_memory_sync(em_deriv_dev, em_deriv); deepmd::malloc_device_memory_sync(rij_dev, rij); @@ -751,7 +751,7 @@ TEST_F(TestEnvMatAMix, prod_gpu_equal_cpu) { max_nbor_size = 4096; } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; convert_nlist(inlist, nlist_a_cpy); @@ -765,7 +765,7 @@ TEST_F(TestEnvMatAMix, prod_gpu_equal_cpu) { double *posi_cpy_dev = NULL, *avg_dev = NULL, *std_dev = NULL; int *f_atype_cpy_dev = NULL, *atype_dev = NULL, *nlist_dev = NULL, *array_int_dev = NULL, *memory_dev = NULL; - uint_64 *array_longlong_dev = NULL; + uint_64* array_longlong_dev = NULL; deepmd::malloc_device_memory_sync(em_dev, em); deepmd::malloc_device_memory_sync(em_deriv_dev, em_deriv); deepmd::malloc_device_memory_sync(rij_dev, rij); diff --git a/source/lib/tests/test_env_mat_r.cc b/source/lib/tests/test_env_mat_r.cc index 3024e651d9..96da7e6963 100644 --- a/source/lib/tests/test_env_mat_r.cc +++ b/source/lib/tests/test_env_mat_r.cc @@ -278,7 +278,7 @@ TEST_F(TestEnvMatR, prod_cpu) { } } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_a_cpy); @@ -313,7 +313,7 @@ TEST_F(TestEnvMatR, prod_cpu_equal_cpu) { } } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_a_cpy); std::vector em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), @@ -378,7 +378,7 @@ TEST_F(TestEnvMatR, prod_gpu) { max_nbor_size = 4096; } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; convert_nlist(inlist, nlist_a_cpy); @@ -392,7 +392,7 @@ TEST_F(TestEnvMatR, prod_gpu) { double *posi_cpy_dev = NULL, *avg_dev = NULL, *std_dev = NULL; int *atype_cpy_dev = NULL, *nlist_dev = NULL, *array_int_dev = NULL, *memory_dev = NULL; - uint_64 *array_longlong_dev = NULL; + uint_64* array_longlong_dev = NULL; deepmd::malloc_device_memory_sync(em_dev, em); deepmd::malloc_device_memory_sync(em_deriv_dev, em_deriv); deepmd::malloc_device_memory_sync(rij_dev, rij); @@ -457,7 +457,7 @@ TEST_F(TestEnvMatR, prod_gpu_equal_cpu) { max_nbor_size = 4096; } std::vector ilist(nloc), numneigh(nloc); - std::vector firstneigh(nloc); + std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; convert_nlist(inlist, nlist_a_cpy); @@ -471,7 +471,7 @@ TEST_F(TestEnvMatR, prod_gpu_equal_cpu) { double *posi_cpy_dev = NULL, *avg_dev = NULL, *std_dev = NULL; int *atype_cpy_dev = NULL, *nlist_dev = NULL, *array_int_dev = NULL, *memory_dev = NULL; - uint_64 *array_longlong_dev = NULL; + uint_64* array_longlong_dev = NULL; deepmd::malloc_device_memory_sync(em_dev, em); deepmd::malloc_device_memory_sync(em_deriv_dev, em_deriv); deepmd::malloc_device_memory_sync(rij_dev, rij); diff --git a/source/lib/tests/test_main.cc b/source/lib/tests/test_main.cc index df7815b694..2ce083b175 100644 --- a/source/lib/tests/test_main.cc +++ b/source/lib/tests/test_main.cc @@ -1,7 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/source/lib/tests/test_tabulate_se_a.cc b/source/lib/tests/test_tabulate_se_a.cc index ce2defb22c..66a77f41fd 100644 --- a/source/lib/tests/test_tabulate_se_a.cc +++ b/source/lib/tests/test_tabulate_se_a.cc @@ -777,7 +777,7 @@ TEST_F(TestTabulateSeA, tabulate_fusion_se_a_gpu) { EXPECT_LT(fabs(xyz_scatter[jj] - expected_xyz_scatter[jj]), 1e-5); } - double *two_embed_dev = nullptr; + double* two_embed_dev = nullptr; deepmd::malloc_device_memory_sync(two_embed_dev, two_embed); deepmd::malloc_device_memory_sync(xyz_scatter_dev, xyz_scatter); deepmd::tabulate_fusion_se_a_gpu(xyz_scatter_dev, table_dev, &info[0], @@ -831,7 +831,7 @@ TEST_F(TestTabulateSeA, tabulate_fusion_se_a_grad_gpu) { EXPECT_LT(fabs(dy_dem[jj] - expected_dy_dem[jj]), 1e-5); } - double *two_embed_dev = nullptr; + double* two_embed_dev = nullptr; deepmd::malloc_device_memory_sync(two_embed_dev, two_embed); deepmd::malloc_device_memory_sync(dy_dem_x_dev, dy_dem_x); deepmd::malloc_device_memory_sync(dy_dem_dev, dy_dem); diff --git a/source/lmp/compute_deeptensor_atom.cpp b/source/lmp/compute_deeptensor_atom.cpp index 68c97a629e..f38279d936 100644 --- a/source/lmp/compute_deeptensor_atom.cpp +++ b/source/lmp/compute_deeptensor_atom.cpp @@ -24,7 +24,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -ComputeDeeptensorAtom::ComputeDeeptensorAtom(LAMMPS *lmp, int narg, char **arg) +ComputeDeeptensorAtom::ComputeDeeptensorAtom(LAMMPS* lmp, int narg, char** arg) : Compute(lmp, narg, arg), dp(lmp), tensor(nullptr) { if (strcmp(update->unit_style, "lj") == 0) { error->all(FLERR, @@ -45,7 +45,7 @@ ComputeDeeptensorAtom::ComputeDeeptensorAtom(LAMMPS *lmp, int narg, char **arg) int gpu_rank = dp.get_node_rank(); try { dt.init(model_file, gpu_rank); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } sel_types = dt.sel_types(); @@ -83,7 +83,7 @@ void ComputeDeeptensorAtom::init() { #endif } -void ComputeDeeptensorAtom::init_list(int /*id*/, NeighList *ptr) { +void ComputeDeeptensorAtom::init_list(int /*id*/, NeighList* ptr) { list = ptr; } @@ -101,10 +101,10 @@ void ComputeDeeptensorAtom::compute_peratom() { array_atom = tensor; } - double **x = atom->x; - double **f = atom->f; - int *type = atom->type; - int *mask = atom->mask; + double** x = atom->x; + double** f = atom->f; + int* type = atom->type; + int* mask = atom->mask; int nlocal = atom->nlocal; int nghost = atom->nghost; int nall = nlocal + nghost; @@ -145,7 +145,7 @@ void ComputeDeeptensorAtom::compute_peratom() { try { dt.compute(gtensor, force, virial, atensor, avirial, dcoord, dtype, dbox, nghost, lmp_list); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } diff --git a/source/lmp/compute_deeptensor_atom.h b/source/lmp/compute_deeptensor_atom.h index a90283aa9e..aeba8c11f4 100644 --- a/source/lmp/compute_deeptensor_atom.h +++ b/source/lmp/compute_deeptensor_atom.h @@ -30,19 +30,19 @@ namespace LAMMPS_NS { class ComputeDeeptensorAtom : public Compute { public: - ComputeDeeptensorAtom(class LAMMPS *, int, char **); + ComputeDeeptensorAtom(class LAMMPS*, int, char**); ~ComputeDeeptensorAtom() override; void init() override; void compute_peratom() override; double memory_usage() override; - void init_list(int, class NeighList *) override; + void init_list(int, class NeighList*) override; double dist_unit_cvt_factor; private: int nmax; - double **tensor; + double** tensor; PairDeepMD dp; - class NeighList *list; + class NeighList* list; deepmd_compat::DeepTensor dt; std::vector sel_types; }; diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index ac161730db..90cb4f4bba 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -24,7 +24,7 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace std; -static bool is_key(const string &input) { +static bool is_key(const string& input) { vector keys; keys.push_back("model"); keys.push_back("type_associate"); @@ -39,7 +39,7 @@ static bool is_key(const string &input) { return false; } -FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg) +FixDPLR::FixDPLR(LAMMPS* lmp, int narg, char** arg) : Fix(lmp, narg, arg), xstr(nullptr), ystr(nullptr), @@ -145,11 +145,11 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg) try { dpt.init(model, 0, "dipole_charge"); dtm.init(model, 0, "dipole_charge"); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } - pair_deepmd = (PairDeepMD *)force->pair_match("deepmd", 1, pair_deepmd_index); + pair_deepmd = (PairDeepMD*)force->pair_match("deepmd", 1, pair_deepmd_index); if (!pair_deepmd) { error->all(FLERR, "pair_style deepmd should be set before this fix\n"); } @@ -305,7 +305,7 @@ void FixDPLR::init() { /* ---------------------------------------------------------------------- */ void FixDPLR::setup_post_neighbor() { - double **x = atom->x; + double** x = atom->x; vector > valid_pairs; get_valid_pairs(valid_pairs, true); @@ -358,7 +358,7 @@ void FixDPLR::min_setup(int vflag) { setup(vflag); } /* ---------------------------------------------------------------------- */ -void FixDPLR::get_valid_pairs(vector > &pairs, bool is_setup) { +void FixDPLR::get_valid_pairs(vector >& pairs, bool is_setup) { pairs.clear(); int nlocal = atom->nlocal; @@ -366,12 +366,12 @@ void FixDPLR::get_valid_pairs(vector > &pairs, bool is_setup) { int nall = nlocal + nghost; vector dtype(nall); // get type - int *type = atom->type; + int* type = atom->type; for (int ii = 0; ii < nall; ++ii) { dtype[ii] = type_idx_map[type[ii] - 1]; } - int **bondlist = neighbor->bondlist; + int** bondlist = neighbor->bondlist; int nbondlist = neighbor->nbondlist; for (int ii = 0; ii < nbondlist; ++ii) { int idx0 = -1, idx1 = -1; @@ -437,9 +437,9 @@ void FixDPLR::get_valid_pairs(vector > &pairs, bool is_setup) { /* ---------------------------------------------------------------------- */ void FixDPLR::pre_exchange() { - double **x = atom->x; - double **v = atom->v; - int *type = atom->type; + double** x = atom->x; + double** v = atom->v; + int* type = atom->type; int nlocal = atom->nlocal; int nghost = atom->nghost; int nall = nlocal + nghost; @@ -461,8 +461,8 @@ void FixDPLR::pre_exchange() { /* ---------------------------------------------------------------------- */ void FixDPLR::pre_force(int vflag) { - double **x = atom->x; - int *type = atom->type; + double** x = atom->x; + int* type = atom->type; int nlocal = atom->nlocal; int nghost = atom->nghost; int nall = nlocal + nghost; @@ -503,7 +503,7 @@ void FixDPLR::pre_force(int vflag) { } } // get lammps nlist - NeighList *list = pair_deepmd->list; + NeighList* list = pair_deepmd->list; deepmd_compat::InputNlist lmp_list(list->inum, list->ilist, list->numneigh, list->firstneigh); lmp_list.set_mask(NEIGHMASK); @@ -515,7 +515,7 @@ void FixDPLR::pre_force(int vflag) { // compute try { dpt.compute(tensor, dcoord, dtype, dbox, nghost, lmp_list); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } // cout << "tensor of size " << tensor.size() << endl; @@ -607,7 +607,7 @@ void FixDPLR::post_force(int vflag) { update_efield_variables(); } - PPPMDPLR *pppm_dplr = (PPPMDPLR *)force->kspace_match("pppm/dplr", 1); + PPPMDPLR* pppm_dplr = (PPPMDPLR*)force->kspace_match("pppm/dplr", 1); int nlocal = atom->nlocal; int nghost = atom->nghost; int nall = nlocal + nghost; @@ -616,7 +616,7 @@ void FixDPLR::post_force(int vflag) { vector dtype(nall, 0); // set values for dcoord, dbox, dfele { - int *type = atom->type; + int* type = atom->type; for (int ii = 0; ii < nall; ++ii) { dtype[ii] = type_idx_map[type[ii] - 1]; } @@ -627,7 +627,7 @@ void FixDPLR::post_force(int vflag) { dbox[6] = domain->h[4] / dist_unit_cvt_factor; // zx dbox[3] = domain->h[5] / dist_unit_cvt_factor; // yx // get coord - double **x = atom->x; + double** x = atom->x; for (int ii = 0; ii < nall; ++ii) { for (int dd = 0; dd < 3; ++dd) { dcoord[ii * 3 + dd] = @@ -636,15 +636,15 @@ void FixDPLR::post_force(int vflag) { } // revise force according to efield if (pppm_dplr) { - const vector &dfele_(pppm_dplr->get_fele()); + const vector& dfele_(pppm_dplr->get_fele()); assert(dfele_.size() == nlocal * 3); for (int ii = 0; ii < nlocal * 3; ++ii) { dfele[ii] += dfele_[ii]; } } // revise force and virial according to efield - double *q = atom->q; - imageint *image = atom->image; + double* q = atom->q; + imageint* image = atom->image; double unwrap[3]; double v[6]; efield_fsum[0] = efield_fsum[1] = efield_fsum[2] = efield_fsum[3] = 0.0; @@ -675,7 +675,7 @@ void FixDPLR::post_force(int vflag) { } } // lmp nlist - NeighList *list = pair_deepmd->list; + NeighList* list = pair_deepmd->list; deepmd_compat::InputNlist lmp_list(list->inum, list->ilist, list->numneigh, list->firstneigh); // bonded pairs @@ -696,7 +696,7 @@ void FixDPLR::post_force(int vflag) { for (int ii = 0; ii < 9; ++ii) { dvcorr[ii] *= ener_unit_cvt_factor; } - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } assert(dfcorr.size() == dcoord.size()); @@ -726,7 +726,7 @@ void FixDPLR::post_force(int vflag) { // cout << endl; // } // apply the force correction - double **f = atom->f; + double** f = atom->f; for (int ii = 0; ii < nlocal; ++ii) { for (int dd = 0; dd < 3; ++dd) { f[ii][dd] += dfcorr[ii * 3 + dd]; @@ -778,7 +778,7 @@ void FixDPLR::min_post_force(int vflag) { post_force(vflag); } /* ---------------------------------------------------------------------- */ -int FixDPLR::pack_reverse_comm(int n, int first, double *buf) { +int FixDPLR::pack_reverse_comm(int n, int first, double* buf) { int m = 0; int last = first + n; for (int i = first; i < last; i++) { @@ -791,7 +791,7 @@ int FixDPLR::pack_reverse_comm(int n, int first, double *buf) { /* ---------------------------------------------------------------------- */ -void FixDPLR::unpack_reverse_comm(int n, int *list, double *buf) { +void FixDPLR::unpack_reverse_comm(int n, int* list, double* buf) { int m = 0; for (int i = 0; i < n; i++) { int j = list[i]; diff --git a/source/lmp/fix_dplr.h b/source/lmp/fix_dplr.h index 5f1161fda6..cd2c54f9d9 100644 --- a/source/lmp/fix_dplr.h +++ b/source/lmp/fix_dplr.h @@ -37,7 +37,7 @@ namespace deepmd_compat = deepmd::hpp; namespace LAMMPS_NS { class FixDPLR : public Fix { public: - FixDPLR(class LAMMPS *, int, char **); + FixDPLR(class LAMMPS*, int, char**); ~FixDPLR() override; int setmask() override; void init() override; @@ -52,14 +52,14 @@ class FixDPLR : public Fix { void min_pre_exchange() override; void min_pre_force(int) override; void min_post_force(int) override; - int pack_reverse_comm(int, int, double *) override; - void unpack_reverse_comm(int, int *, double *) override; + int pack_reverse_comm(int, int, double*) override; + void unpack_reverse_comm(int, int*, double*) override; double compute_scalar(void) override; double compute_vector(int) override; double ener_unit_cvt_factor, dist_unit_cvt_factor, force_unit_cvt_factor; private: - PairDeepMD *pair_deepmd; + PairDeepMD* pair_deepmd; deepmd_compat::DeepTensor dpt; deepmd_compat::DipoleChargeModifier dtm; std::string model; @@ -74,7 +74,7 @@ class FixDPLR : public Fix { std::vector efield; std::vector efield_fsum, efield_fsum_all; int efield_force_flag; - void get_valid_pairs(std::vector > &pairs, bool is_setup); + void get_valid_pairs(std::vector >& pairs, bool is_setup); int varflag; char *xstr, *ystr, *zstr; int xvar, yvar, zvar, xstyle, ystyle, zstyle; diff --git a/source/lmp/fix_ttm_dp.h b/source/lmp/fix_ttm_dp.h index 168f880226..3eb4ccd533 100644 --- a/source/lmp/fix_ttm_dp.h +++ b/source/lmp/fix_ttm_dp.h @@ -13,6 +13,6 @@ class FixTTMDP : public FixTTM { tmp[2] = nzgrid; return tmp; }; - double ***const get_T_electron() const { return T_electron; }; + double*** const get_T_electron() const { return T_electron; }; }; } // namespace LAMMPS_NS diff --git a/source/lmp/pair_base.cpp b/source/lmp/pair_base.cpp index a62956bbe4..ab60ccc780 100644 --- a/source/lmp/pair_base.cpp +++ b/source/lmp/pair_base.cpp @@ -35,9 +35,9 @@ using namespace LAMMPS_NS; using namespace std; -static int stringCmp(const void *a, const void *b) { - char *m = (char *)a; - char *n = (char *)b; +static int stringCmp(const void* a, const void* b) { + char* m = (char*)a; + char* n = (char*)b; int i, sum = 0; for (i = 0; i < MPI_MAX_PROCESSOR_NAME; i++) { @@ -98,7 +98,7 @@ int PairDeepBaseModel::get_node_rank() { return looprank; } -std::string PairDeepBaseModel::get_file_content(const std::string &model) { +std::string PairDeepBaseModel::get_file_content(const std::string& model) { int myrank = 0, root = 0; MPI_Comm_rank(MPI_COMM_WORLD, &myrank); int nchar = 0; @@ -108,7 +108,7 @@ std::string PairDeepBaseModel::get_file_content(const std::string &model) { nchar = file_content.size(); } MPI_Bcast(&nchar, 1, MPI_INT, root, MPI_COMM_WORLD); - char *buff = (char *)malloc(sizeof(char) * nchar); + char* buff = (char*)malloc(sizeof(char) * nchar); if (myrank == root) { memcpy(buff, file_content.c_str(), sizeof(char) * nchar); } @@ -122,7 +122,7 @@ std::string PairDeepBaseModel::get_file_content(const std::string &model) { } std::vector PairDeepBaseModel::get_file_content( - const std::vector &models) { + const std::vector& models) { std::vector file_contents(models.size()); for (unsigned ii = 0; ii < models.size(); ++ii) { file_contents[ii] = get_file_content(models[ii]); @@ -130,11 +130,11 @@ std::vector PairDeepBaseModel::get_file_content( return file_contents; } -void PairDeepBaseModel::make_fparam_from_compute(vector &fparam) { +void PairDeepBaseModel::make_fparam_from_compute(vector& fparam) { assert(do_compute_fparam); int icompute = modify->find_compute(compute_fparam_id); - Compute *compute = modify->compute[icompute]; + Compute* compute = modify->compute[icompute]; if (!compute) { error->all(FLERR, "compute id is not found: " + compute_fparam_id); @@ -152,18 +152,18 @@ void PairDeepBaseModel::make_fparam_from_compute(vector &fparam) { compute->compute_vector(); compute->invoked_flag |= Compute::INVOKED_VECTOR; } - double *cvector = compute->vector; + double* cvector = compute->vector; for (int jj = 0; jj < dim_fparam; ++jj) { fparam[jj] = cvector[jj]; } } } -void PairDeepBaseModel::make_aparam_from_compute(vector &aparam) { +void PairDeepBaseModel::make_aparam_from_compute(vector& aparam) { assert(do_compute_aparam); int icompute = modify->find_compute(compute_aparam_id); - Compute *compute = modify->compute[icompute]; + Compute* compute = modify->compute[icompute]; if (!compute) { error->all(FLERR, "compute id is not found: " + compute_aparam_id); @@ -176,10 +176,10 @@ void PairDeepBaseModel::make_aparam_from_compute(vector &aparam) { compute->invoked_flag |= Compute::INVOKED_PERATOM; } if (dim_aparam == 1) { - double *cvector = compute->vector_atom; + double* cvector = compute->vector_atom; aparam.assign(cvector, cvector + nlocal); } else if (dim_aparam > 1) { - double **carray = compute->array_atom; + double** carray = compute->array_atom; for (int ii = 0; ii < nlocal; ++ii) { for (int jj = 0; jj < dim_aparam; ++jj) { aparam[ii * dim_aparam + jj] = carray[ii][jj]; @@ -189,13 +189,13 @@ void PairDeepBaseModel::make_aparam_from_compute(vector &aparam) { } #ifdef USE_TTM -void PairDeepBaseModel::make_ttm_fparam(vector &fparam) { +void PairDeepBaseModel::make_ttm_fparam(vector& fparam) { assert(do_ttm); // get ttm_fix - const FixTTMDP *ttm_fix = NULL; + const FixTTMDP* ttm_fix = NULL; for (int ii = 0; ii < modify->nfix; ii++) { if (string(modify->fix[ii]->id) == ttm_fix_id) { - ttm_fix = dynamic_cast(modify->fix[ii]); + ttm_fix = dynamic_cast(modify->fix[ii]); } } if (!ttm_fix) { @@ -208,7 +208,7 @@ void PairDeepBaseModel::make_ttm_fparam(vector &fparam) { int nxnodes = nnodes[0]; int nynodes = nnodes[1]; int nznodes = nnodes[2]; - double ***const T_electron = ttm_fix->get_T_electron(); + double*** const T_electron = ttm_fix->get_T_electron(); int numb_effective_nodes = 0; double total_Te = 0; @@ -230,27 +230,27 @@ void PairDeepBaseModel::make_ttm_fparam(vector &fparam) { #endif #ifdef USE_TTM -void PairDeepBaseModel::make_ttm_aparam(vector &daparam) { +void PairDeepBaseModel::make_ttm_aparam(vector& daparam) { assert(do_ttm); // get ttm_fix - const FixTTMDP *ttm_fix = NULL; + const FixTTMDP* ttm_fix = NULL; for (int ii = 0; ii < modify->nfix; ii++) { if (string(modify->fix[ii]->id) == ttm_fix_id) { - ttm_fix = dynamic_cast(modify->fix[ii]); + ttm_fix = dynamic_cast(modify->fix[ii]); } } if (!ttm_fix) { error->all(FLERR, "fix ttm id is not found: " + ttm_fix_id); } // modify - double **x = atom->x; - int *mask = atom->mask; + double** x = atom->x; + int* mask = atom->mask; int nlocal = atom->nlocal; vector nnodes = ttm_fix->get_nodes(); int nxnodes = nnodes[0]; int nynodes = nnodes[1]; int nznodes = nnodes[2]; - double ***const T_electron = ttm_fix->get_T_electron(); + double*** const T_electron = ttm_fix->get_T_electron(); double dx = domain->xprd / nxnodes; double dy = domain->yprd / nynodes; double dz = domain->zprd / nynodes; @@ -275,8 +275,8 @@ void PairDeepBaseModel::make_ttm_aparam(vector &daparam) { } #endif -void PairDeepBaseModel::cum_sum(std::map &sum, - std::map &vec) { +void PairDeepBaseModel::cum_sum(std::map& sum, + std::map& vec) { sum[0] = 0; for (int ii = 1; ii < vec.size(); ++ii) { sum[ii] = sum[ii - 1] + vec[ii - 1]; @@ -284,10 +284,10 @@ void PairDeepBaseModel::cum_sum(std::map &sum, } PairDeepBaseModel::PairDeepBaseModel( - LAMMPS *lmp, - const char *cite_user_package, - deepmd_compat::DeepBaseModel &deep_model, - deepmd_compat::DeepBaseModelDevi &deep_model_devi) + LAMMPS* lmp, + const char* cite_user_package, + deepmd_compat::DeepBaseModel& deep_model, + deepmd_compat::DeepBaseModelDevi& deep_model_devi) : Pair(lmp), deep_base(deep_model), deep_base_model_devi(deep_model_devi) @@ -349,7 +349,7 @@ void PairDeepBaseModel::print_summary(const string pre) const { // capture cout to a string, then call LAMMPS's utils::logmesg // https://stackoverflow.com/a/4043813/9567349 std::stringstream buffer; - std::streambuf *sbuf = std::cout.rdbuf(); + std::streambuf* sbuf = std::cout.rdbuf(); std::cout.rdbuf(buffer.rdbuf()); cout << "Summary of lammps deepmd module ..." << endl; @@ -405,9 +405,9 @@ void PairDeepBaseModel::allocate() { } } -void PairDeepBaseModel::read_restart(FILE *) { is_restart = true; } +void PairDeepBaseModel::read_restart(FILE*) { is_restart = true; } -void PairDeepBaseModel::write_restart(FILE *) { +void PairDeepBaseModel::write_restart(FILE*) { // pass } @@ -454,23 +454,23 @@ double PairDeepBaseModel::init_one(int i, int j) { return cutoff; } -void *PairDeepBaseModel::extract(const char *str, int &dim) { +void* PairDeepBaseModel::extract(const char* str, int& dim) { if (strcmp(str, "cut_coul") == 0) { dim = 0; - return (void *)&cutoff; + return (void*)&cutoff; } if (strcmp(str, "scale") == 0) { dim = 2; - return (void *)scale; + return (void*)scale; } return NULL; } -void ana_st(double &max, - double &min, - double &sum, - const vector &vec, - const int &nloc) { +void ana_st(double& max, + double& min, + double& sum, + const vector& vec, + const int& nloc) { if (nloc == 0) { return; } @@ -488,9 +488,9 @@ void ana_st(double &max, } } -void make_uniform_aparam(vector &daparam, - const vector &aparam, - const int &nlocal) { +void make_uniform_aparam(vector& daparam, + const vector& aparam, + const int& nlocal) { unsigned dim_aparam = aparam.size(); daparam.resize(static_cast(dim_aparam) * nlocal); for (int ii = 0; ii < nlocal; ++ii) { diff --git a/source/lmp/pair_base.h b/source/lmp/pair_base.h index 055b45d20e..1dd4b84041 100644 --- a/source/lmp/pair_base.h +++ b/source/lmp/pair_base.h @@ -30,23 +30,23 @@ namespace deepmd_compat = deepmd::hpp; namespace LAMMPS_NS { class PairDeepBaseModel : public Pair { public: - PairDeepBaseModel(class LAMMPS *, - const char *, - deepmd_compat::DeepBaseModel &, - deepmd_compat::DeepBaseModelDevi &); + PairDeepBaseModel(class LAMMPS*, + const char*, + deepmd_compat::DeepBaseModel&, + deepmd_compat::DeepBaseModelDevi&); virtual ~PairDeepBaseModel() override; - void *extract(const char *, int &) override; + void* extract(const char*, int&) override; void init_style() override; - void write_restart(FILE *) override; - void read_restart(FILE *) override; + void write_restart(FILE*) override; + void read_restart(FILE*) override; double init_one(int i, int j) override; void print_summary(const std::string pre) const; int get_node_rank(); - void cum_sum(std::map &, std::map &); + void cum_sum(std::map&, std::map&); - std::string get_file_content(const std::string &model); + std::string get_file_content(const std::string& model); std::vector get_file_content( - const std::vector &models); + const std::vector& models); std::vector type_names; double ener_unit_cvt_factor, dist_unit_cvt_factor, force_unit_cvt_factor; @@ -54,7 +54,7 @@ class PairDeepBaseModel : public Pair { deepmd_compat::DeepBaseModel deep_base; deepmd_compat::DeepBaseModelDevi deep_base_model_devi; virtual void allocate(); - double **scale; + double** scale; unsigned numb_models; double cutoff; int numb_types; @@ -83,16 +83,16 @@ class PairDeepBaseModel : public Pair { double eps; double eps_v; - void make_fparam_from_compute(std::vector &fparam); + void make_fparam_from_compute(std::vector& fparam); bool do_compute_fparam; std::string compute_fparam_id; - void make_aparam_from_compute(std::vector &aparam); + void make_aparam_from_compute(std::vector& aparam); bool do_compute_aparam; std::string compute_aparam_id; - void make_ttm_fparam(std::vector &fparam); + void make_ttm_fparam(std::vector& fparam); - void make_ttm_aparam(std::vector &dparam); + void make_ttm_aparam(std::vector& dparam); bool do_ttm; std::string ttm_fix_id; int *counts, *displacements; @@ -103,13 +103,13 @@ class PairDeepBaseModel : public Pair { } // namespace LAMMPS_NS -void make_uniform_aparam(std::vector &daparam, - const std::vector &aparam, - const int &nlocal); -void ana_st(double &max, - double &min, - double &sum, - const std::vector &vec, - const int &nloc); +void make_uniform_aparam(std::vector& daparam, + const std::vector& aparam, + const int& nlocal); +void ana_st(double& max, + double& min, + double& sum, + const std::vector& vec, + const int& nloc); #endif diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index a11ad7f99c..3684c38dd9 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -117,7 +117,7 @@ static const char cite_user_deepmd_package[] = " doi = {10.1021/acs.jctc.5c00340},\n" "}\n\n"; -PairDeepMD::PairDeepMD(LAMMPS *lmp) +PairDeepMD::PairDeepMD(LAMMPS* lmp) : PairDeepBaseModel( lmp, cite_user_deepmd_package, deep_pot, deep_pot_model_devi) { // Constructor body can be empty @@ -141,10 +141,10 @@ void PairDeepMD::compute(int eflag, int vflag) { } bool do_ghost = true; // dpa2 communication - commdata_ = (CommBrickDeepMD *)comm; - double **x = atom->x; - double **f = atom->f; - int *type = atom->type; + commdata_ = (CommBrickDeepMD*)comm; + double** x = atom->x; + double** f = atom->f; + int* type = atom->type; int nlocal = atom->nlocal; int nghost = 0; if (do_ghost) { @@ -249,7 +249,7 @@ void PairDeepMD::compute(int eflag, int vflag) { try { deep_pot.compute(dener, dforce, dvirial, dcoord, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } } @@ -260,7 +260,7 @@ void PairDeepMD::compute(int eflag, int vflag) { try { deep_pot.compute(dener, dforce, dvirial, deatom, dvatom, dcoord, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } if (eflag_atom) { @@ -312,7 +312,7 @@ void PairDeepMD::compute(int eflag, int vflag) { deep_pot_model_devi.compute(all_energy, all_force, all_virial, dcoord, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } } else { @@ -321,7 +321,7 @@ void PairDeepMD::compute(int eflag, int vflag) { all_atom_energy, all_atom_virial, dcoord, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } } @@ -449,7 +449,7 @@ void PairDeepMD::compute(int eflag, int vflag) { if (out_each == 1) { vector std_f_all(atom->natoms); // Gather std_f and tags - tagint *tag = atom->tag; + tagint* tag = atom->tag; int nprocs = comm->nprocs; // Grow arrays if necessary if (atom->natoms > stdf_comm_buff_size) { @@ -496,7 +496,7 @@ void PairDeepMD::compute(int eflag, int vflag) { if (numb_models == 1) { try { deep_pot.compute(dener, dforce, dvirial, dcoord, dtype, dbox); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } } else { @@ -525,7 +525,7 @@ void PairDeepMD::compute(int eflag, int vflag) { } } -static bool is_key(const string &input) { +static bool is_key(const string& input) { vector keys; keys.push_back("out_freq"); keys.push_back("out_file"); @@ -548,7 +548,7 @@ static bool is_key(const string &input) { return false; } -void PairDeepMD::settings(int narg, char **arg) { +void PairDeepMD::settings(int narg, char** arg) { if (narg <= 0) { error->all(FLERR, "Illegal pair_style command"); } @@ -568,7 +568,7 @@ void PairDeepMD::settings(int narg, char **arg) { if (numb_models == 1) { try { deep_pot.init(arg[0], get_node_rank(), get_file_content(arg[0])); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } cutoff = deep_pot.cutoff() * dist_unit_cvt_factor; @@ -581,7 +581,7 @@ void PairDeepMD::settings(int narg, char **arg) { deep_pot.init(arg[0], get_node_rank(), get_file_content(arg[0])); deep_pot_model_devi.init(models, get_node_rank(), get_file_content(models)); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } cutoff = deep_pot_model_devi.cutoff() * dist_unit_cvt_factor; @@ -798,7 +798,7 @@ void PairDeepMD::settings(int narg, char **arg) { set coeffs for one or more type pairs ------------------------------------------------------------------------- */ -void PairDeepMD::coeff(int narg, char **arg) { +void PairDeepMD::coeff(int narg, char** arg) { if (!allocated) { allocate(); } @@ -889,7 +889,7 @@ void PairDeepMD::coeff(int narg, char **arg) { /* ---------------------------------------------------------------------- */ -int PairDeepMD::pack_reverse_comm(int n, int first, double *buf) { +int PairDeepMD::pack_reverse_comm(int n, int first, double* buf) { int i, m, last; m = 0; @@ -913,7 +913,7 @@ int PairDeepMD::pack_reverse_comm(int n, int first, double *buf) { /* ---------------------------------------------------------------------- */ -void PairDeepMD::unpack_reverse_comm(int n, int *list, double *buf) { +void PairDeepMD::unpack_reverse_comm(int n, int* list, double* buf) { int i, j, m; m = 0; diff --git a/source/lmp/pair_deepmd.h b/source/lmp/pair_deepmd.h index a8b3c13f4c..6d54a69fe6 100644 --- a/source/lmp/pair_deepmd.h +++ b/source/lmp/pair_deepmd.h @@ -42,20 +42,20 @@ class CommBrickDeepMD : public CommBrick { }; class PairDeepMD : public PairDeepBaseModel { public: - PairDeepMD(class LAMMPS *); + PairDeepMD(class LAMMPS*); ~PairDeepMD() override; - void settings(int, char **) override; - void coeff(int, char **) override; + void settings(int, char**) override; + void coeff(int, char**) override; void compute(int, int) override; - int pack_reverse_comm(int, int, double *) override; - void unpack_reverse_comm(int, int *, double *) override; + int pack_reverse_comm(int, int, double*) override; + void unpack_reverse_comm(int, int*, double*) override; protected: deepmd_compat::DeepPot deep_pot; deepmd_compat::DeepPotModelDevi deep_pot_model_devi; private: - CommBrickDeepMD *commdata_; + CommBrickDeepMD* commdata_; }; } // namespace LAMMPS_NS diff --git a/source/lmp/pair_deepspin.cpp b/source/lmp/pair_deepspin.cpp index accdce4c79..494ddcfb68 100644 --- a/source/lmp/pair_deepspin.cpp +++ b/source/lmp/pair_deepspin.cpp @@ -117,7 +117,7 @@ static const char cite_user_deepmd_package[] = " doi = {10.1021/acs.jctc.5c00340},\n" "}\n\n"; -PairDeepSpin::PairDeepSpin(LAMMPS *lmp) +PairDeepSpin::PairDeepSpin(LAMMPS* lmp) : PairDeepBaseModel( lmp, cite_user_deepmd_package, deep_spin, deep_spin_model_devi) { // Constructor body can be empty @@ -141,10 +141,10 @@ void PairDeepSpin::compute(int eflag, int vflag) { } bool do_ghost = true; // dpa2 communication - commdata_ = (CommBrickDeepSpin *)comm; - double **x = atom->x; - double **f = atom->f; - int *type = atom->type; + commdata_ = (CommBrickDeepSpin*)comm; + double** x = atom->x; + double** f = atom->f; + int* type = atom->type; int nlocal = atom->nlocal; int nghost = 0; if (do_ghost) { @@ -155,8 +155,8 @@ void PairDeepSpin::compute(int eflag, int vflag) { vector dspin(nall * 3, 0.); vector dfm(nall * 3, 0.); - double **sp = atom->sp; - double **fm = atom->fm; + double** sp = atom->sp; + double** fm = atom->fm; // spin initialize if (atom->sp_flag) { // get spin @@ -251,7 +251,7 @@ void PairDeepSpin::compute(int eflag, int vflag) { deep_spin.compute(dener, dforce, dforce_mag, dvirial, dcoord, dspin, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } } @@ -263,7 +263,7 @@ void PairDeepSpin::compute(int eflag, int vflag) { deep_spin.compute(dener, dforce, dforce_mag, dvirial, deatom, dvatom, dcoord, dspin, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } if (eflag_atom) { @@ -315,7 +315,7 @@ void PairDeepSpin::compute(int eflag, int vflag) { deep_spin_model_devi.compute(all_energy, all_force, all_force_mag, all_virial, dcoord, dspin, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } } else { @@ -324,7 +324,7 @@ void PairDeepSpin::compute(int eflag, int vflag) { all_energy, all_force, all_force_mag, all_virial, all_atom_energy, all_atom_virial, dcoord, dspin, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } } @@ -473,7 +473,7 @@ void PairDeepSpin::compute(int eflag, int vflag) { // need support for spin atomic force. vector std_f_all(atom->natoms); // Gather std_f and tags - tagint *tag = atom->tag; + tagint* tag = atom->tag; int nprocs = comm->nprocs; // Grow arrays if necessary if (atom->natoms > stdf_comm_buff_size) { @@ -521,7 +521,7 @@ void PairDeepSpin::compute(int eflag, int vflag) { try { deep_spin.compute(dener, dforce, dforce_mag, dvirial, dcoord, dspin, dtype, dbox); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } } else { @@ -558,7 +558,7 @@ void PairDeepSpin::compute(int eflag, int vflag) { } } -static bool is_key(const string &input) { +static bool is_key(const string& input) { vector keys; keys.push_back("out_freq"); keys.push_back("out_file"); @@ -581,7 +581,7 @@ static bool is_key(const string &input) { return false; } -void PairDeepSpin::settings(int narg, char **arg) { +void PairDeepSpin::settings(int narg, char** arg) { if (narg <= 0) { error->all(FLERR, "Illegal pair_style command"); } @@ -601,7 +601,7 @@ void PairDeepSpin::settings(int narg, char **arg) { if (numb_models == 1) { try { deep_spin.init(arg[0], get_node_rank(), get_file_content(arg[0])); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } cutoff = deep_spin.cutoff() * dist_unit_cvt_factor; @@ -614,7 +614,7 @@ void PairDeepSpin::settings(int narg, char **arg) { deep_spin.init(arg[0], get_node_rank(), get_file_content(arg[0])); deep_spin_model_devi.init(models, get_node_rank(), get_file_content(models)); - } catch (deepmd_compat::deepmd_exception &e) { + } catch (deepmd_compat::deepmd_exception& e) { error->one(FLERR, e.what()); } cutoff = deep_spin_model_devi.cutoff() * dist_unit_cvt_factor; @@ -828,7 +828,7 @@ void PairDeepSpin::settings(int narg, char **arg) { set coeffs for one or more type pairs ------------------------------------------------------------------------- */ -void PairDeepSpin::coeff(int narg, char **arg) { +void PairDeepSpin::coeff(int narg, char** arg) { if (!allocated) { allocate(); } @@ -919,7 +919,7 @@ void PairDeepSpin::coeff(int narg, char **arg) { /* ---------------------------------------------------------------------- */ -int PairDeepSpin::pack_reverse_comm(int n, int first, double *buf) { +int PairDeepSpin::pack_reverse_comm(int n, int first, double* buf) { int i, m, last; m = 0; @@ -946,7 +946,7 @@ int PairDeepSpin::pack_reverse_comm(int n, int first, double *buf) { /* ---------------------------------------------------------------------- */ -void PairDeepSpin::unpack_reverse_comm(int n, int *list, double *buf) { +void PairDeepSpin::unpack_reverse_comm(int n, int* list, double* buf) { int i, j, m; m = 0; diff --git a/source/lmp/pair_deepspin.h b/source/lmp/pair_deepspin.h index 47d6678441..cc31db8bf5 100644 --- a/source/lmp/pair_deepspin.h +++ b/source/lmp/pair_deepspin.h @@ -42,13 +42,13 @@ class CommBrickDeepSpin : public CommBrick { }; class PairDeepSpin : public PairDeepBaseModel { public: - PairDeepSpin(class LAMMPS *); + PairDeepSpin(class LAMMPS*); ~PairDeepSpin() override; - void settings(int, char **) override; - void coeff(int, char **) override; + void settings(int, char**) override; + void coeff(int, char**) override; void compute(int, int) override; - int pack_reverse_comm(int, int, double *) override; - void unpack_reverse_comm(int, int *, double *) override; + int pack_reverse_comm(int, int, double*) override; + void unpack_reverse_comm(int, int*, double*) override; protected: deepmd_compat::DeepSpin deep_spin; @@ -56,7 +56,7 @@ class PairDeepSpin : public PairDeepBaseModel { std::vector > all_force_mag; private: - CommBrickDeepSpin *commdata_; + CommBrickDeepSpin* commdata_; }; } // namespace LAMMPS_NS diff --git a/source/lmp/plugin/deepmdplugin.cpp b/source/lmp/plugin/deepmdplugin.cpp index 4f62cb3944..d3b54f8e41 100644 --- a/source/lmp/plugin/deepmdplugin.cpp +++ b/source/lmp/plugin/deepmdplugin.cpp @@ -15,22 +15,22 @@ using namespace LAMMPS_NS; -static Pair *pairdeepmd(LAMMPS *lmp) { return new PairDeepMD(lmp); } -static Pair *pairdeepspin(LAMMPS *lmp) { return new PairDeepSpin(lmp); } +static Pair* pairdeepmd(LAMMPS* lmp) { return new PairDeepMD(lmp); } +static Pair* pairdeepspin(LAMMPS* lmp) { return new PairDeepSpin(lmp); } -static Compute *computedeepmdtensoratom(LAMMPS *lmp, int narg, char **arg) { +static Compute* computedeepmdtensoratom(LAMMPS* lmp, int narg, char** arg) { return new ComputeDeeptensorAtom(lmp, narg, arg); } -static Fix *fixdplr(LAMMPS *lmp, int narg, char **arg) { +static Fix* fixdplr(LAMMPS* lmp, int narg, char** arg) { return new FixDPLR(lmp, narg, arg); } #if LAMMPS_VERSION_NUMBER >= 20220328 -static KSpace *pppmdplr(LAMMPS *lmp) { return new PPPMDPLR(lmp); } +static KSpace* pppmdplr(LAMMPS* lmp) { return new PPPMDPLR(lmp); } #endif -extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) { +extern "C" void lammpsplugin_init(void* lmp, void* handle, void* regfunc) { lammpsplugin_t plugin; lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc)regfunc; @@ -39,7 +39,7 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) { plugin.name = "deepmd"; plugin.info = "deepmd pair style " STR_GIT_SUMM; plugin.author = "Han Wang"; - plugin.creator.v1 = (lammpsplugin_factory1 *)&pairdeepmd; + plugin.creator.v1 = (lammpsplugin_factory1*)&pairdeepmd; plugin.handle = handle; (*register_plugin)(&plugin, lmp); @@ -48,7 +48,7 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) { plugin.name = "deepspin"; plugin.info = "deepspin pair style " STR_GIT_SUMM; plugin.author = "Duo Zhang"; - plugin.creator.v1 = (lammpsplugin_factory1 *)&pairdeepspin; + plugin.creator.v1 = (lammpsplugin_factory1*)&pairdeepspin; plugin.handle = handle; (*register_plugin)(&plugin, lmp); @@ -56,14 +56,14 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) { plugin.name = "deeptensor/atom"; plugin.info = "compute deeptensor/atom " STR_GIT_SUMM; plugin.author = "Han Wang"; - plugin.creator.v2 = (lammpsplugin_factory2 *)&computedeepmdtensoratom; + plugin.creator.v2 = (lammpsplugin_factory2*)&computedeepmdtensoratom; (*register_plugin)(&plugin, lmp); plugin.style = "fix"; plugin.name = "dplr"; plugin.info = "fix dplr " STR_GIT_SUMM; plugin.author = "Han Wang"; - plugin.creator.v2 = (lammpsplugin_factory2 *)&fixdplr; + plugin.creator.v2 = (lammpsplugin_factory2*)&fixdplr; (*register_plugin)(&plugin, lmp); #if LAMMPS_VERSION_NUMBER >= 20220328 @@ -72,7 +72,7 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) { plugin.name = "pppm/dplr"; plugin.info = "kspace pppm/dplr " STR_GIT_SUMM; plugin.author = "Han Wang"; - plugin.creator.v1 = (lammpsplugin_factory1 *)&pppmdplr; + plugin.creator.v1 = (lammpsplugin_factory1*)&pppmdplr; (*register_plugin)(&plugin, lmp); #endif } diff --git a/source/lmp/pppm_dplr.cpp b/source/lmp/pppm_dplr.cpp index e1bdb828af..3597a31548 100644 --- a/source/lmp/pppm_dplr.cpp +++ b/source/lmp/pppm_dplr.cpp @@ -36,10 +36,10 @@ enum { FORWARD_IK, FORWARD_AD, FORWARD_IK_PERATOM, FORWARD_AD_PERATOM }; #if LAMMPS_VERSION_NUMBER < 20181109 // See lammps/lammps#1165 -PPPMDPLR::PPPMDPLR(LAMMPS *lmp, int narg, char **arg) +PPPMDPLR::PPPMDPLR(LAMMPS* lmp, int narg, char** arg) : PPPM(lmp, narg, arg) #else -PPPMDPLR::PPPMDPLR(LAMMPS *lmp) +PPPMDPLR::PPPMDPLR(LAMMPS* lmp) : PPPM(lmp) #endif { @@ -232,7 +232,7 @@ void PPPMDPLR::compute(int eflag, int vflag) { // ntotal accounts for TIP4P tallying eatom/vatom for ghost atoms if (evflag_atom) { - double *q = atom->q; + double* q = atom->q; int nlocal = atom->nlocal; int ntotal = nlocal; if (tip4pflag) { @@ -288,8 +288,8 @@ void PPPMDPLR::fieldforce_ik() { // (mx,my,mz) = global coords of moving stencil pt // ek = 3 components of E-field on particle - double *q = atom->q; - double **x = atom->x; + double* q = atom->q; + double** x = atom->x; // double **f = atom->f; int nlocal = atom->nlocal; @@ -347,7 +347,7 @@ void PPPMDPLR::fieldforce_ad() { FFT_SCALAR ekx, eky, ekz; double s1, s2, s3; double sf = 0.0; - double *prd; + double* prd; prd = domain->prd; double xprd = prd[0]; @@ -364,8 +364,8 @@ void PPPMDPLR::fieldforce_ad() { // (mx,my,mz) = global coords of moving stencil pt // ek = 3 components of E-field on particle - double *q = atom->q; - double **x = atom->x; + double* q = atom->q; + double** x = atom->x; // double **f = atom->f; int nlocal = atom->nlocal; diff --git a/source/lmp/pppm_dplr.h b/source/lmp/pppm_dplr.h index b7e221c686..79a9a9ce37 100644 --- a/source/lmp/pppm_dplr.h +++ b/source/lmp/pppm_dplr.h @@ -21,14 +21,14 @@ class PPPMDPLR : public PPPM { public: #if LAMMPS_VERSION_NUMBER < 20181109 // See lammps/lammps#1165 - PPPMDPLR(class LAMMPS *, int, char **); + PPPMDPLR(class LAMMPS*, int, char**); #else - PPPMDPLR(class LAMMPS *); + PPPMDPLR(class LAMMPS*); #endif ~PPPMDPLR() override {}; void init() override; - const std::vector &get_fele() const { return fele; }; - std::vector &get_fele() { return fele; } + const std::vector& get_fele() const { return fele; }; + std::vector& get_fele() { return fele; } protected: void compute(int, int) override; diff --git a/source/op/tf/descrpt_se_a_mask.cc b/source/op/tf/descrpt_se_a_mask.cc index 28e4a575db..7f8bcd9411 100644 --- a/source/op/tf/descrpt_se_a_mask.cc +++ b/source/op/tf/descrpt_se_a_mask.cc @@ -32,7 +32,7 @@ struct NeighborInfo { int index; NeighborInfo() : type(0), dist(0), index(0) {} NeighborInfo(int tt, FPTYPE dd, int ii) : type(tt), dist(dd), index(ii) {} - bool operator<(const NeighborInfo &b) const { + bool operator<(const NeighborInfo& b) const { return (type < b.type || (type == b.type && (dist < b.dist || (dist == b.dist && index < b.index)))); @@ -42,24 +42,24 @@ struct NeighborInfo { template class DescrptSeAMaskOp : public OpKernel { public: - explicit DescrptSeAMaskOp(OpKernelConstruction *context) : OpKernel(context) { + explicit DescrptSeAMaskOp(OpKernelConstruction* context) : OpKernel(context) { // OP_REQUIRES_OK(context); } - void Compute(OpKernelContext *context) override { + void Compute(OpKernelContext* context) override { deepmd::safe_compute( - context, [this](OpKernelContext *context) { this->_Compute(context); }); + context, [this](OpKernelContext* context) { this->_Compute(context); }); } - void _Compute(OpKernelContext *context) { + void _Compute(OpKernelContext* context) { // Grab the input tensor int context_input_index = 0; - const Tensor &coord_tensor = context->input(context_input_index++); - const Tensor &type_tensor = context->input(context_input_index++); - const Tensor &mask_matrix_tensor = context->input(context_input_index++); - const Tensor &box_tensor = context->input(context_input_index++); - const Tensor &natoms_tensor = context->input(context_input_index++); - const Tensor &mesh_tensor = context->input(context_input_index++); + const Tensor& coord_tensor = context->input(context_input_index++); + const Tensor& type_tensor = context->input(context_input_index++); + const Tensor& mask_matrix_tensor = context->input(context_input_index++); + const Tensor& box_tensor = context->input(context_input_index++); + const Tensor& natoms_tensor = context->input(context_input_index++); + const Tensor& mesh_tensor = context->input(context_input_index++); // set size of the sample OP_REQUIRES(context, (coord_tensor.shape().dims() == 2), @@ -109,18 +109,18 @@ class DescrptSeAMaskOp : public OpKernel { nlist_shape.AddDim(static_cast(total_atom_num) * total_atom_num); int context_output_index = 0; - Tensor *descrpt_tensor = NULL; + Tensor* descrpt_tensor = NULL; OP_REQUIRES_OK( context, context->allocate_output(context_output_index++, descrpt_shape, &descrpt_tensor)); - Tensor *descrpt_deriv_tensor = NULL; + Tensor* descrpt_deriv_tensor = NULL; OP_REQUIRES_OK(context, context->allocate_output(context_output_index++, descrpt_deriv_shape, &descrpt_deriv_tensor)); - Tensor *rij_tensor = NULL; + Tensor* rij_tensor = NULL; OP_REQUIRES_OK(context, context->allocate_output(context_output_index++, rij_shape, &rij_tensor)); - Tensor *nlist_tensor = NULL; + Tensor* nlist_tensor = NULL; OP_REQUIRES_OK(context, context->allocate_output(context_output_index++, nlist_shape, &nlist_tensor)); @@ -317,9 +317,9 @@ class DescrptSeAMaskOp : public OpKernel { compute_t max_distance = 10000.0; void buildAndSortNeighborList(int i_idx, const std::vector d_coord3, - std::vector &d_type, - std::vector &d_mask, - std::vector &sorted_nlist, + std::vector& d_type, + std::vector& d_mask, + std::vector& sorted_nlist, int total_atom_num) { // sorted_nlist.resize(total_atom_num); std::vector> sel_nei; diff --git a/source/op/tf/dotmul_flt_nvnmd.cc b/source/op/tf/dotmul_flt_nvnmd.cc index 1aca3e8bf8..ecfac60a0a 100644 --- a/source/op/tf/dotmul_flt_nvnmd.cc +++ b/source/op/tf/dotmul_flt_nvnmd.cc @@ -37,15 +37,15 @@ modw = 1: normalize w[hh, : , kk] using namespace tensorflow; template -void split_flt(T x, int64_t &sign, int64_t &expo, int64_t &mant); +void split_flt(T x, int64_t& sign, int64_t& expo, int64_t& mant); // read matmul_flt_nvnmd.cc template // float and double -void find_max_expo(int64_t &max_expo, T *x, int64_t M); +void find_max_expo(int64_t& max_expo, T* x, int64_t M); // read matmul_flt_nvnmd.cc template // float and double -void find_max_expo(int64_t &max_expo, T *x, int64_t N, int64_t M); +void find_max_expo(int64_t& max_expo, T* x, int64_t N, int64_t M); //- register the operator REGISTER_OP("DotmulFltNvnmd") @@ -60,19 +60,19 @@ template class DotmulFltNvnmdOp : public OpKernel { public: /// Constructor. - explicit DotmulFltNvnmdOp(OpKernelConstruction *context) + explicit DotmulFltNvnmdOp(OpKernelConstruction* context) : OpKernel(context) {}; /// Compute the descriptor /// param: context - void Compute(OpKernelContext *context) override { + void Compute(OpKernelContext* context) override { // check DCHECK_EQ(2, context->num_inputs()); - const Tensor &X = context->input(0); - const Tensor &W = context->input(1); + const Tensor& X = context->input(0); + const Tensor& W = context->input(1); - const TensorShape &shX = X.shape(); - const TensorShape &shW = W.shape(); + const TensorShape& shX = X.shape(); + const TensorShape& shW = W.shape(); TensorShape shY; DCHECK_EQ(shW.dims(), shX.dims()); @@ -104,7 +104,7 @@ class DotmulFltNvnmdOp : public OpKernel { } // create output - Tensor *Y = NULL; + Tensor* Y = NULL; OP_REQUIRES_OK(context, context->allocate_output(0, shY, &Y)); // compute @@ -131,8 +131,8 @@ class DotmulFltNvnmdOp : public OpKernel { for (ii = 0; ii < H * N; ii++) { // find x max exponnet - find_max_expo(expo_max1, (FPTYPE *)&x[ii * M], M); - find_max_expo(expo_max2, (FPTYPE *)&w[ii * M], M); + find_max_expo(expo_max1, (FPTYPE*)&x[ii * M], M); + find_max_expo(expo_max2, (FPTYPE*)&w[ii * M], M); // s = 0; for (jj = 0; jj < M; jj++) { diff --git a/source/op/tf/matmul_flt_nvnmd.cc b/source/op/tf/matmul_flt_nvnmd.cc index 22ed23c0a3..c2821096c1 100644 --- a/source/op/tf/matmul_flt_nvnmd.cc +++ b/source/op/tf/matmul_flt_nvnmd.cc @@ -37,15 +37,15 @@ modw = 1: normalize w[hh, : , kk] using namespace tensorflow; template -void split_flt(T x, int64_t &sign, int64_t &expo, int64_t &mant); +void split_flt(T x, int64_t& sign, int64_t& expo, int64_t& mant); // read matmul_flt_nvnmd.cc template // float and double -void find_max_expo(int64_t &max_expo, T *x, int64_t M); +void find_max_expo(int64_t& max_expo, T* x, int64_t M); // read matmul_flt_nvnmd.cc template // float and double -void find_max_expo(int64_t &max_expo, T *x, int64_t N, int64_t M); +void find_max_expo(int64_t& max_expo, T* x, int64_t N, int64_t M); //- register the operator REGISTER_OP("MatmulFltNvnmd") @@ -62,21 +62,21 @@ template class MatmulFltNvnmdOp : public OpKernel { public: /// Constructor. - explicit MatmulFltNvnmdOp(OpKernelConstruction *context) : OpKernel(context) { + explicit MatmulFltNvnmdOp(OpKernelConstruction* context) : OpKernel(context) { OP_REQUIRES_OK(context, context->GetAttr("normx", &normx)); OP_REQUIRES_OK(context, context->GetAttr("normw", &normw)); }; /// Compute the descriptor /// param: context - void Compute(OpKernelContext *context) override { + void Compute(OpKernelContext* context) override { // check DCHECK_EQ(2, context->num_inputs()); - const Tensor &X = context->input(0); - const Tensor &W = context->input(1); + const Tensor& X = context->input(0); + const Tensor& W = context->input(1); - const TensorShape &shX = X.shape(); - const TensorShape &shW = W.shape(); + const TensorShape& shX = X.shape(); + const TensorShape& shW = W.shape(); TensorShape shY; DCHECK_EQ(shW.dims(), shX.dims()); @@ -103,7 +103,7 @@ class MatmulFltNvnmdOp : public OpKernel { } // create output - Tensor *Y = NULL; + Tensor* Y = NULL; OP_REQUIRES_OK(context, context->allocate_output(0, shY, &Y)); // compute @@ -130,7 +130,7 @@ class MatmulFltNvnmdOp : public OpKernel { for (hh = 0; hh < H; hh++) { // find x max exponnet if ((normx & 0x0f) == 0) { // normalize x[:,:] - find_max_expo(expo_max1, (FPTYPE *)&x[hh * N * M], + find_max_expo(expo_max1, (FPTYPE*)&x[hh * N * M], static_cast(N) * M); for (ii = 0; ii < N; ii++) { expo_max1s[ii] = expo_max1; @@ -138,14 +138,14 @@ class MatmulFltNvnmdOp : public OpKernel { } else { // normalize x[ii,:] for (ii = 0; ii < N; ii++) { - find_max_expo(expo_max1, (FPTYPE *)&x[hh * N * M + ii * M], M); + find_max_expo(expo_max1, (FPTYPE*)&x[hh * N * M + ii * M], M); expo_max1s[ii] = expo_max1; } } // find w max exponnet if ((normw & 0x0f) == 0) { // normalize w[:,:] - find_max_expo(expo_max2, (FPTYPE *)&w[hh * M * K], + find_max_expo(expo_max2, (FPTYPE*)&w[hh * M * K], static_cast(M) * K); for (kk = 0; kk < K; kk++) { expo_max2s[kk] = expo_max2; @@ -153,7 +153,7 @@ class MatmulFltNvnmdOp : public OpKernel { } else { // normalize w[:,kk] for (kk = 0; kk < K; kk++) { - find_max_expo(expo_max2, (FPTYPE *)&w[hh * M * K + kk], M, K); + find_max_expo(expo_max2, (FPTYPE*)&w[hh * M * K + kk], M, K); expo_max2s[kk] = expo_max2; } } diff --git a/source/op/tf/optimizer/parallel.cc b/source/op/tf/optimizer/parallel.cc index f5b7c62b6a..87a53b18ae 100644 --- a/source/op/tf/optimizer/parallel.cc +++ b/source/op/tf/optimizer/parallel.cc @@ -27,7 +27,7 @@ // based on tensorflow/core/grappler/optimizers/remapper.cc struct RemapperContext { - explicit RemapperContext(GrapplerItem *item, Status *status) + explicit RemapperContext(GrapplerItem* item, Status* status) : nodes_to_preserve(item->NodesToPreserve()), graph_view(&item->graph, status) {} @@ -35,11 +35,11 @@ struct RemapperContext { utils::MutableGraphView graph_view; }; -bool IsProdForce(const NodeDef &node) { return node.op() == "ProdForceSeA"; } +bool IsProdForce(const NodeDef& node) { return node.op() == "ProdForceSeA"; } -bool FindProdForce(RemapperContext *ctx, int node_index) { - const auto *node_view = ctx->graph_view.GetNode(node_index); - const auto *node_def = node_view->node(); +bool FindProdForce(RemapperContext* ctx, int node_index) { + const auto* node_view = ctx->graph_view.GetNode(node_index); + const auto* node_def = node_view->node(); return IsProdForce(*node_def); } @@ -55,17 +55,17 @@ TF_INT64 GetNThreads() { return tot; } -Status ParallelProdForce(RemapperContext *ctx, +Status ParallelProdForce(RemapperContext* ctx, int node_index, - std::vector *invalidated_nodes, - std::vector *nodes_to_delete) { + std::vector* invalidated_nodes, + std::vector* nodes_to_delete) { // skip on GPUs if (GetNumAvailableGPUs() > 0) { return Status(); } - const NodeDef *ori_node = ctx->graph_view.GetNode(node_index)->node(); - auto &src_attr = ori_node->attr(); + 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(); @@ -75,11 +75,11 @@ Status ParallelProdForce(RemapperContext *ctx, sum_node.set_name(ori_node->name()); sum_node.set_op("AddN"); sum_node.set_device(ori_node->device()); - auto *sum_attr = sum_node.mutable_attr(); + auto* sum_attr = sum_node.mutable_attr(); (*sum_attr)["N"].set_i(tot); (*sum_attr)["T"] = src_attr.at("T"); - utils::Mutation *mutation = ctx->graph_view.GetMutationBuilder(); + utils::Mutation* mutation = ctx->graph_view.GetMutationBuilder(); Status status; for (int ii = 0; ii < tot; ++ii) { @@ -92,7 +92,7 @@ Status ParallelProdForce(RemapperContext *ctx, sub_node.add_input(ori_node->input(jj)); } // set frac - auto *sub_attr = sub_node.mutable_attr(); + auto* sub_attr = sub_node.mutable_attr(); (*sub_attr)["T"] = src_attr.at("T"); (*sub_attr)["n_a_sel"] = src_attr.at("n_a_sel"); (*sub_attr)["n_r_sel"] = src_attr.at("n_r_sel"); @@ -111,9 +111,9 @@ Status ParallelProdForce(RemapperContext *ctx, return Status(); } -Status DPParallel::Optimize(Cluster *cluster, - const GrapplerItem &item, - GraphDef *optimized_graph) { +Status DPParallel::Optimize(Cluster* cluster, + const GrapplerItem& item, + GraphDef* optimized_graph) { GrapplerItem mutable_item = item; Status status; RemapperContext ctx(&mutable_item, &status); @@ -147,7 +147,7 @@ Status DPParallel::Optimize(Cluster *cluster, } // Remove invalidated nodes. - utils::Mutation *mutation = ctx.graph_view.GetMutationBuilder(); + utils::Mutation* mutation = ctx.graph_view.GetMutationBuilder(); for (int i = 0; i < num_nodes; ++i) { if (nodes_to_delete[i]) { mutation->RemoveNode(ctx.graph_view.GetNode(i)); diff --git a/source/op/tf/prod_force_se_a_mask.cc b/source/op/tf/prod_force_se_a_mask.cc index a7b08ae664..6c938f88e0 100644 --- a/source/op/tf/prod_force_se_a_mask.cc +++ b/source/op/tf/prod_force_se_a_mask.cc @@ -17,23 +17,23 @@ using CPUDevice = Eigen::ThreadPoolDevice; template class ProdForceSeAMaskOp : public OpKernel { public: - explicit ProdForceSeAMaskOp(OpKernelConstruction *context) + explicit ProdForceSeAMaskOp(OpKernelConstruction* context) : OpKernel(context) { OP_REQUIRES_OK(context, context->GetAttr("total_atom_num", &total_atom_num)); } - void Compute(OpKernelContext *context) override { + void Compute(OpKernelContext* context) override { deepmd::safe_compute( - context, [this](OpKernelContext *context) { this->_Compute(context); }); + context, [this](OpKernelContext* context) { this->_Compute(context); }); } - void _Compute(OpKernelContext *context) { + void _Compute(OpKernelContext* context) { // Grab the input tensor - const Tensor &net_deriv_tensor = context->input(0); - const Tensor &in_deriv_tensor = context->input(1); - const Tensor &mask_tensor = context->input(2); - const Tensor &nlist_tensor = context->input(3); + const Tensor& net_deriv_tensor = context->input(0); + const Tensor& in_deriv_tensor = context->input(1); + const Tensor& mask_tensor = context->input(2); + const Tensor& nlist_tensor = context->input(3); // set size of the sample OP_REQUIRES(context, (net_deriv_tensor.shape().dims() == 2), @@ -67,7 +67,7 @@ class ProdForceSeAMaskOp : public OpKernel { force_shape.AddDim(3 * static_cast(nall)); // std::cout << "forcesahpe " << force_shape.dim_size(0) << " " << // force_shape.dim_size(1) << std::endl; - Tensor *force_tensor = NULL; + Tensor* force_tensor = NULL; OP_REQUIRES_OK(context, context->allocate_output(0, force_shape, &force_tensor)); diff --git a/source/op/tf/prod_force_se_a_mask_grad.cc b/source/op/tf/prod_force_se_a_mask_grad.cc index a01919199f..c7ff091857 100644 --- a/source/op/tf/prod_force_se_a_mask_grad.cc +++ b/source/op/tf/prod_force_se_a_mask_grad.cc @@ -16,24 +16,24 @@ using CPUDevice = Eigen::ThreadPoolDevice; template class ProdForceSeAMaskGradOp : public OpKernel { public: - explicit ProdForceSeAMaskGradOp(OpKernelConstruction *context) + explicit ProdForceSeAMaskGradOp(OpKernelConstruction* context) : OpKernel(context) { OP_REQUIRES_OK(context, context->GetAttr("total_atom_num", &total_atom_num)); } - void Compute(OpKernelContext *context) override { + void Compute(OpKernelContext* context) override { deepmd::safe_compute( - context, [this](OpKernelContext *context) { this->_Compute(context); }); + context, [this](OpKernelContext* context) { this->_Compute(context); }); } - void _Compute(OpKernelContext *context) { + void _Compute(OpKernelContext* context) { // Grab the input tensor - const Tensor &grad_tensor = context->input(0); - const Tensor &net_deriv_tensor = context->input(1); - const Tensor &in_deriv_tensor = context->input(2); - const Tensor &mask_tensor = context->input(3); - const Tensor &nlist_tensor = context->input(4); + const Tensor& grad_tensor = context->input(0); + const Tensor& net_deriv_tensor = context->input(1); + const Tensor& in_deriv_tensor = context->input(2); + const Tensor& mask_tensor = context->input(3); + const Tensor& nlist_tensor = context->input(4); // set size of the sample TensorShape grad_shape = grad_tensor.shape(); @@ -82,7 +82,7 @@ class ProdForceSeAMaskGradOp : public OpKernel { grad_net_shape.AddDim(static_cast(nloc) * ndescrpt); // allocate the output tensor - Tensor *grad_net_tensor = NULL; + Tensor* grad_net_tensor = NULL; OP_REQUIRES_OK( context, context->allocate_output(0, grad_net_shape, &grad_net_tensor));