remove bug in the calulation of the break condition

This commit is contained in:
Stefan Lankes 2011-04-20 20:41:51 +02:00
parent 7cb05d8f4a
commit a3176aac0b

View file

@ -1,6 +1,6 @@
/*
* Copyright 2011 Stefan Lankes, Alexander Pilz, Maximilian Marx, Michael Ober,
* Chair for Operating Systems, RWTH Aachen University
* Copyright 2010-2011 Stefan Lankes
* Chair for Operating Systems, RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,10 +26,10 @@
#undef errno
extern int errno;
#define MATRIX_SIZE 256
#define MAXVALUE 1337
#define PAGE_SIZE 4096
#define CACHE_SIZE (256*1024)
#define MATRIX_SIZE 128
#define MAXVALUE 1337
#define PAGE_SIZE 4096
#define CACHE_SIZE (256*1024)
#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
static int generate_empty_matrix(double*** A , unsigned int N) {
@ -89,28 +89,26 @@ static int generate_empty_matrix(double*** A , unsigned int N) {
int main(int argc, char **argv)
{
double* temp;
unsigned int i, j, iter_start, iter_end;
unsigned int iterations = 0;
double error, norm, norm_res, max = 0.0;
double** A=0;
double* X;
double* X_old, xi;
double start,stop;
double* temp;
unsigned int i, j, iter_start, iter_end;
unsigned int iterations = 0;
double error, norm, max = 0.0;
double** A=0;
double* X;
double* X_old, xi;
double start,stop;
if (generate_empty_matrix(&A,MATRIX_SIZE) < 0)
{
printf("generate_empty_matrix() failed...\n");
fflush(stdout);
exit(-1);
}
printf("generate_empty_matrix() done...\n");
fflush(stdout);
X=(double*) malloc(MATRIX_SIZE*sizeof(double));
X_old=(double*) malloc(MATRIX_SIZE*sizeof(double));
X = (double*) malloc(MATRIX_SIZE*sizeof(double));
X_old = (double*) malloc(MATRIX_SIZE*sizeof(double));
if(X == NULL || X_old == NULL)
{
printf("X or X_old is NULL...\n");
@ -124,7 +122,6 @@ int main(int argc, char **argv)
}
printf("start calculation...\n");
fflush(stdout);
iter_start = 0;
iter_end = MATRIX_SIZE;
@ -142,7 +139,7 @@ int main(int argc, char **argv)
for (i=iter_start; i<iter_end; i++)
{
for(j=0, xi=0.0; j<i; j++)
xi += A[i][j]* X_old[j];
xi += A[i][j] * X_old[j];
for(j=i+1; j<MATRIX_SIZE; j++)
xi += A[i][j] * X_old[j];
@ -150,14 +147,13 @@ int main(int argc, char **argv)
}
if (iterations % 5000 == 0 ) {/* calculate the Euclidean norm between X_old and X*/
norm_res = norm = 0.0;
norm = 0.0;
for (i=iter_start; i<iter_end; i++)
norm += (X_old[i] - X[i]) * (X_old[i] - X[i]);
/* check the break condition */
norm_res /= (double) MATRIX_SIZE;
if (norm_res < 0.0000001)
norm /= (double) MATRIX_SIZE;
if (norm < 0.0000001)
break;
}
}