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
13 changes: 8 additions & 5 deletions source/source_base/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace ModuleBase
// 1024 Byte = 1 KB
// 1024 KB = 1 MB
// 1024 MB = 1 GB

const double memory_warning_threshold_mb = 20.0;

double Memory::total = 0.0;
int Memory::complex_matrix_memory = 2*sizeof(double); // 16 byte
int Memory::double_memory = sizeof(double); // 8 byte
Expand Down Expand Up @@ -149,7 +152,7 @@ double Memory::record

consume[find] = Memory::calculate_mem(n_in,type);

if(consume[find] > 5)
if(consume[find] > memory_warning_threshold_mb)
{
print(find);
}
Expand Down Expand Up @@ -211,7 +214,7 @@ void Memory::record
{
Memory::total += size_mb - consume[find];
consume[find] = size_mb;
if(consume[find] > 5)
if(consume[find] > memory_warning_threshold_mb)
{
print(find);
}
Expand Down Expand Up @@ -268,7 +271,7 @@ double Memory::record_gpu

consume_gpu[find] = Memory::calculate_mem(n_in,type);

if(consume_gpu[find] > 5)
if(consume_gpu[find] > memory_warning_threshold_mb)
{
print(find);
}
Expand Down Expand Up @@ -330,7 +333,7 @@ void Memory::record_gpu
{
Memory::total_gpu += size_mb - consume_gpu[find];
consume_gpu[find] = size_mb;
if(consume_gpu[find] > 5)
if(consume_gpu[find] > memory_warning_threshold_mb)
{
print(find);
}
Expand All @@ -343,7 +346,7 @@ void Memory::record_gpu

void Memory::print(const int find)
{
GlobalV::ofs_running <<"\n Warning_Memory_Consuming allocated: "
GlobalV::ofs_running <<"\n *** Memory Allocation Warning *** "
<<" "<<name[find]<<" "<<consume[find]<<" MB" << std::endl;
Comment on lines -346 to 347
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A pre-existing bug: print(find) is called from both record and record_gpu and unconditionally prints consume[find] — never consume_gpu[find]. A GPU allocation that crosses the new 20 MB line will print whatever happens to be in the CPU slot (often 0). Worth fixing while you're here.

Recommended fix: pass the data, drop the index
Decouple print from the global table layout entirely. It only needs a name and a size:

// memory.h
static void print(const std::string& name, double size_mb);

// memory.cpp
void Memory::print(const std::string& mem_name, double size_mb)
{
    GlobalV::ofs_running << "\n *** Memory Allocation Warning *** "
        << " " << mem_name << " " << size_mb << " MB" << std::endl;
}

Then at every call site, replace print(find); with the explicit form:

// CPU path
if (consume[find] > memory_warning_threshold_mb) {
    print(name[find], consume[find]);
}

// GPU path
if (consume_gpu[find] > memory_warning_threshold_mb) {
    print(name_gpu[find], consume_gpu[find]);
}

This is the cleanest fix — print no longer has a hidden coupling to "which table am I being called from", and it becomes trivially testable.

return;
}
Expand Down
4 changes: 3 additions & 1 deletion source/source_cell/cal_atoms_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CAL_ATOMS_INFO_H
#include "source_io/module_parameter/parameter.h"
#include "source_estate/cal_nelec_nband.h"
#include "source_base/global_function.h"
class CalAtomsInfo
{
public:
Expand All @@ -27,7 +28,8 @@ class CalAtomsInfo
para.input.nupdown += atoms[it].mag[ia];
}
}
GlobalV::ofs_running << " The readin total magnetization is " << para.inp.nupdown << std::endl;
GlobalV::ofs_running << std::endl;
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "The readin total magnetization", para.inp.nupdown);
Comment on lines +31 to +32
Copy link
Copy Markdown
Collaborator

@dzzz2001 dzzz2001 May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first added line is indented with a tab; the second with spaces. The surrounding file uses spaces — please normalize both to 12 spaces (matching the surrounding code).

}


Expand Down
2 changes: 1 addition & 1 deletion source/source_cell/setup_nonlocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void InfoNonlocal::Set_NonLocal(const int& it,

delete[] tmpBeta_lm;

log << " SET NONLOCAL PSEUDOPOTENTIAL PROJECTORS" << std::endl;
log << " SET NONLOCAL PSEUDOPOTENTIAL PROJECTORS FOR ELEMENT " << atom->label << std::endl;
return;
}

Expand Down
5 changes: 4 additions & 1 deletion source/source_estate/module_charge/charge_init.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <vector>
#include <algorithm>

#include "charge.h"
#include "source_base/global_function.h"
Expand Down Expand Up @@ -32,7 +33,9 @@ void Charge::init_rho(const UnitCell& ucell,
const int nspin = PARAM.inp.nspin;
assert(nspin>0);

std::cout << " START CHARGE : " << PARAM.inp.init_chg << std::endl;
std::string init_chg_upper = PARAM.inp.init_chg;
std::transform(init_chg_upper.begin(), init_chg_upper.end(), init_chg_upper.begin(), ::toupper);
std::cout << " START CHARGE : " << init_chg_upper << std::endl;

// we need to set the omega for the charge density
set_omega(&ucell.omega);
Expand Down
1 change: 1 addition & 0 deletions source/source_estate/read_pseudo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ void read_cell_pseudopots(const std::string& pp_dir, std::ofstream& log, UnitCel
{
upf.complete_default(ucell.atoms[i].ncpp);

log << std::endl;
ModuleBase::GlobalFunc::OUT(log, "Pseudopotential file", ucell.pseudo_fn[i]);
ModuleBase::GlobalFunc::OUT(log, "Pseudopotential type", ucell.atoms[i].ncpp.pp_type);
ModuleBase::GlobalFunc::OUT(log, "Exchange-correlation functional", ucell.atoms[i].ncpp.xc_func);
Expand Down
5 changes: 4 additions & 1 deletion source/source_io/module_output/print_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ void print_parameters(
}
else
{
std::cout << std::setw(16) << kv.get_nkstot();
const int nspin = kv.get_nspin();
const int nkstot = kv.get_nkstot();
const int nkpoints_real = (nspin > 0) ? (nkstot / nspin) : nkstot;
std::cout << std::setw(16) << nkpoints_real;
Comment on lines +99 to +102
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In K_Vectors::set_kup_and_kdw (source_cell/klist.cpp:651-664), nkstot is only doubled for nspin == 2; nspin == 4 falls through without modifying nkstot. So the new formula will display nkstot / 4 for noncollinear / SOC runs — a 4× underreport.
Suggest either: "const int real_nk = (kv.get_nspin() == 2) ? kv.get_nkstot() / 2 : kv.get_nkstot();" or, better, expose an accessor on K_Vectors that returns the spin-independent k-point count and use it everywhere this distinction matters.

}

std::cout << std::setw(12) << GlobalV::NPROC
Expand Down
16 changes: 8 additions & 8 deletions source/source_lcao/module_gint/gint_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void merge_hr_part_to_hR(const std::vector<hamilt::HContainer<double>>& hr_gint_



// C++11-compatible helpers for transfer_dm_2d_to_gint:
// C++11-compatible helpers for transfer_dm2d:
// SFINAE (enable_if) to select same-type vs cross-type code paths at compile time.

// Same-type path (TGint == TDM): transfer directly
Expand Down Expand Up @@ -294,13 +294,13 @@ gather_dm(const HContainer<TDM>& dm_src, HContainer<TGint>& dm_dst,
// gint_info should not have been a parameter, but it was added to initialize dm_gint_full
// In the future, we might try to remove the gint_info parameter
template<typename TGint, typename TDM>
void transfer_dm_2d_to_gint(
void transfer_dm2d(
const GintInfo& gint_info,
const std::vector<HContainer<TDM>*>& dm,
std::vector<HContainer<TGint>>& dm_gint)
{
ModuleBase::TITLE("Gint", "transfer_dm_2d_to_gint");
ModuleBase::timer::start("Gint", "transfer_dm_2d_to_gint");
ModuleBase::TITLE("Gint", "transfer_dm2d");
ModuleBase::timer::start("Gint", "transfer_dm2d");

if (PARAM.inp.nspin != 4)
{
Expand Down Expand Up @@ -368,7 +368,7 @@ void transfer_dm_2d_to_gint(
delete dm2d_tmp;
#endif
}
ModuleBase::timer::end("Gint", "transfer_dm_2d_to_gint");
ModuleBase::timer::end("Gint", "transfer_dm2d");
}

int globalIndex(int localindex, int nblk, int nprocs, int myproc)
Expand Down Expand Up @@ -494,15 +494,15 @@ template void cast_hcontainer_values(
HContainer<double>& dst);
template HContainer<float> make_cast_hcontainer(const HContainer<double>& src);
template HContainer<double> make_cast_hcontainer(const HContainer<float>& src);
template void transfer_dm_2d_to_gint(
template void transfer_dm2d(
const GintInfo& gint_info,
const std::vector<HContainer<double>*>& dm,
std::vector<HContainer<double>>& dm_gint);
template void transfer_dm_2d_to_gint(
template void transfer_dm2d(
const GintInfo& gint_info,
const std::vector<HContainer<double>*>& dm,
std::vector<HContainer<float>>& dm_gint);
template void transfer_dm_2d_to_gint(
template void transfer_dm2d(
const GintInfo& gint_info,
const std::vector<HContainer<std::complex<double>>*>& dm,
std::vector<HContainer<std::complex<double>>>& dm_gint);
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/module_gint/gint_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace ModuleGint
const GintInfo& gint_info);

template<typename TGint, typename TDM>
void transfer_dm_2d_to_gint(
void transfer_dm2d(
const GintInfo& gint_info,
const std::vector<HContainer<TDM>*>& dm,
std::vector<HContainer<TGint>>& dm_gint);
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/module_gint/gint_fvl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void Gint_fvl::cal_gint()
ModuleBase::TITLE("Gint", "cal_gint_fvl");
ModuleBase::timer::start("Gint", "cal_gint_fvl");
init_dm_gint_();
transfer_dm_2d_to_gint(*gint_info_, dm_vec_, dm_gint_vec_);
transfer_dm2d(*gint_info_, dm_vec_, dm_gint_vec_);
cal_fvl_svl_();
ModuleBase::timer::end("Gint", "cal_gint_fvl");
}
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/module_gint/gint_fvl_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void Gint_fvl_gpu::cal_gint()
ModuleBase::TITLE("Gint", "cal_gint_fvl");
ModuleBase::timer::start("Gint", "cal_gint_fvl");
init_dm_gint_();
transfer_dm_2d_to_gint(*gint_info_, dm_vec_, dm_gint_vec_);
transfer_dm2d(*gint_info_, dm_vec_, dm_gint_vec_);
cal_fvl_svl_();
ModuleBase::timer::end("Gint", "cal_gint_fvl");
}
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/module_gint/gint_fvl_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void Gint_fvl_meta::cal_gint()
ModuleBase::TITLE("Gint", "cal_gint_fvl");
ModuleBase::timer::start("Gint", "cal_gint_fvl");
init_dm_gint_();
transfer_dm_2d_to_gint(*gint_info_, dm_vec_, dm_gint_vec_);
transfer_dm2d(*gint_info_, dm_vec_, dm_gint_vec_);
cal_fvl_svl_();
ModuleBase::timer::end("Gint", "cal_gint_fvl");
}
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/module_gint/gint_fvl_meta_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void Gint_fvl_meta_gpu::cal_gint()
ModuleBase::TITLE("Gint", "cal_gint_fvl");
ModuleBase::timer::start("Gint", "cal_gint_fvl");
init_dm_gint_();
transfer_dm_2d_to_gint(*gint_info_, dm_vec_, dm_gint_vec_);
transfer_dm2d(*gint_info_, dm_vec_, dm_gint_vec_);
cal_fvl_svl_();
ModuleBase::timer::end("Gint", "cal_gint_fvl");
}
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/module_gint/gint_rho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void Gint_rho::cal_gint_impl_()
{
rho_data[is] = get_rho_data_<Real>(is, rho_cache);
}
transfer_dm_2d_to_gint(*gint_info_, dm_vec_, dm_gint_vec);
transfer_dm2d(*gint_info_, dm_vec_, dm_gint_vec);
cal_rho_(dm_gint_vec, rho_data);
transfer_rho_cache_<Real>(rho_cache);
}
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/module_gint/gint_rho_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void Gint_rho_gpu::cal_gint_impl_()
}

// 2. Transfer dm from 2D parallel distribution to gint serial distribution
transfer_dm_2d_to_gint(*gint_info_, dm_vec_, dm_gint_vec);
transfer_dm2d(*gint_info_, dm_vec_, dm_gint_vec);

// 3. Transfer dm to GPU
std::vector<CudaMemWrapper<Real>> dm_gint_d_vec(nspin_);
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/module_gint/gint_tau.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void Gint_tau::cal_gint()
ModuleBase::TITLE("Gint", "cal_gint_tau");
ModuleBase::timer::start("Gint", "cal_gint_tau");
init_dm_gint_();
transfer_dm_2d_to_gint(*gint_info_, dm_vec_, dm_gint_vec_);
transfer_dm2d(*gint_info_, dm_vec_, dm_gint_vec_);
cal_tau_();
ModuleBase::timer::end("Gint", "cal_gint_tau");
}
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/module_gint/gint_tau_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void Gint_tau_gpu::cal_gint()
ModuleBase::TITLE("Gint", "cal_gint_tau");
ModuleBase::timer::start("Gint", "cal_gint_tau");
init_dm_gint_();
transfer_dm_2d_to_gint(*gint_info_, dm_vec_, dm_gint_vec_);
transfer_dm2d(*gint_info_, dm_vec_, dm_gint_vec_);
cal_tau_();
ModuleBase::timer::end("Gint", "cal_gint_tau");
}
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/module_gint/test/test_gint_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ TEST_F(GintCommonTest, TransferDm2dToGintSupportsDoubleToFloat)
std::vector<hamilt::HContainer<float>> dm_gint;
dm_gint.push_back(gint_info_->get_hr<float>());

ModuleGint::transfer_dm_2d_to_gint(*gint_info_, dm_vec, dm_gint);
ModuleGint::transfer_dm2d(*gint_info_, dm_vec, dm_gint);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old name documented the operation: take a 2D-block-cyclic DM and reshape it into the gint serial layout. transfer_dm2d reads as "transfer a 2D dm" which doesn't say where to. Since the rename ripples through 9 files plus timer/TITLE labels (which downstream profiling scripts may grep), the win has to clear a high bar. I'd push back on this unless there's a follow-up reason.

If you do want a shorter name, “dm_2d_to_gint” is a better landing spot: drop the verb transfer (the X_to_Y form already conveys "convert/reshape" by convention) but keep both the source layout (2d) and the destination (gint). It goes from 22 → 13 chars without losing information, and the timer/TITLE labels can migrate with a single grep.


ASSERT_EQ(dm_gint.size(), 1);
EXPECT_EQ(dm.get_ijr_info(), dm_gint[0].get_ijr_info());
Expand Down
Loading