Skip to content

Commit 937d6c0

Browse files
[pre-commit.ci lite] apply automatic fixes
1 parent 02a9357 commit 937d6c0

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

source/module_base/scalapack_connector.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,16 @@ extern "C"
180180
template <typename T>
181181
typename std::enable_if<block2d_data_type<T>::value,void>::type Cpxgemr2d(int M, int N, T *A, int IA, int JA, int *DESCA, T *B, int IB, int JB, int *DESCB, int ICTXT)
182182
{
183-
if (std::is_same<T,double>::value) Cpdgemr2d(M, N, reinterpret_cast<double*>(A),IA, JA, DESCA,reinterpret_cast<double*>(B),IB,JB, DESCB,ICTXT);
184-
if (std::is_same<T,std::complex<double>>::value) Cpzgemr2d(M, N, reinterpret_cast<std::complex<double>*>(A),IA, JA, DESCA,reinterpret_cast<std::complex<double>*>(B),IB,JB, DESCB,ICTXT);
185-
if (std::is_same<T,float>::value) Cpsgemr2d(M, N, reinterpret_cast<float*>(A),IA, JA, DESCA,reinterpret_cast<float*>(B),IB,JB, DESCB,ICTXT);
186-
if (std::is_same<T,std::complex<float>>::value) Cpcgemr2d(M, N, reinterpret_cast<std::complex<float>*>(A),IA, JA, DESCA,reinterpret_cast<std::complex<float>*>(B),IB,JB, DESCB,ICTXT);
187-
if (std::is_same<T,int>::value) Cpigemr2d(M, N, reinterpret_cast<int*>(A),IA, JA, DESCA,reinterpret_cast<int*>(B),IB,JB, DESCB,ICTXT);
183+
if (std::is_same<T,double>::value) { Cpdgemr2d(M, N, reinterpret_cast<double*>(A),IA, JA, DESCA,reinterpret_cast<double*>(B),IB,JB, DESCB,ICTXT);
184+
}
185+
if (std::is_same<T,std::complex<double>>::value) { Cpzgemr2d(M, N, reinterpret_cast<std::complex<double>*>(A),IA, JA, DESCA,reinterpret_cast<std::complex<double>*>(B),IB,JB, DESCB,ICTXT);
186+
}
187+
if (std::is_same<T,float>::value) { Cpsgemr2d(M, N, reinterpret_cast<float*>(A),IA, JA, DESCA,reinterpret_cast<float*>(B),IB,JB, DESCB,ICTXT);
188+
}
189+
if (std::is_same<T,std::complex<float>>::value) { Cpcgemr2d(M, N, reinterpret_cast<std::complex<float>*>(A),IA, JA, DESCA,reinterpret_cast<std::complex<float>*>(B),IB,JB, DESCB,ICTXT);
190+
}
191+
if (std::is_same<T,int>::value) { Cpigemr2d(M, N, reinterpret_cast<int*>(A),IA, JA, DESCA,reinterpret_cast<int*>(B),IB,JB, DESCB,ICTXT);
192+
}
188193
};
189194

190195

source/module_lr/utils/test/lr_util_algorithms_test.cpp

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
inline void check_double_eq(double* data1, double* data2, int size)
77
{
8-
for (int i = 0;i < size;++i)
8+
for (int i = 0;i < size;++i) {
99
EXPECT_NEAR(data1[i], data2[i], 1e-10);
10+
}
1011
};
1112
inline void check_double_eq(std::complex<double>* data1, std::complex<double>* data2, int size)
1213
{
@@ -31,7 +32,8 @@ TEST(LR_Util, PsiWrapper)
3132
int nbasis = 6;
3233

3334
psi::Psi<float> k1(1, nbands, nk * nbasis, nk * nbasis, true);
34-
for (int i = 0;i < nbands * nk * nbasis;++i)k1.get_pointer()[i] = i;
35+
for (int i = 0;i < nbands * nk * nbasis;++i) {k1.get_pointer()[i] = i;
36+
}
3537

3638
k1.fix_b(2);
3739
psi::Psi<float> bf = LR_Util::k1_to_bfirst_wrapper(k1, nk, nbasis);
@@ -79,7 +81,8 @@ TEST(LR_Util, PsiWrapper)
7981
}
8082
}
8183
#ifdef __MPI
82-
void set_rand(double* data, int size) { for (int i = 0;i < size;++i) data[i] = double(rand()) / double(RAND_MAX) * 10.0 - 5.0; };
84+
void set_rand(double* data, int size) { for (int i = 0;i < size;++i) { data[i] = double(rand()) / double(RAND_MAX) * 10.0 - 5.0;
85+
}};
8386
TEST(LR_Util, MatSymDouble)
8487
{
8588
int n = 7;
@@ -91,27 +94,34 @@ TEST(LR_Util, MatSymDouble)
9194
Parallel_2D pmat;
9295
LR_Util::setup_2d_division(pmat, 1, n, n);
9396
std::vector<double> din_local(pmat.get_local_size(), 0.0);
94-
for (int i = 0;i < pmat.get_row_size();++i)
95-
for (int j = 0;j < pmat.get_col_size();++j)
97+
for (int i = 0;i < pmat.get_row_size();++i) {
98+
for (int j = 0;j < pmat.get_col_size();++j) {
9699
din_local[j * pmat.get_row_size() + i] = din[pmat.local2global_col(j) * n + pmat.local2global_row(i)];
100+
}
101+
}
97102

98103
std::vector<double> dout_local(pmat.get_local_size(), 0.0);
99104
LR_Util::matsym(din_local.data(), n, pmat, dout_local.data());
100-
for (int i = 0;i < pmat.get_row_size();++i)
101-
for (int j = 0;j < pmat.get_col_size();++j)
105+
for (int i = 0;i < pmat.get_row_size();++i) {
106+
for (int j = 0;j < pmat.get_col_size();++j) {
102107
EXPECT_DOUBLE_EQ(dout_local[j * pmat.get_row_size() + i], dref[pmat.local2global_col(j) * n + pmat.local2global_row(i)]);
108+
}
109+
}
103110

104111
//in-place version
105112
LR_Util::matsym(din.data(), n);
106-
for (int i = 0;i < n * n;++i)
113+
for (int i = 0;i < n * n;++i) {
107114
EXPECT_DOUBLE_EQ(din[i], dref[i]);
115+
}
108116

109117
LR_Util::matsym(din_local.data(), n, pmat);
110-
for (int i = 0;i < pmat.get_local_size();++i)
118+
for (int i = 0;i < pmat.get_local_size();++i) {
111119
EXPECT_DOUBLE_EQ(din_local[i], dout_local[i]);
112120
}
121+
}
113122

114-
void set_rand(std::complex<double>* data, int size) { for (int i = 0;i < size;++i) data[i] = std::complex<double>(rand(), rand()) / double(RAND_MAX) * 10.0 - 5.0; };
123+
void set_rand(std::complex<double>* data, int size) { for (int i = 0;i < size;++i) { data[i] = std::complex<double>(rand(), rand()) / double(RAND_MAX) * 10.0 - 5.0;
124+
}};
115125
TEST(LR_Util, MatSymComplex)
116126
{
117127
int n = 5;
@@ -123,18 +133,21 @@ TEST(LR_Util, MatSymComplex)
123133
Parallel_2D pmat;
124134
LR_Util::setup_2d_division(pmat, 1, n, n);
125135
std::vector<std::complex<double>> din_local(pmat.get_local_size(), std::complex<double>(0.0, 0.0));
126-
for (int i = 0;i < pmat.get_row_size();++i)
127-
for (int j = 0;j < pmat.get_col_size();++j)
136+
for (int i = 0;i < pmat.get_row_size();++i) {
137+
for (int j = 0;j < pmat.get_col_size();++j) {
128138
din_local[j * pmat.get_row_size() + i] = din[pmat.local2global_col(j) * n + pmat.local2global_row(i)];
139+
}
140+
}
129141

130142
std::vector<std::complex<double>> dout_local(pmat.get_local_size(), std::complex<double>(0.0, 0.0));
131143
LR_Util::matsym(din_local.data(), n, pmat, dout_local.data());
132-
for (int i = 0;i < pmat.get_row_size();++i)
144+
for (int i = 0;i < pmat.get_row_size();++i) {
133145
for (int j = 0;j < pmat.get_col_size();++j)
134146
{
135147
EXPECT_DOUBLE_EQ(dout_local[j * pmat.get_row_size() + i].real(), dref[pmat.local2global_col(j) * n + pmat.local2global_row(i)].real());
136148
EXPECT_DOUBLE_EQ(dout_local[j * pmat.get_row_size() + i].imag(), dref[pmat.local2global_col(j) * n + pmat.local2global_row(i)].imag());
137149
}
150+
}
138151

139152
//in-place version
140153
LR_Util::matsym(din.data(), n);
@@ -157,7 +170,8 @@ TEST(LR_Util, RWValue)
157170
const std::string file = "RWValue.txt";
158171
std::ofstream ofs(file);
159172
std::vector<int> vec(2 * 3 * 4 * 5, 0);
160-
for (int i = 0;i < vec.size();++i) vec[i] = i;
173+
for (int i = 0;i < vec.size();++i) { vec[i] = i;
174+
}
161175
LR_Util::write_value(ofs, vec.data(), 2, 3, 4, 5);
162176
ofs.close();
163177

@@ -231,7 +245,7 @@ TEST(LR_Util, DiagScaLapackComplex)
231245

232246
int main(int argc, char** argv)
233247
{
234-
srand(time(NULL)); // for random number generator
248+
srand(time(nullptr)); // for random number generator
235249
MPI_Init(&argc, &argv);
236250
testing::InitGoogleTest(&argc, argv);
237251
int result = RUN_ALL_TESTS();

0 commit comments

Comments
 (0)