From 40f546fd0d7c39ac8e9e789d7cdf106bdc18a000 Mon Sep 17 00:00:00 2001 From: linpz Date: Sat, 14 Mar 2026 04:50:52 +0800 Subject: [PATCH 1/2] Refactor: add nullptr for uninitialized pointer --- source/source_base/intarray.h | 2 +- source/source_base/math_chebyshev.h | 4 +- source/source_base/mathzone_add1.cpp | 2 +- source/source_base/matrix_wrapper.h | 2 +- source/source_base/matrix_wrapper_tianhe2.h | 2 +- source/source_base/mcd.c | 10 ++-- .../ATen/core/tensor_accessor.h | 6 +- .../base/core/gpu_allocator.cpp | 4 +- .../base/third_party/cusolver.h | 16 ++--- .../base/third_party/hipsolver.h | 16 ++--- .../module_container/base/utils/array_ref.h | 2 +- source/source_base/module_fft/fft_dsp.cpp | 4 +- source/source_base/realarray.h | 2 +- .../source_basis/module_ao/ORB_nonlocal_lm.h | 10 ++-- source/source_basis/module_ao/ORB_read.h | 4 +- .../module_ao/parallel_orbitals.h | 6 +- .../module_pw/pw_transform_k_dsp.cpp | 10 ++-- .../source_cell/module_symmetry/symmetry.cpp | 4 +- source/source_esolver/esolver_fp.h | 2 +- .../module_charge/charge_mixing_dmr.cpp | 8 +-- .../module_charge/symmetry_rhog.cpp | 2 +- source/source_hamilt/matrixblock.h | 4 +- source/source_hamilt/module_surchem/surchem.h | 6 +- source/source_hsolver/diago_pexsi.h | 2 +- source/source_hsolver/hsolver_lcao.h | 2 +- source/source_hsolver/hsolver_lcaopw.h | 2 +- source/source_hsolver/hsolver_pw.h | 2 +- .../module_pexsi/dist_bcd_matrix.h | 2 +- .../module_pexsi/dist_ccs_matrix.h | 4 +- .../module_pexsi/dist_matrix_transformer.cpp | 10 ++-- .../module_pexsi/pexsi_solver.h | 8 +-- .../module_bessel/numerical_descriptor.h | 2 +- .../source_io/module_chgpot/get_pchg_lcao.h | 2 +- source/source_io/module_hs/cal_r_overlap_R.h | 2 +- .../module_ml/cal_mlkedf_descriptors.cpp | 2 +- source/source_io/module_output/binstream.h | 2 +- source/source_io/module_unk/berryphase.h | 2 +- .../module_wannier/to_wannier90_lcao.h | 2 +- .../module_wannier/to_wannier90_lcao_in_pw.h | 2 +- source/source_lcao/FORCE.h | 4 +- source/source_lcao/FORCE_STRESS.h | 2 +- source/source_lcao/center2_orb-orb11.h | 2 +- source/source_lcao/center2_orb-orb21.h | 2 +- source/source_lcao/center2_orb-orb22.h | 2 +- source/source_lcao/force_stress_arrays.h | 60 +++++++++---------- .../source_lcao/module_deepks/LCAO_deepks.h | 2 +- .../module_deltaspin/spin_constrain.h | 6 +- source/source_lcao/module_dftu/dftu_force.cpp | 2 +- source/source_lcao/module_gint/gint_atom.h | 6 +- source/source_lcao/module_gint/gint_dvlocal.h | 2 +- .../source_lcao/module_gint/gint_env_gamma.h | 2 +- source/source_lcao/module_gint/gint_env_k.h | 2 +- source/source_lcao/module_gint/gint_info.h | 2 +- source/source_lcao/module_gint/gint_vl.h | 2 +- source/source_lcao/module_gint/gint_vl_gpu.h | 2 +- .../source_lcao/module_gint/gint_vl_metagga.h | 4 +- .../module_gint/gint_vl_metagga_gpu.h | 4 +- .../module_hcontainer/read_hcontainer.h | 2 +- source/source_lcao/module_lr/lr_spectrum.h | 4 +- .../module_operator_lcao/td_ekinetic_lcao.h | 2 +- .../module_operator_lcao/veff_lcao.h | 4 +- source/source_lcao/module_rdmft/rdmft_tools.h | 14 ++--- source/source_lcao/module_rt/propagator.h | 2 +- source/source_lcao/pulay_fs_temp.hpp | 2 +- .../module_pwdft/fs_nonlocal_tools.h | 10 ++-- .../source_pw/module_pwdft/nonlocal_maths.hpp | 2 +- .../module_pwdft/onsite_proj_tools.h | 10 ++-- source/source_pw/module_pwdft/stress_cc.cpp | 2 +- source/source_pw/module_stodft/sto_iter.cpp | 6 +- source/source_relax/bfgs_basic.h | 2 +- source/source_relax/ions_move_cg.h | 8 +-- source/source_relax/ions_move_sd.h | 4 +- source/source_relax/lattice_change_cg.h | 8 +-- 73 files changed, 183 insertions(+), 183 deletions(-) diff --git a/source/source_base/intarray.h b/source/source_base/intarray.h index 9147dc184e6..a35f8aa887e 100644 --- a/source/source_base/intarray.h +++ b/source/source_base/intarray.h @@ -19,7 +19,7 @@ namespace ModuleBase class IntArray { public: - int *ptr; + int * ptr = nullptr; /** * @brief Construct a new Int Array object diff --git a/source/source_base/math_chebyshev.h b/source/source_base/math_chebyshev.h index 581e35eed8b..0b9acf50f08 100644 --- a/source/source_base/math_chebyshev.h +++ b/source/source_base/math_chebyshev.h @@ -249,7 +249,7 @@ class FFTW ~FFTW(); void execute_fftw(); double* dcoef; //[norder2] - fftw_complex* ccoef; + fftw_complex* ccoef = nullptr; fftw_plan coef_plan; }; @@ -262,7 +262,7 @@ class FFTW ~FFTW(); void execute_fftw(); float* dcoef; //[norder2] - fftwf_complex* ccoef; + fftwf_complex* ccoef = nullptr; fftwf_plan coef_plan; }; #endif diff --git a/source/source_base/mathzone_add1.cpp b/source/source_base/mathzone_add1.cpp index de9f9508b38..19e4ee59df7 100644 --- a/source/source_base/mathzone_add1.cpp +++ b/source/source_base/mathzone_add1.cpp @@ -64,7 +64,7 @@ void Mathzone_Add1::SplineD2 // modified by pengfei 13-8-8 add second derivative ModuleBase::timer::tick("Mathzone_Add1","SplineD2"); double dx1, dx2, dy1, dy2, p, qn, sig, un; - double *u; + double * u = nullptr; u = new double[mesh-1]; const double ypmax = 99999.00; diff --git a/source/source_base/matrix_wrapper.h b/source/source_base/matrix_wrapper.h index 30951bca1fa..018bc22ab7a 100644 --- a/source/source_base/matrix_wrapper.h +++ b/source/source_base/matrix_wrapper.h @@ -21,7 +21,7 @@ class Matrix_Wrapper public: int nr; int nc; - double *c; + double * c = nullptr; bool flag_delete_c; Matrix_Wrapper(): nr(0), nc(0), c(nullptr), flag_delete_c(false){} diff --git a/source/source_base/matrix_wrapper_tianhe2.h b/source/source_base/matrix_wrapper_tianhe2.h index 455b60e773d..b3b94e2a05e 100644 --- a/source/source_base/matrix_wrapper_tianhe2.h +++ b/source/source_base/matrix_wrapper_tianhe2.h @@ -16,7 +16,7 @@ namespace ModuleBase class Matrix_Wrapper { public: - double *c; + double * c = nullptr; int nr; int nc; diff --git a/source/source_base/mcd.c b/source/source_base/mcd.c index 2af353b717f..ca5009f468f 100644 --- a/source/source_base/mcd.c +++ b/source/source_base/mcd.c @@ -514,7 +514,7 @@ char *MCD_strdup(const char*s,char*fun,char*file,int line) char *MCD_strdup(char*s,char*fun,char*file,int line) #endif { - char *n; + char * n = nullptr; #ifdef MCD_FASTFREE n=(char*)malloc(sizeof(char)*strlen(s)+1+sizeof(Chunk)); @@ -542,7 +542,7 @@ char *MCD_strndup(const char*s, int z,char*fun,char*file,int line) char *MCD_strndup(char*s, int z,char*fun,char*file,int line) #endif { - char *n; + char * n = nullptr; int size; if((signed)strlen(s)>z) size=z; @@ -575,7 +575,7 @@ int MCD_asprintf(char **ptr,const char *fmt,char *fun, char*file, int line,...) int retval; va_list argptr; #ifdef MCD_FASTFREE - void *fc; + void * fc = nullptr; #endif va_start(argptr,line); @@ -610,7 +610,7 @@ int MCD_vasprintf(char **ptr,const char *fmt,va_list argptr,char *fun, char*file { int retval; #ifdef MCD_FASTFREE - void *fc; + void * fc = nullptr; #endif if((retval=vasprintf(ptr, fmt, argptr))<0) @@ -781,7 +781,7 @@ void showMemStats() Chunk*c=MemoryChunks; int total=0; - FILE *o; + FILE * o = nullptr; if(MemStatLog) o=MemStatLog; diff --git a/source/source_base/module_container/ATen/core/tensor_accessor.h b/source/source_base/module_container/ATen/core/tensor_accessor.h index 40edf98c311..9fbea6f0b81 100644 --- a/source/source_base/module_container/ATen/core/tensor_accessor.h +++ b/source/source_base/module_container/ATen/core/tensor_accessor.h @@ -58,9 +58,9 @@ class TensorAccessorBase { } protected: - T* data_; - const index_t* sizes_; - const index_t* strides_; + T* data_ = nullptr; + const index_t* sizes_ = nullptr; + const index_t* strides_ = nullptr; }; template (A), n, &lwork)); - cuComplex* work; + cuComplex* work = nullptr; CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(cuComplex))); // Perform Cholesky decomposition CHECK_CUSOLVER(cusolverDnCpotri(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast(A), n, work, lwork, nullptr)); @@ -86,7 +86,7 @@ void potri (cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& d { int lwork; CHECK_CUSOLVER(cusolverDnZpotri_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast(A), n, &lwork)); - cuDoubleComplex* work; + cuDoubleComplex* work = nullptr; CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(cuDoubleComplex))); // Perform Cholesky decomposition CHECK_CUSOLVER(cusolverDnZpotri(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast(A), n, work, lwork, nullptr)); @@ -101,7 +101,7 @@ void potrf (cusolverDnHandle_t& cusolver_handle, const char& uplo, const int& n, int *info = nullptr; CHECK_CUDA(cudaMalloc((void**)&info, 1 * sizeof(int))); CHECK_CUSOLVER(cusolverDnSpotrf_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, A, n, &lwork)); - float* work; + float* work = nullptr; CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(float))); // Perform Cholesky decomposition CHECK_CUSOLVER(cusolverDnSpotrf(cusolver_handle, cublas_fill_mode(uplo), n, A, n, work, lwork, info)); @@ -115,7 +115,7 @@ void potrf (cusolverDnHandle_t& cusolver_handle, const char& uplo, const int& n, int *info = nullptr; CHECK_CUDA(cudaMalloc((void**)&info, 1 * sizeof(int))); CHECK_CUSOLVER(cusolverDnDpotrf_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, A, n, &lwork)); - double* work; + double* work = nullptr; CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(double))); // Perform Cholesky decomposition CHECK_CUSOLVER(cusolverDnDpotrf(cusolver_handle, cublas_fill_mode(uplo), n, A, n, work, lwork, info)); @@ -129,7 +129,7 @@ void potrf (cusolverDnHandle_t& cusolver_handle, const char& uplo, const int& n, int *info = nullptr; CHECK_CUDA(cudaMalloc((void**)&info, 1 * sizeof(int))); CHECK_CUSOLVER(cusolverDnCpotrf_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast(A), lda, &lwork)); - cuComplex* work; + cuComplex* work = nullptr; CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(cuComplex))); // Perform Cholesky decomposition CHECK_CUSOLVER(cusolverDnCpotrf(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast(A), lda, work, lwork, info)); @@ -143,7 +143,7 @@ void potrf (cusolverDnHandle_t& cusolver_handle, const char& uplo, const int& n, int *info = nullptr; CHECK_CUDA(cudaMalloc((void**)&info, 1 * sizeof(int))); CHECK_CUSOLVER(cusolverDnZpotrf_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast(A), lda, &lwork)); - cuDoubleComplex* work; + cuDoubleComplex* work = nullptr; CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(cuDoubleComplex))); // Perform Cholesky decomposition CHECK_CUSOLVER(cusolverDnZpotrf(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast(A), lda, work, lwork, info)); diff --git a/source/source_base/module_container/base/third_party/hipsolver.h b/source/source_base/module_container/base/third_party/hipsolver.h index 58db644cb71..af8911be438 100644 --- a/source/source_base/module_container/base/third_party/hipsolver.h +++ b/source/source_base/module_container/base/third_party/hipsolver.h @@ -43,7 +43,7 @@ void potri (hipsolverHandle_t& hipsolver_handle, const char& uplo, const char& d { int lwork; hipsolverErrcheck(hipsolverDnSpotri_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, &lwork)); - float* work; + float* work = nullptr; hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(float))); // Perform Cholesky decomposition hipsolverErrcheck(hipsolverDnSpotri(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, work, lwork, nullptr)); @@ -54,7 +54,7 @@ void potri (hipsolverHandle_t& hipsolver_handle, const char& uplo, const char& d { int lwork; hipsolverErrcheck(hipsolverDnDpotri_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, &lwork)); - double* work; + double* work = nullptr; hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(double))); // Perform Cholesky decomposition hipsolverErrcheck(hipsolverDnDpotri(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, work, lwork, nullptr)); @@ -65,7 +65,7 @@ void potri (hipsolverHandle_t& hipsolver_handle, const char& uplo, const char& d { int lwork; hipsolverErrcheck(hipsolverDnCpotri_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast(A), n, &lwork)); - hipFloatComplex* work; + hipFloatComplex* work = nullptr; hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(hipFloatComplex))); // Perform Cholesky decomposition hipsolverErrcheck(hipsolverDnCpotri(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast(A), n, work, lwork, nullptr)); @@ -76,7 +76,7 @@ void potri (hipsolverHandle_t& hipsolver_handle, const char& uplo, const char& d { int lwork; hipsolverErrcheck(hipsolverDnZpotri_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast(A), n, &lwork)); - hipDoubleComplex* work; + hipDoubleComplex* work = nullptr; hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(hipDoubleComplex))); // Perform Cholesky decomposition hipsolverErrcheck(hipsolverDnZpotri(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast(A), n, work, lwork, nullptr)); @@ -89,7 +89,7 @@ void potrf (hipsolverHandle_t& hipsolver_handle, const char& uplo, const int& n, { int lwork; hipsolverErrcheck(hipsolverDnSpotrf_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, &lwork)); - float* work; + float* work = nullptr; hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(float))); // Perform Cholesky decomposition hipsolverErrcheck(hipsolverDnSpotrf(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, work, lwork, nullptr)); @@ -100,7 +100,7 @@ void potrf (hipsolverHandle_t& hipsolver_handle, const char& uplo, const int& n, { int lwork; hipsolverErrcheck(hipsolverDnDpotrf_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, &lwork)); - double* work; + double* work = nullptr; hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(double))); // Perform Cholesky decomposition hipsolverErrcheck(hipsolverDnDpotrf(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, work, lwork, nullptr)); @@ -111,7 +111,7 @@ void potrf (hipsolverHandle_t& hipsolver_handle, const char& uplo, const int& n, { int lwork; hipsolverErrcheck(hipsolverDnCpotrf_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast(A), n, &lwork)); - hipFloatComplex* work; + hipFloatComplex* work = nullptr; hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(hipFloatComplex))); // Perform Cholesky decomposition hipsolverErrcheck(hipsolverDnCpotrf(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast(A), n, work, lwork, nullptr)); @@ -122,7 +122,7 @@ void potrf (hipsolverHandle_t& hipsolver_handle, const char& uplo, const int& n, { int lwork; hipsolverErrcheck(hipsolverDnZpotrf_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast(A), n, &lwork)); - hipDoubleComplex* work; + hipDoubleComplex* work = nullptr; hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(hipDoubleComplex))); // Perform Cholesky decomposition hipsolverErrcheck(hipsolverDnZpotrf(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast(A), n, work, lwork, nullptr)); diff --git a/source/source_base/module_container/base/utils/array_ref.h b/source/source_base/module_container/base/utils/array_ref.h index 2af73ae9709..735a05c41b6 100644 --- a/source/source_base/module_container/base/utils/array_ref.h +++ b/source/source_base/module_container/base/utils/array_ref.h @@ -12,7 +12,7 @@ template class array_ref final { private: - T* data_; + T* data_ = nullptr; size_t length_; public: diff --git a/source/source_base/module_fft/fft_dsp.cpp b/source/source_base/module_fft/fft_dsp.cpp index ca4a0cd1e4b..67353d9a347 100644 --- a/source/source_base/module_fft/fft_dsp.cpp +++ b/source/source_base/module_fft/fft_dsp.cpp @@ -23,8 +23,8 @@ void FFT_DSP::setupFFT() { PROBLEM pbm_forward; PROBLEM pbm_backward; - PLAN* ptr_plan_forward; - PLAN* ptr_plan_backward; + PLAN* ptr_plan_forward = nullptr; + PLAN* ptr_plan_backward = nullptr; INT num_thread = 8; INT size=0; hthread_dat_load(cluster_id, FFT_DAT_DIR); diff --git a/source/source_base/realarray.h b/source/source_base/realarray.h index a5eacab3cc0..0fb76921487 100644 --- a/source/source_base/realarray.h +++ b/source/source_base/realarray.h @@ -20,7 +20,7 @@ namespace ModuleBase class realArray { public: - double *ptr; + double * ptr = nullptr; realArray(const int d1 = 1, const int d2 = 1, const int d3 = 1); realArray(const int d1, const int d2, const int d3, const int d4); diff --git a/source/source_basis/module_ao/ORB_nonlocal_lm.h b/source/source_basis/module_ao/ORB_nonlocal_lm.h index b3504065ae6..11e00d2470c 100644 --- a/source/source_basis/module_ao/ORB_nonlocal_lm.h +++ b/source/source_basis/module_ao/ORB_nonlocal_lm.h @@ -20,8 +20,8 @@ class Numerical_Nonlocal_Lm public: - double* beta_uniform; - double* dbeta_uniform; + double* beta_uniform = nullptr; + double* dbeta_uniform = nullptr; int nr_uniform; double dr_uniform; @@ -86,11 +86,11 @@ class Numerical_Nonlocal_Lm double dk; double* r_radial; //points of r - double* k_radial; + double* k_radial = nullptr; - double* rab; + double* rab = nullptr; double* beta_r; // |beta(r) * r> - double* beta_k; + double* beta_k = nullptr; }; #endif diff --git a/source/source_basis/module_ao/ORB_read.h b/source/source_basis/module_ao/ORB_read.h index 576759ac7b8..efb4d532b16 100644 --- a/source/source_basis/module_ao/ORB_read.h +++ b/source/source_basis/module_ao/ORB_read.h @@ -83,12 +83,12 @@ class LCAO_Orbitals std::vector cutoffs() const; /// numerical atomic orbitals - Numerical_Orbital* Phi; + Numerical_Orbital* Phi = nullptr; //caoyu add 2021-3-10 /// descriptor bases, saved as one-type atom orbital - Numerical_Orbital* Alpha; + Numerical_Orbital* Alpha = nullptr; // initialized in input.cpp double ecutwfc; diff --git a/source/source_basis/module_ao/parallel_orbitals.h b/source/source_basis/module_ao/parallel_orbitals.h index 1ff74d3b2df..2d6a6e7ad90 100644 --- a/source/source_basis/module_ao/parallel_orbitals.h +++ b/source/source_basis/module_ao/parallel_orbitals.h @@ -30,8 +30,8 @@ class Parallel_Orbitals : public Parallel_2D /// on all adjacent atoms-pairs(2D division) ///--------------------------------------- int nnr=1; - int *nlocdim; - int *nlocstart; + int * nlocdim = nullptr; + int * nlocstart = nullptr; #ifdef __MPI int desc_wfc[9]; //for wfc, nlocal*nbands @@ -49,7 +49,7 @@ class Parallel_Orbitals : public Parallel_2D const int& lld); #endif - int* loc_sizes; + int* loc_sizes = nullptr; int loc_size; int get_wfc_global_nbands () const; diff --git a/source/source_basis/module_pw/pw_transform_k_dsp.cpp b/source/source_basis/module_pw/pw_transform_k_dsp.cpp index 82620738951..251c21372e5 100644 --- a/source/source_basis/module_pw/pw_transform_k_dsp.cpp +++ b/source/source_basis/module_pw/pw_transform_k_dsp.cpp @@ -33,8 +33,8 @@ void PW_Basis_K::real2recip_dsp(const std::complex* in, const bool add, const double factor) const { - const base_device::DEVICE_CPU* ctx; - const base_device::DEVICE_GPU* gpux; + const base_device::DEVICE_CPU* ctx = nullptr; + const base_device::DEVICE_GPU* gpux = nullptr; assert(this->gamma_only == false); auto* auxr = this->fft_bundle.get_auxr_3d_data(); @@ -65,8 +65,8 @@ void PW_Basis_K::recip2real_dsp(const std::complex* in, const double factor) const { assert(this->gamma_only == false); - const base_device::DEVICE_CPU* ctx; - const base_device::DEVICE_GPU* gpux; + const base_device::DEVICE_CPU* ctx = nullptr; + const base_device::DEVICE_GPU* gpux = nullptr; // memset the auxr of 0 in the auxr,here the len of the auxr is nxyz auto* auxr = this->fft_bundle.get_auxr_3d_data(); memset(auxr, 0, this->nxyz * 2 * 8); @@ -115,7 +115,7 @@ void PW_Basis_K::convolution(const base_device::DEVICE_CPU* ctx, ModuleBase::timer::tick(this->classname, "convolution"); assert(this->gamma_only == false); - const base_device::DEVICE_GPU* gpux; + const base_device::DEVICE_GPU* gpux = nullptr; // memset the auxr of 0 in the auxr,here the len of the auxr is nxyz auto* auxr = this->fft_bundle.get_auxr_3d_data(); memset(auxr, 0, this->nxyz * 2 * 8); diff --git a/source/source_cell/module_symmetry/symmetry.cpp b/source/source_cell/module_symmetry/symmetry.cpp index d65bb4ffe4d..30c479d16aa 100644 --- a/source/source_cell/module_symmetry/symmetry.cpp +++ b/source/source_cell/module_symmetry/symmetry.cpp @@ -85,8 +85,8 @@ void Symmetry::set_atom_map(const Atom* atoms) void Symmetry::symmetrize_vec3_nat(double* v)const // pengfei 2016-12-20 { ModuleBase::TITLE("Symmetry", "symmetrize_vec3_nat"); - double* vtot; - int* n; + double* vtot = nullptr; + int* n = nullptr; vtot = new double[nat * 3]; ModuleBase::GlobalFunc::ZEROS(vtot, nat * 3); n = new int[nat]; ModuleBase::GlobalFunc::ZEROS(n, nat); diff --git a/source/source_esolver/esolver_fp.h b/source/source_esolver/esolver_fp.h index 9edf4f33679..a57af07901d 100644 --- a/source/source_esolver/esolver_fp.h +++ b/source/source_esolver/esolver_fp.h @@ -59,7 +59,7 @@ class ESolver_FP: public ESolver //! dense grid for for uspp, used for ultrasoft augmented charge density. //! charge density and potential are defined on dense grids, //! but effective potential needs to be interpolated on smooth grids in order to compute Veff|psi> - ModulePW::PW_Basis* pw_rho; + ModulePW::PW_Basis* pw_rho = nullptr; ModulePW::PW_Basis* pw_rhod; //! dense grid for USPP ModulePW::PW_Basis_Big* pw_big; ///< [temp] pw_basis_big class diff --git a/source/source_estate/module_charge/charge_mixing_dmr.cpp b/source/source_estate/module_charge/charge_mixing_dmr.cpp index 4987110b0f4..9b3ac9f394d 100644 --- a/source/source_estate/module_charge/charge_mixing_dmr.cpp +++ b/source/source_estate/module_charge/charge_mixing_dmr.cpp @@ -58,8 +58,8 @@ void Charge_Mixing::mix_dmr(elecstate::DensityMatrix* DM) dmr_mag_save = new double[nnr * PARAM.inp.nspin]; ModuleBase::GlobalFunc::ZEROS(dmr_mag, nnr * PARAM.inp.nspin); ModuleBase::GlobalFunc::ZEROS(dmr_mag_save, nnr * PARAM.inp.nspin); - double* dmr_up; - double* dmr_down; + double* dmr_up = nullptr; + double* dmr_down = nullptr; // tranfer dmr into dmr_mag dmr_up = dmr[0]->get_wrapper(); dmr_down = dmr[1]->get_wrapper(); @@ -157,8 +157,8 @@ void Charge_Mixing::mix_dmr(elecstate::DensityMatrix, doubl dmr_mag_save = new double[nnr * PARAM.inp.nspin]; ModuleBase::GlobalFunc::ZEROS(dmr_mag, nnr * PARAM.inp.nspin); ModuleBase::GlobalFunc::ZEROS(dmr_mag_save, nnr * PARAM.inp.nspin); - double* dmr_up; - double* dmr_down; + double* dmr_up = nullptr; + double* dmr_down = nullptr; // tranfer dmr into dmr_mag dmr_up = dmr[0]->get_wrapper(); dmr_down = dmr[1]->get_wrapper(); diff --git a/source/source_estate/module_charge/symmetry_rhog.cpp b/source/source_estate/module_charge/symmetry_rhog.cpp index 7d37df1d802..3a537560bbc 100644 --- a/source/source_estate/module_charge/symmetry_rhog.cpp +++ b/source/source_estate/module_charge/symmetry_rhog.cpp @@ -17,7 +17,7 @@ void Symmetry_rho::psymmg(std::complex* rhog_part, const ModulePW::PW_Ba // (2) reduce all rho from the first pool. std::complex* rhogtot; - int* ig2isztot; + int* ig2isztot = nullptr; if(GlobalV::RANK_IN_POOL == 0) { rhogtot = new std::complex[rho_basis->npwtot]; diff --git a/source/source_hamilt/matrixblock.h b/source/source_hamilt/matrixblock.h index 481a95b8a58..03812a3203e 100644 --- a/source/source_hamilt/matrixblock.h +++ b/source/source_hamilt/matrixblock.h @@ -9,10 +9,10 @@ template struct MatrixBlock { /* this is a simple template block of a matrix would change to Eigen in the future */ - T* p; + T* p = nullptr; size_t row; size_t col; - const int* desc; + const int* desc = nullptr; }; } // namespace hamilt diff --git a/source/source_hamilt/module_surchem/surchem.h b/source/source_hamilt/module_surchem/surchem.h index f7aa0a4b028..b272d0f70e5 100644 --- a/source/source_hamilt/module_surchem/surchem.h +++ b/source/source_hamilt/module_surchem/surchem.h @@ -17,9 +17,9 @@ class surchem surchem(); ~surchem(); - double* TOTN_real; - double* delta_phi; - double* epspot; + double* TOTN_real = nullptr; + double* delta_phi = nullptr; + double* epspot = nullptr; ModuleBase::matrix Vcav; ModuleBase::matrix Vel; double qs; diff --git a/source/source_hsolver/diago_pexsi.h b/source/source_hsolver/diago_pexsi.h index 242dd0350e3..9871935f0f0 100644 --- a/source/source_hsolver/diago_pexsi.h +++ b/source/source_hsolver/diago_pexsi.h @@ -22,7 +22,7 @@ class DiagoPexsi public: DiagoPexsi(const Parallel_Orbitals* ParaV_in); void diag(hamilt::Hamilt* phm_in, psi::Psi& psi, Real* eigenvalue_in); - const Parallel_Orbitals* ParaV; + const Parallel_Orbitals* ParaV = nullptr; std::vector DM; std::vector EDM; double totalEnergyH; diff --git a/source/source_hsolver/hsolver_lcao.h b/source/source_hsolver/hsolver_lcao.h index eebab34208b..87ed6ac4c9d 100644 --- a/source/source_hsolver/hsolver_lcao.h +++ b/source/source_hsolver/hsolver_lcao.h @@ -35,7 +35,7 @@ class HSolverLCAO psi::Psi& psi, elecstate::ElecState* pes); - const Parallel_Orbitals* ParaV; + const Parallel_Orbitals* ParaV = nullptr; const std::string method; }; diff --git a/source/source_hsolver/hsolver_lcaopw.h b/source/source_hsolver/hsolver_lcaopw.h index 79c9acde03d..13c359b2e91 100644 --- a/source/source_hsolver/hsolver_lcaopw.h +++ b/source/source_hsolver/hsolver_lcaopw.h @@ -36,7 +36,7 @@ class HSolverLIP const int nat); private: - ModulePW::PW_Basis_K* wfc_basis; + ModulePW::PW_Basis_K* wfc_basis = nullptr; }; } // namespace hsolver diff --git a/source/source_hsolver/hsolver_pw.h b/source/source_hsolver/hsolver_pw.h index ae634fb862d..2ba686063a9 100644 --- a/source/source_hsolver/hsolver_pw.h +++ b/source/source_hsolver/hsolver_pw.h @@ -71,7 +71,7 @@ class HSolverPW void output_iterInfo(); - ModulePW::PW_Basis_K* wfc_basis; + ModulePW::PW_Basis_K* wfc_basis = nullptr; const std::string calculation_type; const std::string basis_type; diff --git a/source/source_hsolver/module_pexsi/dist_bcd_matrix.h b/source/source_hsolver/module_pexsi/dist_bcd_matrix.h index c1b5657b672..bea324cacf9 100644 --- a/source/source_hsolver/module_pexsi/dist_bcd_matrix.h +++ b/source/source_hsolver/module_pexsi/dist_bcd_matrix.h @@ -75,7 +75,7 @@ class DistBCDMatrix // current process id int myproc; - int* prowpcol2pnum; + int* prowpcol2pnum = nullptr; // the local data layout // 'R' or 'r' for row-major, which is used in C/C++ // 'C' or 'c' for column-major, which is used in Fortran diff --git a/source/source_hsolver/module_pexsi/dist_ccs_matrix.h b/source/source_hsolver/module_pexsi/dist_ccs_matrix.h index 86bfddb966d..b4a25fdd9ea 100644 --- a/source/source_hsolver/module_pexsi/dist_ccs_matrix.h +++ b/source/source_hsolver/module_pexsi/dist_ccs_matrix.h @@ -86,8 +86,8 @@ class DistCCSMatrix int firstCol=0; // Array stores the indices to the nonzero row indices in rowptrLocal and nzvalLocal - int* colptrLocal; - int* rowindLocal; + int* colptrLocal = nullptr; + int* rowindLocal = nullptr; // friend class DistMatrixTransformer; }; diff --git a/source/source_hsolver/module_pexsi/dist_matrix_transformer.cpp b/source/source_hsolver/module_pexsi/dist_matrix_transformer.cpp index 7a4ecec6b11..43f069c1238 100644 --- a/source/source_hsolver/module_pexsi/dist_matrix_transformer.cpp +++ b/source/source_hsolver/module_pexsi/dist_matrix_transformer.cpp @@ -554,11 +554,11 @@ int DistMatrixTransformer::transformCCStoBCD(DistCCSMatrix& SRC_Matrix, // setup up sender index and receiver index int sender_size = SRC_Matrix.get_nnzlocal(); - int* sender_index; - double* sender_buffer; - int* dst_index; - int* receiver_index; - double* receiver_buffer; + int* sender_index = nullptr; + double* sender_buffer = nullptr; + int* dst_index = nullptr; + int* receiver_index = nullptr; + double* receiver_buffer = nullptr; if (sender_size > 0) { diff --git a/source/source_hsolver/module_pexsi/pexsi_solver.h b/source/source_hsolver/module_pexsi/pexsi_solver.h index b041d136560..922f1b9fb3d 100644 --- a/source/source_hsolver/module_pexsi/pexsi_solver.h +++ b/source/source_hsolver/module_pexsi/pexsi_solver.h @@ -130,10 +130,10 @@ class PEXSI_Solver int nb; int nrow; int ncol; - double* h; - double* s; - double* DM; - double* EDM; + double* h = nullptr; + double* s = nullptr; + double* DM = nullptr; + double* EDM = nullptr; double totalEnergyH; double totalEnergyS; double totalFreeEnergy; diff --git a/source/source_io/module_bessel/numerical_descriptor.h b/source/source_io/module_bessel/numerical_descriptor.h index ec504ee4a6f..8558779cfd9 100644 --- a/source/source_io/module_bessel/numerical_descriptor.h +++ b/source/source_io/module_bessel/numerical_descriptor.h @@ -32,7 +32,7 @@ class Numerical_Descriptor Bessel_Basis bessel_basis; - ModuleBase::IntArray *mu_index; + ModuleBase::IntArray * mu_index = nullptr; void init_mu_index(const UnitCell& ucell);//mohan added 2021-01-03 // void jlq3d_overlap(ModuleBase::realArray &overlap_Q1, ModuleBase::realArray &overlap_Q2, diff --git a/source/source_io/module_chgpot/get_pchg_lcao.h b/source/source_io/module_chgpot/get_pchg_lcao.h index 130637c7750..4b4de152f81 100644 --- a/source/source_io/module_chgpot/get_pchg_lcao.h +++ b/source/source_io/module_chgpot/get_pchg_lcao.h @@ -101,6 +101,6 @@ class Get_pchg_lcao std::vector bands_picked_; psi::Psi* psi_gamma = nullptr; psi::Psi>* psi_k = nullptr; - const Parallel_Orbitals* ParaV; + const Parallel_Orbitals* ParaV = nullptr; }; #endif // GET_PCHG_LCAO_H diff --git a/source/source_io/module_hs/cal_r_overlap_R.h b/source/source_io/module_hs/cal_r_overlap_R.h index c56f2b02e90..81d093bfe09 100644 --- a/source/source_io/module_hs/cal_r_overlap_R.h +++ b/source/source_io/module_hs/cal_r_overlap_R.h @@ -98,6 +98,6 @@ class cal_r_overlap_R std::map>>>> center2_orb21_r_nonlocal; - const Parallel_Orbitals* ParaV; + const Parallel_Orbitals* ParaV = nullptr; }; #endif diff --git a/source/source_io/module_ml/cal_mlkedf_descriptors.cpp b/source/source_io/module_ml/cal_mlkedf_descriptors.cpp index 7e88cddfdec..b0b627fec23 100644 --- a/source/source_io/module_ml/cal_mlkedf_descriptors.cpp +++ b/source/source_io/module_ml/cal_mlkedf_descriptors.cpp @@ -416,7 +416,7 @@ void Cal_MLKEDF_Descriptors::getF_KS( double epsilonM = pelec->ekb(0,0); assert(PARAM.inp.nspin == 1); - base_device::DEVICE_CPU* ctx; + base_device::DEVICE_CPU* ctx = nullptr; // calculate positive definite kinetic energy density for (int ik = 0; ik < psi->get_nk(); ++ik) diff --git a/source/source_io/module_output/binstream.h b/source/source_io/module_output/binstream.h index ef5cd62a872..c7fbf128ed5 100644 --- a/source/source_io/module_output/binstream.h +++ b/source/source_io/module_output/binstream.h @@ -19,7 +19,7 @@ class Binstream }; Binstream(const std::string,const char*); ~Binstream(); - FILE* fileptr; + FILE* fileptr = nullptr; void close(); void open(const std::string,const char*); bool operator!() const; diff --git a/source/source_io/module_unk/berryphase.h b/source/source_io/module_unk/berryphase.h index a040fe758cf..d7871a028c4 100644 --- a/source/source_io/module_unk/berryphase.h +++ b/source/source_io/module_unk/berryphase.h @@ -24,7 +24,7 @@ class berryphase unkOverlap_pw pw_method; #ifdef __LCAO unkOverlap_lcao lcao_method; - const Parallel_Orbitals* paraV; + const Parallel_Orbitals* paraV = nullptr; #endif int total_string=0; diff --git a/source/source_io/module_wannier/to_wannier90_lcao.h b/source/source_io/module_wannier/to_wannier90_lcao.h index 6681dadece7..b50555c4265 100644 --- a/source/source_io/module_wannier/to_wannier90_lcao.h +++ b/source/source_io/module_wannier/to_wannier90_lcao.h @@ -126,7 +126,7 @@ class toWannier90_LCAO : public toWannier90 std::vector iw2im; std::vector iw2iorb; - const Parallel_Orbitals* ParaV; + const Parallel_Orbitals* ParaV = nullptr; void initialize_orb_table(const UnitCell& ucell); void produce_basis_orb(); diff --git a/source/source_io/module_wannier/to_wannier90_lcao_in_pw.h b/source/source_io/module_wannier/to_wannier90_lcao_in_pw.h index 763c050a81b..04a2414e9fe 100644 --- a/source/source_io/module_wannier/to_wannier90_lcao_in_pw.h +++ b/source/source_io/module_wannier/to_wannier90_lcao_in_pw.h @@ -65,7 +65,7 @@ class toWannier90_LCAO_IN_PW : public toWannier90_PW } protected: - const Parallel_Orbitals* ParaV; + const Parallel_Orbitals* ParaV = nullptr; /// @brief psi initializer for expanding nao in planewave basis psi_initializer>* psi_initer_ = nullptr; diff --git a/source/source_lcao/FORCE.h b/source/source_lcao/FORCE.h index a80dd02f25a..553cdfad769 100644 --- a/source/source_lcao/FORCE.h +++ b/source/source_lcao/FORCE.h @@ -26,9 +26,9 @@ class Force_LCAO ~Force_LCAO(){}; private: - const Parallel_Orbitals* ParaV; + const Parallel_Orbitals* ParaV = nullptr; - elecstate::Potential* pot; + elecstate::Potential* pot = nullptr; // orthonormal force + contribution from T and VNL void ftable(const bool isforce, diff --git a/source/source_lcao/FORCE_STRESS.h b/source/source_lcao/FORCE_STRESS.h index 8fce219b5a8..1265664996e 100644 --- a/source/source_lcao/FORCE_STRESS.h +++ b/source/source_lcao/FORCE_STRESS.h @@ -58,7 +58,7 @@ class Force_Stress_LCAO private: int nat; - Record_adj* RA; + Record_adj* RA = nullptr; Force_LCAO flk; Stress_Func sc_pw; diff --git a/source/source_lcao/center2_orb-orb11.h b/source/source_lcao/center2_orb-orb11.h index 23ffc898def..41a88c72531 100644 --- a/source/source_lcao/center2_orb-orb11.h +++ b/source/source_lcao/center2_orb-orb11.h @@ -42,7 +42,7 @@ class Center2_Orb::Orb11 const Numerical_Orbital_Lm& nA; const Numerical_Orbital_Lm& nB; - const ModuleBase::Sph_Bessel_Recursive::D2* psb_; + const ModuleBase::Sph_Bessel_Recursive::D2* psb_ = nullptr; const ORB_gaunt_table& MGT; std::map> Table_r; // unit: Bohr/MOT.dr diff --git a/source/source_lcao/center2_orb-orb21.h b/source/source_lcao/center2_orb-orb21.h index 37d0d8fe789..715256d298b 100644 --- a/source/source_lcao/center2_orb-orb21.h +++ b/source/source_lcao/center2_orb-orb21.h @@ -45,7 +45,7 @@ class Center2_Orb::Orb21 const Numerical_Orbital_Lm& nA2; const Numerical_Orbital_Lm& nB; - const ModuleBase::Sph_Bessel_Recursive::D2* psb_; + const ModuleBase::Sph_Bessel_Recursive::D2* psb_ = nullptr; const ORB_gaunt_table& MGT; std::map nA; diff --git a/source/source_lcao/center2_orb-orb22.h b/source/source_lcao/center2_orb-orb22.h index 7a57742f20e..1f4af8413f2 100644 --- a/source/source_lcao/center2_orb-orb22.h +++ b/source/source_lcao/center2_orb-orb22.h @@ -49,7 +49,7 @@ class Center2_Orb::Orb22 const Numerical_Orbital_Lm& nB1; const Numerical_Orbital_Lm& nB2; - const ModuleBase::Sph_Bessel_Recursive::D2* psb_; + const ModuleBase::Sph_Bessel_Recursive::D2* psb_ = nullptr; const ORB_gaunt_table& MGT; std::map nB; diff --git a/source/source_lcao/force_stress_arrays.h b/source/source_lcao/force_stress_arrays.h index ab8039ec1d5..725665f5c85 100644 --- a/source/source_lcao/force_stress_arrays.h +++ b/source/source_lcao/force_stress_arrays.h @@ -12,33 +12,33 @@ class ForceStressArrays // force in LCAO // used in gamma only algorithm. //----------------------------------------- - double* DSloc_x; - double* DSloc_y; - double* DSloc_z; + double* DSloc_x = nullptr; + double* DSloc_y = nullptr; + double* DSloc_z = nullptr; //----------------------------------------- // force in LCAO // used in k-points algorithm. //----------------------------------------- - double* DSloc_Rx; - double* DSloc_Ry; - double* DSloc_Rz; + double* DSloc_Rx = nullptr; + double* DSloc_Ry = nullptr; + double* DSloc_Rz = nullptr; //----------------------------------------- // dT + part of dVNL // used in gamma only algorithm. //----------------------------------------- - double* DHloc_fixed_x; - double* DHloc_fixed_y; - double* DHloc_fixed_z; + double* DHloc_fixed_x = nullptr; + double* DHloc_fixed_y = nullptr; + double* DHloc_fixed_z = nullptr; //----------------------------------------- // dT + part of dVNL // used in kpoint algorithm. //----------------------------------------- - double* DHloc_fixedR_x; - double* DHloc_fixedR_y; - double* DHloc_fixedR_z; + double* DHloc_fixedR_x = nullptr; + double* DHloc_fixedR_y = nullptr; + double* DHloc_fixedR_z = nullptr; //---------------------------------------- // r_mu - r_nu @@ -46,26 +46,26 @@ class ForceStressArrays double* DH_r;//zhengdy added 2017-07 - double* stvnl11; - double* stvnl12; - double* stvnl13; - double* stvnl22; - double* stvnl23; - double* stvnl33; + double* stvnl11 = nullptr; + double* stvnl12 = nullptr; + double* stvnl13 = nullptr; + double* stvnl22 = nullptr; + double* stvnl23 = nullptr; + double* stvnl33 = nullptr; - double* DSloc_11; - double* DSloc_12; - double* DSloc_13; - double* DSloc_22; - double* DSloc_23; - double* DSloc_33; + double* DSloc_11 = nullptr; + double* DSloc_12 = nullptr; + double* DSloc_13 = nullptr; + double* DSloc_22 = nullptr; + double* DSloc_23 = nullptr; + double* DSloc_33 = nullptr; - double* DHloc_fixed_11; - double* DHloc_fixed_12; - double* DHloc_fixed_13; - double* DHloc_fixed_22; - double* DHloc_fixed_23; - double* DHloc_fixed_33; + double* DHloc_fixed_11 = nullptr; + double* DHloc_fixed_12 = nullptr; + double* DHloc_fixed_13 = nullptr; + double* DHloc_fixed_22 = nullptr; + double* DHloc_fixed_23 = nullptr; + double* DHloc_fixed_33 = nullptr; }; diff --git a/source/source_lcao/module_deepks/LCAO_deepks.h b/source/source_lcao/module_deepks/LCAO_deepks.h index bb98f75a4b2..0fe4815a956 100644 --- a/source/source_lcao/module_deepks/LCAO_deepks.h +++ b/source/source_lcao/module_deepks/LCAO_deepks.h @@ -156,7 +156,7 @@ class LCAO_Deepks const LCAO_Orbitals& orb, std::ofstream& ofs); - const Parallel_Orbitals* pv; + const Parallel_Orbitals* pv = nullptr; }; #endif diff --git a/source/source_lcao/module_deltaspin/spin_constrain.h b/source/source_lcao/module_deltaspin/spin_constrain.h index f4868aa93a1..c900a771f30 100644 --- a/source/source_lcao/module_deltaspin/spin_constrain.h +++ b/source/source_lcao/module_deltaspin/spin_constrain.h @@ -266,9 +266,9 @@ class SpinConstrain /// @brief if atomic magnetic moment is converged bool is_Mi_converged = false; - TK* sub_h_save; - TK* sub_s_save; - TK* becp_save; + TK* sub_h_save = nullptr; + TK* sub_s_save = nullptr; + TK* becp_save = nullptr; }; diff --git a/source/source_lcao/module_dftu/dftu_force.cpp b/source/source_lcao/module_dftu/dftu_force.cpp index ae588ae15aa..9cfc8c8f3ff 100644 --- a/source/source_lcao/module_dftu/dftu_force.cpp +++ b/source/source_lcao/module_dftu/dftu_force.cpp @@ -383,7 +383,7 @@ void Plus_U::cal_force_gamma(const UnitCell& ucell, for (int dim = 0; dim < 3; dim++) { - double* tmp_ptr; + double* tmp_ptr = nullptr; if (dim == 0) { tmp_ptr = dsloc_x; diff --git a/source/source_lcao/module_gint/gint_atom.h b/source/source_lcao/module_gint/gint_atom.h index aff8aae5b9c..cf917684818 100644 --- a/source/source_lcao/module_gint/gint_atom.h +++ b/source/source_lcao/module_gint/gint_atom.h @@ -88,7 +88,7 @@ class GintAtom private: // the atom object - const Atom* atom_; + const Atom* atom_ = nullptr; // the global index of the atom type int it_; @@ -110,9 +110,9 @@ class GintAtom Vec3d tau_in_biggrid_; // the numerical orbitals of this atom - const Numerical_Orbital* orb_; + const Numerical_Orbital* orb_ = nullptr; - const UnitCell* ucell_; + const UnitCell* ucell_ = nullptr; std::vector p_psi_uniform_; std::vector p_dpsi_uniform_; diff --git a/source/source_lcao/module_gint/gint_dvlocal.h b/source/source_lcao/module_gint/gint_dvlocal.h index c14f14359ac..dc48b102922 100644 --- a/source/source_lcao/module_gint/gint_dvlocal.h +++ b/source/source_lcao/module_gint/gint_dvlocal.h @@ -51,7 +51,7 @@ class Gint_dvlocal : public Gint LCAO_HS_Arrays& HS_Arrays); // input - const double* vr_eff_; + const double* vr_eff_ = nullptr; int nspin_; int npol_; diff --git a/source/source_lcao/module_gint/gint_env_gamma.h b/source/source_lcao/module_gint/gint_env_gamma.h index 39357a578b6..f0c54d8bb4c 100644 --- a/source/source_lcao/module_gint/gint_env_gamma.h +++ b/source/source_lcao/module_gint/gint_env_gamma.h @@ -23,7 +23,7 @@ class Gint_env_gamma : public Gint private: // output - double* rho_; + double* rho_ = nullptr; // intermediate variable std::vector wfc_gint_; diff --git a/source/source_lcao/module_gint/gint_env_k.h b/source/source_lcao/module_gint/gint_env_k.h index 0221fccfc12..afa9b8f8ee0 100644 --- a/source/source_lcao/module_gint/gint_env_k.h +++ b/source/source_lcao/module_gint/gint_env_k.h @@ -35,7 +35,7 @@ class Gint_env_k : public Gint int npol_; // output - double* rho_; + double* rho_ = nullptr; // intermediate variable std::vector> wfc_gint_; diff --git a/source/source_lcao/module_gint/gint_info.h b/source/source_lcao/module_gint/gint_info.h index 2f36548a454..2bec16ac982 100644 --- a/source/source_lcao/module_gint/gint_info.h +++ b/source/source_lcao/module_gint/gint_info.h @@ -62,7 +62,7 @@ class GintInfo // initialize the ijr_info void init_ijr_info_(const UnitCell& ucell, Grid_Driver& gd); - const UnitCell* ucell_; + const UnitCell* ucell_ = nullptr; // the unitcell information std::shared_ptr unitcell_info_; diff --git a/source/source_lcao/module_gint/gint_vl.h b/source/source_lcao/module_gint/gint_vl.h index fe3c9fa8c3b..7cb2abf6dd0 100644 --- a/source/source_lcao/module_gint/gint_vl.h +++ b/source/source_lcao/module_gint/gint_vl.h @@ -28,7 +28,7 @@ class Gint_vl : public Gint void cal_hr_gint_(); // input - const double* vr_eff_; + const double* vr_eff_ = nullptr; // output HContainer* hR_; diff --git a/source/source_lcao/module_gint/gint_vl_gpu.h b/source/source_lcao/module_gint/gint_vl_gpu.h index a671b6b33ac..f4ca9251d10 100644 --- a/source/source_lcao/module_gint/gint_vl_gpu.h +++ b/source/source_lcao/module_gint/gint_vl_gpu.h @@ -31,7 +31,7 @@ class Gint_vl_gpu : public Gint void cal_hr_gint_(); // input - const double* vr_eff_; + const double* vr_eff_ = nullptr; // output diff --git a/source/source_lcao/module_gint/gint_vl_metagga.h b/source/source_lcao/module_gint/gint_vl_metagga.h index 42a2041ddcc..47e31b685dc 100644 --- a/source/source_lcao/module_gint/gint_vl_metagga.h +++ b/source/source_lcao/module_gint/gint_vl_metagga.h @@ -29,8 +29,8 @@ class Gint_vl_metagga : public Gint void cal_hr_gint_(); // input - const double* vr_eff_; - const double* vofk_; + const double* vr_eff_ = nullptr; + const double* vofk_ = nullptr; // output HContainer* hR_; diff --git a/source/source_lcao/module_gint/gint_vl_metagga_gpu.h b/source/source_lcao/module_gint/gint_vl_metagga_gpu.h index f55c409c663..0e50564f3bc 100644 --- a/source/source_lcao/module_gint/gint_vl_metagga_gpu.h +++ b/source/source_lcao/module_gint/gint_vl_metagga_gpu.h @@ -34,8 +34,8 @@ class Gint_vl_metagga_gpu : public Gint void cal_hr_gint_(); // input - const double* vr_eff_; - const double* vofk_; + const double* vr_eff_ = nullptr; + const double* vofk_ = nullptr; // output HContainer* hR_; diff --git a/source/source_lcao/module_hcontainer/read_hcontainer.h b/source/source_lcao/module_hcontainer/read_hcontainer.h index 2a0ca9d4668..3d68079357c 100644 --- a/source/source_lcao/module_hcontainer/read_hcontainer.h +++ b/source/source_lcao/module_hcontainer/read_hcontainer.h @@ -39,7 +39,7 @@ class Read_HContainer hamilt::HContainer* _hcontainer; std::string _filename; int _nlocal; - const UnitCell* _ucell; + const UnitCell* _ucell = nullptr; }; } // namespace hamilt diff --git a/source/source_lcao/module_lr/lr_spectrum.h b/source/source_lcao/module_lr/lr_spectrum.h index 79a188621b4..5ed4678dc9c 100644 --- a/source/source_lcao/module_lr/lr_spectrum.h +++ b/source/source_lcao/module_lr/lr_spectrum.h @@ -67,8 +67,8 @@ namespace LR const int ldim = 1;///< local leading dimension of X, or the data size of each state const int gdim = 1;///< global leading dimension of X const double ana_thr = 0.3; ///< {abs(X) > thr} will appear in the transition analysis log - const double* eig; - const T* X; + const double* eig = nullptr; + const T* X = nullptr; const K_Vectors& kv; std::vector> psi_ks; const std::vector& pX; diff --git a/source/source_lcao/module_operator_lcao/td_ekinetic_lcao.h b/source/source_lcao/module_operator_lcao/td_ekinetic_lcao.h index fba4ccccf83..25f3c65c351 100644 --- a/source/source_lcao/module_operator_lcao/td_ekinetic_lcao.h +++ b/source/source_lcao/module_operator_lcao/td_ekinetic_lcao.h @@ -98,7 +98,7 @@ class TDEkinetic> : public OperatorLCAO const Grid_Driver* Grid = nullptr; - const K_Vectors* kv; + const K_Vectors* kv = nullptr; /// @brief correction term i A nabla void td_ekinetic_scalar(std::complex* Hloc, const TR& Sloc, int nnr); diff --git a/source/source_lcao/module_operator_lcao/veff_lcao.h b/source/source_lcao/module_operator_lcao/veff_lcao.h index 8ec1265a00d..9f06348333f 100644 --- a/source/source_lcao/module_operator_lcao/veff_lcao.h +++ b/source/source_lcao/module_operator_lcao/veff_lcao.h @@ -58,8 +58,8 @@ class Veff> : public OperatorLCAO */ virtual void contributeHR() override; - const UnitCell* ucell; - const Grid_Driver* gd; + const UnitCell* ucell = nullptr; + const Grid_Driver* gd = nullptr; private: diff --git a/source/source_lcao/module_rdmft/rdmft_tools.h b/source/source_lcao/module_rdmft/rdmft_tools.h index d8a34419e7d..01b433f5959 100644 --- a/source/source_lcao/module_rdmft/rdmft_tools.h +++ b/source/source_lcao/module_rdmft/rdmft_tools.h @@ -293,9 +293,9 @@ class Veff_rdmft : public hamilt::OperatorLCAO */ virtual void contributeHR() override; - const UnitCell* ucell; + const UnitCell* ucell = nullptr; - const Grid_Driver* gd; + const Grid_Driver* gd = nullptr; private: @@ -317,19 +317,19 @@ class Veff_rdmft : public hamilt::OperatorLCAO // added by jghan - const Charge* charge_; + const Charge* charge_ = nullptr; std::string potential_; - const ModulePW::PW_Basis* rho_basis_; + const ModulePW::PW_Basis* rho_basis_ = nullptr; const ModuleBase::matrix* vloc_; - const ModuleBase::ComplexMatrix* sf_; + const ModuleBase::ComplexMatrix* sf_ = nullptr; - double* etxc; + double* etxc = nullptr; - double* vtxc; + double* vtxc = nullptr; }; diff --git a/source/source_lcao/module_rt/propagator.h b/source/source_lcao/module_rt/propagator.h index ca9c7c140bd..7a4f9428025 100644 --- a/source/source_lcao/module_rt/propagator.h +++ b/source/source_lcao/module_rt/propagator.h @@ -144,7 +144,7 @@ class Propagator private: int ptype; // type of propagator - const Parallel_Orbitals* ParaV; + const Parallel_Orbitals* ParaV = nullptr; double dt; // time step #ifdef __MPI diff --git a/source/source_lcao/pulay_fs_temp.hpp b/source/source_lcao/pulay_fs_temp.hpp index ba32eedb2e5..0d7c821ddc1 100644 --- a/source/source_lcao/pulay_fs_temp.hpp +++ b/source/source_lcao/pulay_fs_temp.hpp @@ -54,7 +54,7 @@ namespace PulayForceStress const int I1 = ucell.iat2ia[iat]; // get iat1 int iat1 = ucell.itia2iat(T1, I1); - double* f_iat; + double* f_iat = nullptr; if (isforce) { f_iat = &f(iat, 0); } #ifdef _OPENMP // using local stack to avoid false sharing in multi-threaded case diff --git a/source/source_pw/module_pwdft/fs_nonlocal_tools.h b/source/source_pw/module_pwdft/fs_nonlocal_tools.h index a5307dbace5..07b6e1f7167 100644 --- a/source/source_pw/module_pwdft/fs_nonlocal_tools.h +++ b/source/source_pw/module_pwdft/fs_nonlocal_tools.h @@ -144,11 +144,11 @@ class FS_Nonlocal_tools private: /// pointers to access the data without memory arrangement - const Structure_Factor* sf_; - const pseudopot_cell_vnl* nlpp_; - const UnitCell* ucell_; - const K_Vectors* kv_; - const ModulePW::PW_Basis_K* wfc_basis_; + const Structure_Factor* sf_ = nullptr; + const pseudopot_cell_vnl* nlpp_ = nullptr; + const UnitCell* ucell_ = nullptr; + const K_Vectors* kv_ = nullptr; + const ModulePW::PW_Basis_K* wfc_basis_ = nullptr; /// the following variables are used for the calculation Device* ctx = {}; diff --git a/source/source_pw/module_pwdft/nonlocal_maths.hpp b/source/source_pw/module_pwdft/nonlocal_maths.hpp index 3a8b133cb8d..d53b1cc6e4d 100644 --- a/source/source_pw/module_pwdft/nonlocal_maths.hpp +++ b/source/source_pw/module_pwdft/nonlocal_maths.hpp @@ -34,7 +34,7 @@ class Nonlocal_maths private: ModuleBase::matrix nhtol_; int lmax_ = 0; - const UnitCell* ucell_; + const UnitCell* ucell_ = nullptr; Device* ctx = {}; base_device::DEVICE_CPU* cpu_ctx = {}; diff --git a/source/source_pw/module_pwdft/onsite_proj_tools.h b/source/source_pw/module_pwdft/onsite_proj_tools.h index de5a0cce43c..f50efd6701f 100644 --- a/source/source_pw/module_pwdft/onsite_proj_tools.h +++ b/source/source_pw/module_pwdft/onsite_proj_tools.h @@ -93,12 +93,12 @@ class Onsite_Proj_tools private: /// pointers to access the data without memory arrangement - const Structure_Factor* sf_; - const pseudopot_cell_vnl* nlpp_; - const UnitCell* ucell_; + const Structure_Factor* sf_ = nullptr; + const pseudopot_cell_vnl* nlpp_ = nullptr; + const UnitCell* ucell_ = nullptr; const psi::Psi, Device>* psi_; - const K_Vectors* kv_; - const ModulePW::PW_Basis_K* wfc_basis_; + const K_Vectors* kv_ = nullptr; + const ModulePW::PW_Basis_K* wfc_basis_ = nullptr; /// the following variables are used for the calculation Device* ctx = {}; diff --git a/source/source_pw/module_pwdft/stress_cc.cpp b/source/source_pw/module_pwdft/stress_cc.cpp index 06073710749..5ae527bdf34 100644 --- a/source/source_pw/module_pwdft/stress_cc.cpp +++ b/source/source_pw/module_pwdft/stress_cc.cpp @@ -31,7 +31,7 @@ void Stress_Func::stress_cc(ModuleBase::matrix& sigma, } FPTYPE sigmadiag; - FPTYPE* rhocg; + FPTYPE* rhocg = nullptr; int judge=0; for(int nt=0;nt::checkemm(const int& ik, } const int norder = p_che->norder; - T* pchi; + T* pchi = nullptr; int ntest = 1; if (nchip[ik] < ntest) @@ -384,7 +384,7 @@ void Stochastic_Iter::calPn(const int& ik, Stochastic_WF& setmem_var_op()(spolyv, 0, norder * norder); } } - T* pchi; + T* pchi = nullptr; if (PARAM.globalv.nbands_l > 0) { stowf.chiortho->fix_k(ik); @@ -743,7 +743,7 @@ void Stochastic_Iter::calTnchi_ik(const int& ik, Stochastic_WFfix_k(ik); T* out = stowf.shchi->get_pointer(); - T* pchi; + T* pchi = nullptr; if (PARAM.globalv.nbands_l > 0) { stowf.chiortho->fix_k(ik); diff --git a/source/source_relax/bfgs_basic.h b/source/source_relax/bfgs_basic.h index 0e795afe388..777e6c78eb3 100644 --- a/source/source_relax/bfgs_basic.h +++ b/source/source_relax/bfgs_basic.h @@ -32,7 +32,7 @@ class BFGS_Basic double* pos_p; // p: previous double* grad_p; // p: previous - double* move_p; + double* move_p = nullptr; public: // mohan update 2011-06-12 static double relax_bfgs_w1; // fixed: parameters for Wolfe conditions. diff --git a/source/source_relax/ions_move_cg.h b/source/source_relax/ions_move_cg.h index 662ef0c14fe..6e77127ca52 100644 --- a/source/source_relax/ions_move_cg.h +++ b/source/source_relax/ions_move_cg.h @@ -17,10 +17,10 @@ class Ions_Move_CG int cg_step=0; private: - double *pos0; - double *grad0; - double *cg_grad0; - double *move0; + double * pos0 = nullptr; + double * grad0 = nullptr; + double * cg_grad0 = nullptr; + double * move0 = nullptr; double e0=0.0; // setup gradients. void setup_cg_grad(double *grad, diff --git a/source/source_relax/ions_move_sd.h b/source/source_relax/ions_move_sd.h index 2b0e093cb46..0fa56f8696a 100644 --- a/source/source_relax/ions_move_sd.h +++ b/source/source_relax/ions_move_sd.h @@ -14,8 +14,8 @@ class Ions_Move_SD private: double energy_saved; - double* pos_saved; - double* grad_saved; + double* pos_saved = nullptr; + double* grad_saved = nullptr; void cal_tradius_sd(void) const; }; diff --git a/source/source_relax/lattice_change_cg.h b/source/source_relax/lattice_change_cg.h index b93f22c81b4..68fe1b69509 100644 --- a/source/source_relax/lattice_change_cg.h +++ b/source/source_relax/lattice_change_cg.h @@ -14,10 +14,10 @@ class Lattice_Change_CG void start(UnitCell &ucell, const ModuleBase::matrix &stress_in, const double &etot); private: - double *lat0; - double *grad0; - double *cg_grad0; - double *move0; + double * lat0 = nullptr; + double * grad0 = nullptr; + double * cg_grad0 = nullptr; + double * move0 = nullptr; double e0=0.0; // setup gradients. From ed1fe3135b692d5b479eb26c920a04174cbfe923 Mon Sep 17 00:00:00 2001 From: linpz Date: Sat, 14 Mar 2026 05:02:38 +0800 Subject: [PATCH 2/2] remove nullptr in MatrixBlock --- source/source_hamilt/matrixblock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/source_hamilt/matrixblock.h b/source/source_hamilt/matrixblock.h index 03812a3203e..481a95b8a58 100644 --- a/source/source_hamilt/matrixblock.h +++ b/source/source_hamilt/matrixblock.h @@ -9,10 +9,10 @@ template struct MatrixBlock { /* this is a simple template block of a matrix would change to Eigen in the future */ - T* p = nullptr; + T* p; size_t row; size_t col; - const int* desc = nullptr; + const int* desc; }; } // namespace hamilt