# Contents of /trunk/paso/src/PCG.c

Revision 631 - (show annotations)
Thu Mar 23 04:27:32 2006 UTC (13 years, 3 months ago) by dhawcroft
Original Path: trunk/paso/src/Solvers/PCG.c
File MIME type: text/plain
File size: 7904 byte(s)
```Prepended all paso source files with new Copyright notice
```
 1 /* \$Id\$ */ 2 3 4 /* 5 ******************************************************************************** 6 * Copyright © 2006 by ACcESS MNRF * 7 * * 8 * http://www.access.edu.au * 9 * Primary Business: Queensland, Australia * 10 * Licensed under the Open Software License version 3.0 * 11 * http://www.opensource.org/licenses/osl-3.0.php * 12 ******************************************************************************** 13 */ 14 15 /* PCG iterations */ 16 17 #include "SystemMatrix.h" 18 #include "Paso.h" 19 #include "Solver.h" 20 /* #include */ 21 #ifdef _OPENMP 22 #include 23 #endif 24 25 /* 26 * 27 * Purpose 28 * ======= 29 * 30 * PCG solves the linear system A*x = b using the 31 * preconditioned conjugate gradient method plus a smoother 32 * A has to be symmetric. 33 * 34 * Convergence test: norm( b - A*x )< TOL. 35 * For other measures, see the above reference. 36 * 37 * Arguments 38 * ========= 39 * 40 * r (input) DOUBLE PRECISION array, dimension N. 41 * On entry, residual of inital guess x 42 * 43 * x (input/output) DOUBLE PRECISION array, dimension N. 44 * On input, the initial guess. 45 * 46 * ITER (input/output) INT 47 * On input, the maximum iterations to be performed. 48 * On output, actual number of iterations performed. 49 * 50 * INFO (output) INT 51 * 52 * = SOLVER_NO_ERROR: Successful exit. Iterated approximate solution returned. 53 * = SOLVEr_MAXITER_REACHED 54 * = SOLVER_INPUT_ERROR Illegal parameter: 55 * = SOLVEr_BREAKDOWN: If parameters rHO or OMEGA become smaller 56 * = SOLVER_MEMORY_ERROR : If parameters rHO or OMEGA become smaller 57 * 58 * ============================================================== 59 */ 60 61 err_t Paso_Solver_PCG( 62 Paso_SystemMatrix * A, 63 double * r, 64 double * x, 65 dim_t *iter, 66 double * tolerance, 67 Paso_Performance* pp) { 68 69 70 /* Local variables */ 71 dim_t num_iter=0,maxit,num_iter_global; 72 dim_t i0; 73 bool_t breakFlag=FALSE, maxIterFlag=FALSE, convergeFlag=FALSE; 74 err_t status = SOLVER_NO_ERROR; 75 dim_t n = A->num_cols * A-> col_block_size; 76 double *resid = tolerance, *rs=NULL, *p=NULL, *v=NULL, *x2=NULL ; 77 double tau_old,tau,beta,delta,gamma_1,gamma_2,alpha,sum_1,sum_2,sum_3,sum_4,sum_5,tol; 78 double norm_of_residual,norm_of_residual_global; 79 register double r_tmp,d,rs_tmp,x2_tmp,x_tmp; 80 81 /* */ 82 /*-----------------------------------------------------------------*/ 83 /* */ 84 /* Start of Calculation : */ 85 /* --------------------- */ 86 /* */ 87 /* */ 88 rs=TMPMEMALLOC(n,double); 89 p=TMPMEMALLOC(n,double); 90 v=TMPMEMALLOC(n,double); 91 x2=TMPMEMALLOC(n,double); 92 93 /* Test the input parameters. */ 94 95 if (n < 0) { 96 status = SOLVER_INPUT_ERROR; 97 } else if (rs==NULL || p==NULL || v==NULL || x2==NULL) { 98 status = SOLVER_MEMORY_ERROR; 99 } else { 100 maxit = *iter; 101 tol = *resid; 102 #pragma omp parallel firstprivate(maxit,tol,convergeFlag,maxIterFlag,breakFlag) \ 103 private(tau_old,tau,beta,delta,gamma_1,gamma_2,alpha,norm_of_residual,num_iter) 104 { 105 Performance_startMonitor(pp,PERFORMANCE_SOLVER); 106 /* initialize data */ 107 #pragma omp for private(i0) schedule(static) 108 for (i0=0;i0

## Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision