diff --git a/configure.ac b/configure.ac index 7061b83e4ef015059965b3d1637db12e6571e32f..e5fccfaff85ea6ba2d5532233abdfae5e53c2bda 100644 --- a/configure.ac +++ b/configure.ac @@ -379,10 +379,16 @@ AX_PTHREAD([LIBS="$PTHREAD_LIBS $LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" or use CPPFLAGS and LDFLAGS if the library is installed in a non-standard location.])) +# Check whether POSIX thread barriers are implemented (e.g. OSX does not have them) AC_CHECK_LIB(pthread, pthread_barrier_init, AC_DEFINE([HAVE_PTHREAD_BARRIERS], [1], [The posix library implements barriers]), AC_MSG_WARN(POSIX implementation does not have barriers. SWIFT will use home-made ones.)) +# Check whether POSIX file allocation functions exist (e.g. OSX does not have them) +AC_CHECK_LIB(pthread, posix_fallocate, + AC_DEFINE([HAVE_POSIX_FALLOCATE], [1], [The posix library implements file allocation functions.]), + AC_MSG_WARN(POSIX implementation does not have file allocation functions.)) + # Check for metis. Note AX_LIB_METIS exists, but cannot be configured # to be default off (i.e. given no option it tries to locate METIS), so we # don't use that. diff --git a/src/dump.c b/src/dump.c index 2c0cf221ebd897bab0d047c196ce8a2aeddc6eae..416d035221763e023d64024727aa9e552f1b69e0 100644 --- a/src/dump.c +++ b/src/dump.c @@ -17,9 +17,20 @@ * ******************************************************************************/ +/* Config parameters. */ + /* Config parameters. */ #include "../config.h" +#ifdef HAVE_POSIX_FALLOCATE + +/* This object's header. */ +#include "dump.h" + +/* Local headers. */ +#include "atomic.h" +#include "error.h" + /* Some standard headers. */ #include <errno.h> #include <fcntl.h> @@ -29,13 +40,6 @@ #include <sys/types.h> #include <unistd.h> -/* This object's header. */ -#include "dump.h" - -/* Local headers. */ -#include "atomic.h" -#include "error.h" - /** * @brief Obtain a chunk of memory from a dump. * @@ -44,7 +48,6 @@ * @param offset The offset of the returned memory address within the dump file. * @return A pointer to the memory-mapped chunk of data. */ - void *dump_get(struct dump *d, size_t count, size_t *offset) { size_t local_offset = atomic_add(&d->count, count); *offset = local_offset + d->file_offset; @@ -54,7 +57,6 @@ void *dump_get(struct dump *d, size_t count, size_t *offset) { /** * @brief Ensure that at least size bytes are available in the #dump. */ - void dump_ensure(struct dump *d, size_t size) { /* If we have enough space already, just bail. */ @@ -88,7 +90,6 @@ void dump_ensure(struct dump *d, size_t size) { /** * @brief Flush the #dump to disk. */ - void dump_sync(struct dump *d) { if (msync(d->data, d->count, MS_SYNC) != 0) error("Failed to sync memory-mapped data."); @@ -97,7 +98,6 @@ void dump_sync(struct dump *d) { /** * @brief Finalize the #dump. */ - void dump_close(struct dump *d) { /* Unmap the data in memory. */ if (munmap(d->data, d->count) != 0) { @@ -121,7 +121,6 @@ void dump_close(struct dump *d) { * note that it will be overwritten. * @param size The initial buffer size for this #dump. */ - void dump_init(struct dump *d, const char *filename, size_t size) { /* Create the output file. */ @@ -151,3 +150,5 @@ void dump_init(struct dump *d, const char *filename, size_t size) { d->file_offset = 0; d->page_mask = page_mask; } + +#endif /* HAVE_POSIX_FALLOCATE */ diff --git a/src/dump.h b/src/dump.h index a7e934218c271d2f82b99d39f278e5af3047be6e..6857aa3a008a27e0e8ed23854d84f848ee0ca2be 100644 --- a/src/dump.h +++ b/src/dump.h @@ -19,8 +19,13 @@ #ifndef SWIFT_DUMP_H #define SWIFT_DUMP_H -/* Includes. */ -#include "lock.h" +/* Config parameters. */ +#include "../config.h" + +#ifdef HAVE_POSIX_FALLOCATE /* Are we on a sensible platform? */ + +/* Standard headers */ +#include <stdlib.h> /* Some constants. */ #define dump_grow_ensure_factor 10 @@ -54,4 +59,6 @@ void dump_sync(struct dump *d); void dump_close(struct dump *d); void *dump_get(struct dump *d, size_t count, size_t *offset); +#endif /* HAVE_POSIX_FALLOCATE */ + #endif /* SWIFT_DUMP_H */ diff --git a/src/logger.c b/src/logger.c index b2acf47aa70cef55f53d296033f6f5c6162fd5bd..0e0bc930c0841f985da2c353357a69b69aba5d91 100644 --- a/src/logger.c +++ b/src/logger.c @@ -20,6 +20,8 @@ /* Config parameters. */ #include "../config.h" +#ifdef HAVE_POSIX_FALLOCATE /* Are we on a sensible platform? */ + /* Some standard headers. */ #include <stdint.h> #include <stdlib.h> @@ -41,7 +43,6 @@ * * @return The size of the logger message in bytes. */ - int logger_size(unsigned int mask) { /* Start with 8 bytes for the header. */ @@ -95,7 +96,6 @@ int logger_size(unsigned int mask) { * @param offset Pointer to the offset of the previous log of this particle. * @param dump The #dump in which to log the particle data. */ - void logger_log_part(struct part *p, unsigned int mask, size_t *offset, struct dump *dump) { @@ -176,7 +176,6 @@ void logger_log_part(struct part *p, unsigned int mask, size_t *offset, * @param offset Pointer to the offset of the previous log of this particle. * @param dump The #dump in which to log the particle data. */ - void logger_log_gpart(struct gpart *p, unsigned int mask, size_t *offset, struct dump *dump) { @@ -270,7 +269,6 @@ void logger_log_timestamp(unsigned long long int timestamp, size_t *offset, * * @return The mask containing the values read. */ - int logger_read_part(struct part *p, size_t *offset, const char *buff) { /* Jump to the offset. */ @@ -349,7 +347,6 @@ int logger_read_part(struct part *p, size_t *offset, const char *buff) { * * @return The mask containing the values read. */ - int logger_read_gpart(struct gpart *p, size_t *offset, const char *buff) { /* Jump to the offset. */ @@ -416,7 +413,6 @@ int logger_read_gpart(struct gpart *p, size_t *offset, const char *buff) { * * @return The mask containing the values read. */ - int logger_read_timestamp(unsigned long long int *t, size_t *offset, const char *buff) { @@ -444,3 +440,5 @@ int logger_read_timestamp(unsigned long long int *t, size_t *offset, /* Finally, return the mask of the values we just read. */ return mask; } + +#endif /* HAVE_POSIX_FALLOCATE */