Skip to content

Commit f67e344

Browse files
Critsium-xyclaude
andauthored
Refactor: read EXX ABFS/JLE file lists via UnitCell, decouple source_cell (#7598) (#7667)
read_atom_species.cpp (source_cell) parsed the STRU ABFS_ORBITAL / ABFS_JLES_ORBITAL sections directly into GlobalC::exx_info, making the source_cell data-structure layer depend on source_hamilt/module_xc. This was the last remaining reverse dependency in source_cell. Route the lists through UnitCell instead — the same place STRU orbital-file names already live (orbital_fn, descriptor_file): - UnitCell gains neutral members abfs_orbital_files / jle_orbital_files. - read_atom_species parses the sections into those members; the exx_info.h include and the cal_exx guard are removed (absent sections are no-ops). - bcast_cell broadcasts the two members as part of bcast_unitcell. - Exx_NAO::init(ucell) copies them into GlobalC::exx_info before Exx_LRI copies info_ri, keeping the EXX-specific routing in the LCAO EXX layer. Because the lists now travel inside the (already broadcast) UnitCell, the dedicated bcast_exx_file_lists() added in #7635 is redundant and removed. After this, source_cell (non-test) includes only source_base and itself. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 83e5099 commit f67e344

6 files changed

Lines changed: 45 additions & 76 deletions

File tree

source/source_cell/bcast_cell.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66

77
namespace unitcell
88
{
9+
#ifdef __MPI
10+
// Broadcast a vector<string> (size then elements) from rank 0 to all ranks.
11+
static void bcast_string_vector(std::vector<std::string>& v)
12+
{
13+
int size = static_cast<int>(v.size());
14+
Parallel_Common::bcast_int(size);
15+
v.resize(size);
16+
for (int i = 0; i < size; ++i)
17+
{
18+
Parallel_Common::bcast_string(v[i]);
19+
}
20+
}
21+
#endif
22+
923
void bcast_atoms_tau(Atom* atoms,
1024
const int ntype)
1125
{
@@ -112,6 +126,10 @@ namespace unitcell
112126
{
113127
Parallel_Common::bcast_string(ucell.orbital_fn[i]);
114128
}
129+
130+
// ABFS/JLE orbital-file lists (read from STRU on rank 0, used by LCAO EXX)
131+
bcast_string_vector(ucell.abfs_orbital_files);
132+
bcast_string_vector(ucell.jle_orbital_files);
115133
return;
116134
#endif
117135
}

source/source_cell/read_atom_species.cpp

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <sstream>
44

55
#include "source_base/tool_title.h"
6-
#include "source_hamilt/module_xc/exx_info.h" // use GlobalC::exx_info
76

87
namespace unitcell
98
{
@@ -106,33 +105,27 @@ bool read_atom_species(std::ifstream& ifa,
106105
}
107106
#ifdef __LCAO
108107
// Peize Lin add 2016-09-23
109-
#ifdef __MPI
110-
#ifdef __EXX
111-
if( GlobalC::exx_info.info_global.cal_exx || rpa )
108+
// Read the ABFS/JLE orbital filenames (used by LCAO EXX) into the UnitCell.
109+
// The EXX layer copies these into the global Exx_Info during its own setup, so
110+
// source_cell does not depend on the XC module. Absent sections are no-ops.
111+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "ABFS_ORBITAL") )
112112
{
113-
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "ABFS_ORBITAL") )
113+
for(int i=0; i<ntype; i++)
114114
{
115-
for(int i=0; i<ntype; i++)
116-
{
117-
std::string ofile;
118-
ifa >> ofile;
119-
GlobalC::exx_info.info_ri.files_abfs.push_back(ofile);
120-
GlobalC::exx_info.info_opt_abfs.files_abfs.push_back(ofile);
121-
}
115+
std::string ofile;
116+
ifa >> ofile;
117+
ucell.abfs_orbital_files.push_back(ofile);
122118
}
123-
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "ABFS_JLES_ORBITAL") )
119+
}
120+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "ABFS_JLES_ORBITAL") )
121+
{
122+
for(int i=0; i<ntype; i++)
124123
{
125-
for(int i=0; i<ntype; i++)
126-
{
127-
std::string ofile;
128-
ifa >> ofile;
129-
GlobalC::exx_info.info_opt_abfs.files_jles.push_back(ofile);
130-
}
124+
std::string ofile;
125+
ifa >> ofile;
126+
ucell.jle_orbital_files.push_back(ofile);
131127
}
132128
}
133-
134-
#endif // __EXX
135-
#endif // __MPI
136129
#endif // __LCAO
137130
return true;
138131
}

source/source_cell/unitcell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ class UnitCell : public AtomProvider {
233233

234234
std::vector<std::string> orbital_fn; // filenames of orbitals, liuyu add 2022-10-19
235235
std::string descriptor_file; // filenames of descriptor_file, liuyu add 2023-04-06
236+
std::vector<std::string> abfs_orbital_files; // ABFS orbital filenames read from STRU "ABFS_ORBITAL" (used by LCAO EXX)
237+
std::vector<std::string> jle_orbital_files; // JLE orbital filenames read from STRU "ABFS_JLES_ORBITAL" (used by LCAO EXX)
236238

237239
void set_iat2itia();
238240

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
5353
ModuleBase::timer::start("ESolver_KS_LCAO", "before_all_runners");
5454

5555
// 0) init EXX - moved from constructor to ensure GlobalC::exx_info.info_global is already set
56-
this->exx_nao.init();
56+
this->exx_nao.init(ucell);
5757

5858
// 1) before_all_runners in ESolver_KS
5959
ESolver_KS::before_all_runners(ucell, inp);

source/source_lcao/setup_exx.cpp

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,6 @@
33
#ifdef __EXX
44
#include "source_lcao/module_ri/Exx_LRI_interface.h"
55
#include "source_hamilt/module_xc/exx_info.h" // use the global Exx_Info
6-
#if defined(__MPI)
7-
#include "source_base/parallel_common.h"
8-
#include <string>
9-
#include <vector>
10-
#endif
11-
#endif
12-
13-
#ifdef __EXX
14-
#if defined(__MPI)
15-
namespace
16-
{
17-
// Broadcast a vector<string> from rank 0 to all ranks.
18-
// Moved here from source_cell/bcast_cell.cpp so that source_cell no longer
19-
// depends on the XC module just to distribute these ABFS file-name lists.
20-
void bcast_string_vector(std::vector<std::string>& v)
21-
{
22-
int size = static_cast<int>(v.size());
23-
Parallel_Common::bcast_int(size);
24-
v.resize(size);
25-
for (int i = 0; i < size; ++i)
26-
{
27-
Parallel_Common::bcast_string(v[i]);
28-
}
29-
}
30-
} // namespace
31-
#endif
32-
33-
void bcast_exx_file_lists()
34-
{
35-
#if defined(__MPI)
36-
bcast_string_vector(GlobalC::exx_info.info_ri.files_abfs);
37-
bcast_string_vector(GlobalC::exx_info.info_opt_abfs.files_abfs);
38-
bcast_string_vector(GlobalC::exx_info.info_opt_abfs.files_jles);
39-
#endif
40-
}
416
#endif
427

438
template <typename TK>
@@ -48,7 +13,7 @@ Exx_NAO<TK>::~Exx_NAO(){}
4813

4914

5015
template <typename TK>
51-
void Exx_NAO<TK>::init()
16+
void Exx_NAO<TK>::init(const UnitCell& ucell)
5217
{
5318
#ifdef __EXX
5419
// 1. currently this initialization must be put in constructor rather than `before_all_runners()`
@@ -57,9 +22,13 @@ void Exx_NAO<TK>::init()
5722
// 2. always construct but only initialize when if(cal_exx) is true
5823
// because some members like two_level_step are used outside if(cal_exx)
5924

60-
// Distribute the ABFS/JLE file lists (read from STRU on rank 0) to all ranks
61-
// before Exx_LRI copies info_ri below.
62-
bcast_exx_file_lists();
25+
// The ABFS/JLE orbital-file lists are read from STRU into the UnitCell (and
26+
// broadcast with it). Copy them into the EXX info here, before Exx_LRI copies
27+
// info_ri below. This keeps the EXX-specific routing (which list feeds info_ri
28+
// vs info_opt_abfs) in the LCAO EXX layer, so source_cell stays decoupled.
29+
GlobalC::exx_info.info_ri.files_abfs = ucell.abfs_orbital_files;
30+
GlobalC::exx_info.info_opt_abfs.files_abfs = ucell.abfs_orbital_files;
31+
GlobalC::exx_info.info_opt_abfs.files_jles = ucell.jle_orbital_files;
6332

6433
if (GlobalC::exx_info.info_ri.real_number)
6534
{

source/source_lcao/setup_exx.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Exx_NAO
2828
std::shared_ptr<Exx_LRI_Interface<TK, std::complex<double>>> exc = nullptr;
2929
#endif
3030

31-
void init();
31+
void init(const UnitCell& ucell);
3232

3333
void before_runner(
3434
UnitCell& ucell, // unitcell
@@ -47,18 +47,5 @@ class Exx_NAO
4747

4848
};
4949

50-
#ifdef __EXX
51-
/**
52-
* @brief Broadcast the ABFS/JLE orbital-file lists held in the global Exx_Info instance.
53-
*
54-
* The lists are read from STRU on rank 0 during setup_cell and must be
55-
* distributed to all ranks before the LCAO EXX/RI module consumes them.
56-
* This logic lives here (rather than in source_cell or the generic XC module)
57-
* because the ABFS/JLE orbital files are an LCAO-only concept. It is invoked at
58-
* the start of Exx_NAO::init(), before Exx_LRI copies info_ri.
59-
*/
60-
void bcast_exx_file_lists();
61-
#endif
62-
6350

6451
#endif

0 commit comments

Comments
 (0)