Commit 76676d8c authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Less verbose i/o over MPI. Larger buffer alignment for the temporary cache.

parent 531d891a
......@@ -296,16 +296,19 @@ void io_write_attribute_s(hid_t grp, const char* name, const char* str) {
* @brief Reads the Unit System from an IC file.
* @param h_file The (opened) HDF5 file from which to read.
* @param us The unit_system to fill.
* @param mpi_rank The MPI rank we are on.
*
* If the 'Units' group does not exist in the ICs, cgs units will be assumed
*/
void io_read_unit_system(hid_t h_file, struct unit_system* us) {
void io_read_unit_system(hid_t h_file, struct unit_system* us, int mpi_rank) {
/* First check if it exists as this is *not* required. */
const htri_t exists = H5Lexists(h_file, "/Units", H5P_DEFAULT);
if (exists == 0) {
message("'Units' group not found in ICs. Assuming CGS unit system.");
if (mpi_rank == 0)
message("'Units' group not found in ICs. Assuming CGS unit system.");
/* Default to CGS */
us->UnitMass_in_cgs = 1.;
......@@ -320,7 +323,7 @@ void io_read_unit_system(hid_t h_file, struct unit_system* us) {
exists);
}
message("Reading IC units from ICs.");
if (mpi_rank == 0) message("Reading IC units from ICs.");
hid_t h_grp = H5Gopen(h_file, "/Units", H5P_DEFAULT);
/* Ok, Read the damn thing */
......@@ -407,7 +410,8 @@ void io_write_code_description(hid_t h_file) {
*
* @param temp The buffer to be filled. Must be allocated and aligned properly.
* @param e The #engine.
* @param props The #io_props corresponding to the particle field we are copying.
* @param props The #io_props corresponding to the particle field we are
* copying.
* @param N The number of particles to copy
* @param internal_units The system of units used internally.
* @param snapshot_units The system of units used for the snapshots.
......@@ -433,7 +437,7 @@ void io_copy_temp_buffer(void* temp, const struct engine* e,
if (props.convert_part_f != NULL) {
swift_declare_aligned_ptr(float, temp_f, temp, SWIFT_CACHE_ALIGNMENT);
swift_declare_aligned_ptr(float, temp_f, temp, IO_BUFFER_ALIGNMENT);
swift_declare_aligned_ptr(const struct part, parts, props.parts,
SWIFT_STRUCT_ALIGNMENT);
......@@ -443,7 +447,7 @@ void io_copy_temp_buffer(void* temp, const struct engine* e,
} else if (props.convert_part_d != NULL) {
swift_declare_aligned_ptr(double, temp_d, temp, SWIFT_CACHE_ALIGNMENT);
swift_declare_aligned_ptr(double, temp_d, temp, IO_BUFFER_ALIGNMENT);
swift_declare_aligned_ptr(const struct part, parts, props.parts,
SWIFT_STRUCT_ALIGNMENT);
......@@ -453,7 +457,7 @@ void io_copy_temp_buffer(void* temp, const struct engine* e,
} else if (props.convert_gpart_f != NULL) {
swift_declare_aligned_ptr(float, temp_f, temp, SWIFT_CACHE_ALIGNMENT);
swift_declare_aligned_ptr(float, temp_f, temp, IO_BUFFER_ALIGNMENT);
swift_declare_aligned_ptr(const struct gpart, gparts, props.gparts,
SWIFT_STRUCT_ALIGNMENT);
......@@ -463,7 +467,7 @@ void io_copy_temp_buffer(void* temp, const struct engine* e,
} else if (props.convert_gpart_d != NULL) {
swift_declare_aligned_ptr(double, temp_d, temp, SWIFT_CACHE_ALIGNMENT);
swift_declare_aligned_ptr(double, temp_d, temp, IO_BUFFER_ALIGNMENT);
swift_declare_aligned_ptr(const struct gpart, gparts, props.gparts,
SWIFT_STRUCT_ALIGNMENT);
......@@ -484,10 +488,10 @@ void io_copy_temp_buffer(void* temp, const struct engine* e,
/* message("Converting ! factor=%e", factor); */
if (io_is_double_precision(props.type)) {
swift_declare_aligned_ptr(double, temp_d, temp, SWIFT_CACHE_ALIGNMENT);
swift_declare_aligned_ptr(double, temp_d, temp, IO_BUFFER_ALIGNMENT);
for (size_t i = 0; i < num_elements; ++i) temp_d[i] *= factor;
} else {
swift_declare_aligned_ptr(float, temp_f, temp, SWIFT_CACHE_ALIGNMENT);
swift_declare_aligned_ptr(float, temp_f, temp, IO_BUFFER_ALIGNMENT);
for (size_t i = 0; i < num_elements; ++i) temp_f[i] *= factor;
}
}
......
......@@ -30,6 +30,7 @@
#define FIELD_BUFFER_SIZE 200
#define PARTICLE_GROUP_BUFFER_SIZE 50
#define FILENAME_BUFFER_SIZE 150
#define IO_BUFFER_ALIGNMENT 512
/* Avoid cyclic inclusion problems */
struct io_props;
......@@ -72,7 +73,7 @@ void io_write_attribute_s(hid_t grp, const char* name, const char* str);
void io_write_code_description(hid_t h_file);
void io_read_unit_system(hid_t h_file, struct unit_system* us);
void io_read_unit_system(hid_t h_file, struct unit_system* us, int mpi_rank);
void io_write_unit_system(hid_t h_grp, const struct unit_system* us,
const char* groupName);
......
......@@ -262,7 +262,7 @@ void writeArray_chunk(struct engine* e, hid_t h_data, hid_t h_plist_id,
/* Allocate temporary buffer */
void* temp = malloc(num_elements * typeSize);
if (posix_memalign((void**)&temp, SWIFT_CACHE_ALIGNMENT,
if (posix_memalign((void**)&temp, IO_BUFFER_ALIGNMENT,
num_elements * typeSize) != 0)
error("Unable to allocate temporary i/o buffer");
......@@ -584,7 +584,7 @@ void read_ic_parallel(char* fileName, const struct unit_system* internal_units,
/* Read the unit system used in the ICs */
struct unit_system* ic_units = malloc(sizeof(struct unit_system));
if (ic_units == NULL) error("Unable to allocate memory for IC unit system");
io_read_unit_system(h_file, ic_units);
io_read_unit_system(h_file, ic_units, mpi_rank);
/* Tell the user if a conversion will be needed */
if (mpi_rank == 0) {
......@@ -702,7 +702,9 @@ void read_ic_parallel(char* fileName, const struct unit_system* internal_units,
break;
default:
message("Particle Type %d not yet supported. Particles ignored", ptype);
if (mpi_rank == 0)
message("Particle Type %d not yet supported. Particles ignored",
ptype);
}
/* Read everything */
......
......@@ -301,7 +301,7 @@ void writeArray(const struct engine* e, hid_t grp, char* fileName,
/* Allocate temporary buffer */
void* temp = NULL;
if (posix_memalign((void**)&temp, SWIFT_CACHE_ALIGNMENT,
if (posix_memalign((void**)&temp, IO_BUFFER_ALIGNMENT,
num_elements * typeSize) != 0)
error("Unable to allocate temporary i/o buffer");
......@@ -480,7 +480,7 @@ void read_ic_serial(char* fileName, const struct unit_system* internal_units,
/* Read the unit system used in the ICs */
if (ic_units == NULL) error("Unable to allocate memory for IC unit system");
io_read_unit_system(h_file, ic_units);
io_read_unit_system(h_file, ic_units, mpi_rank);
if (units_are_equal(ic_units, internal_units)) {
......@@ -624,8 +624,9 @@ void read_ic_serial(char* fileName, const struct unit_system* internal_units,
break;
default:
message("Particle Type %d not yet supported. Particles ignored",
ptype);
if (mpi_rank == 0)
message("Particle Type %d not yet supported. Particles ignored",
ptype);
}
/* Read everything */
......
......@@ -182,7 +182,7 @@ void writeArray(const struct engine* e, hid_t grp, char* fileName,
/* Allocate temporary buffer */
void* temp = NULL;
if (posix_memalign((void**)&temp, SWIFT_CACHE_ALIGNMENT,
if (posix_memalign((void**)&temp, IO_BUFFER_ALIGNMENT,
num_elements * typeSize) != 0)
error("Unable to allocate temporary i/o buffer");
......@@ -387,7 +387,7 @@ void read_ic_single(char* fileName, const struct unit_system* internal_units,
/* Read the unit system used in the ICs */
struct unit_system* ic_units = malloc(sizeof(struct unit_system));
if (ic_units == NULL) error("Unable to allocate memory for IC unit system");
io_read_unit_system(h_file, ic_units);
io_read_unit_system(h_file, ic_units, 0);
/* Tell the user if a conversion will be needed */
if (units_are_equal(ic_units, internal_units)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment