Skip to content

Commit 9419ba9

Browse files
dyzhengdyzheng
andauthored
Perf: optimize default setting of bx/by/bz (#1861)
* Perf: optimize default setting of bx/by/bz * Fix: modify reference results in integrate/205 cases * Fix: error in CI tests * Fix: error in CI tests * Fix: error in CI tests * Fix: using poolnproc rather than GlobalV::NPROC_IN_POOL --------- Co-authored-by: dyzheng <[email protected]>
1 parent b282881 commit 9419ba9

File tree

25 files changed

+195
-92
lines changed

25 files changed

+195
-92
lines changed

source/module_io/input.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ void Input::Default(void)
222222
nx = 0;
223223
ny = 0;
224224
nz = 0;
225-
bx = 2;
226-
by = 2;
227-
bz = 2;
225+
bx = 0;
226+
by = 0;
227+
bz = 0;
228228
//----------------------------------------------------------
229229
// diagonalization
230230
//----------------------------------------------------------

source/module_io/test/input_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ TEST_F(InputTest, Default)
109109
EXPECT_EQ(INPUT.nx,0);
110110
EXPECT_EQ(INPUT.ny,0);
111111
EXPECT_EQ(INPUT.nz,0);
112-
EXPECT_EQ(INPUT.bx,2);
113-
EXPECT_EQ(INPUT.by,2);
114-
EXPECT_EQ(INPUT.bz,2);
112+
EXPECT_EQ(INPUT.bx,0);
113+
EXPECT_EQ(INPUT.by,0);
114+
EXPECT_EQ(INPUT.bz,0);
115115
EXPECT_EQ(INPUT.diago_proc,0);
116116
EXPECT_EQ(INPUT.pw_diag_nmax,50);
117117
EXPECT_EQ(INPUT.diago_cg_prec,1);

source/module_pw/pw_basis_big.h

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,69 @@ class PW_Basis_Big: public PW_Basis
3838
int nbxx;
3939
int nbzp_start;
4040

41+
void autoset_big_cell_size(int& b_size, const int& nc_size, const int nproc = 0)
42+
{
43+
//original default setting is 4
44+
b_size = 4;
45+
//only for bz
46+
if(nproc > 0)
47+
{
48+
int candidate_lists[4] = {4, 3, 5, 2};
49+
int max_bz[4];
50+
for(int i=0;i<4;i++)
51+
{
52+
int tmp = candidate_lists[i];
53+
max_bz[i] = nc_size / tmp;
54+
if(nc_size % tmp!=0)
55+
{//ignore candidates which can't be factored by nc_size
56+
max_bz[i]=0;
57+
continue;
58+
}
59+
if(max_bz[i] % nproc == 0)
60+
{
61+
b_size = tmp;
62+
return;
63+
}
64+
}
65+
66+
//choose maximum residual
67+
double res = 0.0;
68+
double res_temp = 0.0;
69+
for(int i=0;i<4;i++)
70+
{
71+
if(max_bz[i]==0) continue;
72+
res_temp = double(max_bz[i] % nproc) / nproc;
73+
if(res < res_temp)
74+
{
75+
res = res_temp;
76+
b_size = candidate_lists[i];
77+
}
78+
}
79+
return;
80+
}
81+
//for bx and by, choose maximum residual of (5,4,3)
82+
else
83+
{
84+
int res = 0;
85+
int res_temp = 0;
86+
for(int i=5;i>2;i--)
87+
{
88+
res_temp = nc_size % i;
89+
if(res_temp == 0)
90+
{
91+
b_size = i;
92+
return;
93+
}
94+
else if(res < res_temp)
95+
{
96+
res = res_temp;
97+
b_size = i;
98+
}
99+
}
100+
return;
101+
}
102+
}
103+
41104

42105
virtual void initgrids(const double lat0_in,const ModuleBase::Matrix3 latvec_in,
43106
const double gridecut){
@@ -93,14 +156,6 @@ class PW_Basis_Big: public PW_Basis
93156
{
94157
b = ibox[i];
95158

96-
// mohan add 2011-04-22
97-
if( ibox[i] % s != 0)
98-
{
99-
b = -1; // meaning less
100-
}
101-
else
102-
{
103-
104159
//n2 = n3 = n5 = n7 = 0;
105160
n2 = n3 = n5 = 0;
106161
done_factoring = false;
@@ -128,13 +183,46 @@ class PW_Basis_Big: public PW_Basis
128183
//if (b%7==0) { n7++; b /= 7; continue; }
129184
done_factoring = true;
130185
}
131-
}
132186
ibox[i] += 1;
133187
}
134188
while (b != 1);
135189
ibox[i] -= 1;
136190
// b==1 means fftbox[i] is (2,3,5,7) factorizable
137191
}
192+
//autoset bx/by/bz if not set in INPUT
193+
if(!this->bz)
194+
{
195+
this->autoset_big_cell_size(this->bz, ibox[2], this->poolnproc);
196+
}
197+
if(!this->bx)
198+
{
199+
//if cz == cx, autoset bx==bz for keeping same symmetry
200+
if(ibox[0] == ibox[2])
201+
{
202+
this->bx = this->bz;
203+
}
204+
else
205+
{
206+
this->autoset_big_cell_size(this->bx, ibox[0]);
207+
}
208+
}
209+
if(!this->by)
210+
{
211+
//if cz == cy, autoset by==bz for keeping same symmetry
212+
if(ibox[1] == ibox[2])
213+
{
214+
this->by = this->bz;
215+
}
216+
else
217+
{
218+
this->autoset_big_cell_size(this->by, ibox[1]);
219+
}
220+
}
221+
this->bxyz = this->bx * this->by * this->bz;
222+
if(ibox[0]%this->bx != 0) ibox[0] += (this->bx - ibox[0] % this->bx);
223+
if(ibox[1]%this->by != 0) ibox[1] += (this->by - ibox[1] % this->by);
224+
if(ibox[2]%this->bz != 0) ibox[2] += (this->bz - ibox[2] % this->bz);
225+
138226
this->nx = ibox[0];
139227
this->ny = ibox[1];
140228
this->nz = ibox[2];
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -205.3082139415616609
2-
etotperatomref -102.6541069708
3-
totalforceref 0.466584
4-
totalstressref 44.477323
5-
totaltimeref +1.96794
1+
etotref -205.3098296723026692
2+
etotperatomref -102.6549148362
3+
totalforceref 0.408868
4+
totalstressref 42.121840
5+
totaltimeref +2.31533
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -5063.7353000393713955
2-
etotperatomref -2531.8676500197
3-
totalforceref 120.480264
4-
totalstressref 45245.345840
5-
totaltimeref +2.34409
1+
etotref -5068.9776394698028525
2+
etotperatomref -2534.4888197349
3+
totalforceref 144.906176
4+
totalstressref 41444.222511
5+
totaltimeref +1.87505
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -5064.4146528184537601
2-
etotperatomref -2532.2073264092
3-
totalforceref 122.897568
4-
totalstressref 45625.062810
5-
totaltimeref +2.21314
1+
etotref -5068.2488535164147834
2+
etotperatomref -2534.1244267582
3+
totalforceref 139.100100
4+
totalstressref 40227.405009
5+
totaltimeref +1.79336
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
etotref -4870.339224798580
2-
etotperatomref -2435.1696123993
3-
totaltimeref 11.364
1+
etotref -4870.603143646754
2+
etotperatomref -2435.3015718234
3+
totaltimeref 18.140
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
etotref -10009.76543319581
2-
etotperatomref -2001.9530866392
3-
totaltimeref 12.423
1+
etotref -10011.36600938456
2+
etotperatomref -2002.2732018769
3+
totaltimeref 9.6754
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
etotref -10009.77455065383
2-
etotperatomref -2001.9549101308
3-
totaltimeref 15.487
1+
etotref -10011.36068192394
2+
etotperatomref -2002.2721363848
3+
totaltimeref 11.364
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
etotref -712.6090200722365
2-
etotperatomref -356.3045100361
3-
totaltimeref 6.1420
1+
etotref -712.6052332539930
2+
etotperatomref -356.3026166270
3+
totaltimeref 5.1536

0 commit comments

Comments
 (0)