Skip to content
Snippets Groups Projects
Commit 40df9f1d authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Make sure the right particle size is used

parent ed3f2c46
No related branches found
No related tags found
2 merge requests!136Master,!121Gpart mpi io
...@@ -489,7 +489,8 @@ void prepare_dm_gparts(struct gpart* gparts, size_t Ndm) { ...@@ -489,7 +489,8 @@ void prepare_dm_gparts(struct gpart* gparts, size_t Ndm) {
for (size_t i = 0; i < Ndm; ++i) { for (size_t i = 0; i < Ndm; ++i) {
/* 0 or negative ids are not allowed */ /* 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; gparts[i].id = -gparts[i].id;
} }
......
...@@ -63,14 +63,14 @@ ...@@ -63,14 +63,14 @@
* Calls #error() if an error occurs. * Calls #error() if an error occurs.
*/ */
void readArrayBackEnd(hid_t grp, char* name, enum DATA_TYPE type, int N, 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; hid_t h_data = 0, h_err = 0, h_type = 0;
htri_t exist = 0; htri_t exist = 0;
void* temp; void* temp;
int i = 0; int i = 0;
const size_t typeSize = sizeOfType(type); const size_t typeSize = sizeOfType(type);
const size_t copySize = typeSize * dim; const size_t copySize = typeSize * dim;
const size_t partSize = sizeof(struct part);
char* temp_c = 0; char* temp_c = 0;
/* Check whether the dataspace exists or not */ /* Check whether the dataspace exists or not */
...@@ -155,14 +155,13 @@ void readArrayBackEnd(hid_t grp, char* name, enum DATA_TYPE type, int N, ...@@ -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, void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name,
enum DATA_TYPE type, int N, int dim, char* part_c, enum DATA_TYPE type, int N, int dim, char* part_c,
struct UnitSystem* us, size_t partSize, struct UnitSystem* us,
enum UnitConversionFactor convFactor) { enum UnitConversionFactor convFactor) {
hid_t h_data = 0, h_err = 0, h_space = 0, h_prop = 0; hid_t h_data = 0, h_err = 0, h_space = 0, h_prop = 0;
void* temp = 0; void* temp = 0;
int i = 0, rank = 0; int i = 0, rank = 0;
const size_t typeSize = sizeOfType(type); const size_t typeSize = sizeOfType(type);
const size_t copySize = typeSize * dim; const size_t copySize = typeSize * dim;
const size_t partSize = sizeof(struct part);
char* temp_c = 0; char* temp_c = 0;
hsize_t shape[2]; hsize_t shape[2];
hsize_t chunk_shape[2]; hsize_t chunk_shape[2];
...@@ -273,7 +272,7 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, ...@@ -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, \ #define readArray(grp, name, type, N, dim, part, N_total, offset, field, \
importance) \ importance) \
readArrayBackEnd(grp, name, type, N, dim, (char*)(&(part[0]).field), \ 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. * @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, ...@@ -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, \ #define writeArray(grp, fileName, xmfFile, name, type, N, dim, part, N_total, \
mpi_rank, offset, field, us, convFactor) \ mpi_rank, offset, field, us, convFactor) \
writeArrayBackEnd(grp, fileName, xmfFile, name, type, N, dim, \ 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 */ /* Import the right hydro definition */
#include "hydro_io.h" #include "hydro_io.h"
...@@ -398,8 +397,8 @@ void read_ic_single(char* fileName, double dim[3], struct part** parts, ...@@ -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) / /* message("Allocated %8.2f MB for particles.", *N * sizeof(struct part) /
* (1024.*1024.)); */ * (1024.*1024.)); */
message("BoxSize = %lf", dim[0]); /* message("BoxSize = %lf", dim[0]); */
message("NumPart = [%zd, %zd] Total = %zd", *Ngas, Ndm, *Ngparts); /* message("NumPart = [%zd, %zd] Total = %zd", *Ngas, Ndm, *Ngparts); */
/* Loop over all particle types */ /* Loop over all particle types */
for (int ptype = 0; ptype < NUM_PARTICLE_TYPES; ptype++) { for (int ptype = 0; ptype < NUM_PARTICLE_TYPES; ptype++) {
...@@ -477,9 +476,8 @@ void write_output_single(struct engine* e, struct UnitSystem* us) { ...@@ -477,9 +476,8 @@ void write_output_single(struct engine* e, struct UnitSystem* us) {
/* Number of particles of each type */ /* Number of particles of each type */
const size_t Ndm = Ntot - Ngas; const size_t Ndm = Ntot - Ngas;
int numParticles[NUM_PARTICLE_TYPES] = /* Gadget-2 convention here */
{Ngas, Ndm, 0}; /* Could use size_t instead */ long long N_total[NUM_PARTICLE_TYPES] = {Ngas, Ndm, 0};
int numParticlesHighWord[NUM_PARTICLE_TYPES] = {0};
/* File name */ /* File name */
char fileName[FILENAME_BUFFER_SIZE]; char fileName[FILENAME_BUFFER_SIZE];
...@@ -521,19 +519,27 @@ void write_output_single(struct engine* e, struct UnitSystem* us) { ...@@ -521,19 +519,27 @@ void write_output_single(struct engine* e, struct UnitSystem* us) {
/* Print the relevant information and print status */ /* Print the relevant information and print status */
writeAttribute(h_grp, "BoxSize", DOUBLE, e->s->dim, 3); writeAttribute(h_grp, "BoxSize", DOUBLE, e->s->dim, 3);
writeAttribute(h_grp, "NumPart_ThisFile", UINT, numParticles,
NUM_PARTICLE_TYPES);
double dblTime = e->time; double dblTime = e->time;
writeAttribute(h_grp, "Time", DOUBLE, &dblTime, 1); writeAttribute(h_grp, "Time", DOUBLE, &dblTime, 1);
/* GADGET-2 legacy values */ /* 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, writeAttribute(h_grp, "NumPart_Total", UINT, numParticles,
NUM_PARTICLE_TYPES); NUM_PARTICLE_TYPES);
writeAttribute(h_grp, "NumPart_Total_HighWord", UINT, numParticlesHighWord, writeAttribute(h_grp, "NumPart_Total_HighWord", UINT, numParticlesHighWord,
NUM_PARTICLE_TYPES); 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, "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); NUM_PARTICLE_TYPES);
writeAttribute(h_grp, "NumFilesPerSnapshot", INT, &numFiles, 1); writeAttribute(h_grp, "NumFilesPerSnapshot", INT, &numFiles, 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment