Skip to content

Commit 2947197

Browse files
committed
Merge branch 'hotfix' of https://github.com/Qianruipku/abacus-develop into hotfix
2 parents 862e594 + 5fc36b4 commit 2947197

File tree

1 file changed

+42
-25
lines changed

1 file changed

+42
-25
lines changed

source/module_hsolver/test/diago_mock.h

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,33 +87,36 @@ namespace DIAGOTEST
8787

8888
if(mypnum == 0)
8989
{
90-
for(int j=0;j<npw_local[0];j++) psi_local[j] = psi[j];
90+
for(int j=0;j<npw_local[0];j++) { psi_local[j] = psi[j];
91+
}
9192
#ifdef __MPI
9293
int start_point = npw_local[0];
9394
for(int j=1;j<nprocs;j++)
9495
{
95-
if (std::is_same<T, double>::value)
96+
if (std::is_same<T, double>::value) {
9697
MPI_Send(&(psi[start_point]),npw_local[j],MPI_DOUBLE,j,0,MPI_COMM_WORLD);
97-
else if(std::is_same<T, std::complex<double>>::value)
98+
} else if(std::is_same<T, std::complex<double>>::value) {
9899
MPI_Send(&(psi[start_point]),npw_local[j],MPI_DOUBLE_COMPLEX,j,0,MPI_COMM_WORLD);
99-
else if (std::is_same<T, float>::value)
100+
} else if (std::is_same<T, float>::value) {
100101
MPI_Send(&(psi[start_point]), npw_local[j], MPI_FLOAT, j, 0, MPI_COMM_WORLD);
101-
else if (std::is_same<T, std::complex<float>>::value)
102+
} else if (std::is_same<T, std::complex<float>>::value) {
102103
MPI_Send(&(psi[start_point]), npw_local[j], MPI_C_FLOAT_COMPLEX, j, 0, MPI_COMM_WORLD);
104+
}
103105
start_point += npw_local[j];
104106
}
105107
}
106108
else
107109
{
108110
int recv_len = mypnum < (npw%nprocs) ? npw/nprocs + 1 : npw/nprocs;
109-
if (std::is_same<T, double>::value)
111+
if (std::is_same<T, double>::value) {
110112
MPI_Recv(psi_local, npw_local[mypnum],MPI_DOUBLE,0,0,MPI_COMM_WORLD, MPI_STATUS_IGNORE);
111-
else if(std::is_same<T, std::complex<double>>::value)
113+
} else if(std::is_same<T, std::complex<double>>::value) {
112114
MPI_Recv(psi_local, npw_local[mypnum], MPI_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
113-
else if (std::is_same<T, float>::value)
115+
} else if (std::is_same<T, float>::value) {
114116
MPI_Recv(psi_local, npw_local[mypnum], MPI_FLOAT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
115-
else if (std::is_same<T, std::complex<float>>::value)
117+
} else if (std::is_same<T, std::complex<float>>::value) {
116118
MPI_Recv(psi_local, npw_local[mypnum], MPI_C_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
119+
}
117120
#endif
118121
}
119122
}
@@ -128,8 +131,9 @@ namespace DIAGOTEST
128131
MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
129132
for(int i=0;i<nprocs;i++)
130133
{
131-
if(i<npw%nprocs) npw_local[i] = npw/nprocs + 1;
132-
else npw_local[i] = npw/nprocs;
134+
if(i<npw%nprocs) { npw_local[i] = npw/nprocs + 1;
135+
} else { npw_local[i] = npw/nprocs;
136+
}
133137
}
134138
}
135139

@@ -213,7 +217,8 @@ class HPsi
213217
psi::Psi<T> psitmp(1, nband, npw, ngk);
214218
for(int i=0;i<nband;i++)
215219
{
216-
for(int j=0;j<npw;j++) psitmp(0,i,j) = psimatrix[i * npw + j];
220+
for(int j=0;j<npw;j++) { psitmp(0,i,j) = psimatrix[i * npw + j];
221+
}
217222
}
218223
return psitmp;
219224
};
@@ -255,19 +260,23 @@ void HPsi<double>::genhmatrix()
255260
DIAGOTEST::h_nc = npw;
256261
std::default_random_engine e(100);
257262
std::uniform_int_distribution<unsigned> u(min, max);
258-
if (sparsity < 0) sparsity = 0;
259-
if (sparsity > 10) sparsity = 10;
263+
if (sparsity < 0) { sparsity = 0;
264+
}
265+
if (sparsity > 10) { sparsity = 10;
266+
}
260267
for (int i = 0;i < npw;i++)
261268
{
262269
for (int j = 0;j <= i;j++)
263270
{
264271
double mincoef = 0.0;
265272
double realp = pow(-1.0, u(e) % 2) * static_cast<double>(u(e)) / max;
266-
if (int(u(e) % 10) > int(sparsity - 1)) mincoef = 1.0;
267-
if (i == j)
273+
if (int(u(e) % 10) > int(sparsity - 1)) { mincoef = 1.0;
274+
}
275+
if (i == j) {
268276
hmatrix[i * npw + j] = realp;
269-
else
277+
} else {
270278
hmatrix[j * npw + i] = hmatrix[i * npw + j] = mincoef * realp;
279+
}
271280
}
272281
}
273282
}
@@ -279,16 +288,19 @@ void HPsi<std::complex<double>>::genhmatrix()
279288
DIAGOTEST::h_nc = npw;
280289
std::default_random_engine e(100);
281290
std::uniform_int_distribution<unsigned> u(min, max);
282-
if (sparsity < 0) sparsity = 0;
283-
if (sparsity > 10) sparsity = 10;
291+
if (sparsity < 0) { sparsity = 0;
292+
}
293+
if (sparsity > 10) { sparsity = 10;
294+
}
284295
for (int i = 0;i < npw;i++)
285296
{
286297
for (int j = 0;j <= i;j++)
287298
{
288299
double mincoef = 0.0;
289300
double realp = pow(-1.0, u(e) % 2) * static_cast<double>(u(e)) / max;
290301
//double imagp= pow(-1.0,u(e)%2) * static_cast<double>(u(e))/max;
291-
if (int(u(e) % 10) > int(sparsity - 1)) mincoef = 1.0;
302+
if (int(u(e) % 10) > int(sparsity - 1)) { mincoef = 1.0;
303+
}
292304
if (i == j)
293305
{
294306
hmatrix[i * npw + j] = std::complex<double>{ realp,0.0 };
@@ -310,15 +322,18 @@ void HPsi<std::complex<float>>::genhmatrix()
310322
DIAGOTEST::h_nc = npw;
311323
std::default_random_engine e(100);
312324
std::uniform_int_distribution<unsigned> u(min, max);
313-
if (sparsity < 0) sparsity = 0;
314-
if (sparsity > 10) sparsity = 10;
325+
if (sparsity < 0) { sparsity = 0;
326+
}
327+
if (sparsity > 10) { sparsity = 10;
328+
}
315329
for (int i = 0;i < npw;i++)
316330
{
317331
for (int j = 0;j <= i;j++)
318332
{
319333
float mincoef = 0.0;
320334
float realp = pow(-1.0, u(e) % 2) * static_cast<float>(u(e)) / max;
321-
if (int(u(e) % 10) > int(sparsity - 1)) mincoef = 1.0;
335+
if (int(u(e) % 10) > int(sparsity - 1)) { mincoef = 1.0;
336+
}
322337
if (i == j)
323338
{
324339
hmatrix[i * npw + j] = std::complex<float>{ realp,0.0 };
@@ -339,9 +354,11 @@ void HPsi<double>::genpsi()
339354
psimatrix.resize(nband * npw);
340355
std::default_random_engine e(10);
341356
std::uniform_int_distribution<unsigned> u(min, max);
342-
for (int i = 0;i < nband;i++)
343-
for (int j = 0;j < npw;j++)
357+
for (int i = 0;i < nband;i++) {
358+
for (int j = 0;j < npw;j++) {
344359
psimatrix[i * npw + j] = pow(-1.0, u(e) % 2) * static_cast<double>(u(e)) / max;
360+
}
361+
}
345362
}
346363
}
347364
template<>

0 commit comments

Comments
 (0)