Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
1edd9c08
Commit
1edd9c08
authored
8 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Made the exact gravity force calculation parallel using the threadpool
parent
055253a9
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!333
Gravity multi dt
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/gravity.c
+58
-28
58 additions, 28 deletions
src/gravity.c
with
58 additions
and
28 deletions
src/gravity.c
+
58
−
28
View file @
1edd9c08
...
@@ -32,6 +32,13 @@
...
@@ -32,6 +32,13 @@
#include
"error.h"
#include
"error.h"
#include
"version.h"
#include
"version.h"
struct
exact_force_data
{
const
struct
engine
*
e
;
const
struct
space
*
s
;
int
counter_global
;
double
const_G
;
};
/**
/**
* @brief Checks whether the file containing the exact accelerations for
* @brief Checks whether the file containing the exact accelerations for
* the current choice of parameters already exists.
* the current choice of parameters already exists.
...
@@ -83,32 +90,21 @@ int gravity_exact_force_file_exits(const struct engine *e) {
...
@@ -83,32 +90,21 @@ int gravity_exact_force_file_exits(const struct engine *e) {
}
}
/**
/**
* @brief Run a brute-force gravity calculation for a subset of particles.
* @brief Mapper function for the exact gravity calculation.
*
* All gpart with ID modulo SWIFT_GRAVITY_FORCE_CHECKS will get their forces
* computed.
*
* @param s The #space to use.
* @param e The #engine (to access the current time).
*/
*/
void
gravity_exact_force_compute
(
struct
space
*
s
,
const
struct
engine
*
e
)
{
void
gravity_exact_force_compute_mapper
(
void
*
map_data
,
int
nr_gparts
,
void
*
extra_data
)
{
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
/* Unpack the data */
struct
gpart
*
restrict
gparts
=
(
struct
gpart
*
)
map_data
;
const
ticks
tic
=
getticks
();
struct
exact_force_data
*
data
=
(
struct
exact_force_data
*
)
extra_data
;
const
double
const_G
=
e
->
physical_constants
->
const_newton_G
;
const
struct
space
*
s
=
data
->
s
;
const
struct
engine
*
e
=
data
->
e
;
const
double
const_G
=
data
->
const_G
;
int
counter
=
0
;
int
counter
=
0
;
/* Let's start by checking whether we already computed these forces */
for
(
int
i
=
0
;
i
<
nr_gparts
;
++
i
)
{
if
(
gravity_exact_force_file_exits
(
e
))
{
message
(
"Exact accelerations already computed. Skipping calculation."
);
return
;
}
/* No matching file present ? Do it then */
for
(
size_t
i
=
0
;
i
<
s
->
nr_gparts
;
++
i
)
{
struct
gpart
*
gpi
=
&
s
->
gparts
[
i
];
struct
gpart
*
gpi
=
&
gparts
[
i
];
/* Is the particle active and part of the subset to be tested ? */
/* Is the particle active and part of the subset to be tested ? */
if
(
gpi
->
id_or_neg_offset
%
SWIFT_GRAVITY_FORCE_CHECKS
==
0
&&
if
(
gpi
->
id_or_neg_offset
%
SWIFT_GRAVITY_FORCE_CHECKS
==
0
&&
...
@@ -118,13 +114,13 @@ void gravity_exact_force_compute(struct space *s, const struct engine *e) {
...
@@ -118,13 +114,13 @@ void gravity_exact_force_compute(struct space *s, const struct engine *e) {
double
a_grav
[
3
]
=
{
0
.,
0
.,
0
.};
double
a_grav
[
3
]
=
{
0
.,
0
.,
0
.};
/* Interact it with all other particles in the space.*/
/* Interact it with all other particles in the space.*/
for
(
size_t
j
=
0
;
j
<
s
->
nr_gparts
;
++
j
)
{
for
(
int
j
=
0
;
j
<
(
int
)
s
->
nr_gparts
;
++
j
)
{
/* No self interaction */
if
(
i
==
j
)
continue
;
struct
gpart
*
gpj
=
&
s
->
gparts
[
j
];
struct
gpart
*
gpj
=
&
s
->
gparts
[
j
];
/* No self interaction */
if
(
gpi
==
gpj
)
continue
;
/* Compute the pairwise distance. */
/* Compute the pairwise distance. */
const
double
dx
[
3
]
=
{
gpi
->
x
[
0
]
-
gpj
->
x
[
0
],
// x
const
double
dx
[
3
]
=
{
gpi
->
x
[
0
]
-
gpj
->
x
[
0
],
// x
gpi
->
x
[
1
]
-
gpj
->
x
[
1
],
// y
gpi
->
x
[
1
]
-
gpj
->
x
[
1
],
// y
...
@@ -173,9 +169,43 @@ void gravity_exact_force_compute(struct space *s, const struct engine *e) {
...
@@ -173,9 +169,43 @@ void gravity_exact_force_compute(struct space *s, const struct engine *e) {
counter
++
;
counter
++
;
}
}
}
}
atomic_add
(
&
data
->
counter_global
,
counter
);
}
/**
* @brief Run a brute-force gravity calculation for a subset of particles.
*
* All gpart with ID modulo SWIFT_GRAVITY_FORCE_CHECKS will get their forces
* computed.
*
* @param s The #space to use.
* @param e The #engine (to access the current time).
*/
void
gravity_exact_force_compute
(
struct
space
*
s
,
const
struct
engine
*
e
)
{
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
const
ticks
tic
=
getticks
();
/* Let's start by checking whether we already computed these forces */
if
(
gravity_exact_force_file_exits
(
e
))
{
message
(
"Exact accelerations already computed. Skipping calculation."
);
return
;
}
message
(
"Computed exact gravity for %d gparts (took %.3f %s). "
,
counter
,
/* No matching file present ? Do it then */
clocks_from_ticks
(
getticks
()
-
tic
),
clocks_getunit
());
struct
exact_force_data
data
;
data
.
e
=
e
;
data
.
s
=
s
;
data
.
counter_global
=
0
;
data
.
const_G
=
e
->
physical_constants
->
const_newton_G
;
threadpool_map
(
&
s
->
e
->
threadpool
,
gravity_exact_force_compute_mapper
,
s
->
gparts
,
s
->
nr_gparts
,
sizeof
(
struct
gpart
),
1000
,
&
data
);
message
(
"Computed exact gravity for %d gparts (took %.3f %s). "
,
data
.
counter_global
,
clocks_from_ticks
(
getticks
()
-
tic
),
clocks_getunit
());
#else
#else
error
(
"Gravity checking function called without the corresponding flag."
);
error
(
"Gravity checking function called without the corresponding flag."
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment