Skip to content

Commit

Permalink
update examples to print output to stderr and timing info to stdout
Browse files Browse the repository at this point in the history
Signed-off-by: Uday Bondhugula <udayreddy@gmail.com>
  • Loading branch information
bondhugula committed Oct 11, 2013
1 parent 2c9cd00 commit aa943fa
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 150 deletions.
15 changes: 9 additions & 6 deletions examples/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
#
# Gets included after the local Makefile in an example sub-directory
#
BASEDIR=$(dir $(lastword $(MAKEFILE_LIST)))

CC=icc
#CC=gcc

NPROCS=4
NTHREADS=4
PLC=$(BASEDIR)../polycc

# Intel MKL and AMD ACML library paths
MKL=/opt/intel/mkl
ACML=/usr/local/acml

ifeq ($(CC), icc)
OPT_FLAGS=-O3 -fp-model precise
OPT_FLAGS :=-O3 -fp-model precise
PAR_FLAGS := -parallel
OMP_FLAGS := -openmp
else
Expand All @@ -24,8 +27,8 @@ else
OMP_FLAGS := -fopenmp
endif

CFLAGS = -DTIME
LDFLAGS = -lm
CFLAGS += -DTIME
LDFLAGS += -lm
PLCFLAGS +=
TILEFLAGS +=

Expand Down Expand Up @@ -73,10 +76,10 @@ perf: orig tiled par orig_par

test: orig tiled par
touch .test
./orig > out_orig
./tiled > out_tiled
./orig 2> out_orig
./tiled 2> out_tiled
diff -q out_orig out_tiled
export OMP_NUM_THREADS=4; ./par > out_par4
OMP_NUM_THREADS=$(NTHREADS) ./par 2> out_par4
rm -f .test
diff -q out_orig out_par4
@echo Success!
Expand Down
53 changes: 26 additions & 27 deletions examples/corcol/corcol.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

float float_n = (float) N;
float eps = 0.005;

#pragma declarations
float stddev[M + 1];
float data[M + 1][N + 1];
float mean[M + 1];
float symmat[M + 1][M + 1];
#pragma enddeclarations

int n, m;

#ifdef TIME
#define IF_TIME(foo) foo;
Expand All @@ -36,7 +38,7 @@ void init_array()

for (i=0; i<M; i++) {
for (j=0; j<N; j++) {
data[i][j] = ((float) i*j)/N;
data[i][j] = ((float) i*j+1)/N;
}
}
}
Expand All @@ -47,11 +49,11 @@ void print_array()
int i, j;
for (i=0; i<M; i++) {
for (j=0; j<M; j++) {
fprintf(stdout, "%lf ", symmat[i][j]);
if (i%80 == 20) fprintf(stdout, "\n");
fprintf(stderr, "%lf ", symmat[i][j]);
}
fprintf(stderr, "\n");
}
fprintf(stdout, "\n");
fprintf(stderr, "\n");
}

/** Error handler **************************************************/
Expand Down Expand Up @@ -96,39 +98,30 @@ int main(int argc, char** argv)
{
double t_start, t_end;
int i, j, j1, j2;
n = N;
m = M;
// float *mean, *stddev;

if (fopen(".test", "r")) {
n = N/2;
m = M/2;
}

init_array();

IF_TIME(t_start = rtclock());

float float_n = (float) n;

/* Allocate storage for mean and std. dev. vectors */
// mean = vector(m);
// stddev = vector(m);

/* Determine mean of column vectors of input data matrix */
for (j = 1; j <= m; j++)
for (j = 1; j <= M; j++)
{
mean[j] = 0.0;
for (i = 1; i <= n; i++)
for (i = 1; i <= N; i++)
mean[j] += data[i][j];
mean[j] /= float_n;
}

/* Determine standard deviations of column vectors of data matrix. */
for (j = 1; j <= m; j++)
for (j = 1; j <= M; j++)
{
stddev[j] = 0.0;
for (i = 1; i <= n; i++)
for (i = 1; i <= N; i++)
stddev[j] += (data[i][j] - mean[j]) * (data[i][j] - mean[j]);
stddev[j] /= float_n;
stddev[j] = sqrt(stddev[j]);
Expand All @@ -138,35 +131,41 @@ int main(int argc, char** argv)
stddev[j] = stddev[j] <= eps ? 1.0 : stddev[j];
}

#pragma scop
/* Center and reduce the column vectors. */
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
for (i = 1; i <= N; i++)
for (j = 1; j <= M; j++)
{
data[i][j] -= mean[j];
data[i][j] /= sqrt(float_n) * stddev[j];
}

#pragma scop
/* Calculate the m * m correlation matrix. */
for (j1 = 1; j1 <= m-1; j1++)
for (j1 = 1; j1 <= M-1; j1++)
{
symmat[j1][j1] = 1.0;
for (j2 = j1+1; j2 <= m; j2++)
for (j2 = j1+1; j2 <= M; j2++)
{
symmat[j1][j2] = 0.0;
for (i = 1; i <= n; i++)
for (i = 1; i <= N; i++)
symmat[j1][j2] += ( data[i][j1] * data[i][j2]);
symmat[j2][j1] = symmat[j1][j2];
}
}
#pragma endscop
symmat[m][m] = 1.0;
symmat[M][M] = 1.0;

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

if (fopen(".test", "r")) {
print_array();
#ifdef MPI
if (my_rank == 0) {
print_array();
}
#else
print_array();
#endif
}


Expand Down
55 changes: 31 additions & 24 deletions examples/covcol/covcol.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
#define N 1500
#define M 1500

float float_n = (float) N;
float eps = 0.005;
float stddev[M + 1];
float data[M + 1][N + 1];
float mean[M + 1];
float symmat[M + 1][M + 1];

int n, m;
double float_n = (float) N;
double eps = 0.005;
double stddev[M + 1];
double data[M + 1][N + 1];
double mean[M + 1];
double symmat[M + 1][M + 1];

#ifdef TIME
#define IF_TIME(foo) foo;
Expand Down Expand Up @@ -45,11 +43,11 @@ void print_array()
int m = M;
for (i=1; i<=m; i++) {
for (j=1; j<=m; j++) {
fprintf(stdout, "%0.2lf ", symmat[i][j]);
if (i%80 == 20) fprintf(stdout, "\n");
fprintf(stderr, "%0.2lf ", symmat[i][j]);
}
fprintf(stderr, "\n");
}
fprintf(stdout, "\n");
fprintf(stderr, "\n");
}

double rtclock()
Expand All @@ -72,32 +70,35 @@ int main(int argc, char** argv)
{
double t_start, t_end;
int i, j, j1, j2;
n = N;
m = M;

init_array();

IF_TIME(t_start = rtclock());

#pragma scop
/* Determine mean of column vectors of input data matrix */
for (j = 1; j <= m; j++) {
for (j = 1; j <= M; j++) {
mean[j] = 0.0;
for (i = 1; i <= n; i++)
for (i = 1; i <= N; i++)
mean[j] += data[i][j];
mean[j] /= float_n;
}

/* Center the column vectors. */
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
for (i = 1; i <= N; i++)
for (j = 1; j <= M; j++)
data[i][j] -= mean[j];

/* Calculate the m * m covariance matrix. */
for (j1 = 1; j1 <= m; j1++) {
for (j2 = j1; j2 <= m; j2++) {
for (j1 = 1; j1 <= M; j1++) {
for (j2 = j1; j2 <= M; j2++) {
symmat[j1][j2] = 0.0;
for (i = 1; i <= n; i++) {
}
}

#pragma scop
/* Calculate the m * m covariance matrix. */
for (j1 = 1; j1 <= M; j1++) {
for (j2 = j1; j2 <= M; j2++) {
for (i = 1; i <= N; i++) {
symmat[j1][j2] += data[i][j1] * data[i][j2];
}
symmat[j2][j1] = symmat[j1][j2];
Expand All @@ -106,10 +107,16 @@ int main(int argc, char** argv)
#pragma endscop

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

if (fopen(".test", "r")) {
print_array();
#ifdef MPI
if (my_rank == 0) {
print_array();
}
#else
print_array();
#endif
}

return 0;
Expand Down
29 changes: 17 additions & 12 deletions examples/dsyr2k/dsyr2k.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,22 @@ double t_start, t_end;

int main()
{
long N=NMAX;
int i,j, k;

for (i = 0; i < NMAX; i++) {
for (j = 0; j < NMAX; j++) {
c[i][j] = 0.0;
a[i][j] = 1.0+i*j*32.5/(N*N);
b[i][j] = 1.0+i*j*3.4565/(N*N);
a[i][j] = 1.0+i*j*32.5/(NMAX*NMAX);
b[i][j] = 1.0+i*j*3.4565/(NMAX*NMAX);
}
}

IF_TIME(t_start = rtclock());

#pragma scop
for (i=0; i<N; i++) {
for (j=0; j<N; j++) {
for (k=j; k<N; k++) {
for (i=0; i<NMAX; i++) {
for (j=0; j<NMAX; j++) {
for (k=j; k<NMAX; k++) {
c[j][k] += a[i][j] * b[i][k] + b[i][j] * a[i][k];
}
}
Expand All @@ -57,15 +56,21 @@ int main()


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

if (fopen(".test", "r")) {
for (i = 0; i < NMAX; i++) {
for (j = 0; j < NMAX; j++) {
fprintf(stdout, "%lf ", c[i][j]);
#ifdef MPI
if (my_rank == 0) {
#endif
for (i = 0; i < NMAX; i++) {
for (j = 0; j < NMAX; j++) {
fprintf(stderr, "%lf ", c[i][j]);
}
}
fprintf(stderr, "\n");
#ifdef MPI
}
}
fprintf(stdout, "\n");
#endif
}

return 0;
Expand Down
17 changes: 11 additions & 6 deletions examples/dsyrk/dsyrk.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ int main()
{
double t_start, t_end;

long N=NMAX;
int i,j, k;

for (i = 0; i < NMAX; i++) {
Expand All @@ -46,9 +45,9 @@ int main()
IF_TIME(t_start = rtclock());

#pragma scop
for (i=0; i<N; i++) {
for (j=0; j<N; j++) {
for (k=j; k<N; k++) {
for (i=0; i<NMAX; i++) {
for (j=0; j<NMAX; j++) {
for (k=j; k<NMAX; k++) {
c[j][k] += a[i][j] * a[i][k];
}
}
Expand All @@ -57,15 +56,21 @@ int main()


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

if (fopen(".test", "r")) {
#ifdef MPI
if (my_rank == 0) {
#endif
for (i = 0; i < NMAX; i++) {
for (j = 0; j < NMAX; j++) {
printf("%lf ", c[i][j]);
fprintf(stderr, "%lf ", c[i][j]);
}
}
}
#ifdef MPI
}
#endif

return 0;

Expand Down
Loading

0 comments on commit aa943fa

Please sign in to comment.