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

Merge remote-tracking branch 'origin' into tasks_cleanup

Conflicts:
	src/engine.c
	src/scheduler.c
	src/space.c
	src/task.c
parents 98f8fde9 35b13d49
......@@ -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"
......
This diff is collapsed.
......@@ -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) {
......
......@@ -29,6 +29,9 @@
#include "hydro.h"
#include "kernel_hydro.h"
#define hydro_props_default_max_iterations 30
#define hydro_props_default_volume_change 2.0f
void hydro_props_init(struct hydro_props *p,
const struct swift_params *params) {
......@@ -39,13 +42,13 @@ void hydro_props_init(struct hydro_props *p,
p->delta_neighbours = parser_get_param_float(params, "SPH:delta_neighbours");
/* Ghost stuff */
p->max_smoothing_iterations =
parser_get_param_int(params, "SPH:max_ghost_iterations");
p->max_smoothing_iterations = parser_get_opt_param_int(
params, "SPH:max_ghost_iterations", hydro_props_default_max_iterations);
/* Time integration properties */
p->CFL_condition = parser_get_param_float(params, "SPH:CFL_condition");
const float max_volume_change =
parser_get_param_float(params, "SPH:max_volume_change");
const float max_volume_change = parser_get_opt_param_float(
params, "SPH:max_volume_change", hydro_props_default_volume_change);
p->log_max_h_change = logf(powf(max_volume_change, 0.33333333333f));
}
......@@ -60,4 +63,8 @@ void hydro_props_print(const struct hydro_props *p) {
"Hydrodynamic integration: Max change of volume: %.2f "
"(max|dlog(h)/dt|=%f).",
powf(expf(p->log_max_h_change), 3.f), p->log_max_h_change);
if (p->max_smoothing_iterations != hydro_props_default_max_iterations)
message("Maximal iterations in ghost task set to %d (default is %d)",
p->max_smoothing_iterations, hydro_props_default_max_iterations);
}
......@@ -23,7 +23,7 @@
#include <pthread.h>
/* Includes. */
#include "inline.h"
#include "atomic.h"
#ifdef PTHREAD_SPINLOCK
#include <pthread.h>
......@@ -50,14 +50,14 @@
#define lock_init(l) (*(l) = 0)
#define lock_destroy(l) 0
INLINE static int lock_lock(volatile int *l) {
while (__sync_val_compare_and_swap(l, 0, 1) != 0)
while (atomic_cas(l, 0, 1) != 0)
;
// while( *l );
return 0;
}
#define lock_trylock(l) ((*(l)) ? 1 : __sync_val_compare_and_swap(l, 0, 1))
#define lock_unlock(l) (__sync_val_compare_and_swap(l, 1, 0) != 1)
#define lock_unlock_blind(l) __sync_val_compare_and_swap(l, 1, 0)
#define lock_trylock(l) ((*(l)) ? 1 : atomic_cas(l, 0, 1))
#define lock_unlock(l) (atomic_cas(l, 1, 0) != 1)
#define lock_unlock_blind(l) atomic_cas(l, 1, 0)
#endif
#endif /* SWIFT_LOCK_H */
......@@ -18,15 +18,23 @@
*
******************************************************************************/
#include "map.h"
/* Config parameters. */
#include "../config.h"
/* Some standard headers. */
#include <stdio.h>
#include <stdlib.h>
/* This object's header. */
#include "map.h"
/* Local headers. */
#include "atomic.h"
#include "error.h"
/**
* @brief Mapping function to draw a specific cell (gnuplot).
*/
void map_cells_plot(struct cell *c, void *data) {
int depth = *(int *)data;
......@@ -80,24 +88,21 @@ void map_cells_plot(struct cell *c, void *data) {
/**
* @brief Mapping function for checking if each part is in its box.
*/
void map_check(struct part *p, struct cell *c, void *data) {
/* void map_check ( struct part *p , struct cell *c , void *data ) {
if ( p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] ||
p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] ||
p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] )
printf( "map_check: particle %i is outside of its box.\n" , p->id );
} */
if (p->x[0] < c->loc[0] || p->x[0] > c->loc[0] + c->h[0] ||
p->x[0] < c->loc[0] || p->x[0] > c->loc[0] + c->h[0] ||
p->x[0] < c->loc[0] || p->x[0] > c->loc[0] + c->h[0])
printf("map_check: particle %lld is outside of its box.\n", p->id);
}
/**
* @brief Mapping function for neighbour count.
*/
void map_cellcheck(struct cell *c, void *data) {
int *count = (int *)data;
__sync_fetch_and_add(count, c->count);
atomic_add(count, c->count);
/* Loop over all parts and check if they are in the cell. */
for (int k = 0; k < c->count; k++) {
......@@ -133,7 +138,6 @@ void map_cellcheck(struct cell *c, void *data) {
/**
* @brief Mapping function for maxdepth cell count.
*/
void map_maxdepth(struct cell *c, void *data) {
int maxdepth = ((int *)data)[0];
......@@ -147,7 +151,6 @@ void map_maxdepth(struct cell *c, void *data) {
/**
* @brief Mapping function for neighbour count.
*/
void map_count(struct part *p, struct cell *c, void *data) {
double *wcount = (double *)data;
......@@ -156,7 +159,6 @@ void map_count(struct part *p, struct cell *c, void *data) {
*wcount += p->density.wcount;
}
void map_wcount_min(struct part *p, struct cell *c, void *data) {
struct part **p2 = (struct part **)data;
......@@ -188,7 +190,6 @@ void map_h_max(struct part *p, struct cell *c, void *data) {
/**
* @brief Mapping function for neighbour count.
*/
void map_icount(struct part *p, struct cell *c, void *data) {
// int *count = (int *)data;
......@@ -201,7 +202,6 @@ void map_icount(struct part *p, struct cell *c, void *data) {
/**
* @brief Mapping function to print the particle position.
*/
void map_dump(struct part *p, struct cell *c, void *data) {
double *shift = (double *)data;
......
......@@ -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
......
......@@ -453,9 +453,9 @@ static void repart_edge_metis(int partweights, int bothweights, int nodeID,
/* Skip un-interesting tasks. */
if (t->type != task_type_self && t->type != task_type_pair &&
t->type != task_type_sub && t->type != task_type_ghost &&
t->type != task_type_drift && t->type != task_type_kick &&
t->type != task_type_init)
t->type != task_type_sub_self && t->type != task_type_sub_self &&
t->type != task_type_ghost && t->type != task_type_drift &&
t->type != task_type_kick && t->type != task_type_init)
continue;
/* Get the task weight. */
......@@ -496,15 +496,15 @@ static void repart_edge_metis(int partweights, int bothweights, int nodeID,
/* Self interaction? */
else if ((t->type == task_type_self && ci->nodeID == nodeID) ||
(t->type == task_type_sub && cj == NULL && ci->nodeID == nodeID)) {
(t->type == task_type_sub_self && cj == NULL &&
ci->nodeID == nodeID)) {
/* Self interactions add only to vertex weight. */
if (taskvweights) weights_v[cid] += w;
}
/* Pair? */
else if (t->type == task_type_pair ||
(t->type == task_type_sub && cj != NULL)) {
else if (t->type == task_type_pair || (t->type == task_type_sub_pair)) {
/* In-cell pair? */
if (ci == cj) {
/* Add weight to vertex for ci. */
......
......@@ -34,36 +34,30 @@
#include "queue.h"
/* Local headers. */
#include "atomic.h"
#include "const.h"
#include "error.h"
/* Counter macros. */
#ifdef COUNTER
#define COUNT(c) (__sync_add_and_fetch(&queue_counter[c], 1))
#else
#define COUNT(c)
#endif
/* The counters. */
int queue_counter[queue_counter_count];
/**
* @brief Insert a used tasks into the given queue.
* @brief Enqueue all tasks in the incoming DEQ.
*
* @param q The #queue.
* @param t The #task.
* @param q The #queue, assumed to be locked.
*/
void queue_get_incoming(struct queue *q) {
void queue_insert(struct queue *q, struct task *t) {
int *tid = q->tid;
struct task *tasks = q->tasks;
int k, *tid;
struct task *tasks;
/* Loop over the incoming DEQ. */
while (1) {
/* Lock the queue. */
if (lock_lock(&q->lock) != 0) error("Failed to get queue lock.");
/* Is there a next element? */
const int ind = q->first_incoming % queue_incoming_size;
if (q->tid_incoming[ind] < 0) break;
tid = q->tid;
tasks = q->tasks;
/* Get the next offset off the DEQ. */
const int offset = atomic_swap(&q->tid_incoming[ind], -1);
atomic_inc(&q->first_incoming);
/* Does the queue need to be grown? */
if (q->count == q->size) {
......@@ -77,11 +71,12 @@ void queue_insert(struct queue *q, struct task *t) {
}
/* Drop the task at the end of the queue. */
tid[q->count] = (t - tasks);
tid[q->count] = offset;
q->count += 1;
atomic_dec(&q->count_incoming);
/* Shuffle up. */
for (k = q->count - 1; k > 0; k = (k - 1) / 2)
for (int k = q->count - 1; k > 0; k = (k - 1) / 2)
if (tasks[tid[k]].weight > tasks[tid[(k - 1) / 2]].weight) {
int temp = tid[k];
tid[k] = tid[(k - 1) / 2];
......@@ -90,12 +85,41 @@ void queue_insert(struct queue *q, struct task *t) {
break;
/* Check the queue's consistency. */
/* for ( k = 1 ; k < q->count ; k++ )
/* for (int k = 1; k < q->count; k++)
if ( tasks[ tid[(k-1)/2] ].weight < tasks[ tid[k] ].weight )
error( "Queue heap is disordered." ); */
}
}
/**
* @brief Insert a used tasks into the given queue.
*
* @param q The #queue.
* @param t The #task.
*/
void queue_insert(struct queue *q, struct task *t) {
/* Get an index in the DEQ. */
const int ind = atomic_inc(&q->last_incoming) % queue_incoming_size;
/* Spin until the new offset can be stored. */
while (atomic_cas(&q->tid_incoming[ind], -1, t - q->tasks) != -1) {
/* Unlock the queue. */
if (lock_unlock(&q->lock) != 0) error("Failed to unlock queue.");
/* Try to get the queue lock, non-blocking, ensures that at
least somebody is working on this queue. */
if (lock_trylock(&q->lock) == 0) {
/* Clean up the incoming DEQ. */
queue_get_incoming(q);
/* Release the queue lock. */
if (lock_unlock(&q->lock) != 0) {
error("Unlocking the qlock failed.\n");
}
}
}
/* Increase the incoming count. */
atomic_inc(&q->count_incoming);
}
/**
......@@ -104,7 +128,6 @@ void queue_insert(struct queue *q, struct task *t) {
* @param q The #queue.
* @param tasks List of tasks to which the queue indices refer to.
*/
void queue_init(struct queue *q, struct task *tasks) {
/* Allocate the task list if needed. */
......@@ -120,6 +143,17 @@ void queue_init(struct queue *q, struct task *tasks) {
/* Init the queue lock. */
if (lock_init(&q->lock) != 0) error("Failed to init queue lock.");
/* Init the incoming DEQ. */
if ((q->tid_incoming = (int *)malloc(sizeof(int) * queue_incoming_size)) ==
NULL)
error("Failed to allocate queue incoming buffer.");
for (int k = 0; k < queue_incoming_size; k++) {
q->tid_incoming[k] = -1;
}
q->first_incoming = 0;
q->last_incoming = 0;
q->count_incoming = 0;
}
/**
......@@ -129,7 +163,6 @@ void queue_init(struct queue *q, struct task *tasks) {
* @param prev The previous #task extracted from this #queue.
* @param blocking Block until access to the queue is granted.