Skip to content

Commit e5a28d4

Browse files
committed
Fix: Veff error when MPI_threads larger than nz
1 parent 1e38c0b commit e5a28d4

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

source/module_hamilt/ks_pw/veff_pw.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,38 +46,48 @@ 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 do in real space
52+
// but the 3DFFT can not be skipped, it will cause stuck
53+
if(this->veff->nc != 0)
5254
{
53-
porter[ir] *= current_veff[ir];
55+
GlobalV::ofs_running<<__FILE__<<__LINE__<<" "<<this->veff->nr<<" "<<this->veff->nc<<std::endl;
56+
const double* current_veff = &(this->veff[0](current_spin, 0));
57+
for (int ir = 0; ir < this->veff->nc; ++ir)
58+
{
59+
porter[ir] *= current_veff[ir];
60+
}
5461
}
5562
wfcpw->real2recip(porter, tmhpsi, ik, true);
5663
}
5764
else
5865
{
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-
}
6466
std::complex<double> *porter1 = new std::complex<double>[wfcpw->nmaxgr];
6567
// fft to real space and doing things.
6668
wfcpw->recip2real(tmpsi_in, porter, ik);
6769
wfcpw->recip2real(tmpsi_in + this->max_npw, porter1, ik);
6870
std::complex<double> sup, sdown;
69-
for (int ir = 0; ir < this->veff->nc; ir++)
71+
if(this->veff->nc != 0)
7072
{
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;
73+
const double* current_veff[4];
74+
for(int is=0;is<4;is++)
75+
{
76+
current_veff[is] = &(this->veff[0](is, 0));
77+
}
78+
for (int ir = 0; ir < this->veff->nc; ir++)
79+
{
80+
sup = porter[ir] * (current_veff[0][ir] + current_veff[3][ir])
81+
+ porter1[ir]
82+
* (current_veff[1][ir]
83+
- std::complex<double>(0.0, 1.0) * current_veff[2][ir]);
84+
sdown = porter1[ir] * (current_veff[0][ir] - current_veff[3][ir])
85+
+ porter[ir]
86+
* (current_veff[1][ir]
87+
+ std::complex<double>(0.0, 1.0) * current_veff[2][ir]);
88+
porter[ir] = sup;
89+
porter1[ir] = sdown;
90+
}
8191
}
8292
// (3) fft back to G space.
8393
wfcpw->real2recip(porter, tmhpsi, this->ik, true);

0 commit comments

Comments
 (0)