diff --git a/source/source_base/math_chebyshev.cpp b/source/source_base/math_chebyshev.cpp index aaa0e82b74..8a84686ea5 100644 --- a/source/source_base/math_chebyshev.cpp +++ b/source/source_base/math_chebyshev.cpp @@ -417,7 +417,7 @@ void Chebyshev::calfinalvec_real( std::complex* arrayn = nullptr; std::complex* arrayn_1 = nullptr; assert(N >= 0 && LDA >= N); - int ndmxt; + int ndmxt = 0; if (m == 1) { ndmxt = N * m; @@ -486,7 +486,7 @@ void Chebyshev::calfinalvec_complex( std::complex* arrayn = nullptr; std::complex* arrayn_1 = nullptr; assert(N >= 0 && LDA >= N); - int ndmxt; + int ndmxt = 0; if (m == 1) { ndmxt = N * m; @@ -585,7 +585,7 @@ void Chebyshev::tracepolyA( std::complex* arrayn = nullptr; std::complex* arrayn_1 = nullptr; assert(N >= 0 && LDA >= N); - int ndmxt; + int ndmxt = 0; if (m == 1) { ndmxt = N * m; diff --git a/source/source_base/math_erf_complex.cpp b/source/source_base/math_erf_complex.cpp index 18709c4866..4c7385245a 100644 --- a/source/source_base/math_erf_complex.cpp +++ b/source/source_base/math_erf_complex.cpp @@ -106,7 +106,7 @@ std::complex ErrorFunc::scaled_w(std::complex z, double relerr) else if (x < 10) { double prod2ax = 1, prodm2ax = 1; - double expx2; + double expx2 = 0.0; if (std::isnan(y)) return std::complex(y, y); @@ -235,7 +235,7 @@ std::complex ErrorFunc::scaled_w(std::complex z, double relerr) sum3 = std::exp(-dx * dx) / (a2 * (n0 * n0) + y * y); sum5 = a * n0 * sum3; double exp1 = std::exp(4 * a * dx), exp1dn = 1; - int dn; + int dn = 0; for (dn = 1; n0 - dn > 0; ++dn) { // loop over n0-dn and n0+dn terms double np = n0 + dn, nm = n0 - dn; diff --git a/source/source_base/math_ylmreal.cpp b/source/source_base/math_ylmreal.cpp index 3a11f95438..e94b027bb3 100644 --- a/source/source_base/math_ylmreal.cpp +++ b/source/source_base/math_ylmreal.cpp @@ -179,7 +179,7 @@ void YlmReal::rlylm { int twok = 2 * ik; - double gamma; + double gamma = 0.0; double aux0, aux1, aux2, aux3; aux0 = pow(-1.0, ik) * pow(2.0, -il); diff --git a/source/source_base/tool_check.cpp b/source/source_base/tool_check.cpp index a9450b4fcb..dab7dd5f21 100644 --- a/source/source_base/tool_check.cpp +++ b/source/source_base/tool_check.cpp @@ -49,7 +49,7 @@ void CHECK_INT(std::ifstream &ifs,const int &v,bool quit) void CHECK_DOUBLE(std::ifstream &ifs,const double &v,bool quit) { const double tiny = 1.0e-5; - double v_in; + double v_in = 0.0; ifs >> v_in; if( fabs(v - v_in) > tiny ) { diff --git a/source/source_base/tool_quit.cpp b/source/source_base/tool_quit.cpp index 77c855c7a0..efd72278cc 100644 --- a/source/source_base/tool_quit.cpp +++ b/source/source_base/tool_quit.cpp @@ -65,7 +65,7 @@ void WARNING_QUIT(const std::string &file,const std::string &description) #ifdef __MPI /* if it is MPI run, finalize first, then exit */ std::cout << "Detecting if MPI has been initialized..." << std::endl; - int is_initialized; + int is_initialized = 0; MPI_Initialized(&is_initialized); if (is_initialized) { std::cout << "Terminating ABACUS with multiprocessing environment." << std::endl; diff --git a/source/source_base/ylm.cpp b/source/source_base/ylm.cpp index cd7336718d..b055ed37ad 100644 --- a/source/source_base/ylm.cpp +++ b/source/source_base/ylm.cpp @@ -474,7 +474,7 @@ void Ylm::rlylm { int twok = 2 * ik; - double gamma; + double gamma = 0.0; double aux0, aux1, aux2, aux3; aux0 = pow(-1.0, ik) * pow(2.0, -il); @@ -1107,7 +1107,7 @@ void Ylm::hes_rl_sph_harm hrly.resize( (Lmax+1)*(Lmax+1), std::vector(6) ); double radius2 = x*x+y*y+z*z; - double coeff; + double coeff = 0.0; //begin calculation /*************************** @@ -1867,7 +1867,7 @@ void Ylm::rlylm { int twok = 2 * ik; - double gamma; + double gamma = 0.0; double aux0, aux1, aux2, aux3; aux0 = pow(-1.0, ik) * pow(2.0, -il); diff --git a/source/source_cell/klist.cpp b/source/source_cell/klist.cpp index b9ee8c4eba..1bba575528 100644 --- a/source/source_cell/klist.cpp +++ b/source/source_cell/klist.cpp @@ -466,7 +466,7 @@ void K_Vectors::interpolate_k_between(std::ifstream& ifk, std::vector> zatom >> zion; pp.zv = zion; ifs.ignore(300, '\n'); diff --git a/source/source_cell/read_pp_upf100.cpp b/source/source_cell/read_pp_upf100.cpp index 0e91dffccc..9327ebe712 100644 --- a/source/source_cell/read_pp_upf100.cpp +++ b/source/source_cell/read_pp_upf100.cpp @@ -326,7 +326,7 @@ void Pseudopot_upf::read_pseudo_nl(std::ifstream& ifs, Atom_pseudo& pp) ModuleBase::GlobalFunc::READ_VALUE(ifs, this->nd); // nl_4 for (int i = 0; i < this->nd; i++) { - double swap; + double swap = 0.0; ifs >> nb >> mb >> swap; nb--; mb--; diff --git a/source/source_cell/read_pp_upf201.cpp b/source/source_cell/read_pp_upf201.cpp index e0941664bf..d02bb8e6d5 100644 --- a/source/source_cell/read_pp_upf201.cpp +++ b/source/source_cell/read_pp_upf201.cpp @@ -807,7 +807,7 @@ void Pseudopot_upf::read_pseudo_upf201_fullwfc(std::ifstream& ifs) std::string word; std::string name[50]; std::string val[50]; - int nparameter; + int nparameter = 0; this->aewfc.create(this->nbeta, this->mesh); this->pswfc.create(this->nbeta, this->mesh); ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "", false)) { - int iproj; + int iproj = 0; ModuleBase::GlobalFunc::READ_VALUE(ifs, iproj); if (iproj != p1) { diff --git a/source/source_estate/cal_ux.cpp b/source/source_estate/cal_ux.cpp index 5175e48d5a..f7ea856386 100644 --- a/source/source_estate/cal_ux.cpp +++ b/source/source_estate/cal_ux.cpp @@ -93,7 +93,7 @@ void cal_ux(UnitCell& ucell) { bool judge_parallel(double a[3], ModuleBase::Vector3 b) { bool jp = false; - double cross; + double cross = 0.0; cross = pow((a[1] * b.z - a[2] * b.y), 2) + pow((a[2] * b.x - a[0] * b.z), 2) + pow((a[0] * b.y - a[1] * b.x), 2); diff --git a/source/source_hamilt/module_vdw/vdwd2_parameters.cpp b/source/source_hamilt/module_vdw/vdwd2_parameters.cpp index a562244be3..3ac48e1819 100644 --- a/source/source_hamilt/module_vdw/vdwd2_parameters.cpp +++ b/source/source_hamilt/module_vdw/vdwd2_parameters.cpp @@ -50,7 +50,7 @@ void Vdwd2Parameters::C6_input(const std::string &file, const std::string &unit) ModuleBase::WARNING_QUIT("Vdwd2::C6_input", "Can not find the file " + ModuleBase::GlobalFunc::TO_STRING(file)); std::string element; - double value; + double value = 0.0; while (ifs >> element >> value) C6_[element] = value; ifs.close(); @@ -77,7 +77,7 @@ void Vdwd2Parameters::R0_input(const std::string &file, const std::string &unit) ModuleBase::WARNING_QUIT("Vdwd2::R0_input", "Can not find the file " + ModuleBase::GlobalFunc::TO_STRING(file)); std::string element; - double value; + double value = 0.0; while (ifs >> element >> value) R0_[element] = value; ifs.close(); diff --git a/source/source_hamilt/module_vdw/vdwd3.cpp b/source/source_hamilt/module_vdw/vdwd3.cpp index 95aeac8226..66245e0f09 100644 --- a/source/source_hamilt/module_vdw/vdwd3.cpp +++ b/source/source_hamilt/module_vdw/vdwd3.cpp @@ -88,7 +88,7 @@ void Vdwd3::cal_energy() ModuleBase::timer::tick("Vdwd3", "cal_energy"); init(); - int ij; + int ij = 0; double c6 = 0.0, c8 = 0.0, r2 = 0.0, r6 = 0.0, r8 = 0.0, rr = 0.0, damp6 = 0.0, damp8 = 0.0; double e6 = 0.0, e8 = 0.0, eabc = 0.0; std::vector cc6ab(ucell_.nat * ucell_.nat), cn(ucell_.nat); @@ -96,7 +96,7 @@ void Vdwd3::cal_energy() ModuleBase::Vector3 tau; if (para_.version() == "d3_0") // DFT-D3(zero-damping) { - double tmp; + double tmp = 0.0; for (int iat = 0; iat != ucell_.nat - 1; iat++) { for (int jat = iat + 1; jat != ucell_.nat; jat++) { @@ -178,7 +178,7 @@ void Vdwd3::cal_energy() } // end d3_0 else if (para_.version() == "d3_bj") // DFT-D3(BJ-damping) { - double r42; + double r42 = 0.0; for (int iat = 0; iat != ucell_.nat; iat++) { for (int jat = iat + 1; jat != ucell_.nat; jat++) @@ -860,7 +860,7 @@ void Vdwd3::pbc_gdisp(std::vector> &g, ModuleBase::m } // end d3_0 else if (para_.version() == "d3_bj") { - double r4; + double r4 = 0.0; for (int iat = 0; iat != ucell_.nat; iat++) { get_dc6_dcnij(para_.mxc()[iz_[iat]], para_.mxc()[iz_[iat]], cn[iat], cn[iat], diff --git a/source/source_hamilt/module_xc/xc_funct_corr_gga.cpp b/source/source_hamilt/module_xc/xc_funct_corr_gga.cpp index 2c94989482..3c88eb653c 100644 --- a/source/source_hamilt/module_xc/xc_funct_corr_gga.cpp +++ b/source/source_hamilt/module_xc/xc_funct_corr_gga.cpp @@ -104,7 +104,7 @@ void XC_Functional::ggac(const double &rho,const double &grho, double &sc, doubl y = af * t * t; xy = (1.0 + y) / (1.0 + y + y * y); - double x; + double x = 0.0; x = 1.0 + y + y * y; qy = y * y * (2.0 + y) / (x * x); s1 = 1.0 + 2.0 * al / be * t * t * xy; diff --git a/source/source_hamilt/module_xc/xc_funct_corr_lda.cpp b/source/source_hamilt/module_xc/xc_funct_corr_lda.cpp index 4a749320b8..5b6ff5367b 100644 --- a/source/source_hamilt/module_xc/xc_funct_corr_lda.cpp +++ b/source/source_hamilt/module_xc/xc_funct_corr_lda.cpp @@ -138,7 +138,7 @@ void XC_Functional::vwn(const double &rs, double &ec, double &vc) fx = rs + b * rs12 + c; qx = atan(q / (2.0 * rs12 + b)); - double x; + double x = 0.0; x = (rs12 - x0); ec = a * (log(rs / fx) + f1 * qx - f2 * (log((x * x) / fx) + f3 * qx)); diff --git a/source/source_hamilt/module_xc/xc_functional_gradcorr.cpp b/source/source_hamilt/module_xc/xc_functional_gradcorr.cpp index 66b0a4a0d6..008109377c 100644 --- a/source/source_hamilt/module_xc/xc_functional_gradcorr.cpp +++ b/source/source_hamilt/module_xc/xc_functional_gradcorr.cpp @@ -226,7 +226,7 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, if(nspin0==1) { - double segno; + double segno = 0.0; #ifdef _OPENMP #pragma omp for #endif @@ -249,7 +249,7 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, #ifdef USE_LIBXC if(func_type == 3 || func_type == 5) //the gradcorr part to stress of mGGA { - double v3xc; + double v3xc = 0.0; double atau = chr->kin_r[0][ir]/2.0; XC_Functional_Libxc::tau_xc( func_id, arho, grho2a, atau, sxc, v1xc, v2xc, v3xc); } diff --git a/source/source_hamilt/module_xc/xc_functional_wrapper_gcxc.cpp b/source/source_hamilt/module_xc/xc_functional_wrapper_gcxc.cpp index ea6a5a3e1e..3956d29702 100644 --- a/source/source_hamilt/module_xc/xc_functional_wrapper_gcxc.cpp +++ b/source/source_hamilt/module_xc/xc_functional_wrapper_gcxc.cpp @@ -128,7 +128,7 @@ void XC_Functional::gcx_spin(double rhoup, double rhodw, double grhoup2, double // parameter : double small = 1.e-10; double sxup, sxdw; - int iflag; + int iflag = 0; // exchange double rho = rhoup + rhodw; @@ -247,7 +247,7 @@ void XC_Functional::gcc_spin(double rho, double &zeta, double grho, double &sc, double small = 1.0e-10; double epsr = 1.0e-6; - double x; + double x = 0.0; sc = 0.00; v1cup = 0.00; v1cdw = 0.00; diff --git a/source/source_hamilt/module_xc/xc_functional_wrapper_xc.cpp b/source/source_hamilt/module_xc/xc_functional_wrapper_xc.cpp index d13eb0d129..0a9bffbc42 100644 --- a/source/source_hamilt/module_xc/xc_functional_wrapper_xc.cpp +++ b/source/source_hamilt/module_xc/xc_functional_wrapper_xc.cpp @@ -17,7 +17,7 @@ void XC_Functional::xc(const double &rho, double &exc, double &vxc) double third = 1.0 / 3.0; double pi34 = 0.6203504908994e0 ; // pi34=(3/4pi)^(1/3) - double rs; + double rs = 0.0; double e,v; exc = vxc = 0.00; diff --git a/source/source_hsolver/diago_elpa_native.cpp b/source/source_hsolver/diago_elpa_native.cpp index f320191d28..dc4bf2b6d7 100644 --- a/source/source_hsolver/diago_elpa_native.cpp +++ b/source/source_hsolver/diago_elpa_native.cpp @@ -77,7 +77,7 @@ void DiagoElpaNative::diag_pool(hamilt::MatrixBlock& h_mat, } // elpa_init(20210430); - int success; + int success = 0; elpa_t handle = elpa_allocate(&success); #ifdef _OPENMP int num_threads = omp_get_max_threads(); diff --git a/source/source_hsolver/hsolver_pw.cpp b/source/source_hsolver/hsolver_pw.cpp index 7d178f699b..2ea7b92a2b 100644 --- a/source/source_hsolver/hsolver_pw.cpp +++ b/source/source_hsolver/hsolver_pw.cpp @@ -544,8 +544,8 @@ void HSolverPW::build_k_neighbors() { // Store k-points and corresponding indices struct KPoint { ModuleBase::Vector3 kvec; - int index; - double norm; + int index = 0; + double norm = 0.0; KPoint(const ModuleBase::Vector3& v, int i) : kvec(v), index(i), norm(v.norm()) {} diff --git a/source/source_hsolver/module_genelpa/elpa_new.cpp b/source/source_hsolver/module_genelpa/elpa_new.cpp index 3d214d20fd..d045482190 100644 --- a/source/source_hsolver/module_genelpa/elpa_new.cpp +++ b/source/source_hsolver/module_genelpa/elpa_new.cpp @@ -57,7 +57,7 @@ ELPA_Solver::ELPA_Solver(const bool isReal, else kernel_id = read_complex_kernel(); // cout<<"kernel id is inited as "< NEW_ELPA_HANDLE_POOL; - static int total_handle; + static int total_handle = 0; #ifdef _OPENMP int num_threads = omp_get_max_threads(); @@ -270,7 +270,7 @@ int ELPA_Solver::read_cpuflag() int ELPA_Solver::read_real_kernel() { - int kernel_id; + int kernel_id = 0; if (const char* env = getenv("ELPA_DEFAULT_real_kernel")) { @@ -454,7 +454,7 @@ int ELPA_Solver::read_complex_kernel() int ELPA_Solver::allocate_work() { unsigned long nloc = static_cast(narows) * nacols; // local size - unsigned long maxloc; // maximum local size + unsigned long maxloc = 0; // maximum local size MPI_Allreduce(&nloc, &maxloc, 1, MPI_UNSIGNED_LONG, MPI_MAX, comm); maxloc = nloc; @@ -467,7 +467,7 @@ int ELPA_Solver::allocate_work() void ELPA_Solver::timer(int myid, const char function[], const char step[], double& t0) { - double t1; + double t1 = 0.0; if (t0 < 0) // t0 < 0 means this is the init call before the function { t0 = MPI_Wtime(); diff --git a/source/source_hsolver/module_genelpa/elpa_new_complex.cpp b/source/source_hsolver/module_genelpa/elpa_new_complex.cpp index 0c78009522..cf28835942 100644 --- a/source/source_hsolver/module_genelpa/elpa_new_complex.cpp +++ b/source/source_hsolver/module_genelpa/elpa_new_complex.cpp @@ -19,9 +19,9 @@ extern std::map NEW_ELPA_HANDLE_POOL; int ELPA_Solver::eigenvector(std::complex* A, double* EigenValue, std::complex* EigenVector) { - int info; - int allinfo; - double t; + int info = 0; + int allinfo = 0; + double t = 0.0; if((loglevel>0 && myid==0) || loglevel>1) { @@ -42,7 +42,7 @@ int ELPA_Solver::generalized_eigenvector(std::complex* A, std::complex* EigenVector) { int info, allinfo; - double t; + double t = 0.0; if((loglevel>0 && myid==0) || loglevel>1) { @@ -164,7 +164,7 @@ int ELPA_Solver::decomposeRightMatrix(std::complex* B, double* EigenValu { int info=0; int allinfo=0; - double t; + double t = 0.0; // first try cholesky decomposing if(nFull* B, double* EigenValu int ELPA_Solver::composeEigenVector(int DecomposedState, std::complex* B, std::complex* EigenVector) { - double t; + double t = 0.0; if(DecomposedState==1 || DecomposedState==2) { // transform the eigenvectors to original general equation, let U^-1*q, and put to q diff --git a/source/source_hsolver/module_genelpa/elpa_new_real.cpp b/source/source_hsolver/module_genelpa/elpa_new_real.cpp index a780c89f55..cc6d0242bd 100644 --- a/source/source_hsolver/module_genelpa/elpa_new_real.cpp +++ b/source/source_hsolver/module_genelpa/elpa_new_real.cpp @@ -18,8 +18,8 @@ extern std::map NEW_ELPA_HANDLE_POOL; int ELPA_Solver::eigenvector(double* A, double* EigenValue, double* EigenVector) { - int info; - double t; + int info = 0; + double t = 0.0; if (loglevel > 0 && myid == 0) { @@ -41,7 +41,7 @@ int ELPA_Solver::generalized_eigenvector(double* A, double* EigenVector) { int info, allinfo; - double t; + double t = 0.0; if (loglevel > 0 && myid == 0) { @@ -407,7 +407,7 @@ void ELPA_Solver::verify(double* A, double* EigenValue, double* EigenVector, dou maxError = 0; for (int i = 1; i <= nev; ++i) { - double E; + double E = 0.0; ScalapackConnector::dot(nFull, E, R, 1, i, 1, R, 1, i, 1, desc); // printf("myid: %d, i: %d, E: %lf\n", myid, i, E); sumError += E; diff --git a/source/source_hsolver/module_genelpa/utils.cpp b/source/source_hsolver/module_genelpa/utils.cpp index d9e6e74c59..6654c33b9e 100644 --- a/source/source_hsolver/module_genelpa/utils.cpp +++ b/source/source_hsolver/module_genelpa/utils.cpp @@ -25,7 +25,7 @@ void initBlacsGrid(int loglevel, int nprows, npcols; int myprow, mypcol; int nprocs, myid; - int info; + int info = 0; MPI_Comm_size(comm, &nprocs); MPI_Comm_rank(comm, &myid); // set blacs parameters @@ -137,7 +137,7 @@ void loadMatrix(const char FileName[], int nFull, double* a, int* desca, int bla void saveLocalMatrix(const char filePrefix[], int narows, int nacols, double* a) { char FileName[80]; - int myid; + int myid = 0; std::ofstream matrixFile; #ifdef __MPI MPI_Comm_rank(MPI_COMM_WORLD, &myid); diff --git a/source/source_hsolver/module_pexsi/dist_bcd_matrix.cpp b/source/source_hsolver/module_pexsi/dist_bcd_matrix.cpp index ff3f85f32b..93a6dcb5b0 100644 --- a/source/source_hsolver/module_pexsi/dist_bcd_matrix.cpp +++ b/source/source_hsolver/module_pexsi/dist_bcd_matrix.cpp @@ -48,7 +48,7 @@ DistBCDMatrix::DistBCDMatrix(MPI_Comm comm, } // synchronize matrix parameters to all processes, including those are not in bcd group - int myid_in_comm_world; + int myid_in_comm_world = 0; MPI_Comm_rank(MPI_COMM_WORLD, &myid_in_comm_world); if (myid_in_comm_world == 0) { diff --git a/source/source_hsolver/module_pexsi/dist_ccs_matrix.cpp b/source/source_hsolver/module_pexsi/dist_ccs_matrix.cpp index 74391f2fbe..0a73653c8e 100644 --- a/source/source_hsolver/module_pexsi/dist_ccs_matrix.cpp +++ b/source/source_hsolver/module_pexsi/dist_ccs_matrix.cpp @@ -55,7 +55,7 @@ DistCCSMatrix::DistCCSMatrix(MPI_Comm comm_in, int nproc_data_in, int size_in) this->size = size_in; this->nnz = 0; this->nnzLocal = 0; - int myproc; + int myproc = 0; if (comm != MPI_COMM_NULL) { MPI_Comm_size(comm, &nprocs); diff --git a/source/source_hsolver/module_pexsi/dist_matrix_transformer.cpp b/source/source_hsolver/module_pexsi/dist_matrix_transformer.cpp index 313a840e68..7a4ecec6b1 100644 --- a/source/source_hsolver/module_pexsi/dist_matrix_transformer.cpp +++ b/source/source_hsolver/module_pexsi/dist_matrix_transformer.cpp @@ -28,8 +28,8 @@ inline int DistMatrixTransformer::MinimumIndexPosition(const bool isFirst, { // usually the minimum index is continuous, so it will be a good idea to // check the one next to the previous index first. - static int pre_position; // previous position in index array of minimum index, - static int pre_process; // the process contains previous index + static int pre_position = 0; // previous position in index array of minimum index, + static int pre_process = 0; // the process contains previous index int minimum_index = INT_MAX; // the minimum index, initial value is a large number which is larger than any other index; @@ -110,7 +110,7 @@ inline void DistMatrixTransformer::buildCCSParameter(const int size, int pre_col = -1; int nnz_now = 0; - int p_mini; + int p_mini = 0; p_mini = MinimumIndexPosition(true, nprocs, &size_process[0], &displacement_process[0], position_index); while (p_mini >= 0) { @@ -146,7 +146,7 @@ inline void DistMatrixTransformer::countMatrixDistribution(int N, double* A, std { for (int i = 0; i < N; ++i) { - int key; + int key = 0; if (fabs(A[i] < 1e-31)) key = -100; else diff --git a/source/source_hsolver/module_pexsi/simple_pexsi.cpp b/source/source_hsolver/module_pexsi/simple_pexsi.cpp index edf000ecae..255b1019b3 100644 --- a/source/source_hsolver/module_pexsi/simple_pexsi.cpp +++ b/source/source_hsolver/module_pexsi/simple_pexsi.cpp @@ -27,7 +27,7 @@ namespace pexsi { inline void strtolower(char* sa, char* sb) { - char c; + char c = '\0'; int len = strlen(sa); for (int i = 0; i < len; i++) { @@ -172,8 +172,8 @@ void splitNProc2NProwNPcol(const int NPROC, int& nprow, int& npcol) } else { - int flag; - int i; + int flag = 0; + int i = 0; int low = pow(integral_part, 2); int high = pow(integral_part + 1, 2); if ((NPROC - low) >= (high - NPROC)) @@ -218,7 +218,7 @@ int simplePEXSI(MPI_Comm comm_PEXSI, if (comm_2D == MPI_COMM_NULL && comm_PEXSI == MPI_COMM_NULL) return 0; - int myid; + int myid = 0; std::ofstream f_log; if (comm_PEXSI != MPI_COMM_NULL) { @@ -228,15 +228,15 @@ int simplePEXSI(MPI_Comm comm_PEXSI, // set up PEXSI parameter PPEXSIOptions options; PPEXSISetDefaultOptions(&options); - int numProcessPerPole; - double ZERO_Limit; + int numProcessPerPole = 0; + double ZERO_Limit = 0.0; loadPEXSIOption(comm_PEXSI, PexsiOptionFile, options, numProcessPerPole, ZERO_Limit); options.mu0 = mu0; ModuleBase::timer::tick("Diago_LCAO_Matrix", "setup_PEXSI_plan"); PPEXSIPlan plan; - int info; - int outputFileIndex; + int info = 0; + int outputFileIndex = 0; int pexsi_prow, pexsi_pcol; ModuleBase::timer::tick("Diago_LCAO_Matrix", "splitNProc2NProwNPcol"); splitNProc2NProwNPcol(numProcessPerPole, pexsi_prow, pexsi_pcol); @@ -292,11 +292,11 @@ int simplePEXSI(MPI_Comm comm_PEXSI, SnzvalLocal, &info); - double nelec; - double muMinInertia; - double muMaxInertia; - int numTotalPEXSIIter; - int numTotalInertiaIter; // Number of total inertia[out] + double nelec = 0.0; + double muMinInertia = 0.0; + double muMaxInertia = 0.0; + int numTotalPEXSIIter = 0; + int numTotalInertiaIter = 0; // Number of total inertia[out] // LiuXh modify 2021-04-29, add DONE(ofs_running,"xx") for test ModuleBase::timer::tick("Diago_LCAO_Matrix", "PEXSIDFT"); PPEXSIDFTDriver2(plan, // PEXSI plan[in] diff --git a/source/source_io/bessel_basis.cpp b/source/source_io/bessel_basis.cpp index 5768f411e0..2795fefa25 100644 --- a/source/source_io/bessel_basis.cpp +++ b/source/source_io/bessel_basis.cpp @@ -392,10 +392,10 @@ void Bessel_Basis::readin_C4( if(ModuleBase::GlobalFunc::SCAN_BEGIN(inc4, "")) { - double tmp_ecut; - double tmp_rcut; - double tmp_enumber; - double tmp_tolerence; + double tmp_ecut = 0.0; + double tmp_rcut = 0.0; + double tmp_enumber = 0.0; + double tmp_tolerence = 0.0; ModuleBase::GlobalFunc::READ_VALUE( inc4, tmp_ecut); ModuleBase::GlobalFunc::READ_VALUE( inc4, tmp_rcut); ModuleBase::GlobalFunc::READ_VALUE( inc4, tmp_enumber); diff --git a/source/source_io/cif_io.cpp b/source/source_io/cif_io.cpp index c06ecb7033..a03cd0d15c 100644 --- a/source/source_io/cif_io.cpp +++ b/source/source_io/cif_io.cpp @@ -238,7 +238,7 @@ void bcast_cifmap(std::map>& map, // the m const int rank = 0) // source rank: from which rank to broadcast { #ifdef __MPI - int myrank; + int myrank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &myrank); // use Parallel_Common namespace bcast_int and bcast_string to broadcast the size of map and key, value pairs int size = map.size(); @@ -328,7 +328,7 @@ void ModuleIO::CifParser::write(const std::string& fcif, const std::string& cell_formula_units_z) { #ifdef __MPI // well...very simple... - int myrank; + int myrank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &myrank); if (myrank != rank) // if present rank is not the rank assigned to write the cif file, then return { @@ -402,7 +402,7 @@ void ModuleIO::CifParser::write(const std::string& fcif, const std::string& cell_formula_units_z) { #ifdef __MPI - int myrank; + int myrank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &myrank); if (myrank != rank) // if present rank is not the rank assigned to write the cif file, then return { @@ -429,7 +429,7 @@ void ModuleIO::CifParser::write(const std::string& fcif, const int rank) { #ifdef __MPI - int myrank; + int myrank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &myrank); if (myrank != rank) // if present rank is not the rank assigned to write the cif file, then return { @@ -437,7 +437,7 @@ void ModuleIO::CifParser::write(const std::string& fcif, } #endif std::vector veca, vecb, vecc; - int natom; + int natom = 0; std::vector atom_site_labels; std::vector atom_site_fract_coords; _unpack_ucell(ucell, veca, vecb, vecc, natom, atom_site_labels, atom_site_fract_coords); @@ -468,7 +468,7 @@ void ModuleIO::CifParser::read(const std::string& fcif, // okey for read, cannot just use if rank != 0 then return, because need to broadcast the map out.clear(); #ifdef __MPI - int myrank; + int myrank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &myrank); if (myrank == rank) // only the rank assigned to read the cif file will read the file { diff --git a/source/source_io/csr_reader.cpp b/source/source_io/csr_reader.cpp index 160cb78a61..7e85c137b6 100644 --- a/source/source_io/csr_reader.cpp +++ b/source/source_io/csr_reader.cpp @@ -40,7 +40,7 @@ void csrFileReader::parseFile() for (int i = 0; i < numberOfR; i++) { std::vector RCoord(3); - int nonZero; + int nonZero = 0; readLine(); ss >> RCoord[0] >> RCoord[1] >> RCoord[2] >> nonZero; diff --git a/source/source_io/get_pchg_lcao.cpp b/source/source_io/get_pchg_lcao.cpp index 346b56f12a..82de5db224 100644 --- a/source/source_io/get_pchg_lcao.cpp +++ b/source/source_io/get_pchg_lcao.cpp @@ -408,7 +408,7 @@ void Get_pchg_lcao::idmatrix(const int& ib, if (ib_local >= 0) { - double wg_value; + double wg_value = 0.0; if (if_separate_k) { wg_value = (ib < fermi_band) ? wg_sum_k : wg_sum_k_homo; diff --git a/source/source_io/get_wf_lcao.cpp b/source/source_io/get_wf_lcao.cpp index 6cafa72d60..91d2c0b514 100644 --- a/source/source_io/get_wf_lcao.cpp +++ b/source/source_io/get_wf_lcao.cpp @@ -513,7 +513,7 @@ void Get_wf_lcao::wfc_2d_to_grid(const T* lowf_2d, MPI_Comm_rank(pv.comm(), &rank); // calculate the maximum number of nlocal over all processes in pv.comm() range - long buf_size; + long buf_size = 0; mpi_info = MPI_Reduce(&pv.nloc_wfc, &buf_size, 1, MPI_LONG, MPI_MAX, 0, pv.comm()); mpi_info = MPI_Bcast(&buf_size, 1, MPI_LONG, 0, pv.comm()); // get and then broadcast std::vector lowf_block(buf_size); diff --git a/source/source_io/read_input.cpp b/source/source_io/read_input.cpp index a23bcd0da9..c08c63acc7 100644 --- a/source/source_io/read_input.cpp +++ b/source/source_io/read_input.cpp @@ -104,13 +104,13 @@ bool filter_nonascii_and_comment(std::ifstream& ifs, ifs.clear(); ifs.seekg(0, std::ios::beg); - char c; + char c = '\0'; while (ifs.get(c)) { // If comment start, skip until end of line (but keep the newline) if (c == '#') { - char d; + char d = '\0'; bool newline_found = false; while (ifs.get(d)) { @@ -562,7 +562,7 @@ int ReadInput::current_md_step(const std::string& file_dir) ModuleBase::WARNING_QUIT("current_md_step", "no Restart_md.txt"); } - int md_step; + int md_step = 0; file >> md_step; file.close(); diff --git a/source/source_io/to_qo_kernel.cpp b/source/source_io/to_qo_kernel.cpp index b16917259a..8ce94520a1 100644 --- a/source/source_io/to_qo_kernel.cpp +++ b/source/source_io/to_qo_kernel.cpp @@ -598,7 +598,7 @@ void toQO::read_ovlp(const std::string& dir, const int& nrows, const int& ncols, { if (is_R) { - double val; + double val = 0.0; ifs >> val; inum++; if (inum <= nchi_ * nphi_) { diff --git a/source/source_io/to_qo_mpi.cpp b/source/source_io/to_qo_mpi.cpp index e8823a3ee5..c4a01cc693 100644 --- a/source/source_io/to_qo_mpi.cpp +++ b/source/source_io/to_qo_mpi.cpp @@ -7,7 +7,7 @@ void toQO::bcast_stdvector_ofvector3int(std::vector>& v const int rank) { #ifdef __MPI - int dim; + int dim = 0; std::vector vec_1d; if(rank == 0) { @@ -37,7 +37,7 @@ void toQO::bcast_stdvector_ofvector3double(std::vector vec_1d; if(rank == 0) { diff --git a/source/source_io/to_qo_structures.cpp b/source/source_io/to_qo_structures.cpp index 28679baf58..91f4cf4092 100644 --- a/source/source_io/to_qo_structures.cpp +++ b/source/source_io/to_qo_structures.cpp @@ -60,7 +60,7 @@ void toQO::read_structures(const UnitCell* p_ucell, } for(int i = 0; i < nranks; i++) { - int nks_dim; + int nks_dim = 0; if(iproc_ == 0) nks_dim = nks_divided[i].size(); Parallel_Common::bcast_int(nks_dim); if(iproc_ != 0) nks_divided[i].resize(nks_dim); @@ -244,7 +244,7 @@ void toQO::scan_supercell(const int& rank, const int& nranks) } for(int i = 0; i < nranks; i++) { - int nR_dim; + int nR_dim = 0; if(rank == 0) nR_dim = nR_divided[i].size(); Parallel_Common::bcast_int(nR_dim); if(rank != 0) nR_divided[i].resize(nR_dim); diff --git a/source/source_io/to_wannier90.cpp b/source/source_io/to_wannier90.cpp index a3b814ed82..e7a291dcfc 100644 --- a/source/source_io/to_wannier90.cpp +++ b/source/source_io/to_wannier90.cpp @@ -202,7 +202,7 @@ bool toWannier90::try_read_nnkp(const UnitCell& ucell, const K_Vectors& kv) cal_num_kpts = num_kpts / 2; } - int numkpt_nnkp; + int numkpt_nnkp = 0; ModuleBase::GlobalFunc::READ_VALUE(nnkp_read, numkpt_nnkp); if ((PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) && numkpt_nnkp != num_kpts) { @@ -433,7 +433,7 @@ bool toWannier90::try_read_nnkp(const UnitCell& ucell, const K_Vectors& kv) { for (int ib = 0; ib < nntot; ib++) { - int ik_nnkp; + int ik_nnkp = 0; nnkp_read >> ik_nnkp; if (ik_nnkp != (ik + 1)) { diff --git a/source/source_io/unk_overlap_lcao.cpp b/source/source_io/unk_overlap_lcao.cpp index eaab367041..99726117ff 100644 --- a/source/source_io/unk_overlap_lcao.cpp +++ b/source/source_io/unk_overlap_lcao.cpp @@ -96,7 +96,7 @@ void unkOverlap_lcao::init(const UnitCell& ucell, { local_term++; } - int start; + int start = 0; for (int rank = 0; rank < nproc; rank++) { if (rank == myrank) diff --git a/source/source_lcao/module_deepks/deepks_orbital.cpp b/source/source_lcao/module_deepks/deepks_orbital.cpp index 1a0d91cafe..7f16b6fec1 100644 --- a/source/source_lcao/module_deepks/deepks_orbital.cpp +++ b/source/source_lcao/module_deepks/deepks_orbital.cpp @@ -29,7 +29,7 @@ void DeePKS_domain::cal_o_delta(const std::vector& dm_hl, if (mu >= 0 && nu >= 0) { - int iic; + int iic = 0; if (PARAM.inp.ks_solver == "genelpa" || PARAM.inp.ks_solver == "scalapack_gvx" || PARAM.inp.ks_solver == "pexsi") // save the matrix as column major format { diff --git a/source/source_lcao/module_deepks/deepks_pdm.cpp b/source/source_lcao/module_deepks/deepks_pdm.cpp index edbfec8ef8..fdc838f45a 100644 --- a/source/source_lcao/module_deepks/deepks_pdm.cpp +++ b/source/source_lcao/module_deepks/deepks_pdm.cpp @@ -53,7 +53,7 @@ void DeePKS_domain::read_pdm(bool read_pdm_file, { for (int m2 = 0; m2 < nm; m2++) { - double c; + double c = 0.0; ifs >> c; accessor[m1][m2] = c; } @@ -74,7 +74,7 @@ void DeePKS_domain::read_pdm(bool read_pdm_file, auto accessor = pdm[iat].accessor(); for (int ind = 0; ind < pdm_size; ind++) { - double c; + double c = 0.0; ifs >> c; accessor[ind] = c; } diff --git a/source/source_lcao/module_deepks/deepks_vdelta.cpp b/source/source_lcao/module_deepks/deepks_vdelta.cpp index ba9f35f9fc..ab0f94c3a4 100644 --- a/source/source_lcao/module_deepks/deepks_vdelta.cpp +++ b/source/source_lcao/module_deepks/deepks_vdelta.cpp @@ -38,7 +38,7 @@ void DeePKS_domain::cal_e_delta_band(const std::vector>& dm, if (mu >= 0 && nu >= 0) { - int iic; + int iic = 0; if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.inp.ks_solver)) { iic = mu + nu * pv->nrow; diff --git a/source/source_lcao/module_deltaspin/lambda_loop.cpp b/source/source_lcao/module_deltaspin/lambda_loop.cpp index 8b87f7eedd..5d38c5d261 100644 --- a/source/source_lcao/module_deltaspin/lambda_loop.cpp +++ b/source/source_lcao/module_deltaspin/lambda_loop.cpp @@ -117,9 +117,7 @@ void spinconstrain::SpinConstrain>::run_lambda_loop( std::vector> new_spin(nat, 0.0), spin_plus(nat, 0.0); double alpha_opt, alpha_plus; - double beta; - double mean_error, mean_error_old, rms_error; - double g; + double beta = 0.0, g = 0.0, mean_error = 0.0, mean_error_old = 0.0, rms_error = 0.0; double alpha_trial = this->alpha_trial_; diff --git a/source/source_lcao/module_dftu/dftu_folding.cpp b/source/source_lcao/module_dftu/dftu_folding.cpp index b67db9fcb4..cba6b33991 100644 --- a/source/source_lcao/module_dftu/dftu_folding.cpp +++ b/source/source_lcao/module_dftu/dftu_folding.cpp @@ -246,7 +246,7 @@ void Plus_U::folding_matrix_k(const UnitCell& ucell, continue; } - int iic; + int iic = 0; if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.inp.ks_solver)) { iic = mu + nu * pv.nrow; diff --git a/source/source_lcao/module_dftu/dftu_io.cpp b/source/source_lcao/module_dftu/dftu_io.cpp index f75bc408c6..737c1c590a 100644 --- a/source/source_lcao/module_dftu/dftu_io.cpp +++ b/source/source_lcao/module_dftu/dftu_io.cpp @@ -487,7 +487,7 @@ inline void JacobiRotate(std::vector>& A, int p, int q, int if (std::abs(A[p][q]) > 1e-10) { double r = (A[q][q] - A[p][p]) / (2.0 * A[p][q]); - double t; + double t = 0.0; if (r >= 0) { t = 1.0 / (r + sqrt(1.0 + r * r)); } else { diff --git a/source/source_lcao/module_gint/gint_common.cpp b/source/source_lcao/module_gint/gint_common.cpp index 69957f0b38..3588604f59 100644 --- a/source/source_lcao/module_gint/gint_common.cpp +++ b/source/source_lcao/module_gint/gint_common.cpp @@ -316,7 +316,7 @@ void wfc_2d_to_gint(const T* wfc_2d, MPI_Comm_rank(pv.comm(), &rank); // calculate the maximum number of nlocal over all processes in pv.comm() range - long buf_size; + long buf_size = 0; mpi_info = MPI_Reduce(&pv.nloc_wfc, &buf_size, 1, MPI_LONG, MPI_MAX, 0, pv.comm()); mpi_info = MPI_Bcast(&buf_size, 1, MPI_LONG, 0, pv.comm()); // get and then broadcast std::vector wfc_block(buf_size); diff --git a/source/source_lcao/module_gint/gint_dvlocal.cpp b/source/source_lcao/module_gint/gint_dvlocal.cpp index 3d3888a0b9..7910649b71 100644 --- a/source/source_lcao/module_gint/gint_dvlocal.cpp +++ b/source/source_lcao/module_gint/gint_dvlocal.cpp @@ -72,7 +72,7 @@ void Gint_dvlocal::cal_dvlocal_R_sparseMatrix( std::map, std::map>> pvdpRy_sparseMatrix; std::map, std::map>> pvdpRz_sparseMatrix; - double temp_value_double; + double temp_value_double = 0.0; Vec3d tau1, dtau; for (int iap = 0; iap < pvdpRx.size_atom_pairs(); iap++) diff --git a/source/source_lcao/module_gint/set_ddphi.cpp b/source/source_lcao/module_gint/set_ddphi.cpp index c84f087487..4e7d486fbc 100644 --- a/source/source_lcao/module_gint/set_ddphi.cpp +++ b/source/source_lcao/module_gint/set_ddphi.cpp @@ -72,7 +72,7 @@ void GintAtom::set_ddphi( const double x12 = x1 * x2 / 6; const double x03 = x0 * x3 / 2; - double tmp, dtmp; + double tmp = 0.0, dtmp = 0.0; for(int iw = 0; iw < atom_->nw; ++iw) { diff --git a/source/source_lcao/module_hcontainer/func_folding.cpp b/source/source_lcao/module_hcontainer/func_folding.cpp index 58ba3d267a..4b276846d6 100644 --- a/source/source_lcao/module_hcontainer/func_folding.cpp +++ b/source/source_lcao/module_hcontainer/func_folding.cpp @@ -40,7 +40,7 @@ void folding_HR(const hamilt::HContainer& hR, // if TK==std::complex, kphase is e^{ikR} const ModuleBase::Vector3 dR(r_index.x, r_index.y, r_index.z); const double arg = (kvec_d_in * dR) * ModuleBase::TWO_PI; - double sinp, cosp; + double sinp = 0.0, cosp = 0.0; ModuleBase::libm::sincos(arg, &sinp, &cosp); std::complex kphase = std::complex(cosp, sinp); @@ -86,7 +86,7 @@ void folding_HR(const hamilt::HContainer& hR, // if TK==std::complex, kphase is e^{ikR} const ModuleBase::Vector3 dR(rx, ry, rz); const double arg = (kvec_d_in * dR) * ModuleBase::TWO_PI; - double sinp, cosp; + double sinp = 0.0, cosp = 0.0; ModuleBase::libm::sincos(arg, &sinp, &cosp); std::complex kphase = std::complex(cosp, sinp); diff --git a/source/source_lcao/module_hcontainer/func_transfer.cpp b/source/source_lcao/module_hcontainer/func_transfer.cpp index 1da0c524a1..14566ac01d 100644 --- a/source/source_lcao/module_hcontainer/func_transfer.cpp +++ b/source/source_lcao/module_hcontainer/func_transfer.cpp @@ -169,7 +169,7 @@ void transferParallels2Serial(const hamilt::HContainer& hR_p, hamilt::HConta // send data std::vector receive_values; - long max_size; + long max_size = 0; if (my_rank == serial_rank) { max_size = trans_s->get_max_size(); diff --git a/source/source_lcao/module_hcontainer/test/test_hcontainer.cpp b/source/source_lcao/module_hcontainer/test/test_hcontainer.cpp index 536eb8744e..ef948f87d8 100644 --- a/source/source_lcao/module_hcontainer/test/test_hcontainer.cpp +++ b/source/source_lcao/module_hcontainer/test/test_hcontainer.cpp @@ -542,8 +542,8 @@ TEST_F(HContainerTest, atompair_funcs) } HR.unfix_R(); // check hr_array and hr_array2 are correct - std::complex correct1; - double correct2; + std::complex correct1 = 0.0; + double correct2 = 0.0; double correct_array[16] = { 1, 2, 3, 4, 5, 6, 7, 8, diff --git a/source/source_lcao/module_lr/dm_trans/dmr_complex.cpp b/source/source_lcao/module_lr/dm_trans/dmr_complex.cpp index 3ed8ab69bf..4f62aa2a43 100644 --- a/source/source_lcao/module_lr/dm_trans/dmr_complex.cpp +++ b/source/source_lcao/module_lr/dm_trans/dmr_complex.cpp @@ -47,7 +47,7 @@ namespace elecstate // if TK==std::complex, kphase is e^{ikR} const ModuleBase::Vector3 dR(r_index[0], r_index[1], r_index[2]); const double arg = (this->_kvec_d[ik] * dR) * ModuleBase::TWO_PI; - double sinp, cosp; + double sinp = 0.0, cosp = 0.0; ModuleBase::libm::sincos(arg, &sinp, &cosp); const std::complex kphase = std::complex(cosp, sinp); // set DMR element diff --git a/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp b/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp index 16efc5f046..95b956b7fb 100644 --- a/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp +++ b/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp @@ -692,7 +692,7 @@ void LR::ESolver_LR::read_ks_chg(Charge& chg_gs) std::stringstream ssc; ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube"; GlobalV::ofs_running << ssc.str() << std::endl; - double ef; + double ef = 0.0; if (ModuleIO::read_vdata_palgrid(Pgrid, GlobalV::MY_RANK, GlobalV::ofs_running, diff --git a/source/source_lcao/module_lr/utils/lr_util.cpp b/source/source_lcao/module_lr/utils/lr_util.cpp index ae2f00ffa3..f720012413 100644 --- a/source/source_lcao/module_lr/utils/lr_util.cpp +++ b/source/source_lcao/module_lr/utils/lr_util.cpp @@ -120,7 +120,7 @@ namespace LR_Util ModuleBase::TITLE("LR_Util", "diag_lapack"); int info = 0; char jobz = 'V', uplo = 'U'; - double work_tmp; + double work_tmp = 0.0; const int minus_one = -1; dsyev_(&jobz, &uplo, &n, mat, &n, eig, &work_tmp, &minus_one, &info); // get best lwork const int lwork = work_tmp; @@ -149,7 +149,7 @@ namespace LR_Util ModuleBase::TITLE("LR_Util", "diag_lapack_nh"); int info = 0; char jobvl = 'N', jobvr = 'V'; //calculate right eigenvectors - double work_tmp; + double work_tmp = 0.0; const int minus_one = -1; std::vector eig_real(n); std::vector eig_imag(n); diff --git a/source/source_lcao/module_operator_lcao/dftu_force_stress.hpp b/source/source_lcao/module_operator_lcao/dftu_force_stress.hpp index 2ce46854a4..8175d1009f 100644 --- a/source/source_lcao/module_operator_lcao/dftu_force_stress.hpp +++ b/source/source_lcao/module_operator_lcao/dftu_force_stress.hpp @@ -324,7 +324,7 @@ void DFTU>::cal_force_IJR(const int& iat1, step_trace[3] = col_indexes.size() + 1; } - double tmp[3]; + double tmp[3] = {0.0}; // calculate the local matrix for (int is = 0; is < nspin; is++) { diff --git a/source/source_lcao/module_operator_lcao/dspin_force_stress.hpp b/source/source_lcao/module_operator_lcao/dspin_force_stress.hpp index ff14029e25..449d73c050 100644 --- a/source/source_lcao/module_operator_lcao/dspin_force_stress.hpp +++ b/source/source_lcao/module_operator_lcao/dspin_force_stress.hpp @@ -272,7 +272,7 @@ void DeltaSpin>::cal_force_IJR(const int& iat1, step_trace[2] = col_indexes.size(); step_trace[3] = col_indexes.size() + 1; } - double tmp[3]; + double tmp[3] = {0.0}; // calculate the local matrix for (int is = 1; is < nspin; is++) { diff --git a/source/source_lcao/module_ri/exx_abfs-io.cpp b/source/source_lcao/module_ri/exx_abfs-io.cpp index 0ed196335b..bbdda73897 100644 --- a/source/source_lcao/module_ri/exx_abfs-io.cpp +++ b/source/source_lcao/module_ri/exx_abfs-io.cpp @@ -62,7 +62,7 @@ std::vector> Exx_Abfs::IO::construct_abfs_T( size_t L_size; std::map N_size; size_t meshr; - double dr; + double dr = 0.0; std::map>> psis; /*---------------------- diff --git a/source/source_lcao/module_ri/module_exx_symmetry/irreducible_sector.cpp b/source/source_lcao/module_ri/module_exx_symmetry/irreducible_sector.cpp index b79bfcfc20..f93b8aa040 100644 --- a/source/source_lcao/module_ri/module_exx_symmetry/irreducible_sector.cpp +++ b/source/source_lcao/module_ri/module_exx_symmetry/irreducible_sector.cpp @@ -235,4 +235,4 @@ namespace ModuleSymmetry // this->output_sector_star(); this->write_irreducible_sector(); } -} \ No newline at end of file +} diff --git a/source/source_lcao/module_ri/module_exx_symmetry/irreducible_sector_bvk.cpp b/source/source_lcao/module_ri/module_exx_symmetry/irreducible_sector_bvk.cpp index 50df31b360..8b8879ee1d 100644 --- a/source/source_lcao/module_ri/module_exx_symmetry/irreducible_sector_bvk.cpp +++ b/source/source_lcao/module_ri/module_exx_symmetry/irreducible_sector_bvk.cpp @@ -102,8 +102,8 @@ namespace ModuleSymmetry } // analyze bravis and generate optimized lattice for minimal BvK lattice - double cel_const[6]; - double pre_const[6]; + double cel_const[6] = {0.0}; + double pre_const[6] = {0.0}; int bvk_brav = 0; std::string bvk_latname=""; // bvk_brav = symm.standard_lat(s1, s2, s3, cel_const); //not enough, optimal lattice may change after cell-extension @@ -126,10 +126,10 @@ namespace ModuleSymmetry // generate symmetry operation of the BvK lattice using the original optlat-direct coordinates std::vector bvk_op(48); - int bvk_nop; + int bvk_nop = 0; symm.setgroup(bvk_op.data(), bvk_nop, bvk_brav); bvk_op.resize(bvk_nop); - int bvk_npg, bvk_nsg, bvk_pgnum, bvk_sgnum; + int bvk_npg = 0, bvk_nsg = 0, bvk_pgnum = 0, bvk_sgnum = 0; std::string bvk_pgname, bvk_sgname; std::vector bvk_gmatrix(48); std::vector> bvk_gtrans(48); diff --git a/source/source_lcao/module_ri/module_exx_symmetry/symmetry_rotation.cpp b/source/source_lcao/module_ri/module_exx_symmetry/symmetry_rotation.cpp index e0b4d91b8b..27929737f6 100644 --- a/source/source_lcao/module_ri/module_exx_symmetry/symmetry_rotation.cpp +++ b/source/source_lcao/module_ri/module_exx_symmetry/symmetry_rotation.cpp @@ -203,7 +203,7 @@ namespace ModuleSymmetry TCdouble Symmetry_rotation::get_euler_angle(const ModuleBase::Matrix3& gmatc) const { double threshold = this->eps_; - double alpha, beta, gamma; + double alpha = 0.0, beta = 0.0, gamma = 0.0; if (std::fabs(gmatc.e32) > threshold || std::fabs(gmatc.e31) > threshold) // sin(beta) is not zero { // use the 2-angle elements to get alpha and gamma diff --git a/source/source_lcao/module_rt/boundary_fix.cpp b/source/source_lcao/module_rt/boundary_fix.cpp index 22e7324633..dcdb436153 100644 --- a/source/source_lcao/module_rt/boundary_fix.cpp +++ b/source/source_lcao/module_rt/boundary_fix.cpp @@ -33,7 +33,7 @@ void reset_matrix_boundary(const UnitCell& ucell, //skip unrelevent ik if(arg==0)continue; //calculate correction phase - double sinp, cosp; + double sinp = 0.0, cosp = 0.0; ModuleBase::libm::sincos(arg, &sinp, &cosp); const std::complex phase = std::complex(cosp, sinp); //phase correction for Hamiltionian, overlap matrix and c vec. diff --git a/source/source_lcao/module_rt/norm_psi.cpp b/source/source_lcao/module_rt/norm_psi.cpp index 307cef9f80..d29972dce3 100644 --- a/source/source_lcao/module_rt/norm_psi.cpp +++ b/source/source_lcao/module_rt/norm_psi.cpp @@ -16,7 +16,7 @@ namespace module_rt inline int globalIndex(int localindex, int nblk, int nprocs, int myproc) { - int iblock, gIndex; + int iblock = 0, gIndex = 0; iblock = localindex / nblk; gIndex = (iblock * nprocs + myproc) * nblk + localindex % nblk; return gIndex; diff --git a/source/source_lcao/module_rt/propagator.cpp b/source/source_lcao/module_rt/propagator.cpp index d9a37b8c8b..2854839066 100644 --- a/source/source_lcao/module_rt/propagator.cpp +++ b/source/source_lcao/module_rt/propagator.cpp @@ -24,7 +24,7 @@ void Propagator::compute_propagator(const int nlocal, std::ofstream& ofs_running, const int print_matrix) const { - int tag; + int tag = 0; switch (ptype) { case 0: @@ -56,7 +56,7 @@ void Propagator::compute_propagator_tensor(const int nlocal, const int print_matrix, const bool use_lapack) const { - int tag; + int tag = 0; switch (ptype) { case 0: diff --git a/source/source_lcao/module_rt/td_folding.cpp b/source/source_lcao/module_rt/td_folding.cpp index e0b34cd31f..ed42b7524e 100644 --- a/source/source_lcao/module_rt/td_folding.cpp +++ b/source/source_lcao/module_rt/td_folding.cpp @@ -32,7 +32,7 @@ void folding_HR_td(const UnitCell& ucell, // if TK==std::complex, kphase is e^{ikR} const ModuleBase::Vector3 dR(r_index.x, r_index.y, r_index.z); const double arg = (kvec_d_in * dR) * ModuleBase::TWO_PI + arg_td; - double sinp, cosp; + double sinp = 0.0, cosp = 0.0; ModuleBase::libm::sincos(arg, &sinp, &cosp); std::complex kphase = std::complex(cosp, sinp); @@ -62,7 +62,7 @@ void folding_partial_HR(const UnitCell& ucell, const ModuleBase::Vector3 r_index = tmp.get_R_index(ir); const ModuleBase::Vector3 dR(r_index.x, r_index.y, r_index.z); const double arg = (kvec_d_in * dR) * ModuleBase::TWO_PI; - double sinp, cosp; + double sinp = 0.0, cosp = 0.0; ModuleBase::libm::sincos(arg, &sinp, &cosp); std::complex kphase = std::complex(cosp, sinp); const ModuleBase::Vector3 dR_car = dR * ucell.latvec * ucell.lat0; @@ -105,7 +105,7 @@ void folding_partial_HR_td(const UnitCell& ucell, // if TK==std::complex, kphase is e^{ikR} const ModuleBase::Vector3 dR(r_index.x, r_index.y, r_index.z); const double arg = (kvec_d_in * dR) * ModuleBase::TWO_PI + arg_td; - double sinp, cosp; + double sinp = 0.0, cosp = 0.0; ModuleBase::libm::sincos(arg, &sinp, &cosp); std::complex kphase = std::complex(cosp, sinp); const ModuleBase::Vector3 dR_car = dR * ucell.latvec * ucell.lat0; diff --git a/source/source_lcao/module_rt/velocity_op.cpp b/source/source_lcao/module_rt/velocity_op.cpp index ceec0b1b65..7114fb2495 100644 --- a/source/source_lcao/module_rt/velocity_op.cpp +++ b/source/source_lcao/module_rt/velocity_op.cpp @@ -54,7 +54,7 @@ void Velocity_op::initialize_vcomm_r(const Grid_Driver* GridD, const Paralle for (int iat0 = 0; iat0 < ucell->nat; iat0++) { auto tau0 = ucell->get_tau(iat0); - int T0, I0; + int T0 = 0, I0 = 0; ucell->iat2iait(iat0, &I0, &T0); AdjacentAtomInfo adjs; GridD->Find_atom(*ucell, tau0, T0, I0, &adjs); @@ -129,7 +129,7 @@ void Velocity_op::initialize_grad_term(const Grid_Driver* GridD, const Paral for (int iat1 = 0; iat1 < ucell->nat; iat1++) { auto tau1 = ucell->get_tau(iat1); - int T1, I1; + int T1 = 0, I1 = 0; ucell->iat2iait(iat1, &I1, &T1); AdjacentAtomInfo adjs; GridD->Find_atom(*ucell, tau1, T1, I1, &adjs); @@ -190,7 +190,7 @@ void Velocity_op::calculate_vcomm_r() for (int iat0 = 0; iat0 < this->ucell->nat; iat0++) { auto tau0 = ucell->get_tau(iat0); - int T0, I0; + int T0 = 0, I0 = 0; ucell->iat2iait(iat0, &I0, &T0); AdjacentAtomInfo& adjs = this->adjs_vcommr[iat0]; std::vector>>> nlm_tot; @@ -422,7 +422,7 @@ void Velocity_op::calculate_grad_term() for (int iat1 = 0; iat1 < this->ucell->nat; iat1++) { auto tau1 = ucell->get_tau(iat1); - int T1, I1; + int T1 = 0, I1 = 0; ucell->iat2iait(iat1, &I1, &T1); AdjacentAtomInfo& adjs = this->adjs_grad[iat1]; for (int ad = 0; ad < adjs.adj_num + 1; ++ad) @@ -464,9 +464,9 @@ void Velocity_op::cal_grad_IJR(const int& iat1, // --------------------------------------------- // get info of orbitals of atom1 and atom2 from ucell // --------------------------------------------- - int T1, I1; + int T1 = 0, I1 = 0; this->ucell->iat2iait(iat1, &I1, &T1); - int T2, I2; + int T2 = 0, I2 = 0; this->ucell->iat2iait(iat2, &I2, &T2); Atom& atom1 = this->ucell->atoms[T1]; Atom& atom2 = this->ucell->atoms[T2]; diff --git a/source/source_lcao/spar_dh.cpp b/source/source_lcao/spar_dh.cpp index 7d5d485d56..1848901eea 100644 --- a/source/source_lcao/spar_dh.cpp +++ b/source/source_lcao/spar_dh.cpp @@ -160,8 +160,8 @@ void sparse_format::cal_dSTN_R(const UnitCell& ucell, ModuleBase::Vector3 dtau, tau1, tau2; ModuleBase::Vector3 dtau1, dtau2, tau0; - double temp_value_double; - std::complex temp_value_complex; + double temp_value_double = 0.0; + std::complex temp_value_complex = 0.0; for (int T1 = 0; T1 < ucell.ntype; ++T1) { diff --git a/source/source_lcao/spar_hsr.cpp b/source/source_lcao/spar_hsr.cpp index fb74a15f23..c7e26791d4 100644 --- a/source/source_lcao/spar_hsr.cpp +++ b/source/source_lcao/spar_hsr.cpp @@ -11,7 +11,7 @@ #ifdef __MPI void sparse_format::sync_all_R_coor(std::set>& all_R_coor, MPI_Comm comm) { - int my_rank, nproc; + int my_rank = 0, nproc = 0; MPI_Comm_rank(comm, &my_rank); MPI_Comm_size(comm, &nproc); diff --git a/source/source_lcao/wavefunc_in_pw.cpp b/source/source_lcao/wavefunc_in_pw.cpp index 701f0f42a4..3bc3711e14 100644 --- a/source/source_lcao/wavefunc_in_pw.cpp +++ b/source/source_lcao/wavefunc_in_pw.cpp @@ -125,7 +125,7 @@ void Wavefunc_in_pw::make_table_q( } else { - double no_use; + double no_use = 0.0; for(int ir=0; ir> no_use; @@ -327,7 +327,7 @@ void Wavefunc_in_pw::produce_local_basis_in_pw(const UnitCell& ucell, }//if else {//atomic_wfc_so_mag - double alpha, gamma; + double alpha = 0.0, gamma = 0.0; std::complex fup,fdown; //int nc; //This routine creates two functions only in the case j=l+1/2 or exit in the other case @@ -402,8 +402,8 @@ void Wavefunc_in_pw::produce_local_basis_in_pw(const UnitCell& ucell, } // end if ucell.atoms[it].has_so else {//atomic_wfc_nc - double alpha, gamman; - std::complex fup, fdown; + double alpha = 0.0, gamman = 0.0; + std::complex fup = 0.0, fdown = 0.0; //alpha = ucell.magnet.angle1_[it]; //gamman = -ucell.magnet.angle2_[it] + 0.5*ModuleBase::PI; alpha = ucell.atoms[it].angle1[ia]; diff --git a/source/source_md/msst.cpp b/source/source_md/msst.cpp index 0a9024cdfe..cadea1a8f1 100644 --- a/source/source_md/msst.cpp +++ b/source/source_md/msst.cpp @@ -83,7 +83,7 @@ void MSST::first_half(std::ofstream& ofs) const int sd = mdp.msst_direction; const double dthalf = 0.5 * md_dt; - double vol; + double vol = 0.0; energy_ = potential + kinetic; /// propagate the time derivative of volume 1/2 step diff --git a/source/source_md/nhchain.cpp b/source/source_md/nhchain.cpp index dfe086490a..ac1e23570c 100644 --- a/source/source_md/nhchain.cpp +++ b/source/source_md/nhchain.cpp @@ -390,7 +390,7 @@ void Nose_Hoover::restart(const std::string& global_readin_dir) if (ok) { - double Mnum; + double Mnum = 0.0; file >> step_rst_ >> md_tfirst >> Mnum; if (Mnum != mdp.md_tchain) @@ -494,7 +494,7 @@ void Nose_Hoover::particle_thermo() } /// integrate loop - double factor; + double factor = 0.0; double scale = 1.0; double KE = kinetic; for (int i = 0; i < nc_tchain; ++i) @@ -583,7 +583,7 @@ void Nose_Hoover::baro_thermo() g_peta[0] = (ke_omega - lkt_press) / mass_peta[0]; /// integrate loop - double factor; + double factor = 0.0; double scale = 1.0; double kecurrent = ke_omega; for (int i = 0; i < nc_pchain; ++i) @@ -662,7 +662,7 @@ void Nose_Hoover::update_baro() } term_one /= pdim * ucell.nat; - double g_omega; + double g_omega = 0.0; double term_two = 0; for (int i = 0; i < 3; ++i) { @@ -689,7 +689,7 @@ void Nose_Hoover::update_baro() void Nose_Hoover::vel_baro() { - double factor[3]; + double factor[3] = {0.0}; for (int i = 0; i < 3; ++i) { factor[i] = exp(-(v_omega[i] + mtk_term) * md_dt / 4); @@ -721,7 +721,7 @@ void Nose_Hoover::vel_baro() void Nose_Hoover::update_volume(std::ofstream& ofs) { - double factor; + double factor = 0.0; /// tri mode, off-diagonal components, first half if (pflag[4]) diff --git a/source/source_md/verlet.cpp b/source/source_md/verlet.cpp index 3eafb181e1..66871f8970 100644 --- a/source/source_md/verlet.cpp +++ b/source/source_md/verlet.cpp @@ -75,7 +75,7 @@ void Verlet::apply_thermostat(void) { if (my_rank == 0) { - double deviation; + double deviation = 0.0; for (int i = 0; i < ucell.nat; ++i) { if (static_cast(std::rand()) / RAND_MAX <= 1.0 / mdp.md_nraise) diff --git a/source/source_psi/psi_initializer_nao.cpp b/source/source_psi/psi_initializer_nao.cpp index 7f74b40c44..bd0a29e7d1 100644 --- a/source/source_psi/psi_initializer_nao.cpp +++ b/source/source_psi/psi_initializer_nao.cpp @@ -85,9 +85,9 @@ void psi_initializer_nao::read_external_orbs(const std::string* orbital_files << this->orbital_files_[it] << std::endl; } std::string elem; // garbage value, will discard - double ecut; // garbage value, will discard - int nr; - double dr; + double ecut = 0.0; // garbage value, will discard + int nr = 0; + double dr = 0.0; std::vector nzeta; std::vector> radials; ModuleIO::read_abacus_orb(ifs_it, elem, ecut, nr, dr, nzeta, radials, rank); diff --git a/source/source_pw/module_pwdft/elecond.cpp b/source/source_pw/module_pwdft/elecond.cpp index 068ca01067..985f7f8717 100644 --- a/source/source_pw/module_pwdft/elecond.cpp +++ b/source/source_pw/module_pwdft/elecond.cpp @@ -61,7 +61,7 @@ void EleCond::KG(const int& smear_type, const double gamma = fwhmin / 2.0 / ModuleBase::Ry_to_eV; double dt = dt_in; // unit in a.u., 1 a.u. = 4.837771834548454e-17 s const double expfactor = 23; // exp(-23) = 1e-10 - int nt; // set nt empirically + int nt = 0; // set nt empirically if (smear_type == 1) { nt = ceil(sqrt(2 * expfactor) / sigma / dt); diff --git a/source/source_pw/module_pwdft/forces.cpp b/source/source_pw/module_pwdft/forces.cpp index 255b8e23a2..fbcebe6304 100644 --- a/source/source_pw/module_pwdft/forces.cpp +++ b/source/source_pw/module_pwdft/forces.cpp @@ -197,7 +197,7 @@ void Forces::cal_force(UnitCell& ucell, if (ModuleSymmetry::Symmetry::symm_flag == 1) { - double d1, d2, d3; + double d1 = 0.0, d2 = 0.0, d3 = 0.0; for (int iat = 0; iat < this->nat; iat++) { ModuleBase::Mathzone::Cartesian_to_Direct(force(iat, 0), @@ -449,7 +449,7 @@ void Forces::cal_force_loc(const UnitCell& ucell, for (int ig = 0; ig < rho_basis->npw; ig++) { const double phase = ModuleBase::TWO_PI * (rho_basis->gcar[ig] * ucell.atoms[it].tau[ia]); - double sinp, cosp; + double sinp = 0.0, cosp = 0.0; ModuleBase::libm::sincos(phase, &sinp, &cosp); const double factor = vloc(it, rho_basis->ig2igg[ig]) * (cosp * aux[ig].imag() + sinp * aux[ig].real()); @@ -503,7 +503,7 @@ void Forces::cal_force_ew(const UnitCell& ucell, { if (ucell.atoms[it].na != 0) { - double dzv; + double dzv = 0.0; { dzv = ucell.atoms[it].ncpp.zv; } @@ -526,7 +526,7 @@ void Forces::cal_force_ew(const UnitCell& ucell, } double alpha = 1.1; - double upperbound; + double upperbound = 0.0; do { alpha -= 0.10; @@ -634,7 +634,7 @@ void Forces::cal_force_ew(const UnitCell& ucell, { const ModuleBase::Vector3 gcar = rho_basis->gcar[ig]; const double arg = ModuleBase::TWO_PI * (gcar * ucell.atoms[it].tau[ia]); - double sinp, cosp; + double sinp = 0.0, cosp = 0.0; ModuleBase::libm::sincos(arg, &sinp, &cosp); double sumnb = -cosp * aux[ig].imag() + sinp * aux[ig].real(); forceion(iat, 0) += gcar[0] * sumnb; @@ -686,7 +686,7 @@ void Forces::cal_force_ew(const UnitCell& ucell, { const double rr = sqrt(r2[n]) * ucell.lat0; - double factor; + double factor = 0.0; { factor = ucell.atoms[T1].ncpp.zv * ucell.atoms[T2].ncpp.zv * ModuleBase::e2 / (rr * rr) diff --git a/source/source_pw/module_pwdft/forces_cc.cpp b/source/source_pw/module_pwdft/forces_cc.cpp index a03d49964b..fd8b3ac20c 100644 --- a/source/source_pw/module_pwdft/forces_cc.cpp +++ b/source/source_pw/module_pwdft/forces_cc.cpp @@ -254,7 +254,7 @@ void Forces::deriv_drhoc const UnitCell& ucell_in ) { - int igl0; + int igl0 = 0; double gx = 0, rhocg1 = 0; //double *aux = new double[mesh]; std::vector aux(mesh); diff --git a/source/source_pw/module_pwdft/forces_scc.cpp b/source/source_pw/module_pwdft/forces_scc.cpp index 10681e5114..d77ee3bf2a 100644 --- a/source/source_pw/module_pwdft/forces_scc.cpp +++ b/source/source_pw/module_pwdft/forces_scc.cpp @@ -114,7 +114,7 @@ void Forces::cal_force_scc(ModuleBase::matrix& forcescc, const double rhocgntigg = rhocgnt[rho_basis->ig2igg[ig]]; const double arg = ModuleBase::TWO_PI * (gv * pos); - double sinp, cosp; + double sinp = 0.0, cosp = 0.0; ModuleBase::libm::sincos(arg, &sinp, &cosp); const std::complex cpm = std::complex(sinp, cosp) * conj(psic[ig]); diff --git a/source/source_pw/module_pwdft/fs_nonlocal_tools.h b/source/source_pw/module_pwdft/fs_nonlocal_tools.h index 5a96f71fb9..a5307dbace 100644 --- a/source/source_pw/module_pwdft/fs_nonlocal_tools.h +++ b/source/source_pw/module_pwdft/fs_nonlocal_tools.h @@ -154,13 +154,13 @@ class FS_Nonlocal_tools Device* ctx = {}; base_device::DEVICE_CPU* cpu_ctx = {}; base_device::AbacusDevice_t device = {}; - int nkb; - int nbands; + int nkb = 0; + int nbands = 0; int max_nh = 0; int max_npw = 0; - int ntype; - bool nondiagonal; + int ntype = 0; + bool nondiagonal = false; int pre_ik_s = -1; int pre_ik_f = -1; diff --git a/source/source_pw/module_pwdft/nonlocal_maths.hpp b/source/source_pw/module_pwdft/nonlocal_maths.hpp index 70d812e7c9..3e09675bcb 100644 --- a/source/source_pw/module_pwdft/nonlocal_maths.hpp +++ b/source/source_pw/module_pwdft/nonlocal_maths.hpp @@ -33,7 +33,7 @@ class Nonlocal_maths private: ModuleBase::matrix nhtol_; - int lmax_; + int lmax_ = 0; const UnitCell* ucell_; Device* ctx = {}; diff --git a/source/source_pw/module_pwdft/onsite_proj_tools.h b/source/source_pw/module_pwdft/onsite_proj_tools.h index 2bfa5ebb44..de5a0cce43 100644 --- a/source/source_pw/module_pwdft/onsite_proj_tools.h +++ b/source/source_pw/module_pwdft/onsite_proj_tools.h @@ -104,8 +104,8 @@ class Onsite_Proj_tools Device* ctx = {}; base_device::DEVICE_CPU* cpu_ctx = {}; base_device::AbacusDevice_t device = {}; - int nkb; - int nbands; + int nkb = 0; + int nbands = 0; int deeq_dims[4] = {0, 0, 0, 0}; // deeq can be something other than that in pseudopotentials int deeq_nc_dims[4] = {0, 0, 0, 0}; @@ -113,8 +113,8 @@ class Onsite_Proj_tools int max_nh = 0; int max_npw = 0; - int ntype; - bool nondiagonal; + int ntype = 0; + bool nondiagonal = false; int pre_ik_s = -1; int pre_ik_f = -1; diff --git a/source/source_pw/module_pwdft/onsite_projector.cpp b/source/source_pw/module_pwdft/onsite_projector.cpp index 4c03ce9b74..f9b8ad7cbc 100644 --- a/source/source_pw/module_pwdft/onsite_projector.cpp +++ b/source/source_pw/module_pwdft/onsite_projector.cpp @@ -503,7 +503,7 @@ void projectors::OnsiteProjector::read_abacus_orb(std::ifstream& ifs, { if (rank == 0) { - int l, izeta; + int l = 0, izeta = 0; ifs >> tmp >> tmp >> tmp; ifs >> tmp >> l >> izeta; ichi = radial_map_[l][izeta]; diff --git a/source/source_pw/module_pwdft/op_pw_exx_ace.cpp b/source/source_pw/module_pwdft/op_pw_exx_ace.cpp index d6c7f6517d..3fdef6cb00 100644 --- a/source/source_pw/module_pwdft/op_pw_exx_ace.cpp +++ b/source/source_pw/module_pwdft/op_pw_exx_ace.cpp @@ -149,7 +149,7 @@ void OperatorEXXPW::construct_ace() const for (int iq0 = 0; iq0 < nqs; iq0++) { // For nspin=2, iq should be in the same spin channel as ik - int iq; + int iq = 0; int nk = wfcpw->nks / 2; iq = iq0 + ispin * nk; // iq in the same spin channel diff --git a/source/source_pw/module_pwdft/parallel_grid.cpp b/source/source_pw/module_pwdft/parallel_grid.cpp index 73cbba225e..ff20f40d73 100644 --- a/source/source_pw/module_pwdft/parallel_grid.cpp +++ b/source/source_pw/module_pwdft/parallel_grid.cpp @@ -90,7 +90,7 @@ void Parallel_Grid::init(const int& ncx_in, assert(GlobalV::KPAR > 0); this->nproc_in_pool = new int[GlobalV::KPAR]; - int nprocgroup; + int nprocgroup = 0; if (PARAM.inp.esolver_type == "sdft") { nprocgroup = GlobalV::NPROC_IN_BNDGROUP; diff --git a/source/source_pw/module_pwdft/soc.cpp b/source/source_pw/module_pwdft/soc.cpp index d90b334a2f..a44a0b6a48 100644 --- a/source/source_pw/module_pwdft/soc.cpp +++ b/source/source_pw/module_pwdft/soc.cpp @@ -122,7 +122,7 @@ int Soc::sph_ind(const int l, const double j, const int m, const int spin) // in a spinor with orbital angular momentum l, total angular // momentum j, projection along z of the total angular momentum m+-1/2. // Spin selects the up (spin=1) or down (spin=2) coefficient. - int sph_ind0; + int sph_ind0 = 0; if (spin != 0 && spin != 1) { ModuleBase::WARNING_QUIT("sph_ind", "spin must be 0 1"); diff --git a/source/source_pw/module_pwdft/stress_loc.cpp b/source/source_pw/module_pwdft/stress_loc.cpp index 11c414f4dc..0b932afcdb 100644 --- a/source/source_pw/module_pwdft/stress_loc.cpp +++ b/source/source_pw/module_pwdft/stress_loc.cpp @@ -188,7 +188,7 @@ const UnitCell& ucell_in // - int igl0; + int igl0 = 0; this->device = base_device::get_device_type(this->ctx); std::vector gx_arr(rho_basis->ngg+1); @@ -276,7 +276,7 @@ void Stress_Func::dvloc_coulomb(const UnitCell& ucell, FPTYPE* dvloc, ModulePW::PW_Basis* rho_basis) { - int igl0; + int igl0 = 0; // start from |G|=0 or not. if (rho_basis->gg_uniq[0] < 1.0e-8) { diff --git a/source/source_pw/module_pwdft/vnl_pw.cpp b/source/source_pw/module_pwdft/vnl_pw.cpp index 52d3d447da..73f17850e8 100644 --- a/source/source_pw/module_pwdft/vnl_pw.cpp +++ b/source/source_pw/module_pwdft/vnl_pw.cpp @@ -825,7 +825,7 @@ void pseudopot_cell_vnl::compute_qrad(UnitCell& cell) aux[ir] = besr[ir] * upf->qfuncl(l, ijv, ir); } // then we integrate with all the Q functions - double vqint; + double vqint = 0.0; ModuleBase::Integral::Simpson_Integral(kkbeta, aux, upf->rab.data(), vqint); qrad(it, l, ijv, iq) = vqint * pref; } @@ -1234,7 +1234,7 @@ void pseudopot_cell_vnl::init_vnl_alpha(const UnitCell& ucell) // pengfei Li 201 aux[ir] = ucell.atoms[it].ncpp.betar(ib, ir) * jl[ir] * ucell.atoms[it].ncpp.r[ir] * ucell.atoms[it].ncpp.r[ir]; } - double vqint; + double vqint = 0.0; ModuleBase::Integral::Simpson_Integral(kkbeta, aux, ucell.atoms[it].ncpp.rab.data(), vqint); this->tab_alpha(it, ib, L, iq) = vqint * pref; } diff --git a/source/source_pw/module_pwdft/vnl_pw_grad.cpp b/source/source_pw/module_pwdft/vnl_pw_grad.cpp index eb70520f25..7e22df63bc 100644 --- a/source/source_pw/module_pwdft/vnl_pw_grad.cpp +++ b/source/source_pw/module_pwdft/vnl_pw_grad.cpp @@ -47,7 +47,7 @@ void pseudopot_cell_vnl::initgradq_vnl(const UnitCell &cell) aux[ir] = cell.atoms[it].ncpp.betar(ib, ir) * djl[ir] * pow(cell.atoms[it].ncpp.r[ir],2); } - double vqint; + double vqint = 0.0; ModuleBase::Integral::Simpson_Integral(kkbeta, aux, cell.atoms[it].ncpp.rab.data(), vqint); this->tab_dq(it, ib, iq) = vqint * pref; } diff --git a/source/source_pw/module_stodft/sto_forces.cpp b/source/source_pw/module_stodft/sto_forces.cpp index 3fb761d85c..47a91f3dde 100644 --- a/source/source_pw/module_stodft/sto_forces.cpp +++ b/source/source_pw/module_stodft/sto_forces.cpp @@ -108,7 +108,7 @@ void Sto_Forces::cal_stoforce(ModuleBase::matrix& force, if (ModuleSymmetry::Symmetry::symm_flag == 1) { - double d1, d2, d3; + double d1 = 0.0, d2 = 0.0, d3 = 0.0; for (int iat = 0; iat < ucell.nat; iat++) { ModuleBase::Mathzone::Cartesian_to_Direct(force(iat, 0), diff --git a/source/source_pw/module_stodft/sto_iter.cpp b/source/source_pw/module_stodft/sto_iter.cpp index cd00e2f6f2..99fd2ef2bb 100644 --- a/source/source_pw/module_stodft/sto_iter.cpp +++ b/source/source_pw/module_stodft/sto_iter.cpp @@ -273,7 +273,7 @@ void Stochastic_Iter::itermu(const int iter, elecstate::ElecState* pe { ModuleBase::TITLE("Stochastic_Iter", "itermu"); ModuleBase::timer::tick("Stochastic_Iter", "itermu"); - double dmu; + double dmu = 0.0; if (iter == 1) { dmu = 2; @@ -294,8 +294,8 @@ void Stochastic_Iter::itermu(const int iter, elecstate::ElecState* pe double ne2 = calne(pes); double mu2 = this->stofunc.mu; double Dne = th_ne + 1; - double ne3; - double mu3; + double ne3 = 0.0; + double mu3 = 0.0; while (ne1 > targetne) { @@ -440,7 +440,7 @@ double Stochastic_Iter::calne(elecstate::ElecState* pes) double totne = 0; KS_ne = 0; const int norder = p_che->norder; - double sto_ne; + double sto_ne = 0.0; if (this->method == 1) { // Note: spolyv contains kv.wk[ik] diff --git a/source/source_pw/module_stodft/sto_iter.h b/source/source_pw/module_stodft/sto_iter.h index 20837d708f..8a97796502 100644 --- a/source/source_pw/module_stodft/sto_iter.h +++ b/source/source_pw/module_stodft/sto_iter.h @@ -119,8 +119,8 @@ class Stochastic_Iter Sto_Func stofunc; hamilt::HamiltSdftPW* p_hamilt_sto = nullptr; - double mu0; // chemical potential; unit in Ry - bool change; + double mu0 = 0.0; // chemical potential; unit in Ry + bool change = false; double targetne=0.0; Real* spolyv = nullptr; //[Device] coefficients of Chebyshev expansion Real* spolyv_cpu = nullptr; //[CPU] coefficients of Chebyshev expansion diff --git a/source/source_pw/module_stodft/sto_tool.h b/source/source_pw/module_stodft/sto_tool.h index 65a8b792a0..6b0c9e2a59 100644 --- a/source/source_pw/module_stodft/sto_tool.h +++ b/source/source_pw/module_stodft/sto_tool.h @@ -53,8 +53,8 @@ struct parallel_distribution this->start = st_per; this->num_per = num_per; } - int start; - int num_per; + int start = 0; + int num_per = 0; }; #ifdef __MPI diff --git a/source/source_pw/module_stodft/sto_wf.cpp b/source/source_pw/module_stodft/sto_wf.cpp index de9a4559e1..2ba8db2908 100644 --- a/source/source_pw/module_stodft/sto_wf.cpp +++ b/source/source_pw/module_stodft/sto_wf.cpp @@ -166,7 +166,7 @@ void Stochastic_WF::init_com_orbitals() const bool firstrankmore = false; const int npwx = this->npwx; const int nks = this->nks; - int igroup; + int igroup = 0; // former processor calculate more bands if (firstrankmore) { @@ -219,7 +219,7 @@ void Stochastic_WF::init_com_orbitals() // give value to orbitals in one parallel group one by one. for (int ichi = 0; ichi < nchipk; ++ichi) { - int ig; + int ig = 0; if (igroup < re) { // It has more nchip. diff --git a/source/source_relax/ions_move_bfgs.cpp b/source/source_relax/ions_move_bfgs.cpp index 9c52010862..ee8a9d97e9 100644 --- a/source/source_relax/ions_move_bfgs.cpp +++ b/source/source_relax/ions_move_bfgs.cpp @@ -144,7 +144,7 @@ void Ions_Move_BFGS::restart_bfgs(const double& lat0) std::ifstream hess_file("hess_in"); if(hess_file) { - int rank1,rank2; + int rank1 = 0, rank2 = 0; hess_file >> rank1 >> rank2; if(rank1 == dim && rank2 == dim) { diff --git a/source/source_relax/relax_sync.cpp b/source/source_relax/relax_sync.cpp index 47f3e3b333..492feaea49 100644 --- a/source/source_relax/relax_sync.cpp +++ b/source/source_relax/relax_sync.cpp @@ -383,7 +383,7 @@ void Relax::perform_line_search() // perform line search bool restart_brent = false; double x = dmovel, y = etot; - double xnew, yd; + double xnew = 0.0, yd = 0.0; brent_done = this->ls.line_search(restart_brent, x, y, f, xnew, force_thr_eva); dmove = xnew; @@ -497,7 +497,7 @@ void Relax::move_cell_ions(UnitCell& ucell, const bool is_new_dir) // or a line search step, the treatment is slightly different // and the input variable is_new_dir is used to make the distinction - double fac; // fac1 for force, fac2 for stress + double fac = 0.0; // fac1 for force, fac2 for stress if (is_new_dir) { fac = 1.0; @@ -594,8 +594,7 @@ void Relax::move_cell_ions(UnitCell& ucell, const bool is_new_dir) // ================================================================= // Calculating displacement in Cartesian coordinate (in Angstrom) - double move_ion[nat * 3]; - ModuleBase::zeros(move_ion, nat * 3); + std::vector move_ion(nat * 3, 0.0); for (int iat = 0; iat < nat; iat++) { @@ -630,10 +629,10 @@ void Relax::move_cell_ions(UnitCell& ucell, const bool is_new_dir) if (ModuleSymmetry::Symmetry::symm_flag && ucell.symm.all_mbl && ucell.symm.nrotk > 0) { - ucell.symm.symmetrize_vec3_nat(move_ion); + ucell.symm.symmetrize_vec3_nat(move_ion.data()); } - unitcell::update_pos_taud(ucell.lat,move_ion,ucell.ntype,ucell.nat,ucell.atoms); + unitcell::update_pos_taud(ucell.lat,move_ion.data(),ucell.ntype,ucell.nat,ucell.atoms); // Print the structure file. unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0,GlobalV::ofs_running);