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
cfb3df9a
Commit
cfb3df9a
authored
8 years ago
by
James Willis
Browse files
Options
Downloads
Patches
Plain Diff
Store vectorised results and compare with the brute force version to check accuracy.
parent
a78b4209
No related branches found
No related tags found
1 merge request
!287
Particle caching
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test27cells.c
+36
-1
36 additions, 1 deletion
tests/test27cells.c
with
36 additions
and
1 deletion
tests/test27cells.c
+
36
−
1
View file @
cfb3df9a
...
@@ -30,6 +30,8 @@
...
@@ -30,6 +30,8 @@
/* Local headers. */
/* Local headers. */
#include
"swift.h"
#include
"swift.h"
#define ACC_THRESHOLD 1e-5
enum
velocity_types
{
enum
velocity_types
{
velocity_zero
,
velocity_zero
,
velocity_random
,
velocity_random
,
...
@@ -254,6 +256,26 @@ void dump_particle_fields(char *fileName, struct cell *main_cell,
...
@@ -254,6 +256,26 @@ void dump_particle_fields(char *fileName, struct cell *main_cell,
fclose
(
file
);
fclose
(
file
);
}
}
/**
* @brief Compares the vectorised result against
* the serial result of the interaction.
*
* @param serial_parts Particle array that has been interacted serially
* @param vec_parts Particle array to be interacted using vectors
* @param count No. of particles that have been interacted
* @param threshold Level of accuracy needed
*
* @return Non-zero value if difference found, 0 otherwise
*/
int
check_results
(
struct
part
*
serial_parts
,
struct
part
*
vec_parts
,
int
count
,
double
threshold
)
{
int
result
=
0
;
for
(
int
i
=
0
;
i
<
count
;
i
++
)
result
+=
compare_particles
(
serial_parts
[
i
],
vec_parts
[
i
],
threshold
);
return
result
;
}
/* Just a forward declaration... */
/* Just a forward declaration... */
void
runner_dopair1_density
(
struct
runner
*
r
,
struct
cell
*
ci
,
struct
cell
*
cj
);
void
runner_dopair1_density
(
struct
runner
*
r
,
struct
cell
*
ci
,
struct
cell
*
cj
);
void
runner_doself1_density
(
struct
runner
*
r
,
struct
cell
*
ci
);
void
runner_doself1_density
(
struct
runner
*
r
,
struct
cell
*
ci
);
...
@@ -264,6 +286,7 @@ int main(int argc, char *argv[]) {
...
@@ -264,6 +286,7 @@ int main(int argc, char *argv[]) {
size_t
runs
=
0
,
particles
=
0
;
size_t
runs
=
0
,
particles
=
0
;
double
h
=
1
.
23485
,
size
=
1
.,
rho
=
1
.;
double
h
=
1
.
23485
,
size
=
1
.,
rho
=
1
.;
double
perturbation
=
0
.;
double
perturbation
=
0
.;
double
threshold
=
ACC_THRESHOLD
;
char
outputFileNameExtension
[
200
]
=
""
;
char
outputFileNameExtension
[
200
]
=
""
;
char
outputFileName
[
200
]
=
""
;
char
outputFileName
[
200
]
=
""
;
enum
velocity_types
vel
=
velocity_zero
;
enum
velocity_types
vel
=
velocity_zero
;
...
@@ -279,7 +302,7 @@ int main(int argc, char *argv[]) {
...
@@ -279,7 +302,7 @@ int main(int argc, char *argv[]) {
srand
(
0
);
srand
(
0
);
char
c
;
char
c
;
while
((
c
=
getopt
(
argc
,
argv
,
"m:s:h:n:r:t:d:f:v:"
))
!=
-
1
)
{
while
((
c
=
getopt
(
argc
,
argv
,
"m:s:h:n:r:t:d:f:v:
a:
"
))
!=
-
1
)
{
switch
(
c
)
{
switch
(
c
)
{
case
'h'
:
case
'h'
:
sscanf
(
optarg
,
"%lf"
,
&
h
);
sscanf
(
optarg
,
"%lf"
,
&
h
);
...
@@ -305,6 +328,9 @@ int main(int argc, char *argv[]) {
...
@@ -305,6 +328,9 @@ int main(int argc, char *argv[]) {
case
'v'
:
case
'v'
:
sscanf
(
optarg
,
"%d"
,
(
int
*
)
&
vel
);
sscanf
(
optarg
,
"%d"
,
(
int
*
)
&
vel
);
break
;
break
;
case
'a'
:
sscanf
(
optarg
,
"%lf"
,
&
threshold
);
break
;
case
'?'
:
case
'?'
:
error
(
"Unknown option."
);
error
(
"Unknown option."
);
break
;
break
;
...
@@ -411,6 +437,11 @@ int main(int argc, char *argv[]) {
...
@@ -411,6 +437,11 @@ int main(int argc, char *argv[]) {
}
}
}
}
/* Store the vectorised particle results. */
struct
part
vec_parts
[
main_cell
->
count
];
for
(
int
i
=
0
;
i
<
main_cell
->
count
;
i
++
)
vec_parts
[
i
]
=
main_cell
->
parts
[
i
];
/* Output timing */
/* Output timing */
message
(
"SWIFT calculation took : %15lli ticks."
,
time
/
runs
);
message
(
"SWIFT calculation took : %15lli ticks."
,
time
/
runs
);
...
@@ -441,6 +472,10 @@ int main(int argc, char *argv[]) {
...
@@ -441,6 +472,10 @@ int main(int argc, char *argv[]) {
sprintf
(
outputFileName
,
"brute_force_27_%s.dat"
,
outputFileNameExtension
);
sprintf
(
outputFileName
,
"brute_force_27_%s.dat"
,
outputFileNameExtension
);
dump_particle_fields
(
outputFileName
,
main_cell
,
cells
);
dump_particle_fields
(
outputFileName
,
main_cell
,
cells
);
/* Check serial results against the vectorised results. */
if
(
check_results
(
main_cell
->
parts
,
vec_parts
,
main_cell
->
count
,
threshold
))
message
(
"Differences found..."
);
/* Output timing */
/* Output timing */
message
(
"Brute force calculation took : %15lli ticks."
,
toc
-
tic
);
message
(
"Brute force calculation took : %15lli ticks."
,
toc
-
tic
);
...
...
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