Ifpack Package Browser (Single Doxygen Collection) Development
smsrres.c
Go to the documentation of this file.
00001 /*@HEADER
00002 // ***********************************************************************
00003 // 
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2002) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 //@HEADER
00028 */
00029 
00030 #include <stdlib.h>
00031 #include <stdio.h>
00032 #include <math.h>
00033 #define max(x,y) (( x > y ) ? x : y)     /* max function  */
00034 double smsrres (int m, int n, 
00035         double *val, int *indx, 
00036         double *xlocal, double *x, double *b)
00037 {
00038     int i, j, jbgn, jend, ione = 1;
00039     double sum, norm_tmp = 0.0, norm_b = 0.0;
00040     double scaled_res_norm, res_norm, *tmp, max_norm = 0.0;
00041 
00042 
00043 /*     Computes the residual
00044 
00045                       res = || b - A*x ||
00046 
00047        where x and b are vectors and A is a sparse matrix stored
00048        in MSR format. */
00049 
00050 /*     -------------------------- 
00051        First executable statement 
00052        -------------------------- */
00053 
00054     /* Create tmp workspace */
00055     tmp = (double *) calloc(m,sizeof(double));
00056 
00057 /* .....initialize soln */
00058 
00059     for (i = 0; i < m; i++)
00060   tmp[i] = b[i] - val[i] * xlocal[i];
00061 
00062 /* .....do a series of SPDOTs (sparse dot products) */
00063 
00064     for (i = 0; i <m ; i++) 
00065       {
00066   jbgn = indx[i];
00067   jend = indx[i + 1];
00068   sum = 0.0;
00069   
00070   for (j = jbgn; j < jend; j++)
00071     sum += val[j] * x[indx[j]];
00072 
00073   tmp[i] -= sum;
00074   max_norm = max(fabs(tmp[i]),max_norm);
00075   norm_tmp += tmp[i]*tmp[i];
00076   norm_b += b[i]*b[i];
00077       }
00078    
00079     res_norm = sqrt(norm_tmp);
00080     printf("\n\nMax norm of residual        = %12.4g\n",max_norm);
00081     printf(    "Two norm of residual        = %12.4g\n",res_norm);
00082     if (norm_b > 1.0E-7) 
00083       {
00084      scaled_res_norm = res_norm/sqrt(norm_b);
00085      printf(    "Scaled two norm of residual = %12.4g\n",scaled_res_norm);
00086       }
00087     free((void *) tmp);
00088 
00089     return(scaled_res_norm);
00090 
00091 } /* smsrres */
00092 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines