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
9e7231b4
Commit
9e7231b4
authored
7 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Use an approximation to erfc() instead of an external function call to the math library.
parent
a3f7f044
No related branches found
No related tags found
1 merge request
!604
Parallel mesh assignment and simplification of M2L kernel
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/approx_math.h
+25
-0
25 additions, 0 deletions
src/approx_math.h
src/kernel_long_gravity.h
+3
-3
3 additions, 3 deletions
src/kernel_long_gravity.h
with
28 additions
and
3 deletions
src/approx_math.h
+
25
−
0
View file @
9e7231b4
...
@@ -21,6 +21,31 @@
...
@@ -21,6 +21,31 @@
#include
"inline.h"
#include
"inline.h"
/**
* @brief Approximate version of the complementay error function erfcf(x).
*
* This is based on eq. 7.1.27 of Abramowitz & Stegun, 1972.
* The absolute error is < 4.7*10^-4 over the range 0 < x < infinity.
*
* Returns garbage for x < 0.
* @param x The number to compute erfc for.
*/
__attribute__
((
always_inline
,
const
))
INLINE
static
float
approx_erfcf
(
float
x
)
{
/* 1 + 0.278393*x + 0.230389*x^2 + 0.000972*x^3 + 0.078108*x^4 */
float
arg
=
0
.
07
8108
f
;
arg
=
x
*
arg
+
0
.
000
972
f
;
arg
=
x
*
arg
+
0
.
230389
f
;
arg
=
x
*
arg
+
0
.
278393
f
;
arg
=
x
*
arg
+
1
.
f
;
/* 1 / arg^4 */
const
float
arg2
=
arg
*
arg
;
const
float
arg4
=
arg2
*
arg2
;
return
1
.
f
/
arg4
;
}
/**
/**
* @brief Approximate version of expf(x) using a 4th order Taylor expansion
* @brief Approximate version of expf(x) using a 4th order Taylor expansion
*
*
...
...
This diff is collapsed.
Click to expand it.
src/kernel_long_gravity.h
+
3
−
3
View file @
9e7231b4
...
@@ -90,7 +90,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_derivatives(
...
@@ -90,7 +90,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_derivatives(
const
float
r_s_inv5
=
r_s_inv4
*
r_s_inv
;
const
float
r_s_inv5
=
r_s_inv4
*
r_s_inv
;
/* Derivatives of \chi */
/* Derivatives of \chi */
derivs
->
chi_0
=
erfcf
(
u
);
derivs
->
chi_0
=
approx_
erfcf
(
u
);
derivs
->
chi_1
=
-
r_s_inv
;
derivs
->
chi_1
=
-
r_s_inv
;
derivs
->
chi_2
=
r_s_inv2
*
u
;
derivs
->
chi_2
=
r_s_inv2
*
u
;
derivs
->
chi_3
=
-
r_s_inv3
*
(
u2
-
0
.
5
f
);
derivs
->
chi_3
=
-
r_s_inv3
*
(
u2
-
0
.
5
f
);
...
@@ -158,7 +158,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_pot_eval(
...
@@ -158,7 +158,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_pot_eval(
#ifdef GADGET2_LONG_RANGE_CORRECTION
#ifdef GADGET2_LONG_RANGE_CORRECTION
const
float
arg1
=
u
*
0
.
5
f
;
const
float
arg1
=
u
*
0
.
5
f
;
const
float
term1
=
erfcf
(
arg1
);
const
float
term1
=
approx_
erfcf
(
arg1
);
*
W
=
term1
;
*
W
=
term1
;
#else
#else
...
@@ -190,7 +190,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_force_eval(
...
@@ -190,7 +190,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_force_eval(
const
float
arg1
=
u
*
0
.
5
f
;
const
float
arg1
=
u
*
0
.
5
f
;
const
float
arg2
=
-
arg1
*
arg1
;
const
float
arg2
=
-
arg1
*
arg1
;
const
float
term1
=
erfcf
(
arg1
);
const
float
term1
=
approx_
erfcf
(
arg1
);
const
float
term2
=
u
*
one_over_sqrt_pi
*
expf
(
arg2
);
const
float
term2
=
u
*
one_over_sqrt_pi
*
expf
(
arg2
);
*
W
=
term1
+
term2
;
*
W
=
term1
+
term2
;
...
...
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