Commit 82aaa6b4 authored by Vladislav Perepelkin's avatar Vladislav Perepelkin
Browse files

Fixed averaging bug

parent 04e80045
move/*.png
move/*.txt
rest/*.png
rest/*.txt
density/*.png
density/*.txt
*.avi
...@@ -7,7 +7,7 @@ run: hpprp FORCE ...@@ -7,7 +7,7 @@ run: hpprp FORCE
./hpprp ./hpprp
hpprp: hpprp.c config.c collide.c 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 collide.c: rules.txt scripts/rules_gen.py
python scripts/rules_gen.py rules.txt collide.c python scripts/rules_gen.py rules.txt collide.c
......
// USER CONFIGURATION FILE // USER CONFIGURATION FILE
#define THREADS 1 #define THREADS 4
// Main properties // Main properties
#define WIDTH 400 #define WIDTH 4000
#define HEIGHT 300 #define HEIGHT 4000
#define ITERS 1000 #define ITERS 1000
#define SAVE_PERIOD 10 #define SAVE_PERIOD 100
#define AVERAGING_RADIUS 5 #define AVERAGING_RADIUS 5
// Field initialization // Field initialization
void init() void init()
{ {
fill(0, 0, HEIGHT, WIDTH, // area fill(0, 0, HEIGHT, WIDTH, // area
0.5, 0.5, 0.5, 0.5, // move 0.7, 0.7, 0.7, 0.7, // move
0.0, 0.0, 0.0, 0.0); // rest 0.25, 0.0, 0.0, 0.0); // rest
} }
// Sources rules // Sources rules
...@@ -23,12 +23,7 @@ void sources(int iter) ...@@ -23,12 +23,7 @@ void sources(int iter)
if (iter==0) { if (iter==0) {
fill(0, WIDTH*4/10, HEIGHT, WIDTH*6/10, // area fill(0, WIDTH*4/10, HEIGHT, WIDTH*6/10, // area
1.0, 1.0, 1.0, 1.0, // move 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
}
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
} }
} }
...@@ -13,6 +13,26 @@ void fill(int i0, int j0, int i1, int j1, ...@@ -13,6 +13,26 @@ void fill(int i0, int j0, int i1, int j1,
#include "config.c" #include "config.c"
#include "collide.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, void fill(int i0, int j0, int i1, int j1,
double r, double d, double l, double u, double r, double d, double l, double u,
double r1, double r2, double r3, double r4) double r1, double r2, double r3, double r4)
...@@ -34,26 +54,6 @@ void fill(int i0, int j0, int i1, int j1, ...@@ -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) void sum_mass(int row, int col, int* rest, int* move)
{ {
int i, j; int i, j;
...@@ -85,9 +85,9 @@ void save(int iter) ...@@ -85,9 +85,9 @@ void save(int iter)
sum_mass(i, j, &rest, &move); sum_mass(i, j, &rest, &move);
} }
fprintf(fl_density, "%d\t%lf\n", j, (rest+move)/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/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/square); fprintf(fl_rest, "%d\t%lf\n", j, rest/(HEIGHT-AVERAGING_RADIUS*2-1)/square);
} }
fclose(fl_density); fclose(fl_density);
...@@ -170,7 +170,7 @@ int main() ...@@ -170,7 +170,7 @@ int main()
clock_gettime(CLOCK_MONOTONIC_RAW, &t1); clock_gettime(CLOCK_MONOTONIC_RAW, &t1);
printf("Done %d iters, %lf MCell/sec\n", ITERS, 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)) ((t1.tv_sec-t0.tv_sec)+0.000000001*(t1.tv_nsec-t0.tv_nsec))
/1000000); /1000000);
......
...@@ -62,6 +62,12 @@ def add_rule(s0, s1, p): ...@@ -62,6 +62,12 @@ def add_rule(s0, s1, p):
if p==0: if p==0:
del rules[s0][s1] del rules[s0][s1]
def is_deterministic():
for r in rules:
if len(rules[r])>1:
return False
return True
init_rules() init_rules()
if len(sys.argv) != 3: if len(sys.argv) != 3:
...@@ -115,7 +121,8 @@ try: ...@@ -115,7 +121,8 @@ try:
f=open(sys.argv[2], 'w') f=open(sys.argv[2], 'w')
f.write("char collide(char cell)\n") f.write("char collide(char cell)\n")
f.write("{\n") f.write("{\n")
f.write("\tdouble r=drand48();\n") if not is_deterministic():
f.write("\tdouble r=drand48();\n")
f.write("\tswitch(cell) {\n") f.write("\tswitch(cell) {\n")
for s0 in range(256): for s0 in range(256):
if len(rules[s0])==1 and s0 in rules[s0]: if len(rules[s0])==1 and s0 in rules[s0]:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment