diff --git a/examples/main.c b/examples/main.c index e197830459c6b3ba7c888c66527871b91c1d988a..b3e85987d753d1f54c01dc68e64efce12d34d4f5 100644 --- a/examples/main.c +++ b/examples/main.c @@ -780,6 +780,9 @@ int main(int argc, char *argv[]) { /* Just one restart file. */ strcpy(restart_file, restart_files[0]); + + /* Finished with the list. */ + restart_locate_free(1, restart_files); #endif /* Now read it. */ @@ -1235,7 +1238,7 @@ int main(int argc, char *argv[]) { #endif if (myrank == 0) message("Time integration ready to start. End of dry-run."); - engine_clean(&e, /*fof=*/0); + engine_clean(&e, /*fof=*/0, /*restart=*/0); free(params); return 0; } @@ -1524,7 +1527,7 @@ int main(int argc, char *argv[]) { if (with_self_gravity) pm_mesh_clean(e.mesh); if (with_cooling || with_temperature) cooling_clean(e.cooling_func); if (with_feedback) feedback_clean(e.feedback_props); - engine_clean(&e, /*fof=*/0); + engine_clean(&e, /*fof=*/0, restart); free(params); #ifdef WITH_MPI diff --git a/examples/main_fof.c b/examples/main_fof.c index d566099137893366378ea632c17a2b1d3932105e..aa5de58a5616282399d82716a4733e9289539b1e 100644 --- a/examples/main_fof.c +++ b/examples/main_fof.c @@ -698,7 +698,7 @@ int main(int argc, char *argv[]) { /* Clean everything */ cosmology_clean(&cosmo); pm_mesh_clean(&mesh); - engine_clean(&e, /*fof=*/1); + engine_clean(&e, /*fof=*/1, /*restart=*/0); free(params); /* Say goodbye. */ diff --git a/src/engine.c b/src/engine.c index 2d9d1b9d4ee027bbcec6e9fbd2d752dd37455860..e0316f0e541cff8671041fc5cc9f351625d94109 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1878,7 +1878,7 @@ void engine_prepare(struct engine *e) { /* Perform particle splitting. Only if there is a rebuild coming and no repartitioning. */ - if (e->forcerebuild && !e->forcerepart && e->step > 1) { + if (!e->restarting && e->forcerebuild && !e->forcerepart && e->step > 1) { /* Let's start by drifting everybody to the current time */ if (!drifted_all) engine_drift_all(e, /*drift_mpole=*/0); @@ -5182,8 +5182,9 @@ void engine_recompute_displacement_constraint(struct engine *e) { * * @param e The #engine to clean. * @param fof Was this a stand-alone FOF run? + * @param restart Was this a run that was restarted from check-point files? */ -void engine_clean(struct engine *e, const int fof) { +void engine_clean(struct engine *e, const int fof, const int restart) { /* Start by telling the runners to stop. */ e->step_props = engine_step_prop_done; swift_barrier_wait(&e->run_barrier); @@ -5241,6 +5242,39 @@ void engine_clean(struct engine *e, const int fof) { fclose(e->sfh_logger); } } + + /* If the run was restarted, we should also free the memory allocated + in engine_struct_restore() */ + if (restart) { + free((void *)e->parameter_file); + free((void *)e->external_potential); + free((void *)e->black_holes_properties); + free((void *)e->stars_properties); + free((void *)e->gravity_properties); + free((void *)e->hydro_properties); + free((void *)e->physical_constants); + free((void *)e->internal_units); + free((void *)e->cosmology); + free((void *)e->mesh); + free((void *)e->chemistry); + free((void *)e->entropy_floor); + free((void *)e->cooling_func); + free((void *)e->star_formation); + free((void *)e->feedback_props); +#ifdef WITH_FOF + free((void *)e->fof_properties); +#endif +#ifdef WITH_MPI + free((void *)e->reparttype); +#endif + if (e->output_list_snapshots) free((void *)e->output_list_snapshots); + if (e->output_list_stats) free((void *)e->output_list_stats); + if (e->output_list_stf) free((void *)e->output_list_stf); +#ifdef WITH_LOGGER + if (e->policy & engine_policy_logger) free((void *)e->logger); +#endif + free(e->s); + } } /** @@ -5324,14 +5358,15 @@ void engine_struct_restore(struct engine *e, FILE *stream) { e->s = s; s->e = e; - struct unit_system *us = + struct unit_system *internal_us = (struct unit_system *)malloc(sizeof(struct unit_system)); - units_struct_restore(us, stream); - e->internal_units = us; + units_struct_restore(internal_us, stream); + e->internal_units = internal_us; - us = (struct unit_system *)malloc(sizeof(struct unit_system)); - units_struct_restore(us, stream); - e->snapshot_units = us; + struct unit_system *snap_us = + (struct unit_system *)malloc(sizeof(struct unit_system)); + units_struct_restore(snap_us, stream); + e->snapshot_units = snap_us; struct cosmology *cosmo = (struct cosmology *)malloc(sizeof(struct cosmology)); diff --git a/src/engine.h b/src/engine.h index 27cfd8dd0fab1d62b3c679dbd7ae2aa964c99ec1..d3cf0c99a13d71573bb5dca5e39ec30bca1c9332 100644 --- a/src/engine.h +++ b/src/engine.h @@ -565,7 +565,7 @@ void engine_print_policy(struct engine *e); int engine_is_done(struct engine *e); void engine_pin(void); void engine_unpin(void); -void engine_clean(struct engine *e, const int fof); +void engine_clean(struct engine *e, const int fof, const int restart); int engine_estimate_nr_tasks(const struct engine *e); void engine_print_task_counts(const struct engine *e); void engine_fof(struct engine *e, const int dump_results,