@@ -82,13 +82,13 @@ template <typename TK, typename TR>
82
82
OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
83
83
HContainer<TR>*hR_in,
84
84
const UnitCell& ucell_in,
85
- const K_Vectors& kv_in,
86
- std::vector<std::map<int , std::map<TAC, RI::Tensor<double >>>>* Hexxd_in,
87
- std::vector<std::map<int , std::map<TAC, RI::Tensor<std::complex<double >>>>>* Hexxc_in,
85
+ const K_Vectors& kv_in,
86
+ std::vector<std::map<int , std::map<TAC, RI::Tensor<double >>>>* Hexxd_in,
87
+ std::vector<std::map<int , std::map<TAC, RI::Tensor<std::complex<double >>>>>* Hexxc_in,
88
88
Add_Hexx_Type add_hexx_type_in,
89
89
const int istep,
90
90
int * two_level_step_in,
91
- const bool restart_in)
91
+ const bool restart_in)
92
92
: OperatorLCAO<TK, TR>(hsk_in, kv_in.kvec_d, hR_in),
93
93
ucell (ucell_in),
94
94
kv(kv_in),
@@ -105,42 +105,75 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
105
105
106
106
if (PARAM.inp .calculation == " nscf" && GlobalC::exx_info.info_global .cal_exx )
107
107
{ // if nscf, read HexxR first and reallocate hR according to the read-in HexxR
108
- const std::string file_name_exx = PARAM.globalv .global_readin_dir + " HexxR" + std::to_string (GlobalV::MY_RANK);
109
- bool all_exist = true ;
110
- for (int is=0 ;is<PARAM.inp .nspin ;++is)
108
+ auto file_name_list_csr = []() -> std::vector<std::string>
111
109
{
112
- std::ifstream ifs (file_name_exx + " _" + std::to_string (is) + " .csr" );
113
- if (!ifs) { all_exist = false ; break ; }
114
- }
115
- if (all_exist)
110
+ std::vector<std::string> file_name_list;
111
+ for (int irank=0 ; irank<PARAM.globalv .nproc ; ++irank) {
112
+ for (int is=0 ;is<PARAM.inp .nspin ;++is) {
113
+ file_name_list.push_back ( PARAM.globalv .global_readin_dir + " HexxR" + std::to_string (irank) + " _" + std::to_string (is) + " .csr" );
114
+ } }
115
+ return file_name_list;
116
+ };
117
+ auto file_name_list_cereal = []() -> std::vector<std::string>
118
+ {
119
+ std::vector<std::string> file_name_list;
120
+ for (int irank=0 ; irank<PARAM.globalv .nproc ; ++irank)
121
+ { file_name_list.push_back ( " HexxR_" + std::to_string (irank) ); }
122
+ return file_name_list;
123
+ };
124
+ auto check_exist = [](const std::vector<std::string> &file_name_list) -> bool
125
+ {
126
+ for (const std::string &file_name : file_name_list)
127
+ {
128
+ std::ifstream ifs (file_name);
129
+ if (!ifs.is_open ())
130
+ { return false ; }
131
+ }
132
+ return true ;
133
+ };
134
+
135
+ std::cout<<" Attention: The number of MPI processes must be strictly identical between SCF and NSCF when computing exact-exchange." <<std::endl;
136
+ if (check_exist (file_name_list_csr ()))
116
137
{
138
+ const std::string file_name_exx_csr = PARAM.globalv .global_readin_dir + " HexxR" + std::to_string (PARAM.globalv .myrank );
117
139
// Read HexxR in CSR format
118
140
if (GlobalC::exx_info.info_ri .real_number )
119
141
{
120
- ModuleIO::read_Hexxs_csr (file_name_exx, ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxd);
121
- if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxd, this ->hR ); }
142
+ ModuleIO::read_Hexxs_csr (file_name_exx_csr, ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxd);
143
+ if (this ->add_hexx_type == Add_Hexx_Type::R)
144
+ { reallocate_hcontainer (*Hexxd, this ->hR ); }
122
145
}
123
146
else
124
147
{
125
- ModuleIO::read_Hexxs_csr (file_name_exx, ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxc);
126
- if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxc, this ->hR ); }
148
+ ModuleIO::read_Hexxs_csr (file_name_exx_csr, ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxc);
149
+ if (this ->add_hexx_type == Add_Hexx_Type::R)
150
+ { reallocate_hcontainer (*Hexxc, this ->hR ); }
127
151
}
128
152
}
129
- else
153
+ else if ( check_exist ( file_name_list_cereal ()))
130
154
{
131
155
// Read HexxR in binary format (old version)
132
- const std::string file_name_exx_cereal = PARAM.globalv .global_readin_dir + " HexxR_" + std::to_string (GlobalV::MY_RANK);
156
+ const std::string file_name_exx_cereal = PARAM.globalv .global_readin_dir + " HexxR_" + std::to_string (PARAM.globalv .myrank );
157
+ std::ifstream ifs (file_name_exx_cereal, std::ios::binary);
158
+ if (!ifs)
159
+ { ModuleBase::WARNING_QUIT (" OperatorEXX" , " Can't open EXX file < " + file_name_exx_cereal + " >." ); }
133
160
if (GlobalC::exx_info.info_ri .real_number )
134
161
{
135
162
ModuleIO::read_Hexxs_cereal (file_name_exx_cereal, *Hexxd);
136
- if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxd, this ->hR ); }
163
+ if (this ->add_hexx_type == Add_Hexx_Type::R)
164
+ { reallocate_hcontainer (*Hexxd, this ->hR ); }
137
165
}
138
166
else
139
167
{
140
168
ModuleIO::read_Hexxs_cereal (file_name_exx_cereal, *Hexxc);
141
- if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxc, this ->hR ); }
169
+ if (this ->add_hexx_type == Add_Hexx_Type::R)
170
+ { reallocate_hcontainer (*Hexxc, this ->hR ); }
142
171
}
143
172
}
173
+ else
174
+ {
175
+ ModuleBase::WARNING_QUIT (" OperatorEXX" , " Can't open EXX file in " + PARAM.globalv .global_readin_dir );
176
+ }
144
177
this ->use_cell_nearest = false ;
145
178
}
146
179
else
@@ -207,7 +240,7 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
207
240
else if (this ->add_hexx_type == Add_Hexx_Type::R)
208
241
{
209
242
// read in Hexx(R)
210
- const std::string restart_HR_path = PARAM.globalv .global_readin_dir + " HexxR" + std::to_string (GlobalV::MY_RANK );
243
+ const std::string restart_HR_path = PARAM.globalv .global_readin_dir + " HexxR" + std::to_string (PARAM. globalv . myrank );
211
244
bool all_exist = true ;
212
245
for (int is = 0 ; is < PARAM.inp .nspin ; ++is)
213
246
{
@@ -227,7 +260,7 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
227
260
else
228
261
{
229
262
// Read HexxR in binary format (old version)
230
- const std::string restart_HR_path_cereal = GlobalC::restart.folder + " HexxR_" + std::to_string (GlobalV::MY_RANK );
263
+ const std::string restart_HR_path_cereal = GlobalC::restart.folder + " HexxR_" + std::to_string (PARAM. globalv . myrank );
231
264
if (GlobalC::exx_info.info_ri .real_number ) {
232
265
ModuleIO::read_Hexxs_cereal (restart_HR_path_cereal, *Hexxd);
233
266
}
0 commit comments