diff --git a/examples/main.c b/examples/main.c index e581bfdaadd3b8ca64aea89bac6e4f7d19b7eb27..f349b8e004eae95937a3a219edd8282e6bea2484 100644 --- a/examples/main.c +++ b/examples/main.c @@ -1088,7 +1088,7 @@ int main(int argc, char *argv[]) { #endif if (myrank == 0) message("Time integration ready to start. End of dry-run."); - engine_clean(&e); + engine_clean(&e, /*fof=*/0); free(params); return 0; } @@ -1325,7 +1325,7 @@ int main(int argc, char *argv[]) { if (with_cosmology) cosmology_clean(e.cosmology); if (with_self_gravity) pm_mesh_clean(e.mesh); if (with_cooling || with_temperature) cooling_clean(&cooling_func); - engine_clean(&e); + engine_clean(&e, /*fof=*/0); free(params); /* Say goodbye. */ diff --git a/examples/main_fof.c b/examples/main_fof.c index 13bebc1a4f1baf924a1e0e082c5b14cdad73f1af..2a3822756516ce8fe37610d901a6c67e9f042999 100644 --- a/examples/main_fof.c +++ b/examples/main_fof.c @@ -90,7 +90,6 @@ int main(int argc, char *argv[]) { struct pm_mesh mesh; struct gpart *gparts = NULL; struct gravity_props gravity_properties; - struct hydro_props hydro_properties; struct fof_props fof_properties; struct part *parts = NULL; struct phys_const prog_const; @@ -99,6 +98,10 @@ int main(int argc, char *argv[]) { struct bpart *bparts = NULL; struct unit_system us; + int with_stars = 0; + int with_black_holes = 0; + int with_hydro = 0; + int nr_nodes = 1, myrank = 0; #ifdef WITH_MPI @@ -158,6 +161,11 @@ int main(int argc, char *argv[]) { OPT_HELP(), OPT_GROUP(" Simulation options:\n"), + OPT_BOOLEAN('s', "hydro", &with_hydro, "Run with hydrodynamics.", NULL, 0, + 0), + OPT_BOOLEAN('S', "stars", &with_stars, "Run with stars.", NULL, 0, 0), + OPT_BOOLEAN('B', "black-holes", &with_black_holes, + "Run with black holes.", NULL, 0, 0), OPT_GROUP(" Control options:\n"), OPT_BOOLEAN('a', "pin", &with_aff, @@ -373,9 +381,6 @@ int main(int argc, char *argv[]) { } #endif - /* Common variables for restart and IC sections. */ - int flag_entropy_ICs = 0; - /* Initialize unit system and constants */ units_init_from_params(&us, params, "InternalUnitSystem"); phys_const_init(&us, params, &prog_const); @@ -408,9 +413,6 @@ int main(int argc, char *argv[]) { gravity_props_init(&gravity_properties, params, &cosmo, /*with_cosmology=*/1, periodic); - /* Initialise the hydro scheme */ - hydro_props_init(&hydro_properties, &prog_const, &us, params); - /* Initialise the FOF properties */ bzero(&fof_properties, sizeof(struct fof_props)); if (with_fof) fof_init(&fof_properties, params, &prog_const, &us); @@ -424,6 +426,7 @@ int main(int argc, char *argv[]) { fflush(stdout); /* Get ready to read particles of all kinds */ + int flag_entropy_ICs = 0; size_t Ngas = 0, Ngpart = 0, Nspart = 0, Nbpart = 0; double dim[3] = {0., 0., 0.}; if (myrank == 0) clocks_gettime(&tic); @@ -432,23 +435,21 @@ int main(int argc, char *argv[]) { #if defined(HAVE_PARALLEL_HDF5) read_ic_parallel(ICfileName, &us, dim, &parts, &gparts, &sparts, &bparts, &Ngas, &Ngpart, &Nspart, &Nbpart, &flag_entropy_ICs, - /*with_hydro=*/1, /*with_grav=*/1, - /*with_stars=*/1, /*with_black_holes=*/1, cleanup_h, - cleanup_sqrt_a, cosmo.h, cosmo.a, myrank, nr_nodes, - MPI_COMM_WORLD, MPI_INFO_NULL, nr_threads, /*dry_run=*/0); + with_hydro, /*with_grav=*/1, with_stars, with_black_holes, + cleanup_h, cleanup_sqrt_a, cosmo.h, cosmo.a, myrank, + nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL, nr_threads, + /*dry_run=*/0); #else read_ic_serial(ICfileName, &us, dim, &parts, &gparts, &sparts, &bparts, &Ngas, - &Ngpart, &Nspart, &Nbpart, &flag_entropy_ICs, - /*with_hydro=*/1, /*with_grav=*/1, - /*with_stars=*/1, /*with_black_holes=*/1, cleanup_h, + &Ngpart, &Nspart, &Nbpart, &flag_entropy_ICs, with_hydro, + /*with_grav=*/1, with_stars, with_black_holes, cleanup_h, cleanup_sqrt_a, cosmo.h, cosmo.a, myrank, nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL, nr_threads, /*dry_run=*/0); #endif #else read_ic_single(ICfileName, &us, dim, &parts, &gparts, &sparts, &bparts, &Ngas, - &Ngpart, &Nspart, &Nbpart, &flag_entropy_ICs, - /*with_hydro=*/1, /*with_grav=*/1, - /*with_stars=*/1, /*with_black_holes=*/1, cleanup_h, + &Ngpart, &Nspart, &Nbpart, &flag_entropy_ICs, with_hydro, + /*with_grav=*/1, with_stars, with_black_holes, cleanup_h, cleanup_sqrt_a, cosmo.h, cosmo.a, nr_threads, /*dry_run=*/0); #endif #endif @@ -548,7 +549,8 @@ int main(int argc, char *argv[]) { if (myrank == 0) clocks_gettime(&tic); engine_init(&e, &s, params, N_total[0], N_total[1], N_total[2], N_total[3], engine_policies, talking, &reparttype, &us, &prog_const, &cosmo, - &hydro_properties, /*entropy_floor=*/NULL, &gravity_properties, + /*hydro_properties=*/NULL, /*entropy_floor=*/NULL, + &gravity_properties, /*stars_properties=*/NULL, /*black_holes_properties=*/NULL, /*feedback_properties=*/NULL, &mesh, /*potential=*/NULL, /*cooling_func=*/NULL, @@ -660,7 +662,7 @@ int main(int argc, char *argv[]) { /* Clean everything */ cosmology_clean(&cosmo); pm_mesh_clean(&mesh); - engine_clean(&e); + engine_clean(&e, /*fof=*/1); free(params); /* Say goodbye. */ diff --git a/src/engine.c b/src/engine.c index 64e63b334e77bef6aa447808060a876aec141bc1..64c7afbb1491efee8f89d7a8e3f3a1dc3c6ab6d0 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5263,8 +5263,8 @@ void engine_config(int restart, int fof, struct engine *e, #endif } - /* Open some files */ - if (e->nodeID == 0) { + /* Open some global files */ + if (!fof && e->nodeID == 0) { /* When restarting append to these files. */ const char *mode; @@ -5310,11 +5310,10 @@ void engine_config(int restart, int fof, struct engine *e, "+/- %.4f\n# Eta: %f\n# Config: %s\n# CFLAGS: %s\n", hostname(), git_branch(), git_revision(), compiler_name(), compiler_version(), e->nr_threads, e->nr_nodes, SPH_IMPLEMENTATION, - kernel_name, - e->hydro_properties ? e->hydro_properties->target_neighbours : 0.f, - e->hydro_properties ? e->hydro_properties->delta_neighbours : 0.f, - e->hydro_properties ? e->hydro_properties->eta_neighbours : 0.f, - configuration_options(), compilation_cflags()); + kernel_name, e->hydro_properties->target_neighbours, + e->hydro_properties->delta_neighbours, + e->hydro_properties->eta_neighbours, configuration_options(), + compilation_cflags()); fprintf( e->file_timesteps, @@ -5580,8 +5579,11 @@ void engine_config(int restart, int fof, struct engine *e, fof_create_mpi_types(); #endif - /* Initialise the collection group. */ - collectgroup_init(); + if (!fof) { + + /* Initialise the collection group. */ + collectgroup_init(); + } /* Initialize the threadpool. */ threadpool_init(&e->threadpool, e->nr_threads); @@ -6170,8 +6172,11 @@ void engine_recompute_displacement_constraint(struct engine *e) { /** * @brief Frees up the memory allocated for this #engine + * + * @param e The #engine to clean. + * @param fof Was this a stand-alone FOF run? */ -void engine_clean(struct engine *e) { +void engine_clean(struct engine *e, const int fof) { /* Start by telling the runners to stop. */ e->step_props = engine_step_prop_done; swift_barrier_wait(&e->run_barrier); @@ -6204,7 +6209,7 @@ void engine_clean(struct engine *e) { threadpool_clean(&e->threadpool); /* Close files */ - if (e->nodeID == 0) { + if (!fof && e->nodeID == 0) { fclose(e->file_timesteps); fclose(e->file_stats); diff --git a/src/engine.h b/src/engine.h index a96a67172e19c209a1d0b1a84f773a3251b1d6f4..be96db7e9fe6e9caf387cf7bd2cbcf9ff997e445 100644 --- a/src/engine.h +++ b/src/engine.h @@ -533,7 +533,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); +void engine_clean(struct engine *e, const int fof); 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,