Commit ab1f47ed authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'coding_style' into 'master'

Coding style

Sorry Peter here is another big annoying one. 

 - Improved the code quality in `runner_doiact.h` to match the coding standard used elsewhere: declare variable only where they are needed and use constants where possible.
 - Modified many headers to avoid long unnecessary inclusion lists. Should speed up compilation.

Thanks !

See merge request !182
parents fa9761ec a390c00f
# This file is part of SWIFT.
# Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk),
# Matthieu Schaller (matthieu.schaller@durham.ac.uk).
......
......@@ -93,7 +93,6 @@ void print_help_message() {
* @brief Main routine that loads a few particles and generates some output.
*
*/
int main(int argc, char *argv[]) {
struct clocks_time tic, toc;
......@@ -482,10 +481,8 @@ int main(int argc, char *argv[]) {
if (j % 100 == 2) e.forcerepart = reparttype;
#endif
/* Reset timers */
timers_reset(timers_mask_all);
#ifdef COUNTER
for (k = 0; k < runner_counter_count; k++) runner_counter[k] = 0;
#endif
/* Take a step. */
engine_step(&e);
......
......@@ -19,6 +19,8 @@
#ifndef SWIFT_APPROX_MATH_H
#define SWIFT_APPROX_MATH_H
#include "inline.h"
/**
* @brief Approximate version of expf(x) using a 4th order Taylor expansion
*
......
......@@ -27,8 +27,9 @@
#include "lock.h"
#include "multipole.h"
#include "part.h"
#include "task.h"
/* Forward declaration of space, needed for cell_unpack. */
/* Avoid cyclic inclusions */
struct space;
/* Max tag size set to 2^29 to take into account some MPI implementations
......
......@@ -43,6 +43,8 @@
#include "const.h"
#include "error.h"
#include "kernel_hydro.h"
#include "part.h"
#include "units.h"
#include "version.h"
const char* particle_type_names[NUM_PARTICLE_TYPES] = {
......
......@@ -23,13 +23,11 @@
/* Config parameters. */
#include "../config.h"
/* Includes. */
#include "kernel_hydro.h"
#if defined(HAVE_HDF5)
#include "part.h"
#include "units.h"
#if defined(HAVE_HDF5)
/**
* @brief The different types of data used in the GADGET IC files.
*
......@@ -107,6 +105,6 @@ void writeXMFline(FILE* xmfFile, char* fileName, char* partTypeGroupName,
void writeCodeDescription(hid_t h_file);
void writeUnitSystem(hid_t h_file, struct UnitSystem* us);
#endif
#endif /* defined HDF5 */
#endif /* SWIFT_COMMON_IO_H */
......@@ -20,11 +20,19 @@
*
******************************************************************************/
/* Config parameters. */
#include "../config.h"
/* Some standard headers. */
#include <stdio.h>
/* This object's header. */
#include "debug.h"
/* Local includes. */
#include "config.h"
#include "const.h"
#include "debug.h"
#include "inline.h"
#include "part.h"
/* Import the right hydro definition */
......@@ -51,7 +59,6 @@
*
* (Should be used for debugging only as it runs in O(N).)
*/
void printParticle(struct part *parts, struct xpart *xparts, long long int id,
size_t N) {
......@@ -69,6 +76,17 @@ void printParticle(struct part *parts, struct xpart *xparts, long long int id,
if (!found) printf("## Particles[???] id=%lld not found\n", id);
}
/**
* @brief Looks for the g-particle with the given id and prints its information
* to
* the standard output.
*
* @param gparts The array of g-particles.
* @param id The id too look for.
* @param N The size of the array of g-particles.
*
* (Should be used for debugging only as it runs in O(N).)
*/
void printgParticle(struct gpart *gparts, long long int id, size_t N) {
int found = 0;
......@@ -95,9 +113,7 @@ void printgParticle(struct gpart *gparts, long long int id, size_t N) {
*
* @param p The particle to print
* @param xp The extended data ot the particle to print
*
*/
void printParticle_single(struct part *p, struct xpart *xp) {
printf("## Particle: id=%lld ", p->id);
......@@ -105,6 +121,18 @@ void printParticle_single(struct part *p, struct xpart *xp) {
printf("\n");
}
/**
* @brief Prints the details of a given particle to stdout
*
* @param gp The g-particle to print
*/
void printgParticle_single(struct gpart *gp) {
printf("## g-Particle: id=%lld ", gp->id);
gravity_debug_particle(gp);
printf("\n");
}
#ifdef HAVE_METIS
/**
......
......@@ -19,14 +19,15 @@
#ifndef SWIFT_DEBUG_H
#define SWIFT_DEBUG_H
/* Includes. */
#include "cell.h"
#include "part.h"
struct part;
struct gpart;
struct xpart;
void printParticle(struct part *parts, struct xpart *xparts, long long int id,
size_t N);
void printgParticle(struct gpart *parts, long long int id, size_t N);
void printParticle_single(struct part *p, struct xpart *xp);
void printgParticle_single(struct gpart *gp);
#ifdef HAVE_METIS
#include "metis.h"
......
......@@ -59,9 +59,12 @@
#include "parallel_io.h"
#include "part.h"
#include "partition.h"
#include "proxy.h"
#include "runner.h"
#include "serial_io.h"
#include "single_io.h"
#include "timers.h"
#include "units.h"
const char *engine_policy_names[13] = {"none",
"rand",
......
......@@ -37,13 +37,10 @@
#include <stdio.h>
/* Includes. */
#include "hydro_properties.h"
#include "lock.h"
#include "clocks.h"
#include "parser.h"
#include "partition.h"
#include "physical_constants.h"
#include "potentials.h"
#include "proxy.h"
#include "runner.h"
#include "scheduler.h"
#include "space.h"
......
......@@ -20,12 +20,6 @@
#ifndef SWIFT_RUNNER_IACT_H
#define SWIFT_RUNNER_IACT_H
/* Includes. */
#include "const.h"
#include "kernel_hydro.h"
#include "part.h"
#include "vector.h"
/**
* @brief SPH interaction functions following the Gadget-2 version of SPH.
*
......@@ -44,7 +38,6 @@
/**
* @brief Density loop
*/
__attribute__((always_inline)) INLINE static void runner_iact_density(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......@@ -218,7 +211,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_vec_density(
/**
* @brief Density loop (non-symmetric version)
*/
__attribute__((always_inline)) INLINE static void runner_iact_nonsym_density(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......@@ -267,7 +259,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_density(
/**
* @brief Density loop (non-symmetric vectorized version)
*/
__attribute__((always_inline)) INLINE static void
runner_iact_nonsym_vec_density(float *R2, float *Dx, float *Hi, float *Hj,
struct part **pi, struct part **pj) {
......@@ -360,7 +351,6 @@ runner_iact_nonsym_vec_density(float *R2, float *Dx, float *Hi, float *Hj,
/**
* @brief Force loop
*/
__attribute__((always_inline)) INLINE static void runner_iact_force(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......@@ -456,7 +446,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
/**
* @brief Force loop (Vectorized version)
*/
__attribute__((always_inline)) INLINE static void runner_iact_vec_force(
float *R2, float *Dx, float *Hi, float *Hj, struct part **pi,
struct part **pj) {
......@@ -675,7 +664,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_vec_force(
/**
* @brief Force loop (non-symmetric version)
*/
__attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......@@ -766,7 +754,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
/**
* @brief Force loop (Vectorized non-symmetric version)
*/
__attribute__((always_inline)) INLINE static void runner_iact_nonsym_vec_force(
float *R2, float *Dx, float *Hi, float *Hj, struct part **pi,
struct part **pj) {
......
......@@ -20,12 +20,6 @@
#ifndef SWIFT_RUNNER_IACT_LEGACY_H
#define SWIFT_RUNNER_IACT_LEGACY_H
/* Includes. */
#include "const.h"
#include "kernel_hydro.h"
#include "part.h"
#include "vector.h"
/**
* @brief SPH interaction functions following the Gadget-2 version of SPH.
*
......@@ -42,7 +36,6 @@
/**
* @brief Density loop
*/
__attribute__((always_inline)) INLINE static void runner_iact_density(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......@@ -113,7 +106,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_density(
/**
* @brief Density loop (non-symmetric version)
*/
__attribute__((always_inline)) INLINE static void runner_iact_nonsym_density(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......@@ -162,7 +154,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_density(
/**
* @brief Force loop
*/
__attribute__((always_inline)) INLINE static void runner_iact_force(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......@@ -260,7 +251,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
/**
* @brief Force loop (non-symmetric version)
*/
__attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......
......@@ -19,12 +19,6 @@
#ifndef SWIFT_RUNNER_IACT_MINIMAL_H
#define SWIFT_RUNNER_IACT_MINIMAL_H
/* Includes. */
#include "const.h"
#include "kernel_hydro.h"
#include "part.h"
#include "vector.h"
/**
* @brief Minimal conservative implementation of SPH
*
......@@ -70,7 +64,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_density(
/**
* @brief Density loop (non-symmetric version)
*/
__attribute__((always_inline)) INLINE static void runner_iact_nonsym_density(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......@@ -95,7 +88,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_density(
/**
* @brief Force loop
*/
__attribute__((always_inline)) INLINE static void runner_iact_force(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......@@ -168,7 +160,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
/**
* @brief Force loop (non-symmetric version)
*/
__attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......
......@@ -24,7 +24,6 @@
/* Includes. */
#include "atomic.h"
#include "inline.h"
#ifdef PTHREAD_SPINLOCK
#include <pthread.h>
......
......@@ -37,7 +37,11 @@
/* Local includes. */
#include "common_io.h"
#include "engine.h"
#include "error.h"
#include "kernel_hydro.h"
#include "part.h"
#include "units.h"
/**
* @brief Reads a data array from a given HDF5 group.
......
......@@ -19,6 +19,9 @@
#ifndef SWIFT_PARALLEL_IO_H
#define SWIFT_PARALLEL_IO_H
/* Config parameters. */
#include "../config.h"
/* MPI headers. */
#ifdef WITH_MPI
#include <mpi.h>
......
......@@ -22,9 +22,6 @@
/* Config parameters. */
#include "../config.h"
/* Some standard headers. */
#include <stdlib.h>
/* MPI headers. */
#ifdef WITH_MPI
#include <mpi.h>
......@@ -38,7 +35,7 @@
#define xpart_align 32
#define gpart_align 32
/* Import the right particle definition */
/* Import the right hydro particle definition */
#if defined(MINIMAL_SPH)
#include "./hydro/Minimal/hydro_part.h"
#elif defined(GADGET2_SPH)
......@@ -49,6 +46,7 @@
#error "Invalid choice of SPH variant"
#endif
/* Import the right gravity particle definition */
#include "./gravity/Default/gravity_part.h"
#ifdef WITH_MPI
......
......@@ -40,6 +40,7 @@
/* Local headers. */
#include "approx_math.h"
#include "atomic.h"
#include "cell.h"
#include "const.h"
#include "debug.h"
#include "drift.h"
......@@ -135,7 +136,6 @@ void runner_do_grav_external(struct runner *r, struct cell *c, int timer) {
* @param sort The entries
* @param N The number of entries.
*/
void runner_do_sort_ascending(struct entry *sort, int N) {
struct {
......@@ -217,7 +217,6 @@ void runner_do_sort_ascending(struct entry *sort, int N) {
* @param clock Flag indicating whether to record the timing or not, needed
* for recursive calls.
*/
void runner_do_sort(struct runner *r, struct cell *c, int flags, int clock) {
struct entry *finger;
......@@ -423,7 +422,6 @@ void runner_do_init(struct runner *r, struct cell *c, int timer) {
* @param r The runner thread.
* @param c The cell.
*/
void runner_do_ghost(struct runner *r, struct cell *c) {
struct part *p, *parts = c->parts;
......
......@@ -23,13 +23,12 @@
#ifndef SWIFT_RUNNER_H
#define SWIFT_RUNNER_H
/* Includes. */
#include "cell.h"
#include "inline.h"
extern const double runner_shift[13][3];
extern const char runner_flip[27];
struct cell;
struct engine;
/* A struct representing a runner's thread and its data. */
struct runner {
......
This diff is collapsed.
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