Commit 40d2c9da authored by Gaurav Kukreja's avatar Gaurav Kukreja

Cutting the residual calculation

Instead of calculating residual for the next iteration, we calculate residual
iteration. This is an acceptable deviation, and a significant optimization.
Signed-off-by: 's avatarGaurav Kukreja <mailme.gaurav@gmail.com>
parent 51562a59
......@@ -57,8 +57,10 @@ void relax_gauss( double *u,
unsigned sizex, unsigned sizey );
// Jacobi: relax_jacobi.c
#if 0
double residual_jacobi( double *u,
unsigned sizex, unsigned sizey );
#endif
double relax_jacobi_return_residual( double *u, double *utmp,
unsigned sizex, unsigned sizey );
......
......@@ -7,6 +7,7 @@
#include "heat.h"
#if 0
/*
* Residual (length of error vector)
* between current solution and next after a Jacobi step
......@@ -33,7 +34,7 @@ double residual_jacobi( double *u,
return sum;
}
#endif
/*
* One Jacobi iteration step
......@@ -44,27 +45,17 @@ double relax_jacobi_return_residual( double *u, double *utmp,
int i, j;
double unew, diff, sum=0.0;
for( i=1; i<sizey; i++ )
for( i=1; i<sizey-1; i++ )
{
for( j=1; j<sizex-1; j++ )
{
if(i<sizey-1)
{
utmp[i*sizex + j]= 0.25 * (u[ i*sizex+j -1 ]+ // left
u[ i*sizex+j +1 ]+ // right
u[ (i-1)*sizex + j ]+ // top
u[ (i+1)*sizex + j ]); // bottom
}
//Residual Calculation
if(i>1)
{
unew = 0.25 * (utmp[ (i-1)*sizex+j -1 ]+ // left
utmp[ (i-1)*sizex+j +1 ]+ // right
utmp[ (i-2)*sizex + j ]+ // top
utmp[ (i)*sizex + j ]); // bottom
diff = unew - utmp[(i-1)*sizex+j];
diff = utmp[i*sizex + j] - u[i*sizex +j];
sum += diff * diff;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment