Skip to content

Commit 83e5099

Browse files
Critsium-xyclaude
andauthored
Refactor: move EXX file-list broadcast out of source_cell (#7635) (#7663)
bcast_cell.cpp reached into GlobalC::exx_info (source_hamilt/module_xc) to broadcast the ABFS/JLE orbital-file lists, making the source_cell data-structure layer depend on a higher layer. The ABFS/JLE orbital files are an LCAO-only concept, so the broadcast is placed in the LCAO EXX manager: add bcast_exx_file_lists() in source_lcao/setup_exx.{h,cpp} and invoke it at the start of Exx_NAO::init(), before Exx_LRI copies info_ri. init() runs in ESolver_KS_LCAO::before_all_runners (reused by TDDFT/DM2rho/DoubleXC; LR reuses the moved Exx_LRI), on all ranks, after setup_cell has populated the lists on rank 0 and before every consumer (RI-EXX, opt-ABFs generate_matrix, RPA postSCF). This removes the exx_info.h include, the helper, and the three broadcast calls from bcast_cell.cpp. The per-ionic-step re-broadcast previously done via bcast_unitcell is dropped, which is behaviour-neutral: the file lists are static once read from STRU. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 1dd484d commit 83e5099

3 files changed

Lines changed: 54 additions & 25 deletions

File tree

source/source_cell/bcast_cell.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
11
#include "unitcell.h"
22
#include "source_base/parallel_common.h"
33

4-
#include "source_hamilt/module_xc/exx_info.h" // use GlobalC::exx_info
5-
64
#include <string>
75
#include <vector>
86

97
namespace unitcell
108
{
11-
#if defined(__MPI) && defined(__EXX)
12-
// Broadcast a vector<string> from rank 0 to all ranks.
13-
// Replaces the former cereal-based ModuleBase::bcast_data_cereal, which
14-
// was only ever used here to broadcast plain lists of ABFS file names and
15-
// pulled source_cell into a dependency on source_lcao/module_ri.
16-
static void bcast_string_vector(std::vector<std::string>& v)
17-
{
18-
int size = static_cast<int>(v.size());
19-
Parallel_Common::bcast_int(size);
20-
v.resize(size);
21-
for (int i = 0; i < size; ++i)
22-
{
23-
Parallel_Common::bcast_string(v[i]);
24-
}
25-
}
26-
#endif
27-
289
void bcast_atoms_tau(Atom* atoms,
2910
const int ntype)
3011
{
@@ -131,12 +112,6 @@ namespace unitcell
131112
{
132113
Parallel_Common::bcast_string(ucell.orbital_fn[i]);
133114
}
134-
135-
#ifdef __EXX
136-
bcast_string_vector(GlobalC::exx_info.info_ri.files_abfs);
137-
bcast_string_vector(GlobalC::exx_info.info_opt_abfs.files_abfs);
138-
bcast_string_vector(GlobalC::exx_info.info_opt_abfs.files_jles);
139-
#endif
140115
return;
141116
#endif
142117
}

source/source_lcao/setup_exx.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@
22

33
#ifdef __EXX
44
#include "source_lcao/module_ri/Exx_LRI_interface.h"
5+
#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+
}
541
#endif
642

743
template <typename TK>
@@ -20,6 +56,11 @@ void Exx_NAO<TK>::init()
2056
// which cause the failure of the subsequent procedure reused by ESolver_LCAO_TDDFT
2157
// 2. always construct but only initialize when if(cal_exx) is true
2258
// because some members like two_level_step are used outside if(cal_exx)
59+
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();
63+
2364
if (GlobalC::exx_info.info_ri.real_number)
2465
{
2566
this->exd = std::make_shared<Exx_LRI_Interface<TK, double>>(GlobalC::exx_info.info_ri, GlobalC::exx_info.info_global);

source/source_lcao/setup_exx.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,18 @@ 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+
5063

5164
#endif

0 commit comments

Comments
 (0)