From 45945643d18677278d3833546c9d6e227424b6f6 Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Mon, 29 Jan 2018 15:30:20 +0000 Subject: [PATCH] Save the snapshot counter so we restart correctly Fix issue with attempt to dump partition when not using MPI --- examples/main.c | 2 +- src/engine.c | 5 +++++ src/engine.h | 1 + src/parallel_io.c | 9 ++++----- src/serial_io.c | 9 ++++----- src/single_io.c | 9 ++++----- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/examples/main.c b/examples/main.c index 5afbdbba69..86a6a2c080 100644 --- a/examples/main.c +++ b/examples/main.c @@ -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..."); } diff --git a/src/engine.c b/src/engine.c index 75f35097d9..22befb455b 100644 --- a/src/engine.c +++ b/src/engine.c @@ -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); diff --git a/src/engine.h b/src/engine.h index 452abb2200..c2f6fa63eb 100644 --- a/src/engine.h +++ b/src/engine.h @@ -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; diff --git a/src/parallel_io.c b/src/parallel_io.c index 3e8cadf18a..bc99dd57dd 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -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 */ diff --git a/src/serial_io.c b/src/serial_io.c index 38dd3b3e4d..52a4a71471 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -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 */ diff --git a/src/single_io.c b/src/single_io.c index e8e281b68b..79dc6d43d6 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -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 */ -- GitLab