scscres.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 scscres (int isym, int m, int n, 
00035         double *val, int *indx, int *pntr,
00036         double *x, double *b)
00037 {
00038     int i, j, ibgn, iend, ione = 1;
00039     double 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];
00061 
00062 /* .....do a series of SPAXPYs (sparse saxpys) */
00063 
00064     for (j = 0; j < n ; j++) 
00065       {
00066   ibgn = pntr[j];
00067   iend = pntr[j + 1];
00068   
00069   for (i = ibgn; i < iend; i++)
00070     {
00071       tmp[indx[i]] -= val[i] * x[j];
00072       if (indx[i] != j && isym) tmp[j] -= val[i]*x[indx[i]];
00073     }
00074      }
00075     for (i = 0; i < m; i++)
00076       {
00077   max_norm = max(fabs(tmp[i]),max_norm);
00078   norm_tmp += tmp[i]*tmp[i];
00079   norm_b += b[i]*b[i];
00080       }
00081    
00082     res_norm = sqrt(norm_tmp);
00083     printf("\n\nMax norm of residual        = %12.4g\n",max_norm);
00084     printf(    "Two norm of residual        = %12.4g\n",res_norm);
00085     if (norm_b > 1.0E-7) 
00086       {
00087      scaled_res_norm = res_norm/sqrt(norm_b);
00088      printf(    "Scaled two norm of residual = %12.4g\n",scaled_res_norm);
00089       }
00090 
00091     free((void *) tmp);
00092 
00093     return(scaled_res_norm);
00094 
00095 } /* scscres */
00096 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:05:35 2011 for Ifpack Package Browser (Single Doxygen Collection) by  doxygen 1.6.3