@@ -46,38 +46,47 @@ void Veff<OperatorPW>::act
4646 {
4747 if (this ->npol == 1 )
4848 {
49- const double * current_veff = &(this ->veff [0 ](current_spin, 0 ));
5049 wfcpw->recip2real (tmpsi_in, porter, ik);
51- for (int ir = 0 ; ir < this ->veff ->nc ; ++ir)
50+ // NOTICE: when MPI threads are larger than number of Z grids
51+ // veff would contain nothing, and nothing should be done in real space
52+ // but the 3DFFT can not be skipped, it will cause hanging
53+ if (this ->veff ->nc != 0 )
5254 {
53- porter[ir] *= current_veff[ir];
55+ const double * current_veff = &(this ->veff [0 ](current_spin, 0 ));
56+ for (int ir = 0 ; ir < this ->veff ->nc ; ++ir)
57+ {
58+ porter[ir] *= current_veff[ir];
59+ }
5460 }
5561 wfcpw->real2recip (porter, tmhpsi, ik, true );
5662 }
5763 else
5864 {
59- const double * current_veff[4 ];
60- for (int is=0 ;is<4 ;is++)
61- {
62- current_veff[is] = &(this ->veff [0 ](is, 0 ));
63- }
6465 std::complex <double > *porter1 = new std::complex <double >[wfcpw->nmaxgr ];
6566 // fft to real space and doing things.
6667 wfcpw->recip2real (tmpsi_in, porter, ik);
6768 wfcpw->recip2real (tmpsi_in + this ->max_npw , porter1, ik);
6869 std::complex <double > sup, sdown;
69- for ( int ir = 0 ; ir < this ->veff ->nc ; ir++ )
70+ if ( this ->veff ->nc != 0 )
7071 {
71- sup = porter[ir] * (current_veff[0 ][ir] + current_veff[3 ][ir])
72- + porter1[ir]
73- * (current_veff[1 ][ir]
74- - std::complex <double >(0.0 , 1.0 ) * current_veff[2 ][ir]);
75- sdown = porter1[ir] * (current_veff[0 ][ir] - current_veff[3 ][ir])
76- + porter[ir]
77- * (current_veff[1 ][ir]
78- + std::complex <double >(0.0 , 1.0 ) * current_veff[2 ][ir]);
79- porter[ir] = sup;
80- porter1[ir] = sdown;
72+ const double * current_veff[4 ];
73+ for (int is=0 ;is<4 ;is++)
74+ {
75+ current_veff[is] = &(this ->veff [0 ](is, 0 ));
76+ }
77+ for (int ir = 0 ; ir < this ->veff ->nc ; ir++)
78+ {
79+ sup = porter[ir] * (current_veff[0 ][ir] + current_veff[3 ][ir])
80+ + porter1[ir]
81+ * (current_veff[1 ][ir]
82+ - std::complex <double >(0.0 , 1.0 ) * current_veff[2 ][ir]);
83+ sdown = porter1[ir] * (current_veff[0 ][ir] - current_veff[3 ][ir])
84+ + porter[ir]
85+ * (current_veff[1 ][ir]
86+ + std::complex <double >(0.0 , 1.0 ) * current_veff[2 ][ir]);
87+ porter[ir] = sup;
88+ porter1[ir] = sdown;
89+ }
8190 }
8291 // (3) fft back to G space.
8392 wfcpw->real2recip (porter, tmhpsi, this ->ik , true );
0 commit comments