Skip to content
Snippets Groups Projects
Commit d8bf23e2 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'master' into task_sub_split

parents 2f06ff6f 48ac97ea
No related branches found
No related tags found
1 merge request!180Task sub split
...@@ -269,7 +269,7 @@ int cell_locktree(struct cell *c) { ...@@ -269,7 +269,7 @@ int cell_locktree(struct cell *c) {
/* Undo the holds up to finger. */ /* Undo the holds up to finger. */
for (struct cell *finger2 = c->parent; finger2 != finger; for (struct cell *finger2 = c->parent; finger2 != finger;
finger2 = finger2->parent) finger2 = finger2->parent)
__sync_fetch_and_sub(&finger2->hold, 1); atomic_dec(&finger2->hold);
/* Unlock this cell. */ /* Unlock this cell. */
if (lock_unlock(&c->lock) != 0) error("Failed to unlock cell."); if (lock_unlock(&c->lock) != 0) error("Failed to unlock cell.");
...@@ -309,7 +309,7 @@ int cell_glocktree(struct cell *c) { ...@@ -309,7 +309,7 @@ int cell_glocktree(struct cell *c) {
if (lock_trylock(&finger->glock) != 0) break; if (lock_trylock(&finger->glock) != 0) break;
/* Increment the hold. */ /* Increment the hold. */
__sync_fetch_and_add(&finger->ghold, 1); atomic_inc(&finger->ghold);
/* Unlock the cell. */ /* Unlock the cell. */
if (lock_unlock(&finger->glock) != 0) error("Failed to unlock cell."); if (lock_unlock(&finger->glock) != 0) error("Failed to unlock cell.");
...@@ -327,7 +327,7 @@ int cell_glocktree(struct cell *c) { ...@@ -327,7 +327,7 @@ int cell_glocktree(struct cell *c) {
/* Undo the holds up to finger. */ /* Undo the holds up to finger. */
for (struct cell *finger2 = c->parent; finger2 != finger; for (struct cell *finger2 = c->parent; finger2 != finger;
finger2 = finger2->parent) finger2 = finger2->parent)
__sync_fetch_and_sub(&finger2->ghold, 1); atomic_dec(&finger2->ghold);
/* Unlock this cell. */ /* Unlock this cell. */
if (lock_unlock(&c->glock) != 0) error("Failed to unlock cell."); if (lock_unlock(&c->glock) != 0) error("Failed to unlock cell.");
...@@ -353,7 +353,7 @@ void cell_unlocktree(struct cell *c) { ...@@ -353,7 +353,7 @@ void cell_unlocktree(struct cell *c) {
/* Climb up the tree and unhold the parents. */ /* Climb up the tree and unhold the parents. */
for (struct cell *finger = c->parent; finger != NULL; finger = finger->parent) for (struct cell *finger = c->parent; finger != NULL; finger = finger->parent)
__sync_fetch_and_sub(&finger->hold, 1); atomic_dec(&finger->hold);
TIMER_TOC(timer_locktree); TIMER_TOC(timer_locktree);
} }
...@@ -367,7 +367,7 @@ void cell_gunlocktree(struct cell *c) { ...@@ -367,7 +367,7 @@ void cell_gunlocktree(struct cell *c) {
/* Climb up the tree and unhold the parents. */ /* Climb up the tree and unhold the parents. */
for (struct cell *finger = c->parent; finger != NULL; finger = finger->parent) for (struct cell *finger = c->parent; finger != NULL; finger = finger->parent)
__sync_fetch_and_sub(&finger->ghold, 1); atomic_dec(&finger->ghold);
TIMER_TOC(timer_locktree); TIMER_TOC(timer_locktree);
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <pthread.h> #include <pthread.h>
/* Includes. */ /* Includes. */
#include "atomic.h"
#include "inline.h" #include "inline.h"
#ifdef PTHREAD_SPINLOCK #ifdef PTHREAD_SPINLOCK
...@@ -48,14 +49,14 @@ ...@@ -48,14 +49,14 @@
#define lock_init(l) (*(l) = 0) #define lock_init(l) (*(l) = 0)
#define lock_destroy(l) 0 #define lock_destroy(l) 0
INLINE static int lock_lock(volatile int *l) { 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 ); // while( *l );
return 0; return 0;
} }
#define lock_trylock(l) ((*(l)) ? 1 : __sync_val_compare_and_swap(l, 0, 1)) #define lock_trylock(l) ((*(l)) ? 1 : atomic_cas(l, 0, 1))
#define lock_unlock(l) (__sync_val_compare_and_swap(l, 1, 0) != 1) #define lock_unlock(l) (atomic_cas(l, 1, 0) != 1)
#define lock_unlock_blind(l) __sync_val_compare_and_swap(l, 1, 0) #define lock_unlock_blind(l) atomic_cas(l, 1, 0)
#endif #endif
#endif /* SWIFT_LOCK_H */ #endif /* SWIFT_LOCK_H */
...@@ -18,15 +18,23 @@ ...@@ -18,15 +18,23 @@
* *
******************************************************************************/ ******************************************************************************/
#include "map.h" /* Config parameters. */
#include "../config.h"
/* Some standard headers. */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
/* This object's header. */
#include "map.h"
/* Local headers. */
#include "atomic.h"
#include "error.h" #include "error.h"
/** /**
* @brief Mapping function to draw a specific cell (gnuplot). * @brief Mapping function to draw a specific cell (gnuplot).
*/ */
void map_cells_plot(struct cell *c, void *data) { void map_cells_plot(struct cell *c, void *data) {
int depth = *(int *)data; int depth = *(int *)data;
...@@ -80,24 +88,21 @@ void map_cells_plot(struct cell *c, void *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. * @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] ||
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);
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 );
} */
/** /**
* @brief Mapping function for neighbour count. * @brief Mapping function for neighbour count.
*/ */
void map_cellcheck(struct cell *c, void *data) { void map_cellcheck(struct cell *c, void *data) {
int *count = (int *)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. */ /* Loop over all parts and check if they are in the cell. */
for (int k = 0; k < c->count; k++) { for (int k = 0; k < c->count; k++) {
...@@ -133,7 +138,6 @@ void map_cellcheck(struct cell *c, void *data) { ...@@ -133,7 +138,6 @@ void map_cellcheck(struct cell *c, void *data) {
/** /**
* @brief Mapping function for maxdepth cell count. * @brief Mapping function for maxdepth cell count.
*/ */
void map_maxdepth(struct cell *c, void *data) { void map_maxdepth(struct cell *c, void *data) {
int maxdepth = ((int *)data)[0]; int maxdepth = ((int *)data)[0];
...@@ -147,7 +151,6 @@ void map_maxdepth(struct cell *c, void *data) { ...@@ -147,7 +151,6 @@ void map_maxdepth(struct cell *c, void *data) {
/** /**
* @brief Mapping function for neighbour count. * @brief Mapping function for neighbour count.
*/ */
void map_count(struct part *p, struct cell *c, void *data) { void map_count(struct part *p, struct cell *c, void *data) {
double *wcount = (double *)data; double *wcount = (double *)data;
...@@ -156,7 +159,6 @@ void map_count(struct part *p, struct cell *c, void *data) { ...@@ -156,7 +159,6 @@ void map_count(struct part *p, struct cell *c, void *data) {
*wcount += p->density.wcount; *wcount += p->density.wcount;
} }
void map_wcount_min(struct part *p, struct cell *c, void *data) { void map_wcount_min(struct part *p, struct cell *c, void *data) {
struct part **p2 = (struct part **)data; struct part **p2 = (struct part **)data;
...@@ -188,7 +190,6 @@ void map_h_max(struct part *p, struct cell *c, void *data) { ...@@ -188,7 +190,6 @@ void map_h_max(struct part *p, struct cell *c, void *data) {
/** /**
* @brief Mapping function for neighbour count. * @brief Mapping function for neighbour count.
*/ */
void map_icount(struct part *p, struct cell *c, void *data) { void map_icount(struct part *p, struct cell *c, void *data) {
// int *count = (int *)data; // int *count = (int *)data;
...@@ -201,7 +202,6 @@ void map_icount(struct part *p, struct cell *c, void *data) { ...@@ -201,7 +202,6 @@ void map_icount(struct part *p, struct cell *c, void *data) {
/** /**
* @brief Mapping function to print the particle position. * @brief Mapping function to print the particle position.
*/ */
void map_dump(struct part *p, struct cell *c, void *data) { void map_dump(struct part *p, struct cell *c, void *data) {
double *shift = (double *)data; double *shift = (double *)data;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#define SWIFT_TIMERS_H #define SWIFT_TIMERS_H
/* Includes. */ /* Includes. */
#include "atomic.h"
#include "cycle.h" #include "cycle.h"
#include "inline.h" #include "inline.h"
...@@ -74,7 +75,7 @@ extern ticks timers[timer_count]; ...@@ -74,7 +75,7 @@ extern ticks timers[timer_count];
#define TIMER_TOC2(t) timers_toc(t, tic2) #define TIMER_TOC2(t) timers_toc(t, tic2)
INLINE static ticks timers_toc(int t, ticks tic) { INLINE static ticks timers_toc(int t, ticks tic) {
ticks d = (getticks() - tic); ticks d = (getticks() - tic);
__sync_add_and_fetch(&timers[t], d); atomic_add(&timers[t], d);
return d; return d;
} }
#else #else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment