Skip to content
Open
Show file tree
Hide file tree
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
79 changes: 52 additions & 27 deletions source/source_io/module_hs/cal_r_overlap_R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ void cal_r_overlap_R::get_psi_r_beta(const UnitCell& ucell,
}


void cal_r_overlap_R::out_rR(const UnitCell& ucell, const Grid_Driver& gd, const int& istep)
void cal_r_overlap_R::out_rR(const UnitCell& ucell, const Grid_Driver& gd, const int& istep, const bool& reduce)
{
ModuleBase::TITLE("cal_r_overlap_R", "out_rR");
ModuleBase::timer::start("cal_r_overlap_R", "out_rR");
Expand Down Expand Up @@ -631,10 +631,14 @@ void cal_r_overlap_R::out_rR(const UnitCell& ucell, const Grid_Driver& gd, const

std::stringstream tem1;
tem1 << PARAM.globalv.global_out_dir << "tmp-rr.csr";
if (!reduce && GlobalV::NPROC > 1)
{
tem1 << "." << GlobalV::DRANK;
}
std::ofstream ofs_tem1;
std::ifstream ifs_tem1;

if (GlobalV::DRANK == 0)
if (!reduce || GlobalV::DRANK == 0)
{
if (binary)
{
Expand Down Expand Up @@ -754,26 +758,32 @@ void cal_r_overlap_R::out_rR(const UnitCell& ucell, const Grid_Driver& gd, const
}
}

Parallel_Reduce::reduce_all(rR_nonzero_num, 3);
if (reduce)
{
Parallel_Reduce::reduce_all(rR_nonzero_num, 3);
}

if (rR_nonzero_num[0] || rR_nonzero_num[1] || rR_nonzero_num[2])
{
output_R_number++;

if (binary)
{
ofs_tem1.write(reinterpret_cast<char*>(&dRx), sizeof(int));
ofs_tem1.write(reinterpret_cast<char*>(&dRy), sizeof(int));
ofs_tem1.write(reinterpret_cast<char*>(&dRz), sizeof(int));
}
else
if (!reduce || GlobalV::DRANK == 0)
{
ofs_tem1 << dRx << " " << dRy << " " << dRz << std::endl;
if (binary)
{
ofs_tem1.write(reinterpret_cast<char*>(&dRx), sizeof(int));
ofs_tem1.write(reinterpret_cast<char*>(&dRy), sizeof(int));
ofs_tem1.write(reinterpret_cast<char*>(&dRz), sizeof(int));
}
else
{
ofs_tem1 << dRx << " " << dRy << " " << dRz << std::endl;
}
}

for (int direction = 0; direction < 3; ++direction)
{
if (GlobalV::DRANK == 0)
if (!reduce || GlobalV::DRANK == 0)
{
if (binary)
{
Expand All @@ -791,7 +801,8 @@ void cal_r_overlap_R::out_rR(const UnitCell& ucell, const Grid_Driver& gd, const
psi_r_psi_sparse[direction],
sparse_threshold,
binary,
*(this->ParaV));
*(this->ParaV),
reduce);
}
else
{
Expand All @@ -801,7 +812,7 @@ void cal_r_overlap_R::out_rR(const UnitCell& ucell, const Grid_Driver& gd, const
}
}

if (GlobalV::DRANK == 0)
if (!reduce || GlobalV::DRANK == 0)
{
std::ofstream out_r;
std::stringstream ssr;
Expand All @@ -814,6 +825,10 @@ void cal_r_overlap_R::out_rR(const UnitCell& ucell, const Grid_Driver& gd, const
{
ssr << PARAM.globalv.global_out_dir << "rr.csr";
}
if (!reduce && GlobalV::NPROC > 1)
{
ssr << "." << GlobalV::DRANK;
}

if (binary) // .dat
{
Expand Down Expand Up @@ -864,7 +879,7 @@ void cal_r_overlap_R::out_rR(const UnitCell& ucell, const Grid_Driver& gd, const
return;
}

void cal_r_overlap_R::out_rR_other(const UnitCell& ucell, const int& istep, const std::set<Abfs::Vector3_Order<int>>& output_R_coor)
void cal_r_overlap_R::out_rR_other(const UnitCell& ucell, const int& istep, const std::set<Abfs::Vector3_Order<int>>& output_R_coor, const bool& reduce)
{
ModuleBase::TITLE("cal_r_overlap_R", "out_rR_other");
ModuleBase::timer::start("cal_r_overlap_R", "out_rR_other");
Expand All @@ -887,8 +902,12 @@ void cal_r_overlap_R::out_rR_other(const UnitCell& ucell, const int& istep, cons
{
ssr << PARAM.globalv.global_out_dir << "rr.csr";
}
if (!reduce && GlobalV::NPROC > 1)
{
ssr << "." << GlobalV::DRANK;
}

if (GlobalV::DRANK == 0)
if (!reduce || GlobalV::DRANK == 0)
{
if (binary)
{
Expand Down Expand Up @@ -1030,22 +1049,28 @@ void cal_r_overlap_R::out_rR_other(const UnitCell& ucell, const int& istep, cons
}
}

Parallel_Reduce::reduce_all(rR_nonzero_num, 3);

if (binary) // .dat
if (reduce)
{
out_r.write(reinterpret_cast<char*>(&dRx), sizeof(int));
out_r.write(reinterpret_cast<char*>(&dRy), sizeof(int));
out_r.write(reinterpret_cast<char*>(&dRz), sizeof(int));
Parallel_Reduce::reduce_all(rR_nonzero_num, 3);
}
else // .txt

if (!reduce || GlobalV::DRANK == 0)
{
out_r << dRx << " " << dRy << " " << dRz << std::endl;
if (binary) // .dat
{
out_r.write(reinterpret_cast<char*>(&dRx), sizeof(int));
out_r.write(reinterpret_cast<char*>(&dRy), sizeof(int));
out_r.write(reinterpret_cast<char*>(&dRz), sizeof(int));
}
else // .txt
{
out_r << dRx << " " << dRy << " " << dRz << std::endl;
}
}

for (int direction = 0; direction < 3; ++direction)
{
if (GlobalV::DRANK == 0)
if (!reduce || GlobalV::DRANK == 0)
{
if (binary)
{
Expand All @@ -1059,7 +1084,7 @@ void cal_r_overlap_R::out_rR_other(const UnitCell& ucell, const int& istep, cons

if (rR_nonzero_num[direction])
{
ModuleIO::output_single_R(out_r, psi_r_psi_sparse[direction], sparse_threshold, binary, *(this->ParaV));
ModuleIO::output_single_R(out_r, psi_r_psi_sparse[direction], sparse_threshold, binary, *(this->ParaV), reduce);
}
else
{
Expand All @@ -1068,7 +1093,7 @@ void cal_r_overlap_R::out_rR_other(const UnitCell& ucell, const int& istep, cons
}
}

if (GlobalV::DRANK == 0)
if (!reduce || GlobalV::DRANK == 0)
{
out_r.close();
}
Expand Down
4 changes: 2 additions & 2 deletions source/source_io/module_hs/cal_r_overlap_R.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class cal_r_overlap_R
const ModuleBase::Vector3<double>& R2,
const int& T2
);
void out_rR(const UnitCell& ucell, const Grid_Driver& gd, const int& istep);
void out_rR_other(const UnitCell& ucell, const int& istep, const std::set<Abfs::Vector3_Order<int>>& output_R_coor);
void out_rR(const UnitCell& ucell, const Grid_Driver& gd, const int& istep, const bool& reduce = true);
void out_rR_other(const UnitCell& ucell, const int& istep, const std::set<Abfs::Vector3_Order<int>>& output_R_coor, const bool& reduce = true);

private:
void initialize_orb_table(const UnitCell& ucell, const LCAO_Orbitals& orb);
Expand Down
26 changes: 22 additions & 4 deletions source/source_io/module_hs/output_mat_sparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "cal_r_overlap_R.h"
#include "source_io/module_hs/write_HS_R.h"
#include "source_io/module_parameter/parameter.h"

namespace ModuleIO
{
Expand All @@ -23,10 +24,13 @@ void output_mat_sparse(const bool& out_mat_dh,
{
LCAO_HS_Arrays HS_Arrays; // store sparse arrays

const int out_mat_hsR = PARAM.inp.out_mat_hs2[0];
const bool reduce = (out_mat_hsR != 3 && out_mat_hsR != 4);
const bool binary = (out_mat_hsR == 2 || out_mat_hsR == 4);
//! generate a file containing the kinetic energy matrix
if (out_mat_t)
{
output_TR(istep, ucell, pv, HS_Arrays, grid, two_center_bundle, orb);
output_TR(istep, ucell, pv, HS_Arrays, grid, two_center_bundle, orb, "trs1_nao.csr", binary, 1e-10, reduce);
}

//! generate a file containing the derivatives of the Hamiltonian matrix (in Ry/Bohr)
Expand All @@ -40,7 +44,10 @@ void output_mat_sparse(const bool& out_mat_dh,
grid,
two_center_bundle,
orb,
kv);
kv,
binary,
1e-10,
reduce);
}
//! generate a file containing the derivatives of the overlap matrix (in Ry/Bohr)
if (out_mat_ds)
Expand All @@ -52,15 +59,26 @@ void output_mat_sparse(const bool& out_mat_dh,
grid,
two_center_bundle,
orb,
kv);
kv,
binary,
1e-10,
reduce);
}

// add by jingan for out r_R matrix 2019.8.14
if (out_mat_r)
{
cal_r_overlap_R r_matrix;
r_matrix.init(ucell, pv, orb);
r_matrix.out_rR(ucell, grid, istep);
r_matrix.binary = binary;
if (out_mat_hsR != 0)
{
r_matrix.out_rR_other(ucell, istep, HS_Arrays.output_R_coor, reduce);
}
else
{
r_matrix.out_rR(ucell, grid, istep, reduce);
}
}

return;
Expand Down
Loading
Loading