Skip to content

Commit

Permalink
update some examples
Browse files Browse the repository at this point in the history
Signed-off-by: Uday Bondhugula <uday@csa.iisc.ernet.in>
  • Loading branch information
Uday Bondhugula committed Apr 5, 2012
1 parent 0aab261 commit a830fd2
Show file tree
Hide file tree
Showing 21 changed files with 215 additions and 588 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ polycc.sh
polycc
libtool
getversion.sh
missing
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
swim
71 changes: 63 additions & 8 deletions examples/advect3d/advect3d.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,72 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include <unistd.h>
#include <sys/time.h>
#include <assert.h>

#ifdef PERFCTR
#include <papi.h>
#include "papi_defs.h"
#define nx 300
#define ny 300
#define nz 300
// #define T 20
// #define 9 9

#define f60 0.2
#define f61 0.5
#define f62 0.3

#define halfdtbydx 0.5
#define thirddtbydz 0.3
#define thirddtbydx 0.3
#define thirddtbydy 0.3

double a[nx+10][ny+10][nz+10];
double af[nx+10][ny+10][nz+10];
double ab[nx+10][ny+10][nz+10];
double al[nx+10][ny+10][nz+10];
double athird[nx+10][ny+10][nz+10];
double uxl[nx+10][ny+10][nz+10];
double uzf[nx+10][ny+10][nz+10];
double uyb[nx+10][ny+10][nz+10];


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

#include "decls.h"
void init_array()
{

}


#include "util.h"
void print_array()
{
int i, j, k;

for (i=0; i<nx; i++) {
for (j=0; j<ny; j++) {
for (k=0; k<nz; k++) {
fprintf(stdout, "%lf ", athird[i][j][k]);
if (j%80 == 20) fprintf(stdout, "\n");
}
}
}
fprintf(stdout, "\n");
}


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);
}

#define ceild(n,d) ceil(((double)(n))/((double)(d)))
#define floord(n,d) floor(((double)(n))/((double)(d)))
Expand All @@ -36,7 +91,7 @@ int main()
IF_TIME(t_start = rtclock());
#define reps 10

/* pluto start (nx,ny,nz) */
#pragma scop
for (j = 4; j <= ny+9-2; j++)
for (i = 4; i <= nx+9-3; i++)
for (k = 4; k <= nz+9-3; k++)
Expand Down Expand Up @@ -64,8 +119,8 @@ int main()
for (k = 4; k <= nz+9-3; k++)
athird[j][i][k] = a[j][i][k] + (al[j][i+1][k] - al[j][i][k])
+ (ab[j+1][i][k] - ab[j][i][k]) + (af[j][i][k+1] - af[j][i][k]);
#pragma endscop

/* pluto end */
IF_TIME(t_end = rtclock());
IF_TIME(fprintf(stderr, "%0.6lfs\n", t_end - t_start));

Expand Down
23 changes: 0 additions & 23 deletions examples/advect3d/decls.h

This file was deleted.

40 changes: 0 additions & 40 deletions examples/advect3d/util.h

This file was deleted.

56 changes: 47 additions & 9 deletions examples/dct/dct.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,56 @@
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <unistd.h>
#include <sys/time.h>

#include <assert.h>
#define M 1024
double cos1[M][M+13];
double temp2d[M][M+23];
double block[M][M+43];
double sum2[M][M];

#ifdef PERFCTR
#include <papi.h>
#include "papi_defs.h"
#ifdef TIME
#define IF_TIME(foo) foo;
#else
#define IF_TIME(foo)
#endif

#include "decls.h"
#include "util.h"
void init_array()
{
int i, j;

for (i=0; i<M; i++) {
for (j=0; j<M; j++) {
cos1[i][j] = (1+(i*j)%1024)/2.0;
block[i][j] = (1+(i*j)%1024)/2.0;
}
}
}


void print_array()
{
int i, j;

for (i=0; i<M; i++) {
for (j=0; j<M; j++) {
fprintf(stdout, "%lf ", block[i][j]);
if (j%80 == 79) fprintf(stdout, "\n");
}
fprintf(stdout, "\n");
}
}

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);
}
double t_start, t_end;

int main()
Expand All @@ -28,7 +67,7 @@ int main()
IF_TIME(t_start = rtclock());


/* pluto start (M) */
#pragma scop
for (i = 0; i < M; i++)
for (j = 0; j < M; j++) {
temp2d[i][j] = 0.0;
Expand All @@ -43,9 +82,8 @@ int main()
sum2[i][j] = sum2[i][j] + cos1[i][k] * temp2d[k][j];
block[i][j] = (sum2[i][j]);
}
/* pluto end */
#pragma endscop

/* End of CLooG code */
IF_TIME(t_end = rtclock());
IF_TIME(fprintf(stderr, "%0.6lfs\n", t_end - t_start));

Expand Down
5 changes: 0 additions & 5 deletions examples/dct/decls.h

This file was deleted.

44 changes: 0 additions & 44 deletions examples/dct/util.h

This file was deleted.

6 changes: 0 additions & 6 deletions examples/fdtd-1d/decls.h

This file was deleted.

52 changes: 47 additions & 5 deletions examples/fdtd-1d/fdtd-1d.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include <unistd.h>
#include <sys/time.h>
#include <assert.h>

#include "decls.h"
#include "util.h"
#define N 1000000
#define T 10000
double h[N];
double e[N+1];
#define coeff1 0.5
#define coeff2 0.7

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

void init_array()
{
int i, j;

for (j=0; j<N; j++) {
h[j] = ((double)j)/N;
e[j] = ((double)j)/N;
}
}

void print_array()
{
int i, j;

for (j=0; j<N; j++) {
fprintf(stdout, "%lf ", h[j]);
if (j%80 == 79) fprintf(stdout, "\n");
}
fprintf(stdout, "\n");
}

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);
}

int main()
{
Expand All @@ -17,14 +59,14 @@ int main()

IF_TIME(t_start = rtclock());

/* pluto start (N,T) */
#pragma scop
for (t=1; t<=T; t++){
for (i=1; i<=N-1; i++)
e[i] = e[i] - coeff1*(h[i]-h[i-1]);
for (i=0; i<=N-1; i++)
h[i] = h[i] - coeff2*(e[i+1]-e[i]);
}
/* pluto end */
#pragma endscop

IF_TIME(t_end = rtclock());
IF_TIME(fprintf(stderr, "%0.6lfs\n", t_end - t_start));
Expand Down
Loading

0 comments on commit a830fd2

Please sign in to comment.