diff --git a/examples/main.c b/examples/main.c index 207bfd1ce410b41784d2dd7c239707158022a0f9..b2fb6cbaa89ab7ed380774d2413368056604a5b9 100644 --- a/examples/main.c +++ b/examples/main.c @@ -546,7 +546,8 @@ int main(int argc, char *argv[]) { /* And initialize the engine with the space and policies. */ if (myrank == 0) clocks_gettime(&tic); - engine_config(1, &e, nr_nodes, myrank, nr_threads, with_aff, talking); + engine_config(1, &e, nr_nodes, myrank, nr_threads, with_aff, talking, + restartfile); if (myrank == 0) { clocks_gettime(&toc); message("engine_config took %.3f %s.", clocks_diff(&tic, &toc), @@ -735,7 +736,8 @@ int main(int argc, char *argv[]) { engine_init(&e, &s, params, N_total[0], N_total[1], engine_policies, talking, &reparttype, &us, &prog_const, &hydro_properties, &gravity_properties, &potential, &cooling_func, &sourceterms); - engine_config(0, &e, nr_nodes, myrank, nr_threads, with_aff, talking); + engine_config(0, &e, nr_nodes, myrank, nr_threads, with_aff, talking, + restartfile); if (myrank == 0) { clocks_gettime(&toc); message("engine_init took %.3f %s.", clocks_diff(&tic, &toc), @@ -840,9 +842,6 @@ int main(int argc, char *argv[]) { /* Print the timers. */ if (with_verbose_timers) timers_print(e.step); - /* Create restart files if required. Time/no. steps?*/ - restart_write(&e, restartfile); - #ifdef SWIFT_DEBUG_TASKS /* Dump the task data using the given frequency. */ if (dump_tasks && (dump_tasks == 1 || j % dump_tasks == 1)) { diff --git a/src/engine.c b/src/engine.c index 517612cad0b2c4700742e436292dae013e900fd5..c172ad76ac0f92ff494dcafa1315d935f00c9251 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3729,10 +3729,11 @@ void engine_prepare(struct engine *e) { #ifdef SWIFT_DEBUG_CHECKS if (e->forcerepart || e->forcerebuild) { /* Check that all cells have been drifted to the current time. - * That can include cells that have not - * previously been active on this rank. */ - space_check_drift_point(e->s, e->ti_old, - e->policy & engine_policy_self_gravity); + * That can include cells that have not previously been active on this + * rank. Skip if haven't got any cells (yet). */ + if (e->s->cells_top != NULL) + space_check_drift_point(e->s, e->ti_old, + e->policy & engine_policy_self_gravity); } #endif @@ -4425,11 +4426,14 @@ void engine_step(struct engine *e) { gravity_exact_force_check(e->s, e, 1e-1); #endif - /* Let's trigger a rebuild every-so-often for good measure */ + /* Let's trigger a non-SPH rebuild every-so-often for good measure */ if (!(e->policy & engine_policy_hydro) && // MATTHIEU improve this (e->policy & engine_policy_self_gravity) && e->step % 20 == 0) e->forcerebuild = 1; + /* XXX for SPH as well */ + e->forcerebuild = (e->step % 20 == 0); + /* Collect the values of rebuild from all nodes and recover the (integer) * end of the next time-step. Do these together to reduce the collective MPI * calls per step, but some of the gathered information is not applied just @@ -4438,9 +4442,8 @@ void engine_step(struct engine *e) { e->forcerebuild = e->collect_group1.forcerebuild; /* Save some statistics ? */ - if (e->time - e->timeLastStatistics >= e->deltaTimeStatistics) { + if (e->time - e->timeLastStatistics >= e->deltaTimeStatistics) e->save_stats = 1; - } /* Do we want a snapshot? */ if (e->ti_end_min >= e->ti_nextSnapshot && e->ti_nextSnapshot > 0) @@ -4448,8 +4451,9 @@ void engine_step(struct engine *e) { /* Drift everybody (i.e. what has not yet been drifted) */ /* to the current time */ - if (e->dump_snapshot || e->forcerebuild || e->forcerepart || e->save_stats) - engine_drift_all(e); + int drifted_all = (e->dump_snapshot || e->forcerebuild || e->forcerepart || + e->save_stats); + if (drifted_all) engine_drift_all(e); /* Write a snapshot ? */ if (e->dump_snapshot) { @@ -4462,6 +4466,7 @@ void engine_step(struct engine *e) { /* Flag that we dumped a snapshot */ e->step_props |= engine_step_prop_snapshot; + } /* Save some statistics */ @@ -4489,6 +4494,11 @@ void engine_step(struct engine *e) { /* Time in ticks at the end of this step. */ e->toc_step = getticks(); #endif + + /* XXX Final job is to create a restart file if needed. For now do this on + * steps we have drifted all on (will need to do that). */ + if (drifted_all) restart_write(e, e->restartfile); + } /** @@ -5196,9 +5206,11 @@ void engine_init(struct engine *e, struct space *s, * @param nr_threads The number of threads per MPI rank. * @param with_aff use processor affinity, if supported. * @param verbose Is this #engine talkative ? + * @param restartfile The name of our restart file. */ void engine_config(int restart, struct engine *e, int nr_nodes, int nodeID, - int nr_threads, int with_aff, int verbose) { + int nr_threads, int with_aff, int verbose, + const char *restartfile) { /* Store the values and initialise global fields. */ e->nr_threads = nr_threads; @@ -5216,6 +5228,7 @@ void engine_config(int restart, struct engine *e, int nr_nodes, int nodeID, e->file_timesteps = NULL; e->verbose = verbose; e->wallclock_time = 0.f; + e->restartfile = restartfile; engine_rank = nodeID; /* Get the number of queues */ diff --git a/src/engine.h b/src/engine.h index 8893e2d3eee22268945ea9a2dfe1c59950f38565..88842b0d4053c65157b06b8e5190f51a92bfd2b4 100644 --- a/src/engine.h +++ b/src/engine.h @@ -286,6 +286,9 @@ struct engine { /* Temporary struct to hold a group of deferable properties (in MPI mode * these are reduced together, but may not be required just yet). */ struct collectgroup1 collect_group1; + + /* Name of the restart file. */ + const char *restartfile; }; /* Function prototypes. */ @@ -309,7 +312,8 @@ void engine_init(struct engine *e, struct space *s, const struct cooling_function_data *cooling_func, struct sourceterms *sourceterms); void engine_config(int restart, struct engine *e, int nr_nodes, int nodeID, - int nr_threads, int with_aff, int verbose); + int nr_threads, int with_aff, int verbose, + const char *restartfile); void engine_launch(struct engine *e); void engine_prepare(struct engine *e); void engine_init_particles(struct engine *e, int flag_entropy_ICs, diff --git a/src/space.c b/src/space.c index 26b6cdd1a4ebcf94d3c20507b8be47c5b7efff48..194f5a145b3f2284700ad4b9c03b3790005d167e 100644 --- a/src/space.c +++ b/src/space.c @@ -3326,6 +3326,18 @@ void space_struct_restore(struct space *s, FILE *stream) { "sparts"); } - /* XXX need to reconnect the gravity parts to their hydro and star particles. - * XXX */ + /* Need to reconnect the gravity parts to their hydro and star particles. */ + /* Re-link the parts. */ + if (s->nr_parts > 0 && s->nr_gparts > 0) + part_relink_parts_to_gparts(s->gparts, s->nr_gparts, s->parts); + + /* Re-link the sparts. */ + if (s->nr_sparts > 0 && s->nr_gparts > 0) + part_relink_sparts_to_gparts(s->gparts, s->nr_gparts, s->sparts); + +#ifdef SWIFT_DEBUG_CHECKS + /* Verify that everything is correct */ + part_verify_links(s->parts, s->gparts, s->sparts, s->nr_parts, s->nr_gparts, + s->nr_sparts, 1); +#endif }