Skip to content

Commit 503f08b

Browse files
Merge pull request #198 from EXP-code/RestartFixHDF5
Enable checkpoint restart for OutHDF5
2 parents 5dac382 + 3c25d76 commit 503f08b

2 files changed

Lines changed: 43 additions & 26 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ src/exp
2525
src/user/CylindricalDisk.cc
2626
src/user/EllipsoidForce.cc
2727
src/user/SLSphere.cc
28+
_codeql_detected_source_root

src/OutHDF5.cc

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,13 @@ void OutHDF5::initialize()
175175
//
176176
if (directory) {
177177
std::ostringstream dname;
178-
dname << outdir
179-
<< filename << "_" << setw(5) << setfill('0') << nbeg;
178+
179+
if (chkpt)
180+
dname << outdir
181+
<< "checkpoint_" << runtag;
182+
else
183+
dname << outdir
184+
<< filename << "_" << setw(5) << setfill('0') << nbeg;
180185

181186
std::filesystem::path dir_path = dname.str();
182187

@@ -187,9 +192,16 @@ void OutHDF5::initialize()
187192
}
188193
else {
189194
std::ostringstream fname;
190-
fname << outdir
191-
<< filename << "_" << setw(5) << setfill('0') << nbeg
192-
<< ".1";
195+
196+
if (chkpt) {
197+
fname << outdir
198+
<< "checkpoint_" << runtag;
199+
if (numprocs>1) fname << ".1";
200+
} else {
201+
fname << outdir
202+
<< filename << "_" << setw(5) << setfill('0') << nbeg
203+
<< ".1";
204+
}
193205

194206
std::filesystem::path file_path = fname.str();
195207

@@ -200,31 +212,35 @@ void OutHDF5::initialize()
200212

201213
// Find starting index
202214
//
203-
for (; nbeg<100000; nbeg++) {
204-
// Path name
205-
//
206-
std::ostringstream fname;
207-
fname << outdir
208-
<< filename << "_" << setw(5) << setfill('0') << nbeg;
209-
210-
if (not directory) fname << ".1";
211-
212-
std::filesystem::path path = fname.str();
213-
214-
// See if we can open the directory or file
215-
//
216-
if (directory) {
217-
if (not std::filesystem::is_directory(path)) break;
218-
} else
219-
if (not std::filesystem::is_regular_file(path)) break;
215+
if (not chkpt) {
216+
for (; nbeg<100000; nbeg++) {
217+
// Path name
218+
//
219+
std::ostringstream fname;
220+
fname << outdir
221+
<< filename << "_" << setw(5) << setfill('0') << nbeg;
222+
223+
if (not directory) fname << ".1";
224+
225+
std::filesystem::path path = fname.str();
226+
227+
// See if we can open the directory or file
228+
//
229+
if (directory) {
230+
if (not std::filesystem::is_directory(path)) break;
231+
} else
232+
if (not std::filesystem::is_regular_file(path)) break;
233+
}
234+
235+
std::cout << "---- OutHDF5: found last file <" << nbeg << ">" << std::endl;
220236
}
221-
222-
std::cout << "---- OutHDF5: found last file <" << nbeg << ">" << std::endl;
237+
// END: snapshot mode loop
223238
}
239+
// END: root node read
224240

225-
// Communicate starting file index to all nodes
241+
// Communicate starting file index to all nodes for snapshot mode
226242
//
227-
MPI_Bcast(&nbeg, 1, MPI_INT, 0, MPI_COMM_WORLD);
243+
if (not chkpt) MPI_Bcast(&nbeg, 1, MPI_INT, 0, MPI_COMM_WORLD);
228244
}
229245

230246
return;

0 commit comments

Comments
 (0)