Commit 90c1c276 authored by Vladislav Perepelkin's avatar Vladislav Perepelkin
Browse files

added openmp

parent c9edfab7
......@@ -7,7 +7,7 @@ run: hpprp FORCE
./hpprp
hpprp: hpprp.c config.c collide.c
g++ -O3 hpprp.c -o hpprp -lrt
g++ -fopenmp -O3 hpprp.c -o hpprp -lrt
collide.c: rules.txt scripts/rules_gen.py
python scripts/rules_gen.py rules.txt collide.c
......
// USER CONFIGURATION FILE
// TODO: rules table
#define THREADS 1
// Main properties
#define WIDTH 400
......
......@@ -103,29 +103,8 @@ void swap_buffers()
new_field=tmp;
}
void move()
{
int i;
for (i=0; i<HEIGHT; i++) {
int j;
for (j=0; j<WIDTH; j++) {
char cell=FIELD(i, j)&0xf0; // keep rest mass
if (FIELD(i, (j+WIDTH-1)%WIDTH)&1) cell+=1; // right
if (FIELD(i, (j+1)%WIDTH)&4) cell+=4; // left
if (FIELD((i+HEIGHT-1)%HEIGHT, j)&8) cell+=8; // up
if (FIELD((i+1)%HEIGHT, j)&2) cell+=2; // down
NEW_FIELD(i, j)=cell;
}
}
swap_buffers();
}
int main()
{
int iter;
struct timespec t0, t1;
field=(char*)malloc(WIDTH*HEIGHT);
......@@ -135,11 +114,19 @@ int main()
clock_gettime(CLOCK_MONOTONIC_RAW, &t0);
#pragma omp parallel num_threads(THREADS)
{
int iter;
#pragma omp single
printf("Running %d threads\n", omp_get_num_threads());
for (iter=0; iter<ITERS; iter++) {
int i;
#pragma omp single
sources(iter);
#pragma omp for private(i) schedule(static)
for(i=0; i<HEIGHT; i++) {
int j;
for (j=0; j<WIDTH; j++) {
......@@ -147,11 +134,35 @@ int main()
}
}
move();
#pragma omp barrier
#pragma omp for private(i) schedule(static)
for (i=0; i<HEIGHT; i++) {
int j;
for (j=0; j<WIDTH; j++) {
char cell=FIELD(i, j)&0xf0; // keep rest mass
if (FIELD(i, (j+WIDTH-1)%WIDTH)&1) cell+=1; // right
if (FIELD(i, (j+1)%WIDTH)&4) cell+=4; // left
if (FIELD((i+HEIGHT-1)%HEIGHT, j)&8) cell+=8; // up
if (FIELD((i+1)%HEIGHT, j)&2) cell+=2; // down
NEW_FIELD(i, j)=cell;
}
}
#pragma omp barrier
#pragma omp single
{
swap_buffers();
if (iter%SAVE_PERIOD==0) {
save(iter);
}
}
#pragma omp barrier
}
}
clock_gettime(CLOCK_MONOTONIC_RAW, &t1);
......
......@@ -10,4 +10,4 @@ set output '\"$x.png\"'
plot '\"$x\"'' | gnuplot - 2>/dev/null
done
mencoder mf://$1/*.png -mf fps=10:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o $2
mencoder mf://$1/*.png -mf fps=10:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o $2 >/dev/null 2>/dev/null
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