From e02b329973f77361a4954320bb5b58de830e1b89 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Mon, 21 Mar 2016 17:12:36 +0000 Subject: [PATCH] And done the same for the serial_io case. --- src/serial_io.c | 62 ++++++++++++++++++++++++++++++------------------- src/single_io.c | 2 +- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/serial_io.c b/src/serial_io.c index c0421464a9..9f1f6320cf 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -172,9 +172,10 @@ void readArrayBackEnd(hid_t grp, char* name, enum DATA_TYPE type, int N, * Routines writing an output file *-----------------------------------------------------------------------------*/ -void prepareArray(hid_t grp, char* fileName, FILE* xmfFile, char* name, - enum DATA_TYPE type, long long N_total, int dim, - struct UnitSystem* us, enum UnitConversionFactor convFactor) { +void prepareArray(hid_t grp, char* fileName, FILE* xmfFile, + char* partTypeGroupName, char* name, enum DATA_TYPE type, + long long N_total, int dim, struct UnitSystem* us, + enum UnitConversionFactor convFactor) { hid_t h_data = 0, h_err = 0, h_space = 0, h_prop = 0; int rank = 0; hsize_t shape[2]; @@ -234,7 +235,7 @@ void prepareArray(hid_t grp, char* fileName, FILE* xmfFile, char* name, } /* Write XMF description for this data set */ - writeXMFline(xmfFile, fileName, name, N_total, dim, type); + writeXMFline(xmfFile, fileName, partTypeGroupName, name, N_total, dim, type); /* Write unit conversion factors for this data set */ conversionString(buffer, us, convFactor); @@ -267,10 +268,11 @@ void prepareArray(hid_t grp, char* fileName, FILE* xmfFile, char* name, * * Calls #error() if an error occurs. */ -void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, - enum DATA_TYPE type, int N, int dim, long long N_total, - int mpi_rank, long long offset, char* part_c, - size_t partSize, struct UnitSystem* us, +void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, + char* partTypeGroupName, char* name, enum DATA_TYPE type, + int N, int dim, long long N_total, int mpi_rank, + long long offset, char* part_c, size_t partSize, + struct UnitSystem* us, enum UnitConversionFactor convFactor) { hid_t h_data = 0, h_err = 0, h_memspace = 0, h_filespace = 0; @@ -285,8 +287,8 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, /* Prepare the arrays in the file */ if (mpi_rank == 0) - prepareArray(grp, fileName, xmfFile, name, type, N_total, dim, us, - convFactor); + prepareArray(grp, fileName, xmfFile, partTypeGroupName, name, type, N_total, + dim, us, convFactor); /* Allocate temporary buffer */ temp = malloc(N * dim * sizeOfType(type)); @@ -370,21 +372,26 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, * @param fileName Unused parameter in non-MPI mode * @param xmfFile Unused parameter in non-MPI mode * @param name The name of the array to write. + * @param partTypeGroupName The name of the group containing the particles in + *the HDF5 file. * @param type The #DATA_TYPE of the array. * @param N The number of particles to write. * @param dim The dimension of the data (1 for scalar, 3 for vector) * @param part A (char*) pointer on the first occurrence of the field of - *interest - *in the parts array + *interest in the parts array + * @param N_total Unused parameter in non-MPI mode + * @param mpi_rank Unused parameter in non-MPI mode + * @param offset Unused parameter in non-MPI mode * @param field The name (code name) of the field to read from. * @param us The UnitSystem currently in use * @param convFactor The UnitConversionFactor for this array * */ -#define writeArray(grp, fileName, xmfFile, name, type, N, dim, part, N_total, \ - mpi_rank, offset, field, us, convFactor) \ - writeArrayBackEnd(grp, fileName, xmfFile, name, type, N, dim, N_total, \ - mpi_rank, offset, (char*)(&(part[0]).field), \ +#define writeArray(grp, fileName, xmfFile, partTypeGroupName, name, type, N, \ + dim, part, N_total, mpi_rank, offset, field, us, \ + convFactor) \ + writeArrayBackEnd(grp, fileName, xmfFile, partTypeGroupName, name, type, N, \ + dim, N_total, mpi_rank, offset, (char*)(&(part[0]).field), \ sizeof(part[0]), us, convFactor) /* Import the right hydro definition */ @@ -643,7 +650,7 @@ void write_output_serial(struct engine* e, struct UnitSystem* us, int mpi_rank, xmfFile = prepareXMFfile(); /* Write the part corresponding to this specific output */ - writeXMFheader(xmfFile, N_total[0], fileName, e->time); + writeXMFoutputheader(xmfFile, fileName, e->time); /* Open file */ /* message("Opening file '%s'.", fileName); */ @@ -716,6 +723,10 @@ void write_output_serial(struct engine* e, struct UnitSystem* us, int mpi_rank, /* Don't do anything if no particle of this kind */ if (N_total[ptype] == 0) continue; + /* Add the global information for that particle type to the XMF meta-file + */ + writeXMFgroupheader(xmfFile, fileName, N_total[ptype], ptype); + /* Open the particle group in the file */ char partTypeGroupName[PARTICLE_GROUP_BUFFER_SIZE]; snprintf(partTypeGroupName, PARTICLE_GROUP_BUFFER_SIZE, "/PartType%d", @@ -728,6 +739,9 @@ void write_output_serial(struct engine* e, struct UnitSystem* us, int mpi_rank, /* Close particle group */ H5Gclose(h_grp); + + /* Close this particle group in the XMF file as well */ + writeXMFgroupfooter(xmfFile, ptype); } /* Close file */ @@ -763,9 +777,9 @@ void write_output_serial(struct engine* e, struct UnitSystem* us, int mpi_rank, switch (ptype) { case GAS: - hydro_write_particles(h_grp, fileName, xmfFile, N[ptype], - N_total[ptype], mpi_rank, offset[ptype], - parts, us); + hydro_write_particles(h_grp, fileName, partTypeGroupName, xmfFile, + N[ptype], N_total[ptype], mpi_rank, + offset[ptype], parts, us); break; @@ -780,9 +794,9 @@ void write_output_serial(struct engine* e, struct UnitSystem* us, int mpi_rank, collect_dm_gparts(gparts, Ntot, dmparts, Ndm); /* Write DM particles */ - darkmatter_write_particles(h_grp, fileName, xmfFile, N[ptype], - N_total[ptype], mpi_rank, offset[ptype], - dmparts, us); + darkmatter_write_particles(h_grp, fileName, partTypeGroupName, + xmfFile, N[ptype], N_total[ptype], + mpi_rank, offset[ptype], dmparts, us); /* Free temporary array */ free(dmparts); @@ -805,7 +819,7 @@ void write_output_serial(struct engine* e, struct UnitSystem* us, int mpi_rank, } /* Write footer of LXMF file descriptor */ - if (mpi_rank == 0) writeXMFfooter(xmfFile); + if (mpi_rank == 0) writeXMFoutputfooter(xmfFile, outputCount, e->time); /* message("Done writing particles..."); */ ++outputCount; diff --git a/src/single_io.c b/src/single_io.c index e3231d56de..f347f15863 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -575,7 +575,7 @@ void write_output_single(struct engine* e, struct UnitSystem* us) { /* Don't do anything if no particle of this kind */ if (numParticles[ptype] == 0) continue; - /* Add the global information for that particle type */ + /* Add the global information for that particle type to the XMF meta-file */ writeXMFgroupheader(xmfFile, fileName, numParticles[ptype], ptype); /* Open the particle group in the file */ -- GitLab