Skip to content

Commit 8b81643

Browse files
committed
Fix: 2D-block allolation error
1 parent fe570e1 commit 8b81643

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

source/module_orbital/ORB_control.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void ORB_control::mpi_creat_cart(MPI_Comm* comm_2D,
325325
#endif
326326

327327
#ifdef __MPI
328-
void ORB_control::mat_2d(MPI_Comm vu,
328+
int ORB_control::mat_2d(MPI_Comm vu,
329329
const int &M_A,
330330
const int &N_A,
331331
const int &nb,
@@ -365,7 +365,14 @@ void ORB_control::mat_2d(MPI_Comm vu,
365365
{
366366
ofs_warning << " cpu 2D distribution : " << dim[0] << "*" << dim[1] << std::endl;
367367
ofs_warning << " but, the number of row blocks is " << block << std::endl;
368-
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no row blocks, try a smaller 'nb2d' parameter.");
368+
if(nb>1)
369+
{
370+
return 1;
371+
}
372+
else
373+
{
374+
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no row blocks, try a smaller 'nb2d' parameter.");
375+
}
369376
}
370377

371378
// (2.1) row_b : how many blocks for this processor. (at least)
@@ -428,7 +435,14 @@ void ORB_control::mat_2d(MPI_Comm vu,
428435
{
429436
ofs_warning << " cpu 2D distribution : " << dim[0] << "*" << dim[1] << std::endl;
430437
ofs_warning << " but, the number of column blocks is " << block << std::endl;
431-
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no column blocks.");
438+
if(nb>1)
439+
{
440+
return 1;
441+
}
442+
else
443+
{
444+
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no column blocks.");
445+
}
432446
}
433447

434448
LM.col_b=block/dim[1];
@@ -485,7 +499,14 @@ void ORB_control::mat_2d(MPI_Comm vu,
485499
{
486500
ofs_warning << " cpu 2D distribution : " << dim[0] << "*" << dim[1] << std::endl;
487501
ofs_warning << " but, the number of bands-row-block is " << block << std::endl;
488-
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no bands-row-blocks.");
502+
if(nb>1)
503+
{
504+
return 1;
505+
}
506+
else
507+
{
508+
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no bands-row-blocks.");
509+
}
489510
}
490511
int col_b_bands = block / dim[1];
491512
if (coord[1] < block % dim[1])
@@ -510,7 +531,7 @@ void ORB_control::mat_2d(MPI_Comm vu,
510531
}
511532
pv->nloc_wfc = pv->ncol_bands * LM.row_num;
512533

513-
return;
534+
return 0;
514535
}
515536
#endif
516537

source/module_orbital/ORB_control.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class ORB_control
115115
void mpi_creat_cart(MPI_Comm* comm_2D,
116116
int prow, int pcol, std::ofstream& ofs_running);
117117

118-
void mat_2d(MPI_Comm vu,
118+
int mat_2d(MPI_Comm vu,
119119
const int& M_A, const int& N_A,
120120
const int& NB, LocalMatrix& loc_A,
121121
std::ofstream& ofs_running,

source/module_orbital/parallel_orbitals.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,16 @@ void ORB_control::divide_HS_2d
235235
this->mpi_creat_cart(&pv->comm_2D,pv->dim0,pv->dim1, ofs_running);
236236

237237
// call mat_2d
238-
this->mat_2d(pv->comm_2D, nlocal, nbands, pv->nb,
238+
int try_nb = this->mat_2d(pv->comm_2D, nlocal, nbands, pv->nb,
239239
pv->MatrixInfo, ofs_running, ofs_warning);
240+
if(try_nb==1)
241+
{
242+
ofs_running<<" parameter nb2d is too large: nb2d = "<<pv->nb<<std::endl;
243+
ofs_running<<" reset nb2d to value 1, this set would make the program keep working but maybe get slower during diagonalization."<<std::endl;
244+
pv->nb = 1;
245+
try_nb = this->mat_2d(pv->comm_2D, nlocal, nbands, pv->nb,
246+
pv->MatrixInfo, ofs_running, ofs_warning);
247+
}
240248

241249
// mohan add 2010-06-29
242250
pv->nrow = pv->MatrixInfo.row_num;

0 commit comments

Comments
 (0)