Skip to content

Commit

Permalink
initialize some variables (#3846)
Browse files Browse the repository at this point in the history
* initialize some variables

* fix a semicolon

* Update sincos.cpp

* Update mathzone_add1.cpp

* Update mathzone_add1.cpp

* Update opt_DCsrch.cpp

* Update broyden_mixing.cpp

* Update pulay_mixing.cpp

* Update math_sphbes_test.cpp

* Update ORB_gen_tables.cpp

* Update ORB_table_phi.cpp

* Update math_sphbes_test.cpp
  • Loading branch information
DylanWRh authored Apr 2, 2024
1 parent dc7938b commit fc9a0de
Show file tree
Hide file tree
Showing 23 changed files with 92 additions and 70 deletions.
6 changes: 4 additions & 2 deletions source/module_base/global_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ int NLOCAL = 0; // total number of local basis.
double KSPACING[3] = {0.0,0.0,0.0};
double MIN_DIST_COEF = 0.2;

double PSEUDORCUT=0;//initialization
bool PSEUDO_MESH=0;

double PSEUDORCUT = 0;
bool PSEUDO_MESH = false;


std::string CALCULATION = "scf";
std::string ESOLVER_TYPE = "ksdft";
Expand Down
2 changes: 1 addition & 1 deletion source/module_base/libm/branred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static const double split = CN; /* 2^27 + 1 */
int
__branred(double x, double *a, double *aa)
{
int i,k;
int i=0,k=0;
mynumber u,gor;
double r[6],s,t,sum,b,bb,sum1,sum2,b1,bb1,b2,bb2,x1,x2,t1,t2;

Expand Down
6 changes: 3 additions & 3 deletions source/module_base/libm/sincos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ void
__sincos (double x, double *sinx, double *cosx)
{
mynumber u;
int k;
int k = 0;

u.x = x;
k = u.i[HIGH_HALF] & 0x7fffffff;
Expand Down Expand Up @@ -1229,8 +1229,8 @@ __sincos (double x, double *sinx, double *cosx)
/* |x| < 2^1024. */
if (k < 0x7ff00000)
{
double a, da, xx;
unsigned int n;
double a = 0.0, da = 0.0, xx = 0.0;
unsigned int n = 0;

/* If |x| < 105414350 use simple range reduction. */
n = k < 0x419921FB ? reduce_sincos (x, &a, &da) : __branred (x, &a, &da);
Expand Down
37 changes: 26 additions & 11 deletions source/module_base/math_sphbes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,26 @@ void Sphbes::BESSJY(double x, double xnu, double *rj, double *ry, double *rjp, d
const double EPS = 1.0e-10;
const int MAXIT = 10000;

int i, isign, l, nl;
double a, b, br, bi, c, cr, ci, d, del, del1, den, di, dlr, dli, dr, e, f, fact, fact2,
fact3, ff, gam, gam1, gam2, gammi, gampl, h, p, pimu, pimu2, q, r, rjl,
rjl1, rjmu, rjp1, rjpl, rjtemp, ry1, rymu, rymup, rytemp, sum, sum1,
temp, w, x2, xi, xi2;
// May need some annotations to each variable
int i = 0, isign = 0, l = 0, nl = 0;
double a = 0.0;
double b = 0.0, br = 0.0, bi = 0.0;
double c = 0.0, cr = 0.0, ci = 0.0;
double d = 0.0;
double del = 0.0, del1 = 0.0;
double den = 0.0, di = 0.0, dlr = 0.0, dli = 0.0, dr = 0.0;
double e = 0.0, f = 0.0;
double fact = 0.0, fact2 = 0.0, fact3 = 0.0;
double ff = 0.0;
double gam = 0.0, gam1 = 0.0, gam2 = 0.0, gammi = 0.0, gampl = 0.0;
double h = 0.0;
double p = 0.0, pimu = 0.0, pimu2 = 0.0;
double q = 0.0, r = 0.0;
double rjl = 0.0, rjl1 = 0.0, rjmu = 0.0, rjp1 = 0.0, rjpl = 0.0, rjtemp = 0.0;
double ry1 = 0.0, rymu = 0.0, rymup = 0.0, rytemp = 0.0;
double sum = 0.0, sum1 = 0.0;
double temp = 0.0, w = 0.0;
double x2 = 0.0, xi = 0.0, xi2 = 0.0;

if (x <= 0.0 || xnu < 0.0)
{
Expand Down Expand Up @@ -251,7 +266,7 @@ void Sphbes::BESCHB(double x, double *gam1, double *gam2, double *gampl, double
{
const int NUSE1 = 7;
const int NUSE2 = 8;
double xx;
double xx = 0;
static double c1[] = { -1.142022680371168e0, 6.5165112670737e-3,
3.087090173086e-4, -3.4706269649e-6,
6.9437664e-9, 3.67795e-11, -1.356e-13
Expand Down Expand Up @@ -301,7 +316,7 @@ double Sphbes::Spherical_Bessel_7(const int n, const double &x)
if (n!=0) return 0;
if (n==0) return 1;
}
double order, rj, rjp, ry, ryp;
double order = 0.0, rj = 0.0, rjp = 0.0, ry = 0.0, ryp = 0.0;

if (n < 0 || x <= 0.0)
{
Expand Down Expand Up @@ -689,7 +704,7 @@ double Sphbes::_sphbesj_ascending_recurrence(int l, double x) {
double j0 = std::sin(x) * invx;
double j1 = ( j0 - std::cos(x) ) * invx;

double jl;
double jl = 0.0;
for (int i = 2; i <= l; ++i) {
jl = (2*i-1) * invx * j1 - j0;
j0 = j1;
Expand Down Expand Up @@ -838,9 +853,9 @@ void Sphbes::sphbes_zeros(const int l, const int n, double* const zeros, const b
buffer[i] = (i+1) * PI;
}

int ll; // active l
int ll = 0; // active l
auto jl = [&ll] (double x) { return sphbesj(ll, x); };
int stride;
int stride = 0;
std::function<void()> copy_if_needed;
int offset = 0; // keeps track of the position in zeros for next copy (used when return_all == true)
if (return_all)
Expand Down Expand Up @@ -883,7 +898,7 @@ double Sphbes::illinois(std::function<double(double)> func, double x0, double x1
}

int iter = 0;
double x, f;
double x = 0.0, f = 0.0;
while (++iter <= max_iter && std::abs(f1) > tol)
{
// regula falsi
Expand Down
10 changes: 5 additions & 5 deletions source/module_base/mathzone_add1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ double Mathzone_Add1::Uni_RadialF
const double& newr
)
{
double h1, h2, h3, f1, f2, f3, f4;
double g1, g2, x1, x2, y1, y2, f;
double result;
double h1 = 0.0, h2 = 0.0, h3 = 0.0, f1 = 0.0, f2 = 0.0, f3 = 0.0, f4 = 0.0;
double g1 = 0.0, g2 = 0.0, x1 = 0.0, x2 = 0.0, y1 = 0.0, y2 = 0.0, f = 0.0;
double result = 0.0;
double rmax = (msh-1) * dr;

if (newr < 0.0)
Expand Down Expand Up @@ -366,8 +366,8 @@ void Mathzone_Add1::Uni_Deriv_Phi
//fftw_destroy_plan(p2);
#endif

bool is_re;
double fac;
bool is_re = true;
double fac = 0.0;
if (nd % 4 == 0)
{
is_re = true;
Expand Down
2 changes: 1 addition & 1 deletion source/module_base/module_mixing/broyden_mixing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,4 @@ void Broyden_Mixing::tem_cal_coef(const Mixing_Data& mdata, std::function<double
}
ModuleBase::timer::tick("Charge", "Broyden_mixing");
};
} // namespace Base_Mixing
} // namespace Base_Mixing
2 changes: 1 addition & 1 deletion source/module_base/module_mixing/pulay_mixing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ void Pulay_Mixing::tem_cal_coef(const Mixing_Data& mdata, std::function<double(F

ModuleBase::timer::tick("Charge", "Pulay_mixing");
};
} // namespace Base_Mixing
} // namespace Base_Mixing
12 changes: 6 additions & 6 deletions source/module_base/mymath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace ModuleBase

void heapAjust(double *r, int *ind, int s, int m)
{
int j, ic;
double rc;
int j = 0, ic = 0;
double rc = 0.0;
rc = r[s];
ic = ind[s];

Expand Down Expand Up @@ -36,8 +36,8 @@ void heapAjust(double *r, int *ind, int s, int m)
void heapsort(const int n, double *r, int *ind)
{
ModuleBase::timer::tick("mymath", "heapsort");
int i, ic;
double rc;
int i = 0, ic = 0;
double rc = 0.0;

if (ind[0] == 0)
{
Expand Down Expand Up @@ -89,8 +89,8 @@ c adapted from Numerical Recipes pg. 329 (new edition)
// from hpsort.f90
void hpsort(int n, double *ra, int *ind)
{
int i, ir, j, k, iind;
double rra;
int i = 0, ir = 0, j = 0, k = 0, iind = 0;
double rra = 0.0;

if (ind[0] == 0)
{
Expand Down
11 changes: 6 additions & 5 deletions source/module_base/opt_DCsrch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,11 @@ int dcsrch(double& stp,
double xtrapl = 1.1;
double xtrapu = 4.0;

bool brackt;
int stage;
double finit, ftest, fm, fx, fxm, fy, fym, ginit, gtest, gm, gx, gxm, gy, gym, stx, sty, stmin, stmax, width,
width1;
bool brackt = false;
int stage = 0;
double finit = 0.0, ftest = 0.0, fm = 0.0, fx = 0.0, fxm = 0.0, fy = 0.0, fym = 0.0;
double ginit = 0.0, gtest = 0.0, gm = 0.0, gx = 0.0, gxm = 0.0, gy = 0.0, gym = 0.0;
double stx = 0.0, sty = 0.0, stmin = 0.0, stmax = 0.0, width = 0.0, width1 = 0.0;

extern /* Subroutine */ void dcstep(double&,
double&,
Expand Down Expand Up @@ -728,4 +729,4 @@ void Opt_DCsrch::dcSrch(double& f, double& g, double& rstp, char* rtask)
this->isave_,
this->dsave_);
}
} // namespace ModuleBase
} // namespace ModuleBase
4 changes: 2 additions & 2 deletions source/module_base/parallel_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void Parallel_Global::read_mpi_parameters(int argc,char **argv)
{
#ifdef __MPI
#ifdef _OPENMP
int provided;
int provided = 0;
MPI_Init_thread(&argc,&argv,MPI_THREAD_MULTIPLE,&provided);
if( provided != MPI_THREAD_MULTIPLE )
GlobalV::ofs_warning<<"MPI_Init_thread request "<<MPI_THREAD_MULTIPLE<<" but provide "<<provided<<std::endl;
Expand All @@ -186,7 +186,7 @@ void Parallel_Global::read_mpi_parameters(int argc,char **argv)
#endif
MPI_Comm shmcomm;
MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &shmcomm);
int process_num, local_rank;
int process_num = 0, local_rank = 0;
MPI_Comm_size(shmcomm, &process_num);
MPI_Comm_rank(shmcomm, &local_rank);
MPI_Comm_free(&shmcomm);
Expand Down
8 changes: 4 additions & 4 deletions source/module_base/test/blacs_connector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

TEST(blacs_connector, Cblacs_gridinit)
{
int icontxt;
int icontxt = 0;
char layout[] = "ROW";
int nprow = 1;
int npcol = 1;

int myid, nprocs;
int myid = 0, nprocs = 0;
Cblacs_pinfo(&myid, &nprocs);
Cblacs_get(-1, 0, &icontxt);

Expand All @@ -37,8 +37,8 @@ TEST(blacs_connector, Cblacs_gridinit)

int main(int argc, char** argv)
{
int myrank;
int mysize;
int myrank = 0;
int mysize = 0;

MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &mysize);
Expand Down
10 changes: 5 additions & 5 deletions source/module_base/test/global_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ TEST_F(GlobalFunctionTest, OutV2)
ModuleBase::GlobalFunc::OUT(ofs, "tmp_double", tmp_double);
ModuleBase::GlobalFunc::OUT(ofs, "tmp_string", tmp_string);
std::string para = "";
int length;
int length = 0;
for (int i=0;i<50;i++)
{
para += "a";
Expand Down Expand Up @@ -365,7 +365,7 @@ TEST_F(GlobalFunctionTest, ToString)
EXPECT_EQ(ModuleBase::GlobalFunc::TO_STRING(tmp_double),"5");
EXPECT_EQ(ModuleBase::GlobalFunc::TO_STRING(tmp_string),"string");
std::string para = "";
int length;
int length = 0;
for (int i=0;i<100;i++)
{
para += "a";
Expand Down Expand Up @@ -451,7 +451,7 @@ TEST_F(GlobalFunctionTest, AutoSet)
ModuleBase::GlobalFunc::AUTO_SET("tmp_d", tmp_d);
ModuleBase::GlobalFunc::AUTO_SET("tmp_string", tmp_string);
std::string para = "";
int length;
int length = 0;
for (int i=0;i<10;i++)
{
para += "a";
Expand Down Expand Up @@ -559,8 +559,8 @@ TEST_F(GlobalFunctionTest, ReadValue)
ofs << "string" << std::endl;
ofs.close();
ifs.open("tmp");
int tmp_int;
double tmp_double;
int tmp_int = 0;
double tmp_double = 0.0;
std::string tmp_string;
// source/module_cell/read_atoms.cpp line 153:154
ModuleBase::GlobalFunc::READ_VALUE(ifs, tmp_int);
Expand Down
4 changes: 3 additions & 1 deletion source/module_base/test/math_sphbes_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../math_sphbes.h"

#include <cmath>
#include <cstring> // Dependency for memset initialization
#include <fstream>
#include <iostream>

Expand Down Expand Up @@ -473,8 +474,9 @@ int main(int argc, char** argv)

TEST_F(Sphbes, SphericalBesselsjp)
{
int iii;
int iii = 0;
double* sjp = new double[msh];
std::memset(sjp, 0, msh * sizeof(double));
ModuleBase::Sphbes::Spherical_Bessel(msh, r, q, l0, jl, sjp);
EXPECT_NEAR(mean(jl, msh) / 0.2084468748396, 1.0, doublethreshold);
for (int iii = 0; iii < msh; ++iii)
Expand Down
8 changes: 4 additions & 4 deletions source/module_base/test/tool_threading_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ TEST(ToolThreadingTEST, TastDist1DInt)
int nw=1;
int iw=1;
int nt=16;
int st;
int le;
int st=0;
int le=0;
ModuleBase::TASK_DIST_1D(nw,iw,nt,st,le);
EXPECT_EQ(st,0);
EXPECT_EQ(le,16);
Expand Down Expand Up @@ -81,8 +81,8 @@ TEST(ToolThreadingTEST, BlockTaskDist1DInt)
int nw=1;
int iw=1;
int nt=16;
int st;
int le;
int st=0;
int le=0;
int bs=1;
ModuleBase:: BLOCK_TASK_DIST_1D(nw,iw,nt,bs,st,le);
EXPECT_EQ(st,0);
Expand Down
8 changes: 4 additions & 4 deletions source/module_base/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void timer::tick(const std::string &class_name,const std::string &name)
if(timer_one.start_flag)
{
#ifdef __MPI
int is_initialized;
int is_initialized = 0;
MPI_Initialized(&is_initialized);
if(is_initialized)
{
Expand All @@ -109,7 +109,7 @@ void timer::tick(const std::string &class_name,const std::string &name)
else
{
#ifdef __MPI
int is_initialized;
int is_initialized = 0;
MPI_Initialized(&is_initialized);
if(is_initialized)
{
Expand Down Expand Up @@ -144,11 +144,11 @@ void timer::write_to_json(std::string file_name)
#ifdef __MPI
// in some unit test, the mpi is not initialized, so we need to check it
// if mpi is not initialized, we do not run this function
int is_initialized;
int is_initialized = 0;
MPI_Initialized(&is_initialized);
if (!is_initialized)
return;
int my_rank;
int my_rank = 0;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
if (my_rank != 0)
return;
Expand Down
2 changes: 1 addition & 1 deletion source/module_base/tool_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void CHECK_NAME(std::ifstream &ifs,const std::string &name_in,bool quit)

void CHECK_INT(std::ifstream &ifs,const int &v,bool quit)
{
int v_in;
int v_in = 0;
ifs >> v_in;
if( v!= v_in)
{
Expand Down
2 changes: 1 addition & 1 deletion source/module_basis/module_ao/ORB_gaunt_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ void ORB_gaunt_table::Swap(
int& l2,
int & m2)
{
int tmp1, tmp2;
int tmp1=0, tmp2=0;
if(l1 >= l2) return;
else
{
Expand Down
Loading

0 comments on commit fc9a0de

Please sign in to comment.