forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal_file.cpp
More file actions
277 lines (250 loc) · 7.24 KB
/
global_file.cpp
File metadata and controls
277 lines (250 loc) · 7.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//==========================================================
// AUTHOR : mohan
// DATE : 2008-11-10
//==========================================================
#include "global_file.h"
#include "global_variable.h"
#include "global_function.h"
#ifdef __MPI
#include "mpi.h"
#endif
#include "../src_parallel/parallel_common.h"
#include "../src_parallel/parallel_reduce.h"
//----------------------------------------------------------
// EXPLAIN : Be Called in input.cpp
//----------------------------------------------------------
namespace ModuleBase
{
void ModuleBase::Global_File::make_dir_out(
const std::string &suffix,
const std::string &calculation,
const bool &out_hs,
const int rank,
const bool &restart,
const bool out_alllog)
//const bool linear_scaling, xiaohui modify 2013-09-01. Attention! Maybe there is some problem.
//const bool out_alllog)
{
//----------------------------------------------------------
// USE STL FUNCTION
// NAME : system
//----------------------------------------------------------
std::string prefix ;
#ifdef __EPM
#ifdef __MPI
prefix = "OUT_EPM_MPI.";
#else
prefix = "OUT_EPM.";
#endif
#else
prefix = "OUT.";
#endif
GlobalV::global_out_dir = prefix + suffix + "/";
GlobalV::global_stru_dir = GlobalV::global_out_dir + "STRU/";
GlobalV::global_matrix_dir = GlobalV::global_out_dir + "matrix_HS/";
#ifdef __MPI
MPI_Barrier(MPI_COMM_WORLD);
#endif
int make_dir = 0;
// mohan update 2011-05-03
std::string command0 = "test -d " + GlobalV::global_out_dir + " || mkdir " + GlobalV::global_out_dir;
int times = 0;
while(times<GlobalV::NPROC)
{
if(rank==times)
{
if ( system( command0.c_str() ) == 0 )
{
std::cout << " MAKE THE DIR : " << GlobalV::global_out_dir << std::endl;
make_dir = 1;
}
else
{
std::cout << " PROC " << rank << " CAN NOT MAKE THE DIR !!! " << std::endl;
make_dir = 0;
}
}
#ifdef __MPI
Parallel_Reduce::reduce_int_all(make_dir);
#endif
if(make_dir>0)break;
++times;
}
#ifdef __MPI
if(make_dir==0)
{
std::cout << " CAN NOT MAKE THE OUT DIR......." << std::endl;
ModuleBase::QUIT();
}
MPI_Barrier(MPI_COMM_WORLD);
#endif
if(calculation == "md" || calculation == "sto-md")
{
int make_dir_stru = 0;
std::string command1 = "test -d " + GlobalV::global_stru_dir + " || mkdir " + GlobalV::global_stru_dir;
times = 0;
while(times<GlobalV::NPROC)
{
if(rank==times)
{
if ( system( command1.c_str() ) == 0 )
{
std::cout << " MAKE THE STRU DIR : " << GlobalV::global_stru_dir << std::endl;
make_dir_stru = 1;
}
else
{
std::cout << " PROC " << rank << " CAN NOT MAKE THE STRU DIR !!! " << std::endl;
make_dir_stru = 0;
}
}
#ifdef __MPI
Parallel_Reduce::reduce_int_all(make_dir_stru);
#endif
if(make_dir_stru>0) break;
++times;
}
#ifdef __MPI
if(make_dir_stru==0)
{
std::cout << " CAN NOT MAKE THE STRU DIR......." << std::endl;
ModuleBase::QUIT();
}
MPI_Barrier(MPI_COMM_WORLD);
#endif
}
// make dir for HS matrix output in md calculation
if(out_hs && (calculation == "md" || calculation == "sto-md"))
{
int make_dir_matrix = 0;
std::string command1 = "test -d " + GlobalV::global_matrix_dir + " || mkdir " + GlobalV::global_matrix_dir;
times = 0;
while(times<GlobalV::NPROC)
{
if(rank==times)
{
if ( system( command1.c_str() ) == 0 )
{
std::cout << " MAKE THE MATRIX DIR : " << GlobalV::global_stru_dir << std::endl;
make_dir_matrix = 1;
}
else
{
std::cout << " PROC " << rank << " CAN NOT MAKE THE MATRIX DIR !!! " << std::endl;
make_dir_matrix = 0;
}
}
#ifdef __MPI
Parallel_Reduce::reduce_int_all(make_dir_matrix);
#endif
if(make_dir_matrix>0) break;
++times;
}
#ifdef __MPI
if(make_dir_matrix==0)
{
std::cout << " CAN NOT MAKE THE MATRIX DIR......." << std::endl;
ModuleBase::QUIT();
}
MPI_Barrier(MPI_COMM_WORLD);
#endif
}
std::stringstream ss,ss1;
// mohan add 2010-09-12
if(out_alllog)
{
ss << "running_" << calculation << "_" << rank + 1;
open_log(GlobalV::ofs_running, ss.str(), calculation, restart);
}
else
{
if(rank==0)
{
ss << "running_" << calculation;
open_log(GlobalV::ofs_running, ss.str(), calculation, restart);
}
}
if(rank==0)
{
open_log(GlobalV::ofs_warning, "warning", calculation, restart);
}
#ifdef GATHER_INFO
open_log(GlobalV::ofs_info, "math_info_" + std::to_string(rank), calculation, restart);
#endif
return;
}
void ModuleBase::Global_File::make_dir_atom(const std::string &label)
{
//----------------------------------------------------------
// EXPLAIN : generate atom dir for each type of atom
//----------------------------------------------------------
std::stringstream ss;
ss << GlobalV::global_out_dir << label << "/";
std::string command1 = "test -d " + ss.str() + " || mkdir " + ss.str();
std::system( command1.c_str() );
return;
}
void ModuleBase::Global_File::open_log(std::ofstream &ofs, const std::string &fn, const std::string &calculation, const bool &restart)
{
//----------------------------------------------------------
// USE GLOBAL VARIABLE :
// GlobalV::global_out_dir : (default dir to store "*.log" file)
//----------------------------------------------------------
std::stringstream ss;
ss << GlobalV::global_out_dir << fn << ".log";
if((calculation == "md" || calculation == "sto-md") && restart)
{
ofs.open( ss.str(), ios::app );
}
else
{
ofs.open( ss.str() );
}
// ofs << " WELCOME TO MESIA PROGRAM." << std::endl;
// ofs << " OPEN "<<fn<<".log"<<" DONE."<<std::endl;
return;
}
void ModuleBase::Global_File::close_log( std::ofstream &ofs,const std::string &fn)
{
if(ofs)
{
ofs.close();
}
ofs << "CLOSE "<<fn<<".log"<<" DONE."<<std::endl;
return;
}
void ModuleBase::Global_File::close_all_log(const int rank, const bool out_alllog)
{
//----------------------------------------------------------
// USE GLOBAL VARIABLES :
// NAME : GlobalV::ofs_running
// NAME : GlobalV::ofs_warning
// NAME : ofs_recon
// NAME : ofs_sph_proj
// NAME : ofs_build
//----------------------------------------------------------
// mohan update 2011-01-13
std::stringstream ss;
if(out_alllog)
{
ss << "running_" << GlobalV::CALCULATION << "_cpu" << rank << ".log";
close_log(GlobalV::ofs_running,ss.str());
}
else
{
if(rank==0)
{
ss << "running_" << GlobalV::CALCULATION << ".log";
close_log(GlobalV::ofs_running,ss.str());
}
}
if (rank==0)
{
close_log(GlobalV::ofs_warning, "warning.log");
}
#ifdef GATHER_INFO
close_log(GlobalV::ofs_info, "math_info");
#endif
return;
}
}