Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions source/source_io/write_eig_occ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,94 @@ void ModuleIO::write_eig_iter(const ModuleBase::matrix &ekb,const ModuleBase::ma
GlobalV::ofs_running << std::endl;
}
}


// =============================================================
// MPI communication:
// RANK 0 collect and print out #EIGENVALUES# AND #OCCUPATIONS# for all k-points
// =============================================================
#ifdef __MPI
MPI_Barrier(MPI_COMM_WORLD);

if (kpar > 1 && ip > 0 && PARAM.inp.out_alllog == 0)
{

if (GlobalV::MY_RANK == 0 )
{

// for the current spin channel [is] and pool [ip]
// MPI_Recv the size of matrix, ik2iktot, ekb and wg from RANK_IN_POOL=0
MPI_Status status;
int recv_nks_np, recv_nbands;
MPI_Recv(&recv_nks_np, 1, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
int source_rank = status.MPI_SOURCE;
MPI_Recv(&recv_nbands, 1, MPI_INT, source_rank, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
int* recv_ik2iktot = new int[recv_nks_np];
MPI_Recv(recv_ik2iktot, recv_nks_np, MPI_INT, source_rank, 2, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
ModuleBase::matrix recv_ekb(recv_nks_np, recv_nbands);
MPI_Recv(recv_ekb.c, recv_nks_np * recv_nbands, MPI_DOUBLE, source_rank, 3, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
ModuleBase::matrix recv_wg(recv_nks_np, recv_nbands);
MPI_Recv(recv_wg.c, recv_nks_np * recv_nbands, MPI_DOUBLE, source_rank, 4, MPI_COMM_WORLD, MPI_STATUS_IGNORE);

// print EIGENVALUES and OCCUPATIONS of received k-points
for (int ik = 0; ik < recv_nks_np; ++ik)
{
GlobalV::ofs_running << " spin=" << is+1 << " k-point="
<< recv_ik2iktot[ik] + 1 - is * nkstot_np << std::endl;

GlobalV::ofs_running << std::setw(8) << "Index"
<< std::setw(18) << "Eigenvalues(eV)"
<< std::setw(18) << "Occupations" << std::endl;

for (int ib = 0; ib < recv_nbands; ib++)
{
GlobalV::ofs_running << std::setw(8) << ib + 1
<< std::setw(18) << recv_ekb(ik, ib) * ModuleBase::Ry_to_eV
<< std::setw(18) << recv_wg(ik, ib) << std::endl;
}
GlobalV::ofs_running << std::endl;
}

delete[] recv_ik2iktot;
}
else if (GlobalV::MY_POOL == ip && GlobalV::RANK_IN_POOL == 0 && GlobalV::MY_BNDGROUP == 0)
{
// for the current spin channel [is] and pool [ip]
// MPI_Send the size of matrix, ik2iktot, ekb and wg to RANK=0
const int send_nks_np = nks_np;
const int send_nbands = ekb.nc;
const int is_offset = is * nks_np;
int* send_ik2iktot = new int[send_nks_np];
for (int ik = 0; ik < send_nks_np; ++ik)
{
send_ik2iktot[ik] = kv.ik2iktot[is_offset + ik];
}
MPI_Send(&send_nks_np, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
MPI_Send(&send_nbands, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
MPI_Send(send_ik2iktot, send_nks_np, MPI_INT, 0, 2, MPI_COMM_WORLD);
MPI_Send(ekb.c + is_offset * send_nbands,
send_nks_np * send_nbands,
MPI_DOUBLE, 0, 3, MPI_COMM_WORLD);
MPI_Send(wg.c + is_offset * send_nbands,
send_nks_np * send_nbands,
MPI_DOUBLE, 0, 4, MPI_COMM_WORLD);

delete[] send_ik2iktot;
}

MPI_Barrier(MPI_COMM_WORLD);
}
// =============================================================
// End of MPI Communication
// =============================================================
#endif
}
#ifdef __MPI
MPI_Barrier(MPI_COMM_WORLD);
#endif
}


ModuleBase::timer::tick("ModuleIO", "write_eig_iter");
}

Expand Down
Loading