From 866c8f97dea89938befdac77bc580c7f1a161fc0 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Fri, 6 Apr 2018 14:46:36 +0100 Subject: [PATCH] Correct use of the HAVE_HDF5 option throughout the whole code. --- examples/main.c | 2 ++ src/common_io.c | 91 +++++++++++++++++++++++++------------------------ src/common_io.h | 9 ++--- src/engine.c | 2 ++ src/parser.h | 5 ++- 5 files changed, 57 insertions(+), 52 deletions(-) diff --git a/examples/main.c b/examples/main.c index fcf51e7807..ca91c9e718 100644 --- a/examples/main.c +++ b/examples/main.c @@ -642,6 +642,7 @@ int main(int argc, char *argv[]) { double dim[3] = {0., 0., 0.}; int periodic = 0; if (myrank == 0) clocks_gettime(&tic); +#if defined(HAVE_HDF5) #if defined(WITH_MPI) #if defined(HAVE_PARALLEL_HDF5) read_ic_parallel(ICfileName, &us, dim, &parts, &gparts, &sparts, &Ngas, @@ -661,6 +662,7 @@ int main(int argc, char *argv[]) { &Ngpart, &Nspart, &periodic, &flag_entropy_ICs, with_hydro, (with_external_gravity || with_self_gravity), with_stars, cleanup_h, cosmo.h, nr_threads, dry_run); +#endif #endif if (myrank == 0) { clocks_gettime(&toc); diff --git a/src/common_io.c b/src/common_io.c index 19adc57fbd..c235060b10 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -21,21 +21,6 @@ /* Config parameters. */ #include "../config.h" -#if defined(HAVE_HDF5) - -/* Some standard headers. */ -#include <hdf5.h> -#include <math.h> -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -/* MPI headers. */ -#ifdef WITH_MPI -#include <mpi.h> -#endif - /* This object's header. */ #include "common_io.h" @@ -50,6 +35,22 @@ #include "units.h" #include "version.h" +/* Some standard headers. */ +#include <math.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#if defined(HAVE_HDF5) + +#include <hdf5.h> + +/* MPI headers. */ +#ifdef WITH_MPI +#include <mpi.h> +#endif + /** * @brief Converts a C data type to the HDF5 equivalent. * @@ -84,36 +85,6 @@ hid_t io_hdf5_type(enum IO_DATA_TYPE type) { } } -/** - * @brief Returns the memory size of the data type - */ -size_t io_sizeof_type(enum IO_DATA_TYPE type) { - - switch (type) { - case INT: - return sizeof(int); - case UINT: - return sizeof(unsigned int); - case LONG: - return sizeof(long); - case ULONG: - return sizeof(unsigned long); - case LONGLONG: - return sizeof(long long); - case ULONGLONG: - return sizeof(unsigned long long); - case FLOAT: - return sizeof(float); - case DOUBLE: - return sizeof(double); - case CHAR: - return sizeof(char); - default: - error("Unknown type"); - return 0; - } -} - /** * @brief Return 1 if the type has double precision * @@ -429,6 +400,36 @@ void io_write_engine_policy(hid_t h_file, const struct engine* e) { #endif /* HAVE_HDF5 */ +/** + * @brief Returns the memory size of the data type + */ +size_t io_sizeof_type(enum IO_DATA_TYPE type) { + + switch (type) { + case INT: + return sizeof(int); + case UINT: + return sizeof(unsigned int); + case LONG: + return sizeof(long); + case ULONG: + return sizeof(unsigned long); + case LONGLONG: + return sizeof(long long); + case ULONGLONG: + return sizeof(unsigned long long); + case FLOAT: + return sizeof(float); + case DOUBLE: + return sizeof(double); + case CHAR: + return sizeof(char); + default: + error("Unknown type"); + return 0; + } +} + /** * @brief Mapper function to copy #part or #gpart fields into a buffer. */ diff --git a/src/common_io.h b/src/common_io.h index 49358d8a37..4f6d75fad0 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -37,8 +37,6 @@ struct io_props; struct engine; struct threadpool; -#if defined(HAVE_HDF5) - /** * @brief The different types of data used in the GADGET IC files. * @@ -56,9 +54,9 @@ enum IO_DATA_TYPE { CHAR }; +#if defined(HAVE_HDF5) + hid_t io_hdf5_type(enum IO_DATA_TYPE type); -size_t io_sizeof_type(enum IO_DATA_TYPE type); -int io_is_double_precision(enum IO_DATA_TYPE type); void io_read_attribute(hid_t grp, const char* name, enum IO_DATA_TYPE type, void* data); @@ -86,6 +84,9 @@ void io_copy_temp_buffer(void* temp, const struct engine* e, #endif /* defined HDF5 */ +size_t io_sizeof_type(enum IO_DATA_TYPE type); +int io_is_double_precision(enum IO_DATA_TYPE type); + void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot, struct gpart* const dmparts, size_t Ndm); void io_prepare_dm_gparts(struct threadpool* tp, struct gpart* const gparts, diff --git a/src/engine.c b/src/engine.c index 47c96abab2..fd7b2cd94e 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5089,6 +5089,7 @@ void engine_dump_snapshot(struct engine *e) { #endif /* Dump... */ +#if defined(WITH_HDF5) #if defined(WITH_MPI) #if defined(HAVE_PARALLEL_HDF5) write_output_parallel(e, e->snapshotBaseName, e->internal_units, @@ -5102,6 +5103,7 @@ void engine_dump_snapshot(struct engine *e) { #else write_output_single(e, e->snapshotBaseName, e->internal_units, e->snapshotUnits); +#endif #endif e->dump_snapshot = 0; diff --git a/src/parser.h b/src/parser.h index 4e61b16ab5..7909b12090 100644 --- a/src/parser.h +++ b/src/parser.h @@ -23,9 +23,8 @@ /* Config parameters. */ #include "../config.h" -#if defined(HAVE_HDF5) -#include <hdf5.h> -#endif +/* Standard headers */ +#include <stdio.h> /* Some constants. */ #define PARSER_MAX_LINE_SIZE 256 -- GitLab