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 f3e3eb1 commit 2b27949
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 11 deletions.
16 changes: 11 additions & 5 deletions examples/lu/lu.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ void print_array()

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

double rtclock()
Expand Down Expand Up @@ -86,10 +86,16 @@ int main()
#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")) {
#ifdef MPI
if (my_rank == 0) {
print_array();
}
#else
print_array();
#endif
}
return 0;
}
62 changes: 56 additions & 6 deletions examples/mvt/mvt.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <sys/time.h>

#include <assert.h>
#define N 10000
double a[N][N], y_1[N+17], y_2[N+19], x1[N+23], z0[N+29], x2[N+31];

#include "decls.h"
#ifdef TIME
#define IF_TIME(foo) foo;
#else
#define IF_TIME(foo)
#endif

#include "util.h"
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);
}

void init_array()
{
int i, j;

for (i=0; i<N; i++) {
y_1[i] = i;
y_2[i] = i+1;
x1[i] = 0.0;
x2[i] = 0.0;

for (j=0; j<N; j++)
a[i][j] = i+j+1.0;
}
}

void print_array()
{
int i, j;

for (i=0; i<N; i++) {
fprintf(stderr, "%lf ", x1[i]);
if (j%80 == 20) fprintf(stderr, "\n");
}
fprintf(stderr, "\n");
for (i=0; i<N; i++) {
fprintf(stderr, "%lf ", x2[i]);
if (j%80 == 20) fprintf(stderr, "\n");
}
fprintf(stderr, "\n");
}

int main()
{
Expand All @@ -18,7 +64,6 @@ int main()

IF_TIME(t_start = rtclock());

/* pluto start (N) */
#pragma scop
for (i=0; i<N; i++) {
for (j=0; j<N; j++) {
Expand All @@ -32,13 +77,18 @@ int main()
}
}
#pragma endscop
/* pluto end */

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) {
print_array();
}
#else
print_array();
#endif
}
return 0;
}

0 comments on commit 2b27949

Please sign in to comment.