Skip to content

Commit 4c3e0e2

Browse files
authored
Merge branch 'develop' into dev-1
2 parents 6353cf4 + 1bea8dd commit 4c3e0e2

File tree

88 files changed

+8010
-47546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+8010
-47546
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2977,7 +2977,7 @@ These variables are relevant when using hybrid functionals with *[basis_type](#b
29772977
- **Type**: Real
29782978
- **Availability**: *[calculation](#calculation)==gen_opt_abfs*
29792979
- **Description**: The threshold when solving for the zeros of spherical Bessel functions. A reasonable choice is 1e-12.
2980-
- **Default**: 0
2980+
- **Default**: 1E-12
29812981

29822982
### exx_real_number
29832983

source/Makefile.Objects

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ OBJS_HAMILT=hamilt_pw.o\
334334
op_exx_pw.o\
335335
ekinetic_pw.o\
336336
ekinetic_op.o\
337+
exx_pw_ace.o\
338+
exx_pw_pot.o\
337339
hpsi_norm_op.o\
338340
veff_pw.o\
339341
veff_op.o\

source/source_base/module_device/device.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ std::string get_device_flag(const std::string& device,
6565
/**
6666
* @brief Get the rank of current node
6767
* Note that GPU can only be binded with CPU in the same node
68-
*
69-
* @return int
68+
*
69+
* @return int
7070
*/
7171
int get_node_rank();
7272
int get_node_rank_with_mpi_shared(const MPI_Comm mpi_comm = MPI_COMM_WORLD);
@@ -91,6 +91,14 @@ void record_device_memory(const Device* dev, std::ofstream& ofs_device, std::str
9191
return;
9292
}
9393

94+
#if defined(__CUDA) || defined(__ROCM)
95+
template <>
96+
void print_device_info<base_device::DEVICE_GPU>(const base_device::DEVICE_GPU *ctx, std::ofstream &ofs_device);
97+
98+
template <>
99+
void record_device_memory<base_device::DEVICE_GPU>(const base_device::DEVICE_GPU* dev, std::ofstream& ofs_device, std::string str, size_t size);
100+
#endif
101+
94102
} // end of namespace information
95103
} // end of namespace base_device
96104

source/source_base/module_device/output_device.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void print_device_info<base_device::DEVICE_GPU>(
190190
ofs_device << "Detected " << deviceCount << " CUDA Capable device(s)\n";
191191
}
192192
int dev = 0, driverVersion = 0, runtimeVersion = 0;
193-
cudaErrcheck(cudaSetDevice(dev));
193+
cudaErrcheck(cudaGetDevice(&dev));
194194
cudaDeviceProp deviceProp;
195195
cudaErrcheck(cudaGetDeviceProperties(&deviceProp, dev));
196196
ofs_device << "\nDevice " << dev << ":\t " << deviceProp.name << std::endl;
@@ -429,7 +429,7 @@ void print_device_info<base_device::DEVICE_GPU>(
429429
ofs_device << "Detected " << deviceCount << " CUDA Capable device(s)\n";
430430
}
431431
int dev = 0, driverVersion = 0, runtimeVersion = 0;
432-
hipErrcheck(hipSetDevice(dev));
432+
hipErrcheck(hipGetDevice(&dev));
433433
hipDeviceProp_t deviceProp;
434434
hipErrcheck(hipGetDeviceProperties(&deviceProp, dev));
435435
ofs_device << "\nDevice " << dev << ":\t " << deviceProp.name << std::endl;

source/source_cell/pseudo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "pseudo.h"
22
#include "source_base/tool_title.h"
3+
#include <cstdint>
34

45
pseudo::pseudo()
56
{

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,20 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
589589
auto start = std::chrono::high_resolution_clock::now();
590590
exx_helper.set_firstiter(false);
591591
exx_helper.op_exx->first_iter = false;
592+
double dexx = 0.0;
593+
if (PARAM.inp.exx_thr_type == "energy")
594+
{
595+
dexx = exx_helper.cal_exx_energy(this->kspw_psi);
596+
}
592597
exx_helper.set_psi(this->kspw_psi);
598+
if (PARAM.inp.exx_thr_type == "energy")
599+
{
600+
dexx -= exx_helper.cal_exx_energy(this->kspw_psi);
601+
// std::cout << "dexx = " << dexx << std::endl;
602+
}
603+
bool conv_ene = std::abs(dexx) < PARAM.inp.exx_ene_thr;
593604

594-
conv_esolver = exx_helper.exx_after_converge(iter);
595-
605+
conv_esolver = exx_helper.exx_after_converge(iter, conv_ene);
596606
if (!conv_esolver)
597607
{
598608
auto duration = std::chrono::high_resolution_clock::now() - start;
@@ -602,6 +612,7 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
602612
exx_helper.op_exx->first_iter = false;
603613
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
604614
update_pot(ucell, istep, iter, conv_esolver);
615+
exx_helper.iter_inc();
605616
}
606617
}
607618
}
@@ -614,8 +625,9 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
614625
//----------------------------------------------------------
615626
// 3) Print out electronic wavefunctions in pw basis
616627
//----------------------------------------------------------
617-
if (iter % PARAM.inp.out_freq_elec == 0 || iter == PARAM.inp.scf_nmax || conv_esolver)
628+
if (iter % PARAM.inp.out_freq_elec == 0 || iter == PARAM.inp.scf_nmax)
618629
{
630+
// conv_esolver == true has already been dealt with in after_scf
619631
ModuleIO::write_wfc_pw(GlobalV::KPAR,
620632
GlobalV::MY_POOL,
621633
GlobalV::MY_RANK,

source/source_hamilt/module_xc/exx_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct Exx_Info
8181
{
8282
int abfs_Lmax = 0; // tmp
8383
double ecut_exx = 60;
84-
double tolerence = 1E-2;
84+
double tolerence = 1E-12;
8585
double kmesh_times = 4;
8686
};
8787
Exx_Info_Opt_ABFs info_opt_abfs;

source/source_io/module_parameter/input_parameter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ struct Input_para
546546
///< calculating Columb potential is to that of atomic orbitals
547547
int exx_opt_orb_lmax = 0; ///< the maximum l of the spherical Bessel functions for opt ABFs
548548
double exx_opt_orb_ecut = 0.0; ///< the cut-off of plane wave expansion for opt ABFs
549-
double exx_opt_orb_tolerence = 0.0; ///< the threshold when solving for the zeros of spherical Bessel
549+
double exx_opt_orb_tolerence = 1E-12; ///< the threshold when solving for the zeros of spherical Bessel
550550
///< functions for opt ABFs
551551
bool exx_symmetry_realspace
552552
= true; ///< whether to reduce the real-space sector in when using symmetry=1 in EXX calculation
@@ -654,6 +654,8 @@ struct Input_para
654654
// EXX for planewave basis, rhx0820 2025-03-10
655655
bool exxace = true; // exxace, exact exchange for planewave basis, https://doi.org/10.1021/acs.jctc.6b00092
656656
bool exx_gamma_extrapolation = true; // gamma point extrapolation for exx, https://doi.org/10.1103/PhysRevB.79.205114
657+
std::string exx_thr_type = "density"; // threshold type for exx outer loop, energy or density
658+
double exx_ene_thr = 1e-5; // threshold for exx outer loop when exx_thr_type = energy
657659

658660
// ==== #Parameters (23.XC external parameterization) ========
659661
/*

source/source_io/read_input_item_other.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,32 @@ void ReadInput::item_others()
545545
read_sync_bool(input.exx_gamma_extrapolation);
546546
this->add_item(item);
547547
}
548+
{
549+
Input_Item item("exx_thr_type");
550+
item.annotation = "threshold type for exx outer loop, energy or density";
551+
read_sync_string(input.exx_thr_type);
552+
item.check_value = [](const Input_Item& item, const Parameter& para) {
553+
std::string thr_type = para.input.exx_thr_type;
554+
std::transform(thr_type.begin(), thr_type.end(), thr_type.begin(), ::tolower);
555+
if (thr_type != "energy" && thr_type != "density")
556+
{
557+
ModuleBase::WARNING_QUIT("ReadInput", "exx_thr_type should be energy or density");
558+
}
559+
};
560+
this->add_item(item);
561+
}
562+
{
563+
Input_Item item("exx_ene_thr");
564+
item.annotation = "threshold for exx outer loop when exx_thr_type = energy";
565+
read_sync_double(input.exx_ene_thr);
566+
item.check_value = [](const Input_Item& item, const Parameter& para) {
567+
if (para.input.exx_ene_thr <= 0)
568+
{
569+
ModuleBase::WARNING_QUIT("ReadInput", "exx_ene_thr must > 0");
570+
}
571+
};
572+
this->add_item(item);
573+
}
548574

549575
}
550576
} // namespace ModuleIO

source/source_io/test/read_input_ptest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ TEST_F(InputParaTest, ParaRead)
296296
EXPECT_DOUBLE_EQ(param.inp.rpa_ccp_rmesh_times, 10.0);
297297
EXPECT_EQ(param.inp.exx_opt_orb_lmax, 0);
298298
EXPECT_DOUBLE_EQ(param.inp.exx_opt_orb_ecut, 0.0);
299-
EXPECT_DOUBLE_EQ(param.inp.exx_opt_orb_tolerence, 0.0);
299+
EXPECT_DOUBLE_EQ(param.inp.exx_opt_orb_tolerence, 1E-12);
300300
EXPECT_FALSE(param.inp.noncolin);
301301
EXPECT_FALSE(param.inp.lspinorb);
302302
EXPECT_DOUBLE_EQ(param.inp.soc_lambda, 1.0);

0 commit comments

Comments
 (0)