From f63fb1306570eed3011a524a0cb9b1d09a586bcd Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Fri, 13 Sep 2019 21:35:49 +0200 Subject: [PATCH] Code formatting. Do not comile the logger functions when MPI is enabled. --- logger/logger_particle.h | 2 +- logger/logger_time.c | 16 +++++++--------- logger/tests/testTimeArray.c | 15 +++++++-------- src/engine.c | 2 +- src/logger_io.c | 4 ++-- src/logger_io.h | 10 ++++++---- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/logger/logger_particle.h b/logger/logger_particle.h index 8906fd3462..addd23564b 100644 --- a/logger/logger_particle.h +++ b/logger/logger_particle.h @@ -104,4 +104,4 @@ void logger_particle_interpolate(struct logger_particle *part_curr, const struct logger_particle *part_next, const double time); -#endif //LOGGER_LOGGER_PARTICLE_H +#endif // LOGGER_LOGGER_PARTICLE_H diff --git a/logger/logger_time.c b/logger/logger_time.c index 829b87a1e1..d2c6ebc3f9 100644 --- a/logger/logger_time.c +++ b/logger/logger_time.c @@ -45,7 +45,6 @@ void time_array_ensure_size(struct time_array *t) { /* Set the pointer to the new array */ t->records = tmp; - } /** @@ -236,14 +235,12 @@ size_t time_array_get_index(const struct time_array *t, const size_t offset) { while (left <= right) { size_t center = (left + right) / 2; const size_t offset_center = t->records[center].offset; - + if (offset > offset_center) { left = center + 1; - } - else if (offset < offset_center) { + } else if (offset < offset_center) { right = center - 1; - } - else { + } else { return center; } } @@ -277,8 +274,8 @@ void time_array_print(const struct time_array *t) { size_t n = t->size; size_t up_threshold = n - threshold; - printf("Times (size %lu): [%lli (%g)", n, - t->records[0].int_time, t->records[0].time); + printf("Times (size %lu): [%lli (%g)", n, t->records[0].int_time, + t->records[0].time); /* Loop over all elements. */ for (size_t i = 1; i < n; i++) { @@ -308,7 +305,8 @@ void time_array_print_offset(const struct time_array *t) { /* Loop over all elements. */ for (size_t i = 1; i < n; i++) { /* Skip the offset in the middle of the array. */ - if (i < threshold || i > up_threshold) printf(", %lu", t->records[i].offset); + if (i < threshold || i > up_threshold) + printf(", %lu", t->records[i].offset); if (i == threshold) printf(", ..."); } diff --git a/logger/tests/testTimeArray.c b/logger/tests/testTimeArray.c index f07f167496..929a7124ba 100644 --- a/logger/tests/testTimeArray.c +++ b/logger/tests/testTimeArray.c @@ -17,9 +17,9 @@ * ******************************************************************************/ -#include "logger_time.h" -#include <time.h> #include <stdlib.h> +#include <time.h> +#include "logger_time.h" #define NUMBER_OF_ELEMENT 10000 #define TIME_BASE 0.04 @@ -40,16 +40,16 @@ int main(int argc, char *argv[]) { time_array_init(×); /* Add elements */ - for(size_t i = 0; i < NUMBER_OF_ELEMENT; i++) { + for (size_t i = 0; i < NUMBER_OF_ELEMENT; i++) { integertime_t int_time = i; double time = i * TIME_BASE; size_t offset = i * OFFSET_BASE; - + time_array_append(×, int_time, time, offset); } /* Check the elements */ - for(size_t i = 0; i < NUMBER_OF_ELEMENT; i++) { + for (size_t i = 0; i < NUMBER_OF_ELEMENT; i++) { integertime_t int_time = i; double time = i * TIME_BASE; size_t offset = i * OFFSET_BASE; @@ -66,14 +66,13 @@ int main(int argc, char *argv[]) { /* Get the index from the offset */ size_t ind = time_array_get_index(×, read_offset); - + /* Check the values obtained */ assert(i == ind); assert(int_time == times.records[ind].int_time); assert(time == times.records[ind].time); - assert(offset == times.records[ind].offset); + assert(offset == times.records[ind].offset); } - return 0; } diff --git a/src/engine.c b/src/engine.c index 2b9cbd3895..e58590d2be 100644 --- a/src/engine.c +++ b/src/engine.c @@ -4792,7 +4792,7 @@ void engine_dump_snapshot(struct engine *e) { */ void engine_dump_index(struct engine *e) { -#if defined(WITH_LOGGER) +#if defined(WITH_LOGGER) && !defined(WITH_MPI) struct clocks_time time1, time2; clocks_gettime(&time1); diff --git a/src/logger_io.c b/src/logger_io.c index 9a4f10ea2e..c6be1f2924 100644 --- a/src/logger_io.c +++ b/src/logger_io.c @@ -21,7 +21,7 @@ /* Config parameters. */ #include "../config.h" -#ifdef WITH_LOGGER +#if defined(WITH_LOGGER) && defined(HAVE_HDF5) && !defined(WITH_MPI) /* Some standard headers. */ #include <hdf5.h> @@ -296,4 +296,4 @@ void write_index_single(struct engine* e, const char* baseName, ++outputCount; } -#endif /* HAVE_HDF5 */ +#endif /* WITH_LOGGER && HAVE_HDF5 && !WITH_MPI */ diff --git a/src/logger_io.h b/src/logger_io.h index 574fc0129d..a424c5c104 100644 --- a/src/logger_io.h +++ b/src/logger_io.h @@ -50,11 +50,13 @@ __attribute__((always_inline)) INLINE static void hydro_write_index( *num_fields = 2; /* List what we want to write */ - list[0] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, 0.f, parts, id, "will be erased"); + list[0] = + io_make_output_field("ParticleIDs", ULONGLONG, 1, UNIT_CONV_NO_UNITS, 0.f, + parts, id, "will be erased"); - list[1] = io_make_output_field("Offset", ULONGLONG, 1, UNIT_CONV_NO_UNITS, 0.f, - xparts, logger_data.last_offset, "will be erased"); + list[1] = + io_make_output_field("Offset", ULONGLONG, 1, UNIT_CONV_NO_UNITS, 0.f, + xparts, logger_data.last_offset, "will be erased"); } #endif -- GitLab