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

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

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

revision 1708 by ksteube, Thu Aug 14 22:42:24 2008 UTC revision 2562 by artak, Tue Jul 28 01:25:12 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    
15  /* TFQMR iterations */  /* TFQMR iterations */
16    
# Line 40  Line 41 
41  *  =========  *  =========
42  *  *
43  *  r       (input) DOUBLE PRECISION array, dimension N.  *  r       (input) DOUBLE PRECISION array, dimension N.
44  *          On entry, residual of inital guess x  *        
45  *  *
46  *  x       (input/output) DOUBLE PRECISION array, dimension N.  *  x       (input/output) DOUBLE PRECISION array, dimension N.
47  *          On input, the initial guess.  *        
48  *  *
49  *  ITER    (input/output) INT  *  ITER    (input/output) INT
50  *          On input, the maximum iterations to be performed.  *          On input, the maximum iterations to be performed.
# Line 83  err_t Paso_Solver_TFQMR( Line 84  err_t Paso_Solver_TFQMR(
84    bool_t breakFlag=FALSE, maxIterFlag=FALSE, convergeFlag=FALSE;    bool_t breakFlag=FALSE, maxIterFlag=FALSE, convergeFlag=FALSE;
85    err_t status = SOLVER_NO_ERROR;    err_t status = SOLVER_NO_ERROR;
86    dim_t n = Paso_SystemMatrix_getTotalNumRows(A);    dim_t n = Paso_SystemMatrix_getTotalNumRows(A);
87    double  *u1=NULL, *u2=NULL, *y1=NULL, *y2=NULL, *d=NULL, *w=NULL, *v=NULL, *v_old=NULL, *tmp=NULL ;    double  *u1=NULL, *u2=NULL, *y1=NULL, *y2=NULL, *d=NULL, *w=NULL, *v=NULL, *v_old=NULL, *temp_vector=NULL,*res=NULL;
88    
89    double eta,theta,tau,rho,beta,alpha,sigma,rhon,c;    double eta,theta,tau,rho,beta,alpha,sigma,rhon,c;
90    
# Line 104  err_t Paso_Solver_TFQMR( Line 105  err_t Paso_Solver_TFQMR(
105    w=TMPMEMALLOC(n,double);    w=TMPMEMALLOC(n,double);
106    v=TMPMEMALLOC(n,double);    v=TMPMEMALLOC(n,double);
107    v_old=TMPMEMALLOC(n,double);    v_old=TMPMEMALLOC(n,double);
108        temp_vector=TMPMEMALLOC(n,double);
109        res=TMPMEMALLOC(n,double);
   tmp=TMPMEMALLOC(n,double);  
     
110    
111   if (u1 ==NULL || u2== NULL || y1 == NULL || y2== NULL || d==NULL || w==NULL || v==NULL || v_old==NULL) {   if (u1 ==NULL || u2== NULL || y1 == NULL || y2== NULL || d==NULL || w==NULL || v==NULL || v_old==NULL) {
112       status=SOLVER_MEMORY_ERROR;       status=SOLVER_MEMORY_ERROR;
# Line 121  err_t Paso_Solver_TFQMR( Line 120  err_t Paso_Solver_TFQMR(
120    }    }
121        
122    Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);    Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);
123    Paso_Solver_solvePreconditioner(A,r,r);    Paso_Solver_solvePreconditioner(A,res,r);
124    Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);    Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);
125        
126    Performance_startMonitor(pp,PERFORMANCE_SOLVER);    Performance_startMonitor(pp,PERFORMANCE_SOLVER);
# Line 129  err_t Paso_Solver_TFQMR( Line 128  err_t Paso_Solver_TFQMR(
128    Paso_zeroes(n,u2);    Paso_zeroes(n,u2);
129    Paso_zeroes(n,y2);    Paso_zeroes(n,y2);
130        
131    Paso_Copy(n,w,r);    Paso_Copy(n,w,res);
132    Paso_Copy(n,y1,r);    Paso_Copy(n,y1,res);
133                
134    Paso_zeroes(n,d);    Paso_zeroes(n,d);
135        
136    Performance_stopMonitor(pp,PERFORMANCE_SOLVER);    Performance_stopMonitor(pp,PERFORMANCE_SOLVER);
137    Performance_startMonitor(pp,PERFORMANCE_MVM);    Performance_startMonitor(pp,PERFORMANCE_MVM);
138    Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(ONE, A, y1,ZERO,v);    Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(PASO_ONE, A, y1,PASO_ZERO,temp_vector);
139    Performance_stopMonitor(pp,PERFORMANCE_MVM);    Performance_stopMonitor(pp,PERFORMANCE_MVM);
140    Performance_startMonitor(pp,PERFORMANCE_SOLVER);    Performance_startMonitor(pp,PERFORMANCE_SOLVER);
141        
142    Performance_stopMonitor(pp,PERFORMANCE_SOLVER);    Performance_stopMonitor(pp,PERFORMANCE_SOLVER);
143    Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);    Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);
144    Paso_Solver_solvePreconditioner(A,v,v);    Paso_Solver_solvePreconditioner(A,v,temp_vector);
145    Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);    Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);
146    Performance_startMonitor(pp,PERFORMANCE_SOLVER);    Performance_startMonitor(pp,PERFORMANCE_SOLVER);
147        
# Line 151  err_t Paso_Solver_TFQMR( Line 150  err_t Paso_Solver_TFQMR(
150    theta = 0.0;    theta = 0.0;
151    eta = 0.0;    eta = 0.0;
152        
153    tau = Paso_l2(n,r,A->mpi_info);    tau = Paso_l2(n,res,A->mpi_info);
154        
155    rho = tau * tau;    rho = tau * tau;
156                
# Line 161  err_t Paso_Solver_TFQMR( Line 160  err_t Paso_Solver_TFQMR(
160    {    {
161                        
162    
163       sigma=Paso_InnerProduct(n,r,v,A->mpi_info);       sigma=Paso_InnerProduct(n,res,v,A->mpi_info);
164            
165       if (! (breakFlag = (ABS(sigma) == 0.))) {       if (! (breakFlag = (ABS(sigma) == 0.))) {
166            
# Line 175  err_t Paso_Solver_TFQMR( Line 174  err_t Paso_Solver_TFQMR(
174                        
175            Performance_stopMonitor(pp,PERFORMANCE_SOLVER);            Performance_stopMonitor(pp,PERFORMANCE_SOLVER);
176            Performance_startMonitor(pp,PERFORMANCE_MVM);            Performance_startMonitor(pp,PERFORMANCE_MVM);
177            Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(ONE, A, y2,ZERO,u2);            Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(PASO_ONE, A, y2,PASO_ZERO,temp_vector);
178            Performance_stopMonitor(pp,PERFORMANCE_MVM);            Performance_stopMonitor(pp,PERFORMANCE_MVM);
179            Performance_startMonitor(pp,PERFORMANCE_SOLVER);            Performance_startMonitor(pp,PERFORMANCE_SOLVER);
180                        
181            Performance_stopMonitor(pp,PERFORMANCE_SOLVER);            Performance_stopMonitor(pp,PERFORMANCE_SOLVER);
182            Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);            Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);
183            Paso_Solver_solvePreconditioner(A,u2,u2);            Paso_Solver_solvePreconditioner(A,u2,temp_vector);
184            Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);            Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);
185            Performance_startMonitor(pp,PERFORMANCE_SOLVER);            Performance_startMonitor(pp,PERFORMANCE_SOLVER);
186           }           }
# Line 204  err_t Paso_Solver_TFQMR( Line 203  err_t Paso_Solver_TFQMR(
203    
204       breakFlag = (ABS(rho) == 0);       breakFlag = (ABS(rho) == 0);
205    
206       rhon = Paso_InnerProduct(n,r,w,A->mpi_info);       rhon = Paso_InnerProduct(n,res,w,A->mpi_info);
207       beta = rhon / rho;       beta = rhon / rho;
208       rho = rhon;       rho = rhon;
209        
210       Paso_LinearCombination(n,y1,1.,w,beta,y2);       Paso_LinearCombination(n,y1,1.,w,beta,y2);
211    
212       Performance_stopMonitor(pp,PERFORMANCE_SOLVER);       Performance_stopMonitor(pp,PERFORMANCE_SOLVER);
213        
214       Performance_startMonitor(pp,PERFORMANCE_MVM);       Performance_startMonitor(pp,PERFORMANCE_MVM);
215       Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(ONE, A, y1,ZERO,u1);       Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(PASO_ONE, A, y1,PASO_ZERO,temp_vector);
216       Performance_stopMonitor(pp,PERFORMANCE_MVM);       Performance_stopMonitor(pp,PERFORMANCE_MVM);
      Performance_startMonitor(pp,PERFORMANCE_SOLVER);  
217            
      Performance_stopMonitor(pp,PERFORMANCE_SOLVER);  
218       Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);       Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);
219       Paso_Solver_solvePreconditioner(A,u1,u1);       Paso_Solver_solvePreconditioner(A,u1,temp_vector);
220       Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);       Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);
221        
222       Performance_startMonitor(pp,PERFORMANCE_SOLVER);       Performance_startMonitor(pp,PERFORMANCE_SOLVER);
223            
224       Paso_Copy(n,v_old,v);       Paso_Copy(n,v_old,v);
# Line 250  err_t Paso_Solver_TFQMR( Line 249  err_t Paso_Solver_TFQMR(
249      TMPMEMFREE(w);      TMPMEMFREE(w);
250      TMPMEMFREE(v);      TMPMEMFREE(v);
251      TMPMEMFREE(v_old);      TMPMEMFREE(v_old);
252          TMPMEMFREE(temp_vector);
253        TMPMEMFREE(res);
254      *iter=num_iter;      *iter=num_iter;
255      *tolerance=norm_of_residual;      *tolerance=norm_of_residual;
256            

Legend:
Removed from v.1708  
changed lines
  Added in v.2562

  ViewVC Help
Powered by ViewVC 1.1.26