diff --git a/src/common_io.c b/src/common_io.c index 65dd4cfec1c366818f6b658ea4856b7e9bfc4028..9e1eb0854c0cdeaa0e3db4d89ffcc12c2c458731 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -791,16 +791,19 @@ void io_duplicate_stars_gparts(struct threadpool* tp, * * @param parts The array of #part containing all particles. * @param xparts The array of #xpart containing all particles. - * @param parts_written The array of #part to fill with particles we want to write. - * @param xparts_written The array of #xpart to fill with particles we want to write. + * @param parts_written The array of #part to fill with particles we want to + * write. + * @param xparts_written The array of #xpart to fill with particles we want to + * write. * @param Nparts The total number of #part. * @param Nparts_written The total number of #part to write. */ void io_collect_parts_to_write(const struct part* restrict parts, - const struct xpart* restrict xparts, - struct part* restrict parts_written, - struct xpart* restrict xparts_written, - const size_t Nparts, const size_t Nparts_written) { + const struct xpart* restrict xparts, + struct part* restrict parts_written, + struct xpart* restrict xparts_written, + const size_t Nparts, + const size_t Nparts_written) { size_t count = 0; @@ -808,7 +811,7 @@ void io_collect_parts_to_write(const struct part* restrict parts, for (size_t i = 0; i < Nparts; ++i) { /* And collect the ones that have not been removed */ - if(parts[i].time_bin != time_bin_inhibited) { + if (parts[i].time_bin != time_bin_inhibited) { parts_written[count] = parts[i]; xparts_written[count] = xparts[i]; @@ -826,13 +829,15 @@ void io_collect_parts_to_write(const struct part* restrict parts, * @brief Copy every non-inhibited #spart into the sparts_written array. * * @param sparts The array of #spart containing all particles. - * @param sparts_written The array of #spart to fill with particles we want to write. + * @param sparts_written The array of #spart to fill with particles we want to + * write. * @param Nsparts The total number of #part. * @param Nsparts_written The total number of #part to write. */ void io_collect_sparts_to_write(const struct spart* restrict sparts, - struct spart* restrict sparts_written, - const size_t Nsparts, const size_t Nsparts_written) { + struct spart* restrict sparts_written, + const size_t Nsparts, + const size_t Nsparts_written) { size_t count = 0; @@ -840,7 +845,7 @@ void io_collect_sparts_to_write(const struct spart* restrict sparts, for (size_t i = 0; i < Nsparts; ++i) { /* And collect the ones that have not been removed */ - if(sparts[i].time_bin != time_bin_inhibited) { + if (sparts[i].time_bin != time_bin_inhibited) { sparts_written[count] = sparts[i]; count++; @@ -857,13 +862,15 @@ void io_collect_sparts_to_write(const struct spart* restrict sparts, * @brief Copy every non-inhibited DM #gpart into the gparts_written array. * * @param gparts The array of #gpart containing all particles. - * @param gparts_written The array of #gpart to fill with particles we want to write. + * @param gparts_written The array of #gpart to fill with particles we want to + * write. * @param Ngparts The total number of #part. * @param Ngparts_written The total number of #part to write. */ void io_collect_gparts_to_write(const struct gpart* restrict gparts, - struct gpart* restrict gparts_written, - const size_t Ngparts, const size_t Ngparts_written) { + struct gpart* restrict gparts_written, + const size_t Ngparts, + const size_t Ngparts_written) { size_t count = 0; @@ -871,8 +878,8 @@ void io_collect_gparts_to_write(const struct gpart* restrict gparts, for (size_t i = 0; i < Ngparts; ++i) { /* And collect the ones that have not been removed */ - if((gparts[i].time_bin != time_bin_inhibited) && - (gparts[i].type == swift_type_dark_matter)) { + if ((gparts[i].time_bin != time_bin_inhibited) && + (gparts[i].type == swift_type_dark_matter)) { gparts_written[count] = gparts[i]; count++; diff --git a/src/common_io.h b/src/common_io.h index a79acdb16c55ae69eab4f6f0af28ae188387d8a9..016c5138e18ae8636834c35d659e07d8fcd46e36 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -93,16 +93,19 @@ size_t io_sizeof_type(enum IO_DATA_TYPE type); int io_is_double_precision(enum IO_DATA_TYPE type); void io_collect_parts_to_write(const struct part* restrict parts, - const struct xpart* restrict xparts, - struct part* restrict parts_written, - struct xpart* restrict xparts_written, - const size_t Nparts, const size_t Nparts_written); + const struct xpart* restrict xparts, + struct part* restrict parts_written, + struct xpart* restrict xparts_written, + const size_t Nparts, + const size_t Nparts_written); void io_collect_sparts_to_write(const struct spart* restrict sparts, - struct spart* restrict sparts_written, - const size_t Nsparts, const size_t Nsparts_written); + struct spart* restrict sparts_written, + const size_t Nsparts, + const size_t Nsparts_written); void io_collect_gparts_to_write(const struct gpart* restrict gparts, - struct gpart* restrict gparts_written, - const size_t Ngparts, const size_t Ngparts_written); + struct gpart* restrict gparts_written, + const size_t Ngparts, + const size_t Ngparts_written); void io_prepare_dm_gparts(struct threadpool* tp, struct gpart* const gparts, size_t Ndm); void io_duplicate_hydro_gparts(struct threadpool* tp, struct part* const parts, diff --git a/src/parallel_io.c b/src/parallel_io.c index 600eee21cece8692f839b94a53f8de819b450ab4..07cbfaeb6b9f18b7864e632233f3dff322a148bf 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1181,18 +1181,20 @@ void write_output_parallel(struct engine* e, const char* baseName, const size_t Ntot = e->s->nr_gparts; const size_t Ngas = e->s->nr_parts; const size_t Nstars = e->s->nr_sparts; - //const size_t Nbaryons = Ngas + Nstars; - //const size_t Ndm = Ntot > 0 ? Ntot - Nbaryons : 0; + // const size_t Nbaryons = Ngas + Nstars; + // const size_t Ndm = Ntot > 0 ? Ntot - Nbaryons : 0; /* Number of particles that we will write */ - const size_t Ntot_written = e->s->nr_gparts - e->s->nr_inhibited_sparts; + const size_t Ntot_written = e->s->nr_gparts - e->s->nr_inhibited_sparts; const size_t Ngas_written = e->s->nr_parts - e->s->nr_inhibited_parts; const size_t Nstars_written = e->s->nr_sparts - e->s->nr_inhibited_gparts; const size_t Nbaryons_written = Ngas_written + Nstars_written; - const size_t Ndm_written = Ntot_written > 0 ? Ntot_written - Nbaryons_written : 0; + const size_t Ndm_written = + Ntot_written > 0 ? Ntot_written - Nbaryons_written : 0; /* Compute offset in the file and total number of particles */ - size_t N[swift_type_count] = {Ngas_written, Ndm_written, 0, 0, Nstars_written, 0}; + size_t N[swift_type_count] = { + Ngas_written, Ndm_written, 0, 0, Nstars_written, 0}; long long N_total[swift_type_count] = {0}; long long offset[swift_type_count] = {0}; MPI_Exscan(&N, &offset, swift_type_count, MPI_LONG_LONG_INT, MPI_SUM, comm); @@ -1347,93 +1349,94 @@ void write_output_parallel(struct engine* e, const char* baseName, struct xpart* xparts_written = NULL; struct gpart* gparts_written = NULL; struct spart* sparts_written = NULL; - + /* Write particle fields from the particle structure */ switch (ptype) { - case swift_type_gas: - { - if (Ngas == Ngas_written) { - - /* No inhibted particles: easy case */ - Nparticles = Ngas; - hydro_write_particles(parts, xparts, list, &num_fields); - num_fields += chemistry_write_particles(parts, list + num_fields); - num_fields += cooling_write_particles(xparts, list + num_fields, e->cooling_func); - } - else { - - /* Ok, we need to fish out the particles we want */ - Nparticles = Ngas_written; - - /* Allocate temporary arrays */ - if (posix_memalign((void**)&parts_written, part_align, Ngas_written * sizeof(struct part)) != 0) - error("Error while allocating temporart memory for parts"); - if (posix_memalign((void**)&xparts_written, xpart_align, Ngas_written * sizeof(struct xpart)) != 0) - error("Error while allocating temporart memory for xparts"); - - /* Collect the particles we want to write */ - io_collect_parts_to_write(parts, xparts, parts_written, xparts_written, Ngas, Ngas_written); - - /* Select the fields to write */ - hydro_write_particles(parts_written, xparts_written, list, &num_fields); - num_fields += chemistry_write_particles(parts_written, list + num_fields); - num_fields += cooling_write_particles(xparts_written, list + num_fields, e->cooling_func); - } - } - break; + case swift_type_gas: { + if (Ngas == Ngas_written) { + + /* No inhibted particles: easy case */ + Nparticles = Ngas; + hydro_write_particles(parts, xparts, list, &num_fields); + num_fields += chemistry_write_particles(parts, list + num_fields); + num_fields += cooling_write_particles(xparts, list + num_fields, + e->cooling_func); + } else { + + /* Ok, we need to fish out the particles we want */ + Nparticles = Ngas_written; + + /* Allocate temporary arrays */ + if (posix_memalign((void**)&parts_written, part_align, + Ngas_written * sizeof(struct part)) != 0) + error("Error while allocating temporart memory for parts"); + if (posix_memalign((void**)&xparts_written, xpart_align, + Ngas_written * sizeof(struct xpart)) != 0) + error("Error while allocating temporart memory for xparts"); + + /* Collect the particles we want to write */ + io_collect_parts_to_write(parts, xparts, parts_written, + xparts_written, Ngas, Ngas_written); + + /* Select the fields to write */ + hydro_write_particles(parts_written, xparts_written, list, + &num_fields); + num_fields += + chemistry_write_particles(parts_written, list + num_fields); + num_fields += cooling_write_particles( + xparts_written, list + num_fields, e->cooling_func); + } + } break; - case swift_type_dark_matter: - { - if(Ntot == Ndm_written) { - - /* This is a DM-only run without inhibited particles */ - Nparticles = Ntot; - darkmatter_write_particles(gparts, list, &num_fields); - } - else { - - /* Ok, we need to fish out the particles we want */ - Nparticles = Ndm_written; - - /* Allocate temporary array */ - if (posix_memalign((void**)&gparts_written, gpart_align, Ndm_written * sizeof(struct gpart)) != 0) - error("Error while allocating temporart memory for gparts"); - - /* Collect the non-inhibited DM particles from gpart */ - io_collect_gparts_to_write(gparts, gparts_written, Ntot, Ndm_written); - - /* Write DM particles */ - darkmatter_write_particles(gparts_written, list, &num_fields); - } - } - break; + case swift_type_dark_matter: { + if (Ntot == Ndm_written) { - case swift_type_stars: - { - if(Nstars == Nstars_written) { + /* This is a DM-only run without inhibited particles */ + Nparticles = Ntot; + darkmatter_write_particles(gparts, list, &num_fields); + } else { - /* No inhibted particles: easy case */ - Nparticles = Nstars; - stars_write_particles(sparts, list, &num_fields); - } - else { + /* Ok, we need to fish out the particles we want */ + Nparticles = Ndm_written; - /* Ok, we need to fish out the particles we want */ - Nparticles = Nstars_written; + /* Allocate temporary array */ + if (posix_memalign((void**)&gparts_written, gpart_align, + Ndm_written * sizeof(struct gpart)) != 0) + error("Error while allocating temporart memory for gparts"); - /* Allocate temporary arrays */ - if (posix_memalign((void**)&sparts_written, spart_align, Nstars_written * sizeof(struct spart)) != 0) - error("Error while allocating temporart memory for sparts"); + /* Collect the non-inhibited DM particles from gpart */ + io_collect_gparts_to_write(gparts, gparts_written, Ntot, Ndm_written); - /* Collect the particles we want to write */ - io_collect_sparts_to_write(sparts, sparts_written, Nstars, Nstars_written); + /* Write DM particles */ + darkmatter_write_particles(gparts_written, list, &num_fields); + } + } break; - /* Select the fields to write */ - stars_write_particles(sparts, list, &num_fields); - } - } - break; + case swift_type_stars: { + if (Nstars == Nstars_written) { + + /* No inhibted particles: easy case */ + Nparticles = Nstars; + stars_write_particles(sparts, list, &num_fields); + } else { + + /* Ok, we need to fish out the particles we want */ + Nparticles = Nstars_written; + + /* Allocate temporary arrays */ + if (posix_memalign((void**)&sparts_written, spart_align, + Nstars_written * sizeof(struct spart)) != 0) + error("Error while allocating temporart memory for sparts"); + + /* Collect the particles we want to write */ + io_collect_sparts_to_write(sparts, sparts_written, Nstars, + Nstars_written); + + /* Select the fields to write */ + stars_write_particles(sparts, list, &num_fields); + } + } break; default: error("Particle Type %d not yet supported. Aborting", ptype); @@ -1455,10 +1458,10 @@ void write_output_parallel(struct engine* e, const char* baseName, } /* Free temporary array */ - if(parts_written) free(parts_written); - if(xparts_written) free(xparts_written); - if(gparts_written) free(gparts_written); - if(sparts_written) free(sparts_written); + if (parts_written) free(parts_written); + if (xparts_written) free(xparts_written); + if (gparts_written) free(gparts_written); + if (sparts_written) free(sparts_written); #ifdef IO_SPEED_MEASUREMENT MPI_Barrier(MPI_COMM_WORLD); diff --git a/src/serial_io.c b/src/serial_io.c index 5ae2062482a2ed0be62de006031e4ec135d329b3..5458f97231402848ca9ad819ab05652b397486c9 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -752,15 +752,16 @@ void write_output_serial(struct engine* e, const char* baseName, const size_t Ntot = e->s->nr_gparts; const size_t Ngas = e->s->nr_parts; const size_t Nstars = e->s->nr_sparts; - //const size_t Nbaryons = Ngas + Nstars; - //const size_t Ndm = Ntot > 0 ? Ntot - Nbaryons : 0; + // const size_t Nbaryons = Ngas + Nstars; + // const size_t Ndm = Ntot > 0 ? Ntot - Nbaryons : 0; /* Number of particles that we will write */ - const size_t Ntot_written = e->s->nr_gparts - e->s->nr_inhibited_sparts; + const size_t Ntot_written = e->s->nr_gparts - e->s->nr_inhibited_sparts; const size_t Ngas_written = e->s->nr_parts - e->s->nr_inhibited_parts; const size_t Nstars_written = e->s->nr_sparts - e->s->nr_inhibited_gparts; const size_t Nbaryons_written = Ngas_written + Nstars_written; - const size_t Ndm_written = Ntot_written > 0 ? Ntot_written - Nbaryons_written : 0; + const size_t Ndm_written = + Ntot_written > 0 ? Ntot_written - Nbaryons_written : 0; /* File name */ char fileName[FILENAME_BUFFER_SIZE]; @@ -772,7 +773,8 @@ void write_output_serial(struct engine* e, const char* baseName, e->snapshot_output_count); /* Compute offset in the file and total number of particles */ - size_t N[swift_type_count] = {Ngas_written, Ndm_written, 0, 0, Nstars_written, 0}; + size_t N[swift_type_count] = { + Ngas_written, Ndm_written, 0, 0, Nstars_written, 0}; long long N_total[swift_type_count] = {0}; long long offset[swift_type_count] = {0}; MPI_Exscan(&N, &offset, swift_type_count, MPI_LONG_LONG_INT, MPI_SUM, comm); @@ -1018,97 +1020,99 @@ void write_output_serial(struct engine* e, const char* baseName, struct io_props list[100]; size_t Nparticles = 0; - struct part* parts_written = NULL; - struct xpart* xparts_written = NULL; - struct gpart* gparts_written = NULL; - struct spart* sparts_written = NULL; + struct part* parts_written = NULL; + struct xpart* xparts_written = NULL; + struct gpart* gparts_written = NULL; + struct spart* sparts_written = NULL; /* Write particle fields from the particle structure */ switch (ptype) { - case swift_type_gas: - { - if (Ngas == Ngas_written) { - - /* No inhibted particles: easy case */ - Nparticles = Ngas; - hydro_write_particles(parts, xparts, list, &num_fields); - num_fields += chemistry_write_particles(parts, list + num_fields); - num_fields += cooling_write_particles(xparts, list + num_fields, e->cooling_func); - } - else { - - /* Ok, we need to fish out the particles we want */ - Nparticles = Ngas_written; - - /* Allocate temporary arrays */ - if (posix_memalign((void**)&parts_written, part_align, Ngas_written * sizeof(struct part)) != 0) - error("Error while allocating temporart memory for parts"); - if (posix_memalign((void**)&xparts_written, xpart_align, Ngas_written * sizeof(struct xpart)) != 0) - error("Error while allocating temporart memory for xparts"); - - /* Collect the particles we want to write */ - io_collect_parts_to_write(parts, xparts, parts_written, xparts_written, Ngas, Ngas_written); - - /* Select the fields to write */ - hydro_write_particles(parts_written, xparts_written, list, &num_fields); - num_fields += chemistry_write_particles(parts_written, list + num_fields); - num_fields += cooling_write_particles(xparts_written, list + num_fields, e->cooling_func); - } - } - break; + case swift_type_gas: { + if (Ngas == Ngas_written) { + + /* No inhibted particles: easy case */ + Nparticles = Ngas; + hydro_write_particles(parts, xparts, list, &num_fields); + num_fields += chemistry_write_particles(parts, list + num_fields); + num_fields += cooling_write_particles(xparts, list + num_fields, + e->cooling_func); + } else { + + /* Ok, we need to fish out the particles we want */ + Nparticles = Ngas_written; + + /* Allocate temporary arrays */ + if (posix_memalign((void**)&parts_written, part_align, + Ngas_written * sizeof(struct part)) != 0) + error("Error while allocating temporart memory for parts"); + if (posix_memalign((void**)&xparts_written, xpart_align, + Ngas_written * sizeof(struct xpart)) != 0) + error("Error while allocating temporart memory for xparts"); + + /* Collect the particles we want to write */ + io_collect_parts_to_write(parts, xparts, parts_written, + xparts_written, Ngas, Ngas_written); + + /* Select the fields to write */ + hydro_write_particles(parts_written, xparts_written, list, + &num_fields); + num_fields += + chemistry_write_particles(parts_written, list + num_fields); + num_fields += cooling_write_particles( + xparts_written, list + num_fields, e->cooling_func); + } + } break; - case swift_type_dark_matter: - { - if(Ntot == Ndm_written) { - - /* This is a DM-only run without inhibited particles */ - Nparticles = Ntot; - darkmatter_write_particles(gparts, list, &num_fields); - } - else { - - /* Ok, we need to fish out the particles we want */ - Nparticles = Ndm_written; - - /* Allocate temporary array */ - if (posix_memalign((void**)&gparts_written, gpart_align, Ndm_written * sizeof(struct gpart)) != 0) - error("Error while allocating temporart memory for gparts"); - - /* Collect the non-inhibited DM particles from gpart */ - io_collect_gparts_to_write(gparts, gparts_written, Ntot, Ndm_written); - - /* Write DM particles */ - darkmatter_write_particles(gparts_written, list, &num_fields); - } - } - break; - - case swift_type_stars: - { - if(Nstars == Nstars_written) { - - /* No inhibted particles: easy case */ - Nparticles = Nstars; - stars_write_particles(sparts, list, &num_fields); - } - else { - - /* Ok, we need to fish out the particles we want */ - Nparticles = Nstars_written; - - /* Allocate temporary arrays */ - if (posix_memalign((void**)&sparts_written, spart_align, Nstars_written * sizeof(struct spart)) != 0) - error("Error while allocating temporart memory for sparts"); - - /* Collect the particles we want to write */ - io_collect_sparts_to_write(sparts, sparts_written, Nstars, Nstars_written); - - /* Select the fields to write */ - stars_write_particles(sparts, list, &num_fields); - } - } - break; + case swift_type_dark_matter: { + if (Ntot == Ndm_written) { + + /* This is a DM-only run without inhibited particles */ + Nparticles = Ntot; + darkmatter_write_particles(gparts, list, &num_fields); + } else { + + /* Ok, we need to fish out the particles we want */ + Nparticles = Ndm_written; + + /* Allocate temporary array */ + if (posix_memalign((void**)&gparts_written, gpart_align, + Ndm_written * sizeof(struct gpart)) != 0) + error("Error while allocating temporart memory for gparts"); + + /* Collect the non-inhibited DM particles from gpart */ + io_collect_gparts_to_write(gparts, gparts_written, Ntot, + Ndm_written); + + /* Write DM particles */ + darkmatter_write_particles(gparts_written, list, &num_fields); + } + } break; + + case swift_type_stars: { + if (Nstars == Nstars_written) { + + /* No inhibted particles: easy case */ + Nparticles = Nstars; + stars_write_particles(sparts, list, &num_fields); + } else { + + /* Ok, we need to fish out the particles we want */ + Nparticles = Nstars_written; + + /* Allocate temporary arrays */ + if (posix_memalign((void**)&sparts_written, spart_align, + Nstars_written * sizeof(struct spart)) != 0) + error("Error while allocating temporart memory for sparts"); + + /* Collect the particles we want to write */ + io_collect_sparts_to_write(sparts, sparts_written, Nstars, + Nstars_written); + + /* Select the fields to write */ + stars_write_particles(sparts, list, &num_fields); + } + } break; default: error("Particle Type %d not yet supported. Aborting", ptype); @@ -1130,10 +1134,10 @@ void write_output_serial(struct engine* e, const char* baseName, } /* Free temporary array */ - if(parts_written) free(parts_written); - if(xparts_written) free(xparts_written); - if(gparts_written) free(gparts_written); - if(sparts_written) free(sparts_written); + if (parts_written) free(parts_written); + if (xparts_written) free(xparts_written); + if (gparts_written) free(gparts_written); + if (sparts_written) free(sparts_written); /* Close particle group */ H5Gclose(h_grp); diff --git a/src/single_io.c b/src/single_io.c index 2586b2909a7c6df8d21c2e9ddbcb3c5dd29e6833..30c0e6b09e21bcd27c5e6a89d81ba4b9629168be 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -610,24 +610,29 @@ void write_output_single(struct engine* e, const char* baseName, const struct gpart* gparts = e->s->gparts; const struct spart* sparts = e->s->sparts; struct swift_params* params = e->parameter_file; - + /* Number of particles currently in the arrays */ const size_t Ntot = e->s->nr_gparts; const size_t Ngas = e->s->nr_parts; const size_t Nstars = e->s->nr_sparts; - //const size_t Nbaryons = Ngas + Nstars; - //const size_t Ndm = Ntot > 0 ? Ntot - Nbaryons : 0; + // const size_t Nbaryons = Ngas + Nstars; + // const size_t Ndm = Ntot > 0 ? Ntot - Nbaryons : 0; /* Number of particles that we will write */ - const size_t Ntot_written = e->s->nr_gparts - e->s->nr_inhibited_sparts; + const size_t Ntot_written = e->s->nr_gparts - e->s->nr_inhibited_sparts; const size_t Ngas_written = e->s->nr_parts - e->s->nr_inhibited_parts; const size_t Nstars_written = e->s->nr_sparts - e->s->nr_inhibited_gparts; const size_t Nbaryons_written = Ngas_written + Nstars_written; - const size_t Ndm_written = Ntot_written > 0 ? Ntot_written - Nbaryons_written : 0; + const size_t Ndm_written = + Ntot_written > 0 ? Ntot_written - Nbaryons_written : 0; /* Format things in a Gadget-friendly array */ - long long N_total[swift_type_count] = { - (long long)Ngas_written, (long long)Ndm_written, 0, 0, (long long)Nstars_written, 0}; + long long N_total[swift_type_count] = {(long long)Ngas_written, + (long long)Ndm_written, + 0, + 0, + (long long)Nstars_written, + 0}; /* File name */ char fileName[FILENAME_BUFFER_SIZE]; @@ -843,89 +848,90 @@ void write_output_single(struct engine* e, const char* baseName, /* Write particle fields from the particle structure */ switch (ptype) { - case swift_type_gas: - { - if (Ngas == Ngas_written) { - - /* No inhibted particles: easy case */ - N = Ngas; - hydro_write_particles(parts, xparts, list, &num_fields); - num_fields += chemistry_write_particles(parts, list + num_fields); - num_fields += cooling_write_particles(xparts, list + num_fields, e->cooling_func); - } - else { - - /* Ok, we need to fish out the particles we want */ - N = Ngas_written; - - /* Allocate temporary arrays */ - if (posix_memalign((void**)&parts_written, part_align, Ngas_written * sizeof(struct part)) != 0) - error("Error while allocating temporart memory for parts"); - if (posix_memalign((void**)&xparts_written, xpart_align, Ngas_written * sizeof(struct xpart)) != 0) - error("Error while allocating temporart memory for xparts"); - - /* Collect the particles we want to write */ - io_collect_parts_to_write(parts, xparts, parts_written, xparts_written, Ngas, Ngas_written); - - /* Select the fields to write */ - hydro_write_particles(parts_written, xparts_written, list, &num_fields); - num_fields += chemistry_write_particles(parts_written, list + num_fields); - num_fields += cooling_write_particles(xparts_written, list + num_fields, e->cooling_func); - } - } - break; + case swift_type_gas: { + if (Ngas == Ngas_written) { + + /* No inhibted particles: easy case */ + N = Ngas; + hydro_write_particles(parts, xparts, list, &num_fields); + num_fields += chemistry_write_particles(parts, list + num_fields); + num_fields += cooling_write_particles(xparts, list + num_fields, + e->cooling_func); + } else { + + /* Ok, we need to fish out the particles we want */ + N = Ngas_written; + + /* Allocate temporary arrays */ + if (posix_memalign((void**)&parts_written, part_align, + Ngas_written * sizeof(struct part)) != 0) + error("Error while allocating temporart memory for parts"); + if (posix_memalign((void**)&xparts_written, xpart_align, + Ngas_written * sizeof(struct xpart)) != 0) + error("Error while allocating temporart memory for xparts"); + + /* Collect the particles we want to write */ + io_collect_parts_to_write(parts, xparts, parts_written, + xparts_written, Ngas, Ngas_written); + + /* Select the fields to write */ + hydro_write_particles(parts_written, xparts_written, list, + &num_fields); + num_fields += + chemistry_write_particles(parts_written, list + num_fields); + num_fields += cooling_write_particles( + xparts_written, list + num_fields, e->cooling_func); + } + } break; - case swift_type_dark_matter: - { - if(Ntot == Ndm_written) { - - /* This is a DM-only run without inhibited particles */ - N = Ntot; - darkmatter_write_particles(gparts, list, &num_fields); - } - else { - - /* Ok, we need to fish out the particles we want */ - N = Ndm_written; - - /* Allocate temporary array */ - if (posix_memalign((void**)&gparts_written, gpart_align, Ndm_written * sizeof(struct gpart)) != 0) - error("Error while allocating temporart memory for gparts"); - - /* Collect the non-inhibited DM particles from gpart */ - io_collect_gparts_to_write(gparts, gparts_written, Ntot, Ndm_written); - - /* Write DM particles */ - darkmatter_write_particles(gparts_written, list, &num_fields); - } - } - break; + case swift_type_dark_matter: { + if (Ntot == Ndm_written) { - case swift_type_stars: - { - if(Nstars == Nstars_written) { + /* This is a DM-only run without inhibited particles */ + N = Ntot; + darkmatter_write_particles(gparts, list, &num_fields); + } else { - /* No inhibted particles: easy case */ - N = Nstars; - stars_write_particles(sparts, list, &num_fields); - } - else { + /* Ok, we need to fish out the particles we want */ + N = Ndm_written; - /* Ok, we need to fish out the particles we want */ - N = Nstars_written; + /* Allocate temporary array */ + if (posix_memalign((void**)&gparts_written, gpart_align, + Ndm_written * sizeof(struct gpart)) != 0) + error("Error while allocating temporart memory for gparts"); - /* Allocate temporary arrays */ - if (posix_memalign((void**)&sparts_written, spart_align, Nstars_written * sizeof(struct spart)) != 0) - error("Error while allocating temporart memory for sparts"); + /* Collect the non-inhibited DM particles from gpart */ + io_collect_gparts_to_write(gparts, gparts_written, Ntot, Ndm_written); - /* Collect the particles we want to write */ - io_collect_sparts_to_write(sparts, sparts_written, Nstars, Nstars_written); + /* Write DM particles */ + darkmatter_write_particles(gparts_written, list, &num_fields); + } + } break; - /* Select the fields to write */ - stars_write_particles(sparts, list, &num_fields); - } - } - break; + case swift_type_stars: { + if (Nstars == Nstars_written) { + + /* No inhibted particles: easy case */ + N = Nstars; + stars_write_particles(sparts, list, &num_fields); + } else { + + /* Ok, we need to fish out the particles we want */ + N = Nstars_written; + + /* Allocate temporary arrays */ + if (posix_memalign((void**)&sparts_written, spart_align, + Nstars_written * sizeof(struct spart)) != 0) + error("Error while allocating temporart memory for sparts"); + + /* Collect the particles we want to write */ + io_collect_sparts_to_write(sparts, sparts_written, Nstars, + Nstars_written); + + /* Select the fields to write */ + stars_write_particles(sparts, list, &num_fields); + } + } break; default: error("Particle Type %d not yet supported. Aborting", ptype); @@ -946,11 +952,11 @@ void write_output_single(struct engine* e, const char* baseName, } /* Free temporary arrays */ - if(parts_written) free(parts_written); - if(xparts_written) free(xparts_written); - if(gparts_written) free(gparts_written); - if(sparts_written) free(sparts_written); - + if (parts_written) free(parts_written); + if (xparts_written) free(xparts_written); + if (gparts_written) free(gparts_written); + if (sparts_written) free(sparts_written); + /* Close particle group */ H5Gclose(h_grp);