Commit 45945643 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Save the snapshot counter so we restart correctly

Fix issue with attempt to dump partition when not using MPI
parent 93542fc8
......@@ -858,7 +858,7 @@ int main(int argc, char *argv[]) {
* files. */
if (j % restart_stop_steps == 0) {
force_stop = restart_stop_now(restart_dir, 0);
if (myrank == 0)
if (myrank == 0 && force_stop)
message("Forcing application exit, dumping restart files...");
}
......
......@@ -5211,6 +5211,7 @@ void engine_init(
parser_get_opt_param_int(params, "Snapshots:compression", 0);
e->snapshotUnits = malloc(sizeof(struct unit_system));
units_init_default(e->snapshotUnits, params, "Snapshots", internal_units);
e->snapshotOutputCount = 0;
e->dt_min = parser_get_param_double(params, "TimeIntegration:dt_min");
e->dt_max = parser_get_param_double(params, "TimeIntegration:dt_max");
e->deltaTimeStatistics =
......@@ -5802,9 +5803,11 @@ void engine_struct_dump(struct engine *e, FILE *stream) {
units_struct_dump(e->internal_units, stream);
units_struct_dump(e->snapshotUnits, stream);
#ifdef WITH_MPI
/* Save the partition for restoration. */
partition_store_celllist(e->s, e->reparttype);
partition_struct_dump(e->reparttype, stream);
#endif
phys_const_struct_dump(e->physical_constants, stream);
hydro_props_struct_dump(e->hydro_properties, stream);
......@@ -5848,9 +5851,11 @@ void engine_struct_restore(struct engine *e, FILE *stream) {
units_struct_restore(us, stream);
e->snapshotUnits = us;
#ifdef WITH_MPI
struct repartition *reparttype = malloc(sizeof(struct repartition));
partition_struct_restore(reparttype, stream);
e->reparttype = reparttype;
#endif
struct phys_const *physical_constants = malloc(sizeof(struct phys_const));
phys_const_struct_restore(physical_constants, stream);
......
......@@ -195,6 +195,7 @@ struct engine {
char snapshotBaseName[PARSER_MAX_LINE_SIZE];
int snapshotCompression;
struct unit_system *snapshotUnits;
int snapshotOutputCount;
/* Statistics information */
FILE *file_stats;
......
......@@ -833,7 +833,6 @@ void write_output_parallel(struct engine* e, const char* baseName,
struct gpart* gparts = e->s->gparts;
struct gpart* dmparts = NULL;
struct spart* sparts = e->s->sparts;
static int outputCount = 0;
FILE* xmfFile = 0;
/* Number of unassociated gparts */
......@@ -842,10 +841,10 @@ void write_output_parallel(struct engine* e, const char* baseName,
/* File name */
char fileName[FILENAME_BUFFER_SIZE];
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
outputCount);
e->snapshotOutputCount);
/* First time, we need to create the XMF file */
if (outputCount == 0 && mpi_rank == 0) xmf_create_file(baseName);
if (e->snapshotOutputCount == 0 && mpi_rank == 0) xmf_create_file(baseName);
/* Prepare the XMF file for the new entry */
if (mpi_rank == 0) xmfFile = xmf_prepare_file(baseName);
......@@ -1158,7 +1157,7 @@ void write_output_parallel(struct engine* e, const char* baseName,
#endif
/* Write LXMF file descriptor */
if (mpi_rank == 0) xmf_write_outputfooter(xmfFile, outputCount, e->time);
if (mpi_rank == 0) xmf_write_outputfooter(xmfFile, e->snapshotOutputCount, e->time);
#ifdef IO_SPEED_MEASUREMENT
MPI_Barrier(MPI_COMM_WORLD);
......@@ -1193,7 +1192,7 @@ void write_output_parallel(struct engine* e, const char* baseName,
clocks_getunit());
#endif
++outputCount;
e->snapshotOutputCount++;
}
#endif /* HAVE_HDF5 */
......@@ -712,7 +712,6 @@ void write_output_serial(struct engine* e, const char* baseName,
struct gpart* gparts = e->s->gparts;
struct gpart* dmparts = NULL;
struct spart* sparts = e->s->sparts;
static int outputCount = 0;
FILE* xmfFile = 0;
/* Number of unassociated gparts */
......@@ -721,7 +720,7 @@ void write_output_serial(struct engine* e, const char* baseName,
/* File name */
char fileName[FILENAME_BUFFER_SIZE];
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
outputCount);
e->snapshotOutputCount);
/* Compute offset in the file and total number of particles */
size_t N[swift_type_count] = {Ngas, Ndm, 0, 0, Nstars, 0};
......@@ -741,7 +740,7 @@ void write_output_serial(struct engine* e, const char* baseName,
if (mpi_rank == 0) {
/* First time, we need to create the XMF file */
if (outputCount == 0) xmf_create_file(baseName);
if (e->snapshotOutputCount == 0) xmf_create_file(baseName);
/* Prepare the XMF file for the new entry */
xmfFile = xmf_prepare_file(baseName);
......@@ -1002,10 +1001,10 @@ void write_output_serial(struct engine* e, const char* baseName,
}
/* Write footer of LXMF file descriptor */
if (mpi_rank == 0) xmf_write_outputfooter(xmfFile, outputCount, e->time);
if (mpi_rank == 0) xmf_write_outputfooter(xmfFile, e->snapshotOutputCount, e->time);
/* message("Done writing particles..."); */
++outputCount;
e->snapshotOutputCount++;
}
#endif /* HAVE_HDF5 && HAVE_MPI */
......@@ -577,7 +577,6 @@ void write_output_single(struct engine* e, const char* baseName,
struct gpart* gparts = e->s->gparts;
struct gpart* dmparts = NULL;
struct spart* sparts = e->s->sparts;
static int outputCount = 0;
/* Number of unassociated gparts */
const size_t Ndm = Ntot > 0 ? Ntot - (Ngas + Nstars) : 0;
......@@ -587,10 +586,10 @@ void write_output_single(struct engine* e, const char* baseName,
/* File name */
char fileName[FILENAME_BUFFER_SIZE];
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
outputCount);
e->snapshotOutputCount);
/* First time, we need to create the XMF file */
if (outputCount == 0) xmf_create_file(baseName);
if (e->snapshotOutputCount == 0) xmf_create_file(baseName);
/* Prepare the XMF file for the new entry */
FILE* xmfFile = 0;
......@@ -807,14 +806,14 @@ void write_output_single(struct engine* e, const char* baseName,
}
/* Write LXMF file descriptor */
xmf_write_outputfooter(xmfFile, outputCount, e->time);
xmf_write_outputfooter(xmfFile, e->snapshotOutputCount, e->time);
/* message("Done writing particles..."); */
/* Close file */
H5Fclose(h_file);
++outputCount;
e->snapshotOutputCount++;
}
#endif /* HAVE_HDF5 */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment