Skip to content

Commit

Permalink
Add examples/trisolv
Browse files Browse the repository at this point in the history
Add trisolv to examples/

Signed-off-by: Uday Reddy <udayreddy@gmail.com>
  • Loading branch information
bondhugula committed May 20, 2011
1 parent 4b4bfdb commit 7eb7340
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/trisolv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.par.c
*.tiled.c
*.cloog
*.pluto.c
out_*
tiled
orig
par
opt
orig_par
23 changes: 23 additions & 0 deletions examples/trisolv/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SRC= trisolv

PLCFLAGS = #--unroll
TILEFLAGS = #--l2tile

include ../common.mk

$(SRC).par2d.c:
$(PLC) $(SRC).c --tile --parallel --multipipe $(TILEFLAGS) $(PLCFLAGS)

par2d: $(SRC).par2d.c decls.h util.h
$(CC) $(OPT_FLAGS) -openmp -lm $(SRC).par2d.c -o par2d

par2d_test: $(SRC).par2d.c decls.h util.h
$(CC) $(OPT_FLAGS) -openmp -lm $(SRC).par2d.c -o par2d_test -DTEST

ptest: tiled_test par2d_test par_test
./tiled_test 2> out_tiled
export OMP_NUM_THREADS=4
./par_test 2> out_par4
diff -q out_tiled out_par4
export OMP_NUM_THREADS=4; ./par2d_test 2> out_par2d
diff -q out_tiled out_par2d
4 changes: 4 additions & 0 deletions examples/trisolv/decls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define NMAX 3000

static double B[NMAX][NMAX], L[NMAX][NMAX];

47 changes: 47 additions & 0 deletions examples/trisolv/trisolv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/time.h>

#include "decls.h"
#include "util.h"

void trisolv(long N)
{
long i,j,k;

#pragma scop
for (i=0;i<=N-1;i++) {
for (j=0;j<=N-1;j++) {
for (k=0;k<=j-1;k++) {
B[j][i]=B[j][i]-L[j][k]*B[k][i]; //S1 ;

}
B[j][i]=B[j][i]/L[j][j]; // S2 ;
} // for j
} // for i
#pragma endscop
}


int main()
{
long N=NMAX;
int i,j;
double t_start, t_end;

IF_TIME(t_start = rtclock());
trisolv(N);
IF_TIME(t_end = rtclock());
IF_TIME(fprintf(stderr, "%0.6lfs\n", t_end - t_start));

if (fopen(".test", "r")) {
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
fprintf(stdout, "%lf ", B[i][j]);
}
fprintf(stdout, "\n");
}
}
return 0;
}
33 changes: 33 additions & 0 deletions examples/trisolv/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <unistd.h>
#include <sys/time.h>

#ifdef TIME
#define IF_TIME(foo) foo;
#else
#define IF_TIME(foo)
#endif

void init_array()
{
int i, j;

for (i = 0; i < NMAX; i++) {
for (j = 0; j < NMAX; j++) {
B[i][j] = i+j;
L[i][j] = (i+j+3.45) *i*j*0.5;
}
}


}


double rtclock()
{
struct timezone Tzp;
struct timeval Tp;
int stat;
stat = gettimeofday (&Tp, &Tzp);
if (stat != 0) printf("Error return from gettimeofday: %d",stat);
return(Tp.tv_sec + Tp.tv_usec*1.0e-6);
}

0 comments on commit 7eb7340

Please sign in to comment.