1414#include < cerrno>
1515#include < sstream>
1616#include " global_function.h"
17- #include " source_io/module_parameter/parameter.h"
1817#include " global_variable.h"
1918#include " source_base/parallel_common.h"
2019#include " source_base/parallel_reduce.h"
@@ -31,7 +30,16 @@ void ModuleBase::Global_File::make_dir_out(
3130 const bool &out_wfc_dir,
3231 const int rank,
3332 const bool &restart,
34- const bool out_alllog)
33+ const bool out_alllog,
34+ const std::string &global_out_dir,
35+ const std::string &global_stru_dir,
36+ const std::string &global_matrix_dir,
37+ const std::string &global_wfc_dir,
38+ const std::string &global_mlkedf_descriptor_dir,
39+ const std::string &global_deepks_label_elec_dir,
40+ const std::string &log_file,
41+ const bool of_ml_gene_data,
42+ const bool deepks_out_freq_elec)
3543{
3644// ----------------------------------------------------------
3745// USE STL FUNCTION
@@ -43,17 +51,16 @@ void ModuleBase::Global_File::make_dir_out(
4351#endif
4452 int make_dir = 0 ;
4553 // mohan update 2011-05-03
46- // std::string command0 = "test -d " + PARAM.globalv.global_out_dir + " || mkdir " + PARAM.globalv.global_out_dir;
4754
4855 int times = 0 ;
4956 while (times<GlobalV::NPROC )
5057 {
5158 if (rank==times)
5259 {
53- int ret = mkdir (PARAM . globalv . global_out_dir .c_str (), 0755 );
60+ int ret = mkdir (global_out_dir.c_str (), 0755 );
5461 if ( ret == 0 || errno == EEXIST )
5562 {
56- std::cout << " MAKE THE DIR : " << PARAM . globalv . global_out_dir << std::endl;
63+ std::cout << " MAKE THE DIR : " << global_out_dir << std::endl;
5764 make_dir = 1 ;
5865 }
5966 else
@@ -82,17 +89,16 @@ void ModuleBase::Global_File::make_dir_out(
8289 if (calculation == " md" )
8390 {
8491 int make_dir_stru = 0 ;
85- // std::string command1 = "test -d " + PARAM.globalv.global_stru_dir + " || mkdir " + PARAM.globalv.global_stru_dir;
8692
8793 times = 0 ;
8894 while (times<GlobalV::NPROC )
8995 {
9096 if (rank==times)
9197 {
92- int ret = mkdir (PARAM . globalv . global_stru_dir .c_str (), 0755 );
98+ int ret = mkdir (global_stru_dir.c_str (), 0755 );
9399 if ( ret == 0 || errno == EEXIST )
94100 {
95- std::cout << " MAKE THE STRU DIR : " << PARAM . globalv . global_stru_dir << std::endl;
101+ std::cout << " MAKE THE STRU DIR : " << global_stru_dir << std::endl;
96102 make_dir_stru = 1 ;
97103 }
98104 else
@@ -123,17 +129,16 @@ void ModuleBase::Global_File::make_dir_out(
123129 if ((out_dir) && calculation == " md" )
124130 {
125131 int make_dir_matrix = 0 ;
126- // std::string command1 = "test -d " + PARAM.globalv.global_matrix_dir + " || mkdir " + PARAM.globalv.global_matrix_dir;
127132
128133 times = 0 ;
129134 while (times<GlobalV::NPROC )
130135 {
131136 if (rank==times)
132137 {
133- int ret = mkdir (PARAM . globalv . global_matrix_dir .c_str (), 0755 );
138+ int ret = mkdir (global_matrix_dir.c_str (), 0755 );
134139 if ( ret == 0 || errno == EEXIST )
135140 {
136- std::cout << " MAKE THE MATRIX DIR : " << PARAM . globalv . global_matrix_dir << std::endl;
141+ std::cout << " MAKE THE MATRIX DIR : " << global_matrix_dir << std::endl;
137142 make_dir_matrix = 1 ;
138143 }
139144 else
@@ -163,17 +168,16 @@ void ModuleBase::Global_File::make_dir_out(
163168 if (out_wfc_dir)
164169 {
165170 int make_dir_wfc = 0 ;
166- // std::string command1 = "test -d " + PARAM.globalv.global_wfc_dir + " || mkdir " + PARAM.globalv.global_wfc_dir;
167171
168172 times = 0 ;
169173 while (times<GlobalV::NPROC )
170174 {
171175 if (rank==times)
172176 {
173- int ret = mkdir (PARAM . globalv . global_wfc_dir .c_str (), 0755 );
177+ int ret = mkdir (global_wfc_dir.c_str (), 0755 );
174178 if ( ret == 0 || errno == EEXIST )
175179 {
176- std::cout << " MAKE THE WFC DIR : " << PARAM . globalv . global_wfc_dir << std::endl;
180+ std::cout << " MAKE THE WFC DIR : " << global_wfc_dir << std::endl;
177181 make_dir_wfc = 1 ;
178182 }
179183 else
@@ -200,20 +204,19 @@ void ModuleBase::Global_File::make_dir_out(
200204#endif
201205 }
202206
203- if (PARAM . inp . of_ml_gene_data == 1 )
207+ if (of_ml_gene_data)
204208 {
205209 int make_dir_descrip = 0 ;
206- // std::string command1 = "test -d " + PARAM.globalv.global_mlkedf_descriptor_dir + " || mkdir " + PARAM.globalv.global_mlkedf_descriptor_dir;
207210
208211 times = 0 ;
209212 while (times<GlobalV::NPROC )
210213 {
211214 if (rank==times)
212215 {
213- int ret = mkdir (PARAM . globalv . global_mlkedf_descriptor_dir .c_str (), 0755 );
216+ int ret = mkdir (global_mlkedf_descriptor_dir.c_str (), 0755 );
214217 if ( ret == 0 || errno == EEXIST )
215218 {
216- std::cout << " MAKE THE MLKEDF DESCRIPTOR DIR : " << PARAM . globalv . global_mlkedf_descriptor_dir << std::endl;
219+ std::cout << " MAKE THE MLKEDF DESCRIPTOR DIR : " << global_mlkedf_descriptor_dir << std::endl;
217220 make_dir_descrip = 1 ;
218221 }
219222 else
@@ -226,7 +229,7 @@ void ModuleBase::Global_File::make_dir_out(
226229 Parallel_Reduce::reduce_all (make_dir_descrip);
227230#endif
228231 if (make_dir_descrip > 0 )
229- {
232+ {
230233 break ;
231234 }
232235 ++times;
@@ -242,20 +245,19 @@ void ModuleBase::Global_File::make_dir_out(
242245#endif
243246 }
244247
245- if (PARAM . inp . deepks_out_freq_elec > 0 )
248+ if (deepks_out_freq_elec)
246249 {
247250 int make_dir_deepks_elec = 0 ;
248- // std::string command1 = "test -d " + PARAM.globalv.global_deepks_label_elec_dir + " || mkdir " + PARAM.globalv.global_deepks_label_elec_dir;
249251
250252 times = 0 ;
251253 while (times<GlobalV::NPROC )
252254 {
253255 if (rank==times)
254256 {
255- int ret = mkdir (PARAM . globalv . global_deepks_label_elec_dir .c_str (), 0755 );
257+ int ret = mkdir (global_deepks_label_elec_dir.c_str (), 0755 );
256258 if ( ret == 0 || errno == EEXIST )
257259 {
258- std::cout << " MAKE THE DEEPKS LABELS (ELEC) DIR : " << PARAM . globalv . global_deepks_label_elec_dir << std::endl;
260+ std::cout << " MAKE THE DEEPKS LABELS (ELEC) DIR : " << global_deepks_label_elec_dir << std::endl;
259261 make_dir_deepks_elec = 1 ;
260262 }
261263 else
@@ -268,7 +270,7 @@ void ModuleBase::Global_File::make_dir_out(
268270 Parallel_Reduce::reduce_all (make_dir_deepks_elec);
269271#endif
270272 if (make_dir_deepks_elec > 0 )
271- {
273+ {
272274 break ;
273275 }
274276 ++times;
@@ -287,53 +289,53 @@ void ModuleBase::Global_File::make_dir_out(
287289 // mohan add 2010-09-12
288290 if (out_alllog)
289291 {
290- open_log (GlobalV::ofs_running, PARAM . globalv . log_file , calculation, restart);
292+ open_log (GlobalV::ofs_running, log_file, calculation, restart, global_out_dir );
291293 #if defined(__CUDA) || defined(__ROCM)
292- open_log (GlobalV::ofs_device, " device" + std::to_string (rank) + " .log" , calculation, restart);
294+ open_log (GlobalV::ofs_device, " device" + std::to_string (rank) + " .log" , calculation, restart, global_out_dir );
293295 #endif
294296 }
295297 else
296298 {
297299 if (rank==0 )
298300 {
299- open_log (GlobalV::ofs_running, PARAM . globalv . log_file , calculation, restart);
301+ open_log (GlobalV::ofs_running, log_file, calculation, restart, global_out_dir );
300302 #if defined(__CUDA) || defined(__ROCM)
301- open_log (GlobalV::ofs_device, " device.log" , calculation, restart);
303+ open_log (GlobalV::ofs_device, " device.log" , calculation, restart, global_out_dir );
302304 #endif
303305 }
304306 }
305307
306308 if (rank==0 )
307309 {
308- open_log (GlobalV::ofs_warning, " warning.log" , calculation, restart);
310+ open_log (GlobalV::ofs_warning, " warning.log" , calculation, restart, global_out_dir );
309311 }
310312
311313#ifdef GATHER_INFO
312- open_log (GlobalV::ofs_info, " math_info_" + std::to_string (rank) + " .log" , calculation, restart);
314+ open_log (GlobalV::ofs_info, " math_info_" + std::to_string (rank) + " .log" , calculation, restart, global_out_dir );
313315#endif
314316
315317 return ;
316318}
317319
318- void ModuleBase::Global_File::make_dir_atom (const std::string &label)
320+ void ModuleBase::Global_File::make_dir_atom (const std::string &label, const std::string &global_out_dir )
319321{
320322// ----------------------------------------------------------
321323// EXPLAIN : generate atom dir for each type of atom
322324// ----------------------------------------------------------
323325 std::stringstream ss;
324- ss << PARAM . globalv . global_out_dir << label << " /" ;
326+ ss << global_out_dir << label << " /" ;
325327 ModuleBase::GlobalFunc::MAKE_DIR (ss.str ());
326328 return ;
327329}
328330
329- void ModuleBase::Global_File::open_log (std::ofstream &ofs, const std::string &fn, const std::string &calculation, const bool &restart)
331+ void ModuleBase::Global_File::open_log (std::ofstream &ofs, const std::string &fn, const std::string &calculation, const bool &restart, const std::string &global_out_dir )
330332{
331333// ----------------------------------------------------------
332334// USE GLOBAL VARIABLE :
333- // PARAM.globalv. global_out_dir : (default dir to store "*.log" file)
335+ // global_out_dir : (default dir to store "*.log" file)
334336// ----------------------------------------------------------
335337 std::stringstream ss;
336- ss << PARAM . globalv . global_out_dir << fn;
338+ ss << global_out_dir << fn;
337339
338340 if (calculation == " md" && restart)
339341 {
0 commit comments