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
68a2fe79
Commit
68a2fe79
authored
7 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Also use vectorzation caches for the self PP-gravity interaction.
parent
d5a8d3a4
No related branches found
No related tags found
1 merge request
!400
Bug fix in the test suite. Move the gravity leaf P-P interaction in the frame of the cells. Use a cache for the self P-P interaction.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/runner_doiact_grav.h
+252
-0
252 additions, 0 deletions
src/runner_doiact_grav.h
with
252 additions
and
0 deletions
src/runner_doiact_grav.h
+
252
−
0
View file @
68a2fe79
...
@@ -907,6 +907,125 @@ void runner_dopair_grav_pp(struct runner *r, struct cell *ci, struct cell *cj) {
...
@@ -907,6 +907,125 @@ void runner_dopair_grav_pp(struct runner *r, struct cell *ci, struct cell *cj) {
*/
*/
void
runner_doself_grav_pp_full
(
struct
runner
*
r
,
struct
cell
*
c
)
{
void
runner_doself_grav_pp_full
(
struct
runner
*
r
,
struct
cell
*
c
)
{
/* Some constants */
const
struct
engine
*
const
e
=
r
->
e
;
struct
gravity_cache
*
const
ci_cache
=
&
r
->
ci_gravity_cache
;
/* Cell properties */
const
int
gcount
=
c
->
gcount
;
struct
gpart
*
restrict
gparts
=
c
->
gparts
;
const
int
c_active
=
cell_is_active
(
c
,
e
);
/* Anything to do here ?*/
if
(
!
c_active
)
return
;
/* Check that we fit in cache */
if
(
gcount
>
ci_cache
->
count
)
error
(
"Not enough space in the caches! gcount_i=%d"
,
gcount
);
/* Computed the padded counts */
const
int
gcount_padded
=
gcount
-
(
gcount
%
VEC_SIZE
)
+
VEC_SIZE
;
gravity_cache_populate_no_shift
(
ci_cache
,
gparts
,
gcount
,
gcount_padded
);
/* Ok... Here we go ! */
/* Loop over all particles in ci... */
for
(
int
pid
=
0
;
pid
<
gcount
;
pid
++
)
{
/* Skip inactive particles */
if
(
!
gpart_is_active
(
&
gparts
[
pid
],
e
))
continue
;
const
float
x_i
=
ci_cache
->
x
[
pid
];
const
float
y_i
=
ci_cache
->
y
[
pid
];
const
float
z_i
=
ci_cache
->
z
[
pid
];
/* Some powers of the softening length */
const
float
h_i
=
ci_cache
->
epsilon
[
pid
];
const
float
h2_i
=
h_i
*
h_i
;
const
float
h_inv_i
=
1
.
f
/
h_i
;
const
float
h_inv3_i
=
h_inv_i
*
h_inv_i
*
h_inv_i
;
/* Local accumulators for the acceleration */
float
a_x
=
0
.
f
,
a_y
=
0
.
f
,
a_z
=
0
.
f
;
/* Make the compiler understand we are in happy vectorization land */
swift_align_information
(
ci_cache
->
x
,
SWIFT_CACHE_ALIGNMENT
);
swift_align_information
(
ci_cache
->
y
,
SWIFT_CACHE_ALIGNMENT
);
swift_align_information
(
ci_cache
->
z
,
SWIFT_CACHE_ALIGNMENT
);
swift_align_information
(
ci_cache
->
m
,
SWIFT_CACHE_ALIGNMENT
);
swift_assume_size
(
gcount_padded
,
VEC_SIZE
);
/* Loop over every other particle in the cell. */
for
(
int
pjd
=
0
;
pjd
<
gcount_padded
;
pjd
++
)
{
/* No self interaction */
if
(
pid
==
pjd
)
continue
;
/* Get info about j */
const
float
x_j
=
ci_cache
->
x
[
pjd
];
const
float
y_j
=
ci_cache
->
y
[
pjd
];
const
float
z_j
=
ci_cache
->
z
[
pjd
];
const
float
mass_j
=
ci_cache
->
m
[
pjd
];
/* Compute the pairwise (square) distance. */
const
float
dx
=
x_i
-
x_j
;
const
float
dy
=
y_i
-
y_j
;
const
float
dz
=
z_i
-
z_j
;
const
float
r2
=
dx
*
dx
+
dy
*
dy
+
dz
*
dz
;
#ifdef SWIFT_DEBUG_CHECKS
if
(
r2
==
0
.
f
)
error
(
"Interacting particles with 0 distance"
);
/* Check that particles have been drifted to the current time */
if
(
gparts
[
pid
].
ti_drift
!=
e
->
ti_current
)
error
(
"gpi not drifted to current time"
);
if
(
pjd
<
gcount
&&
gparts
[
pjd
].
ti_drift
!=
e
->
ti_current
)
error
(
"gpj not drifted to current time"
);
#endif
/* Get the inverse distance */
const
float
r_inv
=
1
.
f
/
sqrtf
(
r2
);
float
f_ij
,
W_ij
;
if
(
r2
>=
h2_i
)
{
/* Get Newtonian gravity */
f_ij
=
mass_j
*
r_inv
*
r_inv
*
r_inv
;
}
else
{
const
float
r
=
r2
*
r_inv
;
const
float
ui
=
r
*
h_inv_i
;
kernel_grav_eval
(
ui
,
&
W_ij
);
/* Get softened gravity */
f_ij
=
mass_j
*
h_inv3_i
*
W_ij
;
}
/* Store it back */
a_x
-=
f_ij
*
dx
;
a_y
-=
f_ij
*
dy
;
a_z
-=
f_ij
*
dz
;
#ifdef SWIFT_DEBUG_CHECKS
/* Update the interaction counter if it's not a padded gpart */
if
(
pjd
<
gcount
)
gparts
[
pid
].
num_interacted
++
;
#endif
}
/* Store everything back in cache */
ci_cache
->
a_x
[
pid
]
+=
a_x
;
ci_cache
->
a_y
[
pid
]
+=
a_y
;
ci_cache
->
a_z
[
pid
]
+=
a_z
;
}
gravity_cache_write_back
(
ci_cache
,
gparts
,
gcount
);
#ifdef MATTHIEU_OLD_STUFF
/* Some constants */
/* Some constants */
const
struct
engine
*
const
e
=
r
->
e
;
const
struct
engine
*
const
e
=
r
->
e
;
...
@@ -976,6 +1095,8 @@ void runner_doself_grav_pp_full(struct runner *r, struct cell *c) {
...
@@ -976,6 +1095,8 @@ void runner_doself_grav_pp_full(struct runner *r, struct cell *c) {
}
}
}
}
}
}
#endif
}
}
/**
/**
...
@@ -997,6 +1118,136 @@ void runner_doself_grav_pp_truncated(struct runner *r, struct cell *c) {
...
@@ -997,6 +1118,136 @@ void runner_doself_grav_pp_truncated(struct runner *r, struct cell *c) {
const
double
rlr
=
cell_width
*
a_smooth
;
const
double
rlr
=
cell_width
*
a_smooth
;
const
float
rlr_inv
=
1
.
/
rlr
;
const
float
rlr_inv
=
1
.
/
rlr
;
/* Caches to play with */
struct
gravity_cache
*
const
ci_cache
=
&
r
->
ci_gravity_cache
;
/* Cell properties */
const
int
gcount
=
c
->
gcount
;
struct
gpart
*
restrict
gparts
=
c
->
gparts
;
const
int
c_active
=
cell_is_active
(
c
,
e
);
/* Anything to do here ?*/
if
(
!
c_active
)
return
;
/* Check that we fit in cache */
if
(
gcount
>
ci_cache
->
count
)
error
(
"Not enough space in the caches! gcount_i=%d"
,
gcount
);
/* Computed the padded counts */
const
int
gcount_padded
=
gcount
-
(
gcount
%
VEC_SIZE
)
+
VEC_SIZE
;
gravity_cache_populate_no_shift
(
ci_cache
,
gparts
,
gcount
,
gcount_padded
);
/* Ok... Here we go ! */
/* Loop over all particles in ci... */
for
(
int
pid
=
0
;
pid
<
gcount
;
pid
++
)
{
/* Skip inactive particles */
if
(
!
gpart_is_active
(
&
gparts
[
pid
],
e
))
continue
;
const
float
x_i
=
ci_cache
->
x
[
pid
];
const
float
y_i
=
ci_cache
->
y
[
pid
];
const
float
z_i
=
ci_cache
->
z
[
pid
];
/* Some powers of the softening length */
const
float
h_i
=
ci_cache
->
epsilon
[
pid
];
const
float
h2_i
=
h_i
*
h_i
;
const
float
h_inv_i
=
1
.
f
/
h_i
;
const
float
h_inv3_i
=
h_inv_i
*
h_inv_i
*
h_inv_i
;
/* Local accumulators for the acceleration */
float
a_x
=
0
.
f
,
a_y
=
0
.
f
,
a_z
=
0
.
f
;
/* Make the compiler understand we are in happy vectorization land */
swift_align_information
(
ci_cache
->
x
,
SWIFT_CACHE_ALIGNMENT
);
swift_align_information
(
ci_cache
->
y
,
SWIFT_CACHE_ALIGNMENT
);
swift_align_information
(
ci_cache
->
z
,
SWIFT_CACHE_ALIGNMENT
);
swift_align_information
(
ci_cache
->
m
,
SWIFT_CACHE_ALIGNMENT
);
swift_assume_size
(
gcount_padded
,
VEC_SIZE
);
/* Loop over every other particle in the cell. */
for
(
int
pjd
=
0
;
pjd
<
gcount_padded
;
pjd
++
)
{
/* No self interaction */
if
(
pid
==
pjd
)
continue
;
/* Get info about j */
const
float
x_j
=
ci_cache
->
x
[
pjd
];
const
float
y_j
=
ci_cache
->
y
[
pjd
];
const
float
z_j
=
ci_cache
->
z
[
pjd
];
const
float
mass_j
=
ci_cache
->
m
[
pjd
];
/* Compute the pairwise (square) distance. */
const
float
dx
=
x_i
-
x_j
;
const
float
dy
=
y_i
-
y_j
;
const
float
dz
=
z_i
-
z_j
;
const
float
r2
=
dx
*
dx
+
dy
*
dy
+
dz
*
dz
;
#ifdef SWIFT_DEBUG_CHECKS
if
(
r2
==
0
.
f
)
error
(
"Interacting particles with 0 distance"
);
/* Check that particles have been drifted to the current time */
if
(
gparts
[
pid
].
ti_drift
!=
e
->
ti_current
)
error
(
"gpi not drifted to current time"
);
if
(
pjd
<
gcount
&&
gparts
[
pjd
].
ti_drift
!=
e
->
ti_current
)
error
(
"gpj not drifted to current time"
);
#endif
/* Get the inverse distance */
const
float
r_inv
=
1
.
f
/
sqrtf
(
r2
);
const
float
r
=
r2
*
r_inv
;
float
f_ij
,
W_ij
,
corr_lr
;
if
(
r2
>=
h2_i
)
{
/* Get Newtonian gravity */
f_ij
=
mass_j
*
r_inv
*
r_inv
*
r_inv
;
}
else
{
const
float
ui
=
r
*
h_inv_i
;
kernel_grav_eval
(
ui
,
&
W_ij
);
/* Get softened gravity */
f_ij
=
mass_j
*
h_inv3_i
*
W_ij
;
}
/* Get long-range correction */
const
float
u_lr
=
r
*
rlr_inv
;
kernel_long_grav_eval
(
u_lr
,
&
corr_lr
);
f_ij
*=
corr_lr
;
/* Store it back */
a_x
-=
f_ij
*
dx
;
a_y
-=
f_ij
*
dy
;
a_z
-=
f_ij
*
dz
;
#ifdef SWIFT_DEBUG_CHECKS
/* Update the interaction counter if it's not a padded gpart */
if
(
pjd
<
gcount
)
gparts
[
pid
].
num_interacted
++
;
#endif
}
/* Store everything back in cache */
ci_cache
->
a_x
[
pid
]
+=
a_x
;
ci_cache
->
a_y
[
pid
]
+=
a_y
;
ci_cache
->
a_z
[
pid
]
+=
a_z
;
}
gravity_cache_write_back
(
ci_cache
,
gparts
,
gcount
);
#ifdef MATTHIEU_OLD_STUFF
/* Some constants */
const
struct
engine
*
const
e
=
r
->
e
;
const
struct
space
*
s
=
e
->
s
;
const
double
cell_width
=
s
->
width
[
0
];
const
double
a_smooth
=
e
->
gravity_properties
->
a_smooth
;
const
double
rlr
=
cell_width
*
a_smooth
;
const
float
rlr_inv
=
1
.
/
rlr
;
/* Cell properties */
/* Cell properties */
const
int
gcount
=
c
->
gcount
;
const
int
gcount
=
c
->
gcount
;
struct
gpart
*
restrict
gparts
=
c
->
gparts
;
struct
gpart
*
restrict
gparts
=
c
->
gparts
;
...
@@ -1063,6 +1314,7 @@ void runner_doself_grav_pp_truncated(struct runner *r, struct cell *c) {
...
@@ -1063,6 +1314,7 @@ void runner_doself_grav_pp_truncated(struct runner *r, struct cell *c) {
}
}
}
}
}
}
#endif
}
}
/**
/**
...
...
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