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
7295cf3d
Commit
7295cf3d
authored
Mar 29, 2020
by
Matthieu Schaller
Browse files
Only use atomic operations when SWIFT_TASKS_WITHOUT_ATOMICS is not defined
parent
3742104d
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/gravity/MultiSoftening/gravity.h
View file @
7295cf3d
...
...
@@ -78,7 +78,11 @@ __attribute__((always_inline)) INLINE static float gravity_get_softening(
__attribute__
((
always_inline
))
INLINE
static
void
gravity_add_comoving_potential
(
struct
gpart
*
restrict
gp
,
float
pot
)
{
#ifdef SWIFT_TASKS_WITHOUT_ATOMICS
gp
->
potential
+=
pot
;
#else
atomic_add_f
(
&
gp
->
potential
,
pot
);
#endif
}
/**
...
...
src/gravity/Potential/gravity.h
View file @
7295cf3d
...
...
@@ -64,7 +64,11 @@ __attribute__((always_inline)) INLINE static float gravity_get_softening(
__attribute__
((
always_inline
))
INLINE
static
void
gravity_add_comoving_potential
(
struct
gpart
*
restrict
gp
,
float
pot
)
{
#ifdef SWIFT_TASKS_WITHOUT_ATOMICS
gp
->
potential
+=
pot
;
#else
atomic_add_f
(
&
gp
->
potential
,
pot
);
#endif
}
/**
...
...
src/gravity_cache.h
View file @
7295cf3d
...
...
@@ -491,9 +491,15 @@ __attribute__((always_inline)) INLINE static void gravity_cache_write_back(
/* Write stuff back to the particles */
for
(
int
i
=
0
;
i
<
gcount
;
++
i
)
{
if
(
active
[
i
])
{
#ifdef SWIFT_TASKS_WITHOUT_ATOMICS
gparts
[
i
].
a_grav
[
0
]
+=
a_x
[
i
];
gparts
[
i
].
a_grav
[
1
]
+=
a_y
[
i
];
gparts
[
i
].
a_grav
[
2
]
+=
a_z
[
i
];
#else
atomic_add_f
(
&
gparts
[
i
].
a_grav
[
0
],
a_x
[
i
]);
atomic_add_f
(
&
gparts
[
i
].
a_grav
[
1
],
a_y
[
i
]);
atomic_add_f
(
&
gparts
[
i
].
a_grav
[
2
],
a_z
[
i
]);
#endif
gravity_add_comoving_potential
(
&
gparts
[
i
],
pot
[
i
]);
}
}
...
...
src/mesh_gravity.c
View file @
7295cf3d
...
...
@@ -334,10 +334,16 @@ void mesh_to_gparts_CIC(struct gpart* gp, const double* pot, const int N,
/* ---- */
/* Store things back */
gravity_add_comoving_potential
(
gp
,
p
);
#ifdef SWIFT_TASKS_WITHOUT_ATOMICS
gp
->
a_grav
[
0
]
+=
fac
*
a
[
0
];
gp
->
a_grav
[
1
]
+=
fac
*
a
[
1
];
gp
->
a_grav
[
2
]
+=
fac
*
a
[
2
];
#else
atomic_add_f
(
&
gp
->
a_grav
[
0
],
fac
*
a
[
0
]);
atomic_add_f
(
&
gp
->
a_grav
[
1
],
fac
*
a
[
1
]);
atomic_add_f
(
&
gp
->
a_grav
[
2
],
fac
*
a
[
2
]);
#endif
gravity_add_comoving_potential
(
gp
,
p
);
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
gp
->
potential_PM
=
p
;
gp
->
a_grav_PM
[
0
]
=
fac
*
a
[
0
];
...
...
src/multipole.h
View file @
7295cf3d
...
...
@@ -2589,9 +2589,15 @@ INLINE static void gravity_L2P(const struct grav_tensor *lb,
#endif
/* Update the particle */
#ifdef SWIFT_TASKS_WITHOUT_ATOMICS
gp
->
a_grav
[
0
]
+=
a_grav
[
0
];
gp
->
a_grav
[
1
]
+=
a_grav
[
1
];
gp
->
a_grav
[
2
]
+=
a_grav
[
2
];
#else
atomic_add_f
(
&
gp
->
a_grav
[
0
],
a_grav
[
0
]);
atomic_add_f
(
&
gp
->
a_grav
[
1
],
a_grav
[
1
]);
atomic_add_f
(
&
gp
->
a_grav
[
2
],
a_grav
[
2
]);
#endif
gravity_add_comoving_potential
(
gp
,
pot
);
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
...
...
src/runner_doiact_grav.c
View file @
7295cf3d
...
...
@@ -1359,6 +1359,7 @@ static INLINE void runner_dopair_grav_mm_symmetric(struct runner *r,
cj
->
grav
.
ti_old_multipole
,
cj
->
nodeID
,
ci
->
nodeID
,
e
->
ti_current
);
#endif
#ifndef SWIFT_TASKS_WITHOUT_ATOMICS
/* Lock the multipoles
* Note we impose a hierarchy to solve the dining philosopher problem */
if
(
ci
<
cj
)
{
...
...
@@ -1368,15 +1369,18 @@ static INLINE void runner_dopair_grav_mm_symmetric(struct runner *r,
lock_lock
(
&
cj
->
grav
.
mlock
);
lock_lock
(
&
ci
->
grav
.
mlock
);
}
#endif
/* Let's interact at this level */
gravity_M2L_symmetric
(
&
ci
->
grav
.
multipole
->
pot
,
&
cj
->
grav
.
multipole
->
pot
,
multi_i
,
multi_j
,
ci
->
grav
.
multipole
->
CoM
,
cj
->
grav
.
multipole
->
CoM
,
props
,
periodic
,
dim
,
r_s_inv
);
#ifndef SWIFT_TASKS_WITHOUT_ATOMICS
/* Unlock the multipoles */
if
(
lock_unlock
(
&
ci
->
grav
.
mlock
)
!=
0
)
error
(
"Failed to unlock multipole"
);
if
(
lock_unlock
(
&
cj
->
grav
.
mlock
)
!=
0
)
error
(
"Failed to unlock multipole"
);
#endif
TIMER_TOC
(
timer_dopair_grav_mm
);
}
...
...
@@ -1424,6 +1428,7 @@ static INLINE void runner_dopair_grav_mm_nonsym(struct runner *r,
cj
->
grav
.
ti_old_multipole
,
cj
->
nodeID
,
ci
->
nodeID
,
e
->
ti_current
);
#endif
#ifndef SWIFT_TASKS_WITHOUT_ATOMICS
/* Lock the multipoles
* Note we impose a hierarchy to solve the dining philosopher problem */
if
(
ci
<
cj
)
{
...
...
@@ -1433,14 +1438,17 @@ static INLINE void runner_dopair_grav_mm_nonsym(struct runner *r,
lock_lock
(
&
cj
->
grav
.
mlock
);
lock_lock
(
&
ci
->
grav
.
mlock
);
}
#endif
/* Let's interact at this level */
gravity_M2L_nonsym
(
&
ci
->
grav
.
multipole
->
pot
,
multi_j
,
ci
->
grav
.
multipole
->
CoM
,
cj
->
grav
.
multipole
->
CoM
,
props
,
periodic
,
dim
,
r_s_inv
);
#ifndef SWIFT_TASKS_WITHOUT_ATOMICS
/* Unlock the multipoles */
if
(
lock_unlock
(
&
ci
->
grav
.
mlock
)
!=
0
)
error
(
"Failed to unlock multipole"
);
if
(
lock_unlock
(
&
cj
->
grav
.
mlock
)
!=
0
)
error
(
"Failed to unlock multipole"
);
#endif
TIMER_TOC
(
timer_dopair_grav_mm
);
}
...
...
src/timestep_limiter_iact.h
View file @
7295cf3d
...
...
@@ -87,8 +87,12 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_limiter(
/* Wake up the neighbour? */
if
(
pj
->
time_bin
>
pi
->
time_bin
+
time_bin_neighbour_max_delta_bin
)
{
/* Store the smallest time bin that woke up this particle */
/* Store the smallest time bin that woke up this particle */
#ifdef SWIFT_TASKS_WITHOUT_ATOMICS
pj
->
limiter_data
.
wakeup
=
max
(
pj
->
limiter_data
.
wakeup
,
-
pi
->
time_bin
);
#else
atomic_max_c
(
&
pj
->
limiter_data
.
wakeup
,
-
pi
->
time_bin
);
#endif
}
}
...
...
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