@@ -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 ];
0 commit comments