Skip to content
Snippets Groups Projects
Commit 0bfe900f authored by Daniel Maier's avatar Daniel Maier
Browse files

added test code

parent 7d9683c3
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <math.h>
#include <sys/time.h>
#define N 1024
#define M 1024
float A[N][M];
int main() {
int i, j;
struct timeval stop, start;
/* initialize */
for(i = 0; i < N; i++) {
for(j = 0; j < M; j++) {
A[i][j] = 0;
}
}
gettimeofday(&start, NULL);
#pragma scop
for(i = 0; i < N; i++) {
for(j = 0; j < M; j++) {
A[i][j] += 10;
}
}
for(j = 0; j < M; j++) {
for(i = 0; i < N; i += 2) {
A[j][i] *= 10;
}
}
#pragma endscop
gettimeofday(&stop, NULL);
/* calculate error */
double err = 0;
for(i = 0; i < N; i++) {
for(j = 0; j < M; j++) {
double e;
if(j % 2 == 0)
e = fabs(100 - A[i][j])/100;
else
e = fabs(10 - A[i][j])/10;
if(e != e || e > 1)
e = 1;
err += e;
}
}
err /= N*M;
printf("%f\n", (stop.tv_usec - start.tv_usec)/1000.);
printf("error: %f\n", err);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment