/[escript]/trunk/paso/src/MINRES.c
ViewVC logotype

Diff of /trunk/paso/src/MINRES.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1787 by artak, Mon Sep 15 01:36:34 2008 UTC revision 2826 by artak, Fri Dec 18 01:33:35 2009 UTC
# Line 1  Line 1 
1    
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2009 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14  /* TFQMR iterations */  
15    /* MINRES iterations */
16    
17  #include "SystemMatrix.h"  #include "SystemMatrix.h"
18  #include "Paso.h"  #include "Paso.h"
# Line 71  err_t Paso_Solver_MINRES( Line 72  err_t Paso_Solver_MINRES(
72      double * r,      double * r,
73      double * x,      double * x,
74      dim_t *iter,      dim_t *iter,
     double *tol,  
75      double * tolerance,      double * tolerance,
76      Paso_Performance* pp) {      Paso_Performance* pp) {
77    
# Line 83  err_t Paso_Solver_MINRES( Line 83  err_t Paso_Solver_MINRES(
83    dim_t n = Paso_SystemMatrix_getTotalNumRows(A);    dim_t n = Paso_SystemMatrix_getTotalNumRows(A);
84    double  *w=NULL, *w1=NULL, *w2=NULL, *r1=NULL, *r2=NULL, *y=NULL, *v=NULL;    double  *w=NULL, *w1=NULL, *w2=NULL, *r1=NULL, *r2=NULL, *y=NULL, *v=NULL;
85    
86    double Anorm,ynorm,oldb,dbar,epsln,phibar,rhs1,rhs2,rnorm,tnorm2,ynorm2,cs,sn,eps,s,alfa,denom,z,beta1,beta;    double Anorm,Arnorm,ynorm,oldb,dbar,epsln,phibar,rhs1,rhs2,rnorm,tnorm2,ynorm2,cs,sn,eps,s,alfa,denom,z,beta1,beta;
87    double gmax,gmin,oldeps,delta,gbar,gamma,phi;    double gmax,gmin,oldeps,delta,gbar,gamma,phi,root,epsx;
88    
89    double norm_of_residual;    double norm_of_residual=0;
90        
91  /*                                                                 */  /*                                                                 */
92  /*-----------------------------------------------------------------*/  /*-----------------------------------------------------------------*/
# Line 135  err_t Paso_Solver_MINRES( Line 135  err_t Paso_Solver_MINRES(
135    Paso_zeroes(n,w);    Paso_zeroes(n,w);
136    Paso_zeroes(n,w2);    Paso_zeroes(n,w2);
137        
138        Paso_zeroes(n,x);
139      
140    Paso_Copy(n,r2,r1);    Paso_Copy(n,r2,r1);
141        
142    Anorm = 0;    Anorm = 0;
# Line 151  err_t Paso_Solver_MINRES( Line 153  err_t Paso_Solver_MINRES(
153    ynorm2 = 0;    ynorm2 = 0;
154    cs     = -1;    cs     = -1;
155    sn     = 0;    sn     = 0;
156    eps    = 0.0001;    eps    = 0.000001;
157    
158    while (!(convergeFlag || maxIterFlag || breakFlag || (status !=SOLVER_NO_ERROR) ))    while (!(convergeFlag || (status !=SOLVER_NO_ERROR) ))
159    {    {
160                        
161       s=1/beta;       s=1/beta;
# Line 161  err_t Paso_Solver_MINRES( Line 163  err_t Paso_Solver_MINRES(
163            
164       Performance_stopMonitor(pp,PERFORMANCE_SOLVER);       Performance_stopMonitor(pp,PERFORMANCE_SOLVER);
165       Performance_startMonitor(pp,PERFORMANCE_MVM);       Performance_startMonitor(pp,PERFORMANCE_MVM);
166       Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(ONE, A, v,ZERO,y);       Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(PASO_ONE, A, v,PASO_ZERO,y);
167       Performance_stopMonitor(pp,PERFORMANCE_MVM);       Performance_stopMonitor(pp,PERFORMANCE_MVM);
168       Performance_startMonitor(pp,PERFORMANCE_SOLVER);       Performance_startMonitor(pp,PERFORMANCE_SOLVER);
169            
# Line 170  err_t Paso_Solver_MINRES( Line 172  err_t Paso_Solver_MINRES(
172       }       }
173    
174       alfa = Paso_InnerProduct(n,v,y,A->mpi_info);       alfa = Paso_InnerProduct(n,v,y,A->mpi_info);
175       Paso_Update(n, 1., y, -(alfa/beta), r2);       Paso_Update(n, 1., y, (-alfa/beta), r2);
176       Paso_Copy(n,r1,r2);       Paso_Copy(n,r1,r2);
177       Paso_Copy(n,r2,y);       Paso_Copy(n,r2,y);
178    
# Line 204  err_t Paso_Solver_MINRES( Line 206  err_t Paso_Solver_MINRES(
206       epsln  =               sn * beta ;       epsln  =               sn * beta ;
207       dbar   =            -  cs * beta;       dbar   =            -  cs * beta;
208            
209         root   = sqrt(gbar*gbar+dbar*dbar) ;
210         Arnorm = phibar*root;
211        
212       gamma  = sqrt(gbar*gbar+beta*beta) ;       gamma  = sqrt(gbar*gbar+beta*beta) ;
213       gamma  = MAX(gamma,eps) ;       gamma  = MAX(gamma,eps) ;
214       cs     = gbar / gamma ;                   cs     = gbar / gamma ;            
# Line 234  err_t Paso_Solver_MINRES( Line 239  err_t Paso_Solver_MINRES(
239       ynorm  = sqrt( ynorm2 ) ;       ynorm  = sqrt( ynorm2 ) ;
240    
241       rnorm  = phibar;       rnorm  = phibar;
242         epsx   = Anorm*ynorm*eps;
243       maxIterFlag = (num_iter > maxit);      
244       norm_of_residual=rnorm;      
245       convergeFlag=(norm_of_residual<Anorm*ynorm*(*tolerance));       if (status==SOLVER_NO_ERROR) {  
246                maxIterFlag = (num_iter > maxit);
247                norm_of_residual=rnorm;
248       if (maxIterFlag) {          convergeFlag=((norm_of_residual/(Anorm*ynorm))<(*tolerance) || 1+(norm_of_residual/(Anorm*ynorm)) <=1);
249           status = SOLVER_MAXITER_REACHED;          if (maxIterFlag) {
250       } else if (breakFlag) {              status = SOLVER_MAXITER_REACHED;
251           status = SOLVER_BREAKDOWN;          } else if (breakFlag) {
252                status = SOLVER_BREAKDOWN;
253            }
254       }       }
255      ++(num_iter);      ++(num_iter);
     /*printf("residual norm %.10f < %.10f %.10f %.10f \n",rnorm,Anorm*ynorm*(*tolerance), Anorm*ynorm, (*tolerance));*/  
256    }    }
257      /* end of iteration */      /* end of iteration */
258            
# Line 260  err_t Paso_Solver_MINRES( Line 266  err_t Paso_Solver_MINRES(
266      TMPMEMFREE(v);      TMPMEMFREE(v);
267        
268      *iter=num_iter;      *iter=num_iter;
269      *tol=norm_of_residual;      *tolerance=norm_of_residual;
270            
271    /*     End of MINRES */    /*     End of MINRES */
272    return status;    return status;

Legend:
Removed from v.1787  
changed lines
  Added in v.2826

  ViewVC Help
Powered by ViewVC 1.1.26