44#include " LCAO_deepks_io.h" // mohan add 2024-07-22
55#include " source_estate/cal_dm.h"
66#include " source_lcao/module_hcontainer/hcontainer.h"
7+ #include " source_lcao/module_hcontainer/hcontainer_funcs.h"
78#include " source_lcao/module_hcontainer/output_hcontainer.h"
89#include " source_io/module_parameter/parameter.h"
910#include " source_base/global_variable.h"
@@ -444,12 +445,23 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
444445 + (PARAM.inp .deepks_out_labels == 1 ? " deepks_hrtot.csr" : " deepks_hamiltonian_r.csr" );
445446 hamilt::HContainer<TR>* hR_tot = (p_ham->getHR ());
446447
448+ const int nbasis = hR_tot->get_nbasis ();
449+ #ifdef __MPI
450+ Parallel_Orbitals serialV;
451+ serialV.init (nbasis, nbasis, nbasis, ParaV->comm ());
452+ serialV.set_serial (nbasis, nbasis);
453+ serialV.set_atomic_trace (ucell.get_iat2iwt (), ucell.nat , nbasis);
454+ hamilt::HContainer<TR> hR_serial (&serialV);
455+ hamilt::gatherParallels (*hR_tot, &hR_serial, 0 );
456+ #else
457+ hamilt::HContainer<TR> hR_serial (*hR_tot);
458+ #endif
447459 if (rank == 0 )
448460 {
449461 std::ofstream ofs_hr (file_hrtot, std::ios::out);
450- ofs_hr << " Matrix Dimension of H(R): " << hR_tot-> get_nbasis () << std::endl;
462+ ofs_hr << " Matrix Dimension of H(R): " << nbasis << std::endl;
451463 ofs_hr << " Matrix number of H(R): " << hR_tot->size_R_loop () << std::endl;
452- hamilt::Output_HContainer<TR> out_hr (hR_tot , ofs_hr, sparse_threshold, precision);
464+ hamilt::Output_HContainer<TR> out_hr (&hR_serial , ofs_hr, sparse_threshold, precision);
453465 out_hr.write (true ); // write all the matrices, including empty ones
454466 ofs_hr.close ();
455467 }
@@ -461,12 +473,18 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
461473 const std::string file_vdeltar = PARAM.globalv .global_out_dir + " deepks_hrdelta.csr" ;
462474 hamilt::HContainer<TR>* h_deltaR = p_ham->get_V_delta_R ();
463475
476+ #ifdef __MPI
477+ hamilt::HContainer<TR> h_deltaR_serial (&serialV);
478+ hamilt::gatherParallels (*h_deltaR, &h_deltaR_serial, 0 );
479+ #else
480+ hamilt::HContainer<TR> h_deltaR_serial (*h_deltaR);
481+ #endif
464482 if (rank == 0 )
465483 {
466484 std::ofstream ofs_hr (file_vdeltar, std::ios::out);
467485 ofs_hr << " Matrix Dimension of H_delta(R): " << h_deltaR->get_nbasis () << std::endl;
468486 ofs_hr << " Matrix number of H_delta(R): " << h_deltaR->size_R_loop () << std::endl;
469- hamilt::Output_HContainer<TR> out_hr (h_deltaR , ofs_hr, sparse_threshold, precision);
487+ hamilt::Output_HContainer<TR> out_hr (&h_deltaR_serial , ofs_hr, sparse_threshold, precision);
470488 out_hr.write (true ); // write all the matrices, including empty ones
471489 ofs_hr.close ();
472490 }
0 commit comments