diff --git a/src/common_io.c b/src/common_io.c index f6a4803333581b69671e3adc223b46122ec5364c..4be334ccd602c7b0c450f5dbe4aedd9155b35ff1 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -489,7 +489,8 @@ void prepare_dm_gparts(struct gpart* gparts, size_t Ndm) { for (size_t i = 0; i < Ndm; ++i) { /* 0 or negative ids are not allowed */ - if (gparts[i].id <= 0) error("0 or negative ID for DM particle"); + if (gparts[i].id <= 0) + error("0 or negative ID for DM particle %zd: ID=%lld", i, gparts[i].id); gparts[i].id = -gparts[i].id; } diff --git a/src/single_io.c b/src/single_io.c index 373d685174d6ead7e2541f7d8af22d00800dba7b..f3082fd083235d24d856f3235706948633996d98 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -63,14 +63,14 @@ * Calls #error() if an error occurs. */ void readArrayBackEnd(hid_t grp, char* name, enum DATA_TYPE type, int N, - int dim, char* part_c, enum DATA_IMPORTANCE importance) { + int dim, char* part_c, size_t partSize, + enum DATA_IMPORTANCE importance) { hid_t h_data = 0, h_err = 0, h_type = 0; htri_t exist = 0; void* temp; int i = 0; const size_t typeSize = sizeOfType(type); const size_t copySize = typeSize * dim; - const size_t partSize = sizeof(struct part); char* temp_c = 0; /* Check whether the dataspace exists or not */ @@ -155,14 +155,13 @@ void readArrayBackEnd(hid_t grp, char* name, enum DATA_TYPE type, int N, */ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, enum DATA_TYPE type, int N, int dim, char* part_c, - struct UnitSystem* us, + size_t partSize, struct UnitSystem* us, enum UnitConversionFactor convFactor) { hid_t h_data = 0, h_err = 0, h_space = 0, h_prop = 0; void* temp = 0; int i = 0, rank = 0; const size_t typeSize = sizeOfType(type); const size_t copySize = typeSize * dim; - const size_t partSize = sizeof(struct part); char* temp_c = 0; hsize_t shape[2]; hsize_t chunk_shape[2]; @@ -273,7 +272,7 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, #define readArray(grp, name, type, N, dim, part, N_total, offset, field, \ importance) \ readArrayBackEnd(grp, name, type, N, dim, (char*)(&(part[0]).field), \ - importance) + sizeof(part[0]),importance) /** * @brief A helper macro to call the readArrayBackEnd function more easily. @@ -298,7 +297,7 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, #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, \ - (char*)(&(part[0]).field), us, convFactor) + (char*)(&(part[0]).field), sizeof(part[0]), us, convFactor) /* Import the right hydro definition */ #include "hydro_io.h" @@ -398,8 +397,8 @@ void read_ic_single(char* fileName, double dim[3], struct part** parts, /* message("Allocated %8.2f MB for particles.", *N * sizeof(struct part) / * (1024.*1024.)); */ - message("BoxSize = %lf", dim[0]); - message("NumPart = [%zd, %zd] Total = %zd", *Ngas, Ndm, *Ngparts); + /* message("BoxSize = %lf", dim[0]); */ + /* message("NumPart = [%zd, %zd] Total = %zd", *Ngas, Ndm, *Ngparts); */ /* Loop over all particle types */ for (int ptype = 0; ptype < NUM_PARTICLE_TYPES; ptype++) { @@ -477,9 +476,8 @@ void write_output_single(struct engine* e, struct UnitSystem* us) { /* Number of particles of each type */ const size_t Ndm = Ntot - Ngas; - int numParticles[NUM_PARTICLE_TYPES] = /* Gadget-2 convention here */ - {Ngas, Ndm, 0}; /* Could use size_t instead */ - int numParticlesHighWord[NUM_PARTICLE_TYPES] = {0}; + + long long N_total[NUM_PARTICLE_TYPES] = {Ngas, Ndm, 0}; /* File name */ char fileName[FILENAME_BUFFER_SIZE]; @@ -521,19 +519,27 @@ void write_output_single(struct engine* e, struct UnitSystem* us) { /* Print the relevant information and print status */ writeAttribute(h_grp, "BoxSize", DOUBLE, e->s->dim, 3); - writeAttribute(h_grp, "NumPart_ThisFile", UINT, numParticles, - NUM_PARTICLE_TYPES); double dblTime = e->time; writeAttribute(h_grp, "Time", DOUBLE, &dblTime, 1); /* GADGET-2 legacy values */ + /* Number of particles of each type */ + unsigned int numParticles[NUM_PARTICLE_TYPES] = {0}; + unsigned int numParticlesHighWord[NUM_PARTICLE_TYPES] = {0}; + for(int ptype = 0; ptype < NUM_PARTICLE_TYPES; ++ptype) { + numParticles[ptype] = (unsigned int) N_total[ptype]; + numParticlesHighWord[ptype] = (unsigned int) (N_total[ptype] >> 32); + } + writeAttribute(h_grp, "NumPart_ThisFile", LONGLONG, N_total, + NUM_PARTICLE_TYPES); writeAttribute(h_grp, "NumPart_Total", UINT, numParticles, NUM_PARTICLE_TYPES); writeAttribute(h_grp, "NumPart_Total_HighWord", UINT, numParticlesHighWord, NUM_PARTICLE_TYPES); - double MassTable[NUM_PARTICLE_TYPES] = {0., 0., 0., 0., 0., 0.}; + double MassTable[NUM_PARTICLE_TYPES] = {0}; writeAttribute(h_grp, "MassTable", DOUBLE, MassTable, NUM_PARTICLE_TYPES); - writeAttribute(h_grp, "Flag_Entropy_ICs", UINT, numParticlesHighWord, + unsigned int flagEntropy[NUM_PARTICLE_TYPES] = {0}; + writeAttribute(h_grp, "Flag_Entropy_ICs", UINT, flagEntropy, NUM_PARTICLE_TYPES); writeAttribute(h_grp, "NumFilesPerSnapshot", INT, &numFiles, 1);