Commit d6e9e073 authored by Matthieu Schaller's avatar Matthieu Schaller

Restart fixes

parent 4dd854a0
...@@ -780,6 +780,9 @@ int main(int argc, char *argv[]) { ...@@ -780,6 +780,9 @@ int main(int argc, char *argv[]) {
/* Just one restart file. */ /* Just one restart file. */
strcpy(restart_file, restart_files[0]); strcpy(restart_file, restart_files[0]);
/* Finished with the list. */
restart_locate_free(1, restart_files);
#endif #endif
/* Now read it. */ /* Now read it. */
...@@ -1235,7 +1238,7 @@ int main(int argc, char *argv[]) { ...@@ -1235,7 +1238,7 @@ int main(int argc, char *argv[]) {
#endif #endif
if (myrank == 0) if (myrank == 0)
message("Time integration ready to start. End of dry-run."); message("Time integration ready to start. End of dry-run.");
engine_clean(&e, /*fof=*/0); engine_clean(&e, /*fof=*/0, /*restart=*/0);
free(params); free(params);
return 0; return 0;
} }
...@@ -1524,7 +1527,7 @@ int main(int argc, char *argv[]) { ...@@ -1524,7 +1527,7 @@ int main(int argc, char *argv[]) {
if (with_self_gravity) pm_mesh_clean(e.mesh); if (with_self_gravity) pm_mesh_clean(e.mesh);
if (with_cooling || with_temperature) cooling_clean(e.cooling_func); if (with_cooling || with_temperature) cooling_clean(e.cooling_func);
if (with_feedback) feedback_clean(e.feedback_props); if (with_feedback) feedback_clean(e.feedback_props);
engine_clean(&e, /*fof=*/0); engine_clean(&e, /*fof=*/0, restart);
free(params); free(params);
#ifdef WITH_MPI #ifdef WITH_MPI
......
...@@ -698,7 +698,7 @@ int main(int argc, char *argv[]) { ...@@ -698,7 +698,7 @@ int main(int argc, char *argv[]) {
/* Clean everything */ /* Clean everything */
cosmology_clean(&cosmo); cosmology_clean(&cosmo);
pm_mesh_clean(&mesh); pm_mesh_clean(&mesh);
engine_clean(&e, /*fof=*/1); engine_clean(&e, /*fof=*/1, /*restart=*/0);
free(params); free(params);
/* Say goodbye. */ /* Say goodbye. */
......
...@@ -1878,7 +1878,7 @@ void engine_prepare(struct engine *e) { ...@@ -1878,7 +1878,7 @@ void engine_prepare(struct engine *e) {
/* Perform particle splitting. Only if there is a rebuild coming and no /* Perform particle splitting. Only if there is a rebuild coming and no
repartitioning. */ 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 */ /* Let's start by drifting everybody to the current time */
if (!drifted_all) engine_drift_all(e, /*drift_mpole=*/0); if (!drifted_all) engine_drift_all(e, /*drift_mpole=*/0);
...@@ -5182,8 +5182,9 @@ void engine_recompute_displacement_constraint(struct engine *e) { ...@@ -5182,8 +5182,9 @@ void engine_recompute_displacement_constraint(struct engine *e) {
* *
* @param e The #engine to clean. * @param e The #engine to clean.
* @param fof Was this a stand-alone FOF run? * @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. */ /* Start by telling the runners to stop. */
e->step_props = engine_step_prop_done; e->step_props = engine_step_prop_done;
swift_barrier_wait(&e->run_barrier); swift_barrier_wait(&e->run_barrier);
...@@ -5241,6 +5242,39 @@ void engine_clean(struct engine *e, const int fof) { ...@@ -5241,6 +5242,39 @@ void engine_clean(struct engine *e, const int fof) {
fclose(e->sfh_logger); 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) { ...@@ -5324,14 +5358,15 @@ void engine_struct_restore(struct engine *e, FILE *stream) {
e->s = s; e->s = s;
s->e = e; s->e = e;
struct unit_system *us = struct unit_system *internal_us =
(struct unit_system *)malloc(sizeof(struct unit_system)); (struct unit_system *)malloc(sizeof(struct unit_system));
units_struct_restore(us, stream); units_struct_restore(internal_us, stream);
e->internal_units = us; e->internal_units = internal_us;
us = (struct unit_system *)malloc(sizeof(struct unit_system)); struct unit_system *snap_us =
units_struct_restore(us, stream); (struct unit_system *)malloc(sizeof(struct unit_system));
e->snapshot_units = us; units_struct_restore(snap_us, stream);
e->snapshot_units = snap_us;
struct cosmology *cosmo = struct cosmology *cosmo =
(struct cosmology *)malloc(sizeof(struct cosmology)); (struct cosmology *)malloc(sizeof(struct cosmology));
......
...@@ -565,7 +565,7 @@ void engine_print_policy(struct engine *e); ...@@ -565,7 +565,7 @@ void engine_print_policy(struct engine *e);
int engine_is_done(struct engine *e); int engine_is_done(struct engine *e);
void engine_pin(void); void engine_pin(void);
void engine_unpin(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); int engine_estimate_nr_tasks(const struct engine *e);
void engine_print_task_counts(const struct engine *e); void engine_print_task_counts(const struct engine *e);
void engine_fof(struct engine *e, const int dump_results, void engine_fof(struct engine *e, const int dump_results,
......
Markdown is supported
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