Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Perepelkin
hppca
Commits
82aaa6b4
Commit
82aaa6b4
authored
Jun 01, 2016
by
Vladislav Perepelkin
Browse files
Fixed averaging bug
parent
04e80045
Changes
5
Hide whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
82aaa6b4
move/*.png
move/*.txt
rest/*.png
rest/*.txt
density/*.png
density/*.txt
*.avi
Makefile
View file @
82aaa6b4
...
...
@@ -7,7 +7,7 @@ run: hpprp FORCE
./hpprp
hpprp
:
hpprp.c config.c collide.c
g++
-fopenmp
-O3
hpprp.c
-o
hpprp
-lrt
g++
-fopenmp
-O3
hpprp.c
-o
hpprp
-lrt
-Wall
collide.c
:
rules.txt scripts/rules_gen.py
python scripts/rules_gen.py rules.txt collide.c
...
...
config.c
View file @
82aaa6b4
// USER CONFIGURATION FILE
#define THREADS
1
#define THREADS
4
// Main properties
#define WIDTH 400
#define HEIGHT
3
00
#define WIDTH 400
0
#define HEIGHT
40
00
#define ITERS 1000
#define SAVE_PERIOD 10
#define SAVE_PERIOD 10
0
#define AVERAGING_RADIUS 5
// Field initialization
void
init
()
{
fill
(
0
,
0
,
HEIGHT
,
WIDTH
,
// area
0
.
5
,
0
.
5
,
0
.
5
,
0
.
5
,
// move
0
.
0
,
0
.
0
,
0
.
0
,
0
.
0
);
// rest
0
.
7
,
0
.
7
,
0
.
7
,
0
.
7
,
// move
0
.
25
,
0
.
0
,
0
.
0
,
0
.
0
);
// rest
}
// Sources rules
...
...
@@ -23,12 +23,7 @@ void sources(int iter)
if
(
iter
==
0
)
{
fill
(
0
,
WIDTH
*
4
/
10
,
HEIGHT
,
WIDTH
*
6
/
10
,
// area
1
.
0
,
1
.
0
,
1
.
0
,
1
.
0
,
// move
0
.
0
,
0
.
0
,
0
.
0
,
0
.
0
);
// rest
}
if
(
iter
==
ITERS
/
3
)
{
fill
(
0
,
WIDTH
*
2
/
10
,
HEIGHT
,
WIDTH
*
3
/
10
,
// area
1
.
0
,
1
.
0
,
1
.
0
,
1
.
0
,
// move
0
.
0
,
0
.
0
,
0
.
0
,
0
.
0
);
// rest
0
.
75
,
0
.
0
,
0
.
0
,
0
.
0
);
// rest
}
}
hpprp.c
View file @
82aaa6b4
...
...
@@ -13,6 +13,26 @@ void fill(int i0, int j0, int i1, int j1,
#include "config.c"
#include "collide.c"
inline
int
get_move
(
char
cell
)
{
int
mass
=
0
;
if
(
cell
&
1
)
mass
+=
1
;
if
(
cell
&
2
)
mass
+=
1
;
if
(
cell
&
4
)
mass
+=
1
;
if
(
cell
&
8
)
mass
+=
1
;
return
mass
;
}
inline
int
get_rest
(
char
cell
)
{
int
mass
=
0
;
if
(
cell
&
16
)
mass
+=
2
;
if
(
cell
&
32
)
mass
+=
4
;
if
(
cell
&
64
)
mass
+=
8
;
if
(
cell
&
128
)
mass
+=
16
;
return
mass
;
}
void
fill
(
int
i0
,
int
j0
,
int
i1
,
int
j1
,
double
r
,
double
d
,
double
l
,
double
u
,
double
r1
,
double
r2
,
double
r3
,
double
r4
)
...
...
@@ -34,26 +54,6 @@ void fill(int i0, int j0, int i1, int j1,
}
}
inline
int
get_move
(
char
cell
)
{
int
mass
=
0
;
if
(
cell
&
1
)
mass
+=
1
;
if
(
cell
&
2
)
mass
+=
1
;
if
(
cell
&
4
)
mass
+=
1
;
if
(
cell
&
8
)
mass
+=
1
;
return
mass
;
}
inline
int
get_rest
(
char
cell
)
{
int
mass
=
0
;
if
(
cell
&
16
)
mass
+=
2
;
if
(
cell
&
32
)
mass
+=
4
;
if
(
cell
&
64
)
mass
+=
8
;
if
(
cell
&
128
)
mass
+=
16
;
return
mass
;
}
void
sum_mass
(
int
row
,
int
col
,
int
*
rest
,
int
*
move
)
{
int
i
,
j
;
...
...
@@ -85,9 +85,9 @@ void save(int iter)
sum_mass
(
i
,
j
,
&
rest
,
&
move
);
}
fprintf
(
fl_density
,
"%d
\t
%lf
\n
"
,
j
,
(
rest
+
move
)
/
HEIGHT
/
square
);
fprintf
(
fl_move
,
"%d
\t
%lf
\n
"
,
j
,
move
/
HEIGHT
/
square
);
fprintf
(
fl_rest
,
"%d
\t
%lf
\n
"
,
j
,
rest
/
HEIGHT
/
square
);
fprintf
(
fl_density
,
"%d
\t
%lf
\n
"
,
j
,
(
rest
+
move
)
/
(
HEIGHT
-
AVERAGING_RADIUS
*
2
-
1
)
/
square
);
fprintf
(
fl_move
,
"%d
\t
%lf
\n
"
,
j
,
move
/
(
HEIGHT
-
AVERAGING_RADIUS
*
2
-
1
)
/
square
);
fprintf
(
fl_rest
,
"%d
\t
%lf
\n
"
,
j
,
rest
/
(
HEIGHT
-
AVERAGING_RADIUS
*
2
-
1
)
/
square
);
}
fclose
(
fl_density
);
...
...
@@ -170,7 +170,7 @@ int main()
clock_gettime
(
CLOCK_MONOTONIC_RAW
,
&
t1
);
printf
(
"Done %d iters, %lf MCell/sec
\n
"
,
ITERS
,
ITERS
*
HEIGHT
*
WIDTH
/
1
.
0
*
ITERS
*
HEIGHT
*
WIDTH
/
((
t1
.
tv_sec
-
t0
.
tv_sec
)
+
0
.
000000001
*
(
t1
.
tv_nsec
-
t0
.
tv_nsec
))
/
1000000
);
...
...
scripts/rules_gen.py
View file @
82aaa6b4
...
...
@@ -62,6 +62,12 @@ def add_rule(s0, s1, p):
if
p
==
0
:
del
rules
[
s0
][
s1
]
def
is_deterministic
():
for
r
in
rules
:
if
len
(
rules
[
r
])
>
1
:
return
False
return
True
init_rules
()
if
len
(
sys
.
argv
)
!=
3
:
...
...
@@ -115,7 +121,8 @@ try:
f
=
open
(
sys
.
argv
[
2
],
'w'
)
f
.
write
(
"char collide(char cell)
\n
"
)
f
.
write
(
"{
\n
"
)
f
.
write
(
"
\t
double r=drand48();
\n
"
)
if
not
is_deterministic
():
f
.
write
(
"
\t
double r=drand48();
\n
"
)
f
.
write
(
"
\t
switch(cell) {
\n
"
)
for
s0
in
range
(
256
):
if
len
(
rules
[
s0
])
==
1
and
s0
in
rules
[
s0
]:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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