Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
92e093d7
Commit
92e093d7
authored
Jun 14, 2016
by
Matthieu Schaller
Browse files
Unified the atomic calls everywhere using the defined macros
parent
a4f97e08
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/cell.c
View file @
92e093d7
...
...
@@ -269,7 +269,7 @@ int cell_locktree(struct cell *c) {
/* Undo the holds up to finger. */
for
(
struct
cell
*
finger2
=
c
->
parent
;
finger2
!=
finger
;
finger2
=
finger2
->
parent
)
__sync_fetch_and_sub
(
&
finger2
->
hold
,
1
);
atomic_dec
(
&
finger2
->
hold
);
/* Unlock this cell. */
if
(
lock_unlock
(
&
c
->
lock
)
!=
0
)
error
(
"Failed to unlock cell."
);
...
...
@@ -309,7 +309,7 @@ int cell_glocktree(struct cell *c) {
if
(
lock_trylock
(
&
finger
->
glock
)
!=
0
)
break
;
/* Increment the hold. */
__sync_fetch_and_add
(
&
finger
->
ghold
,
1
);
atomic_inc
(
&
finger
->
ghold
);
/* Unlock the cell. */
if
(
lock_unlock
(
&
finger
->
glock
)
!=
0
)
error
(
"Failed to unlock cell."
);
...
...
@@ -327,7 +327,7 @@ int cell_glocktree(struct cell *c) {
/* Undo the holds up to finger. */
for
(
struct
cell
*
finger2
=
c
->
parent
;
finger2
!=
finger
;
finger2
=
finger2
->
parent
)
__sync_fetch_and_sub
(
&
finger2
->
ghold
,
1
);
atomic_dec
(
&
finger2
->
ghold
);
/* Unlock this cell. */
if
(
lock_unlock
(
&
c
->
glock
)
!=
0
)
error
(
"Failed to unlock cell."
);
...
...
@@ -353,7 +353,7 @@ void cell_unlocktree(struct cell *c) {
/* Climb up the tree and unhold the parents. */
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
);
}
...
...
@@ -367,7 +367,7 @@ void cell_gunlocktree(struct cell *c) {
/* Climb up the tree and unhold the parents. */
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
);
}
...
...
src/lock.h
View file @
92e093d7
...
...
@@ -23,6 +23,7 @@
#include
<pthread.h>
/* Includes. */
#include
"atomic.h"
#include
"inline.h"
#ifdef PTHREAD_SPINLOCK
...
...
@@ -48,14 +49,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 */
src/map.c
View file @
92e093d7
...
...
@@ -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
;
...
...
src/timers.h
View file @
92e093d7
...
...
@@ -23,6 +23,7 @@
#define SWIFT_TIMERS_H
/* Includes. */
#include
"atomic.h"
#include
"cycle.h"
#include
"inline.h"
...
...
@@ -71,7 +72,7 @@ extern ticks timers[timer_count];
#define TIMER_TOC2(t) timers_toc(t, tic2)
INLINE
static
ticks
timers_toc
(
int
t
,
ticks
tic
)
{
ticks
d
=
(
getticks
()
-
tic
);
__sync_add_and_fetch
(
&
timers
[
t
],
d
);
atomic_add
(
&
timers
[
t
],
d
);
return
d
;
}
#else
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment