Commit efc90268 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

applied clang-format -i Google to all files in src, added defines to header files.


Former-commit-id: ad57abd66743bb61032ac57dfe07b616a8a6434a
parent decf122a
/*******************************************************************************
* This file is part of SWIFT.
* Coypright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
******************************************************************************/
#ifndef SWIFT_ATOMIC_H
#define SWIFT_ATOMIC_H
#include "inline.h"
#define atomic_add(v,i) __sync_fetch_and_add( v , i )
#define atomic_inc(v) atomic_add( v , 1 )
#define atomic_dec(v) atomic_add( v , -1 )
#define atomic_cas(v,o,n) __sync_val_compare_and_swap( v , o , n )
#define atomic_add(v, i) __sync_fetch_and_add(v, i)
#define atomic_inc(v) atomic_add(v, 1)
#define atomic_dec(v) atomic_add(v, -1)
#define atomic_cas(v, o, n) __sync_val_compare_and_swap(v, o, n)
#endif /* SWIFT_ATOMIC_H */
This diff is collapsed.
/*******************************************************************************
* This file is part of SWIFT.
* Coypright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
******************************************************************************/
#ifndef SWIFT_CELL_H
#define SWIFT_CELL_H
/* Some constants. */
#define cell_sid_dt 13
#define cell_max_tag (1 << 16)
#define cell_sid_dt 13
#define cell_max_tag (1 << 16)
/* Global variables. */
extern int cell_next_tag;
/* Packed cell. */
struct pcell {
/* Stats on this cell's particles. */
double h_max, dt_min, dt_max;
/* Number of particles in this cell. */
int count;
/* tag used for MPI communication. */
int tag;
/* Stats on this cell's particles. */
double h_max, dt_min, dt_max;
/* Number of particles in this cell. */
int count;
/* Relative indices of the cell's progeny. */
int progeny[8];
};
/* tag used for MPI communication. */
int tag;
/* Relative indices of the cell's progeny. */
int progeny[8];
};
/* Structure to store the data of a single cell. */
struct cell {
/* The cell location on the grid. */
double loc[3];
/* The cell dimensions. */
double h[3];
/* Max radii in this cell. */
double h_max;
/* Minimum and maximum dt in this cell. */
double dt_min, dt_max;
/* Minimum dimension, i.e. smallest edge of this cell. */
float dmin;
/* Maximum slack allowed for particle movement. */
float slack;
/* Maximum particle movement in this cell. */
float dx_max;
/* The depth of this cell in the tree. */
int depth, split, maxdepth;
/* Nr of parts. */
int count, gcount;
/* Pointers to the particle data. */
struct part *parts;
/* Pointers to the extra particle data. */
struct xpart *xparts;
/* Pointers to the gravity particle data. */
struct gpart *gparts;
/* Pointers for the sorted indices. */
struct entry *sort, *gsort;
unsigned int sorted, gsorted;
/* Pointers to the next level of cells. */
struct cell *progeny[8];
/* Parent cell. */
struct cell *parent;
/* Super cell, i.e. the highest-level supercell that has interactions. */
struct cell *super;
/* The task computing this cell's sorts. */
struct task *sorts, *gsorts;
int sortsize, gsortsize;
/* The tasks computing this cell's density. */
struct link *density, *force, *grav;
int nr_density, nr_force, nr_grav;
/* The ghost task to link density to interactions. */
struct task *ghost, *kick1, *kick2;
/* Task receiving data. */
struct task *recv_xv, *recv_rho;
/* Tasks for gravity tree. */
struct task *grav_up, *grav_down;
/* Number of tasks that are associated with this cell. */
int nr_tasks;
/* Is the data of this cell being used in a sub-cell? */
int hold, ghold;
/* Spin lock for various uses. */
lock_type lock, glock;
/* ID of the previous owner, e.g. runner. */
int owner;
/* Momentum of particles in cell. */
float mom[3], ang[3];
/* Potential and kinetic energy of particles in this cell. */
double epot, ekin;
/* Number of particles updated in this cell. */
int updated;
/* Linking pointer for "memory management". */
struct cell *next;
/* ID of the node this cell lives on. */
int nodeID;
/* Bit mask of the proxies this cell is registered with. */
unsigned long long int sendto;
/* Pointer to this cell's packed representation. */
struct pcell *pcell;
int pcell_size;
int tag;
/* This cell's multipole. */
struct multipole multipole;
} __attribute__((aligned (64)));
/* The cell location on the grid. */
double loc[3];
/* The cell dimensions. */
double h[3];
/* Max radii in this cell. */
double h_max;
/* Minimum and maximum dt in this cell. */
double dt_min, dt_max;
/* Minimum dimension, i.e. smallest edge of this cell. */
float dmin;
/* Maximum slack allowed for particle movement. */
float slack;
/* Maximum particle movement in this cell. */
float dx_max;
/* The depth of this cell in the tree. */
int depth, split, maxdepth;
/* Nr of parts. */
int count, gcount;
/* Pointers to the particle data. */
struct part *parts;
/* Pointers to the extra particle data. */
struct xpart *xparts;
/* Pointers to the gravity particle data. */
struct gpart *gparts;
/* Pointers for the sorted indices. */
struct entry *sort, *gsort;
unsigned int sorted, gsorted;
/* Pointers to the next level of cells. */
struct cell *progeny[8];
/* Parent cell. */
struct cell *parent;
/* Super cell, i.e. the highest-level supercell that has interactions. */
struct cell *super;
/* The task computing this cell's sorts. */
struct task *sorts, *gsorts;
int sortsize, gsortsize;
/* The tasks computing this cell's density. */
struct link *density, *force, *grav;
int nr_density, nr_force, nr_grav;
/* The ghost task to link density to interactions. */
struct task *ghost, *kick1, *kick2;
/* Task receiving data. */
struct task *recv_xv, *recv_rho;
/* Tasks for gravity tree. */
struct task *grav_up, *grav_down;
/* Number of tasks that are associated with this cell. */
int nr_tasks;
/* Is the data of this cell being used in a sub-cell? */
int hold, ghold;
/* Spin lock for various uses. */
lock_type lock, glock;
/* ID of the previous owner, e.g. runner. */
int owner;
/* Momentum of particles in cell. */
float mom[3], ang[3];
/* Potential and kinetic energy of particles in this cell. */
double epot, ekin;
/* Number of particles updated in this cell. */
int updated;
/* Linking pointer for "memory management". */
struct cell *next;
/* ID of the node this cell lives on. */
int nodeID;
/* Bit mask of the proxies this cell is registered with. */
unsigned long long int sendto;
/* Pointer to this cell's packed representation. */
struct pcell *pcell;
int pcell_size;
int tag;
/* This cell's multipole. */
struct multipole multipole;
} __attribute__((aligned(64)));
/* Function prototypes. */
void cell_split ( struct cell *c );
int cell_locktree( struct cell *c );
void cell_unlocktree( struct cell *c );
int cell_glocktree( struct cell *c );
void cell_gunlocktree( struct cell *c );
int cell_pack ( struct cell *c , struct pcell *pc );
int cell_unpack ( struct pcell *pc , struct cell *c , struct space *s );
int cell_getsize ( struct cell *c );
int cell_link ( struct cell *c , struct part *parts );
void cell_split(struct cell *c);
int cell_locktree(struct cell *c);
void cell_unlocktree(struct cell *c);
int cell_glocktree(struct cell *c);
void cell_gunlocktree(struct cell *c);
int cell_pack(struct cell *c, struct pcell *pc);
int cell_unpack(struct pcell *pc, struct cell *c, struct space *s);
int cell_getsize(struct cell *c);
int cell_link(struct cell *c, struct part *parts);
#endif /* SWIFT_CELL_H */
This diff is collapsed.
......@@ -2,21 +2,23 @@
* This file is part of SWIFT.
* Coypright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk),
* Matthieu Schaller (matthieu.schaller@durham.ac.uk).
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
******************************************************************************/
#ifndef SWIFT_COMMON_IO_H
#define SWIFT_COMMON_IO_H
/* Config parameters. */
#include "../config.h"
......@@ -25,29 +27,40 @@
#if defined(HAVE_HDF5)
/**
* @brief The different types of data used in the GADGET IC files.
*
* (This is admittedly a poor substitute to C++ templates...)
*/
enum DATA_TYPE{INT, LONG, LONGLONG, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, CHAR};
enum DATA_TYPE {
INT,
LONG,
LONGLONG,
UINT,
ULONG,
ULONGLONG,
FLOAT,
DOUBLE,
CHAR
};
/**
* @brief The two sorts of data present in the GADGET IC files: compulsory to start a run or optional.
* @brief The two sorts of data present in the GADGET IC files: compulsory to
*start a run or optional.
*
*/
enum DATA_IMPORTANCE{COMPULSORY=1, OPTIONAL=0};
enum DATA_IMPORTANCE {
COMPULSORY = 1,
OPTIONAL = 0
};
hid_t hdf5Type(enum DATA_TYPE type);
size_t sizeOfType(enum DATA_TYPE type);
void readAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data);
void writeAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data, int num);
void writeAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data,
int num);
void writeAttribute_d(hid_t grp, char* name, double data);
void writeAttribute_f(hid_t grp, char* name, float data);
......@@ -58,9 +71,9 @@ void writeAttribute_s(hid_t grp, char* name, char* str);
void createXMFfile();
FILE* prepareXMFfile();
void writeXMFfooter(FILE* xmfFile);
void writeXMFheader(FILE* xmfFile, long long N, char* hdfFileName, float time);
void writeXMFline(FILE* xmfFile, char* fileName, char* name, long long N, int dim, enum DATA_TYPE type);
void writeXMFheader(FILE* xmfFile, long long N, char* hdfFileName, float time);
void writeXMFline(FILE* xmfFile, char* fileName, char* name, long long N,
int dim, enum DATA_TYPE type);
/**
* @brief Writes the current model of SPH to the file
......@@ -74,5 +87,6 @@ void writeSPHflavour(hid_t h_file);
*/
void writeUnitSystem(hid_t h_file, struct UnitSystem* us);
#endif
#endif /* SWIFT_COMMON_IO_H */
......@@ -2,63 +2,74 @@
* This file is part of SWIFT.
* Coypright (c) 2012 Pedro Gonnet (ptcedro.gonnet@durham.ac.uk)
* Matthieu Schaller (matthieu.schaller@durham.ac.uk)
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
******************************************************************************/
#ifndef SWIFT_CONST_H
#define SWIFT_CONST_H
/* Hydrodynamical constants. */
#define const_hydro_gamma (5.0f/3.0f)
#define const_hydro_gamma (5.0f / 3.0f)
/* SPH Viscosity constants. */
#define const_viscosity_alpha 0.8f /* Used in the legacy gadget-2 SPH mode only */
#define const_viscosity_alpha_min 0.1f /* Values taken from (Price,2004), not used in legacy gadget mode */
#define const_viscosity_alpha_max 2.0f /* Values taken from (Price,2004), not used in legacy gadget mode */
#define const_viscosity_length 0.1f /* Values taken from (Price,2004), not used in legacy gadget mode */
#define const_viscosity_alpha \
0.8f /* Used in the legacy gadget-2 SPH mode only */
#define const_viscosity_alpha_min \
0.1f /* Values taken from (Price,2004), not used in legacy gadget mode */
#define const_viscosity_alpha_max \
2.0f /* Values taken from (Price,2004), not used in legacy gadget mode */
#define const_viscosity_length \
0.1f /* Values taken from (Price,2004), not used in legacy gadget mode */
/* SPH Thermal conductivity constants. */
#define const_conductivity_alpha 1.f /* Value taken from (Price,2008), not used in legacy gadget mode */
#define const_conductivity_alpha \
1.f /* Value taken from (Price,2008), not used in legacy gadget mode */
/* Time integration constants. */
#define const_cfl 0.3f
#define const_ln_max_h_change 0.231111721f /* Particle can't change volume by more than a factor of 2=1.26^3 over one time step */
#define const_max_u_change 0.1f
#define const_cfl 0.3f
#define const_ln_max_h_change \
0.231111721f /* Particle can't change volume by more than a factor of \
2=1.26^3 over one time step */
#define const_max_u_change 0.1f
/* Neighbour search constants. */
#define const_eta_kernel 1.2349f /* Corresponds to 48 ngbs with the cubic spline kernel */
#define const_delta_nwneigh 1.f
#define const_eta_kernel \
1.2349f /* Corresponds to 48 ngbs with the cubic spline kernel */
#define const_delta_nwneigh 1.f
#define CUBIC_SPLINE_KERNEL
/* Gravity stuff. */
#define const_theta_max 0.57735f /* Opening criteria, which is the ratio of the
cell distance over the cell width. */
#define const_theta_max \
0.57735f /* Opening criteria, which is the ratio of the \
cell distance over the cell width. */
// #define const_G 6.67384e-8f /* Gravitational constant. */
#define const_G 6.672e-8f /* Gravitational constant. */
#define const_epsilon 0.0014f /* Gravity blending distance. */
#define const_iepsilon 714.285714286f /* Inverse gravity blending distance. */
#define const_iepsilon2 (const_iepsilon*const_iepsilon)
#define const_iepsilon3 (const_iepsilon2*const_iepsilon)
#define const_iepsilon4 (const_iepsilon2*const_iepsilon2)
#define const_iepsilon5 (const_iepsilon3*const_iepsilon2)
#define const_iepsilon6 (const_iepsilon3*const_iepsilon3)
#define const_G 6.672e-8f /* Gravitational constant. */
#define const_epsilon 0.0014f /* Gravity blending distance. */
#define const_iepsilon 714.285714286f /* Inverse gravity blending distance. */
#define const_iepsilon2 (const_iepsilon* const_iepsilon)
#define const_iepsilon3 (const_iepsilon2* const_iepsilon)
#define const_iepsilon4 (const_iepsilon2* const_iepsilon2)
#define const_iepsilon5 (const_iepsilon3* const_iepsilon2)
#define const_iepsilon6 (const_iepsilon3* const_iepsilon3)
/* SPH variant to use */
#define LEGACY_GADGET2_SPH
/* System of units */
#define const_unit_length_in_cgs 1 /* 3.08567810e16 /\* 1Mpc *\/ */
#define const_unit_mass_in_cgs 1 /* 1.9891e33 /\* 1 M_sun *\/ */
#define const_unit_velocity_in_cgs 1 /* 1e5 /\* km s^-1 *\/ */
#define const_unit_length_in_cgs 1 /* 3.08567810e16 /\* 1Mpc *\/ */
#define const_unit_mass_in_cgs 1 /* 1.9891e33 /\* 1 M_sun *\/ */
#define const_unit_velocity_in_cgs 1 /* 1e5 /\* km s^-1 *\/ */
#endif /* SWIFT_CONST_H */
......@@ -23,7 +23,6 @@
*
*/
/* machine-dependent cycle counters code. Needs to be inlined. */
/***************************************************************************/
......@@ -52,25 +51,28 @@
defined according to whether the corresponding function/type/header
is available on your system. The necessary macros are most
conveniently defined if you are using GNU autoconf, via the tests:
dnl ---------------------------------------------------------------------
AC_C_INLINE
AC_HEADER_TIME
AC_CHECK_HEADERS([sys/time.h c_asm.h intrinsics.h mach/mach_time.h])
AC_CHECK_TYPE([hrtime_t],[AC_DEFINE(HAVE_HRTIME_T, 1, [Define to 1 if hrtime_t is defined in <sys/time.h>])],,[#if HAVE_SYS_TIME_H
AC_CHECK_TYPE([hrtime_t],[AC_DEFINE(HAVE_HRTIME_T, 1, [Define to 1 if
hrtime_t is defined in <sys/time.h>])],,[#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif])
AC_CHECK_FUNCS([gethrtime read_real_time time_base_to_time clock_gettime mach_absolute_time])
AC_CHECK_FUNCS([gethrtime read_real_time time_base_to_time clock_gettime
mach_absolute_time])
dnl Cray UNICOS _rtc() (real-time clock) intrinsic
AC_MSG_CHECKING([for _rtc intrinsic])
rtc_ok=yes
AC_TRY_LINK([#ifdef HAVE_INTRINSICS_H
#include <intrinsics.h>
#endif], [_rtc()], [AC_DEFINE(HAVE__RTC,1,[Define if you have the UNICOS _rtc() intrinsic.])], [rtc_ok=no])
#endif], [_rtc()], [AC_DEFINE(HAVE__RTC,1,[Define if you have the UNICOS _rtc()
intrinsic.])], [rtc_ok=no])
AC_MSG_RESULT($rtc_ok)
dnl ---------------------------------------------------------------------
......@@ -79,24 +81,25 @@
/***************************************************************************/
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#include <sys/time.h>
#include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
#define INLINE_ELAPSED(INL) static INL double elapsed(ticks t1, ticks t0) \
{ \
return (double)t1 - (double)t0; \
}
#define INLINE_ELAPSED(INL) \
static INL double elapsed(ticks t1, ticks t0) { \
return (double)t1 - (double)t0; \
}
/*----------------------------------------------------------------*/
/* Solaris */
#if defined(HAVE_GETHRTIME) && defined(HAVE_HRTIME_T) && !defined(HAVE_TICK_COUNTER)
#if defined(HAVE_GETHRTIME) && defined(HAVE_HRTIME_T) && \
!defined(HAVE_TICK_COUNTER)
typedef hrtime_t ticks;
#define getticks gethrtime
......@@ -108,22 +111,22 @@ INLINE_ELAPSED(inline)
/*----------------------------------------------------------------*/
/* AIX v. 4+ routines to read the real-time clock or time-base register */
#if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER)
#if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && \
!defined(HAVE_TICK_COUNTER)
typedef timebasestruct_t ticks;
static __inline ticks getticks(void)
{
ticks t;
read_real_time(&t, TIMEBASE_SZ);
return t;
static __inline ticks getticks(void) {
ticks t;
read_real_time(&t, TIMEBASE_SZ);
return t;
}
static __inline double elapsed(ticks t1, ticks t0) /* time in nanoseconds */
{
time_base_to_time(&t1, TIMEBASE_SZ);
time_base_to_time(&t0, TIMEBASE_SZ);
return (((double)t1.tb_high - (double)