Contents of /branches/windows_from_1456_trunk_1580_merged_in/paso/src/PCG.c

Revision 1582 - (show annotations)
Wed Jun 4 07:20:59 2008 UTC (13 years, 11 months ago) by phornby
File MIME type: text/plain
File size: 13212 byte(s)
```Merge in trunk changes from 1574 to 1580.

```
 1 2 /* \$Id\$ */ 3 4 /******************************************************* 5 * 6 * Copyright 2003-2007 by ACceSS MNRF 7 * Copyright 2007 by University of Queensland 8 * 9 * http://esscc.uq.edu.au 10 * Primary Business: Queensland, Australia 11 * Licensed under the Open Software License version 3.0 12 * http://www.opensource.org/licenses/osl-3.0.php 13 * 14 *******************************************************/ 15 16 /* PCG iterations */ 17 18 #include "SystemMatrix.h" 19 #include "Paso.h" 20 #include "Solver.h" 21 22 #ifdef _OPENMP 23 #include 24 #endif 25 26 #ifdef PASO_MPI 27 #include 28 #endif 29 30 /* 31 * 32 * Purpose 33 * ======= 34 * 35 * PCG solves the linear system A*x = b using the 36 * preconditioned conjugate gradient method plus a smoother 37 * A has to be symmetric. 38 * 39 * Convergence test: norm( b - A*x )< TOL. 40 * For other measures, see the above reference. 41 * 42 * Arguments 43 * ========= 44 * 45 * r (input) DOUBLE PRECISION array, dimension N. 46 * On entry, residual of inital guess x 47 * 48 * x (input/output) DOUBLE PRECISION array, dimension N. 49 * On input, the initial guess. 50 * 51 * ITER (input/output) INT 52 * On input, the maximum iterations to be performed. 53 * On output, actual number of iterations performed. 54 * 55 * INFO (output) INT 56 * 57 * = SOLVER_NO_ERROR: Successful exit. Iterated approximate solution returned. 58 * = SOLVEr_MAXITER_REACHED 59 * = SOLVER_INPUT_ERROR Illegal parameter: 60 * = SOLVEr_BREAKDOWN: If parameters rHO or OMEGA become smaller 61 * = SOLVER_MEMORY_ERROR : If parameters rHO or OMEGA become smaller 62 * 63 * ============================================================== 64 */ 65 66 /* #define PASO_DYNAMIC_SCHEDULING_MVM */ 67 68 #if defined PASO_DYNAMIC_SCHEDULING_MVM && defined __OPENMP 69 #define USE_DYNAMIC_SCHEDULING 70 #endif 71 72 err_t Paso_Solver_PCG( 73 Paso_SystemMatrix * A, 74 double * r, 75 double * x, 76 dim_t *iter, 77 double * tolerance, 78 Paso_Performance* pp) { 79 80 /* Local variables */ 81 dim_t num_iter=0,maxit,num_iter_global, chunk_size=-1, len,rest, n_chunks, np, ipp; 82 register double ss,ss1; 83 dim_t i0, istart, iend; 84 bool_t breakFlag=FALSE, maxIterFlag=FALSE, convergeFlag=FALSE; 85 err_t status = SOLVER_NO_ERROR; 86 dim_t n = Paso_SystemMatrix_getTotalNumRows(A); 87 double *resid = tolerance, *rs=NULL, *p=NULL, *v=NULL, *x2=NULL ; 88 double tau_old,tau,beta,delta,gamma_1,gamma_2,alpha,sum_1,sum_2,sum_3,sum_4,sum_5,tol; 89 #ifdef PASO_MPI 90 double loc_sum[2], sum[2]; 91 #endif 92 double norm_of_residual,norm_of_residual_global; 93 register double d; 94 char* chksz_chr; 95 np=omp_get_max_threads(); 96 97 #ifdef USE_DYNAMIC_SCHEDULING 98 chksz_chr=getenv("PASO_CHUNK_SIZE_PCG"); 99 if (chksz_chr!=NULL) sscanf(chksz_chr, "%d",&chunk_size); 100 chunk_size=MIN(MAX(1,chunk_size),n/np); 101 n_chunks=n/chunk_size; 102 if (n_chunks*chunk_sizempi_info->comm); 199 #endif 200 tau_old=tau; 201 tau=sum_1; 202 /* p=v+beta*p */ 203 #pragma omp parallel private(i0, istart, iend, ipp,beta) 204 { 205 #ifdef USE_DYNAMIC_SCHEDULING 206 #pragma omp for schedule(dynamic, 1) 207 for (ipp=0; ipp < n_chunks; ++ipp) { 208 istart=chunk_size*ipp; 209 iend=MIN(istart+chunk_size,n); 210 #else 211 #pragma omp for schedule(static) 212 for (ipp=0; ipp mpi_info->comm); 268 #endif 269 delta=sum_2; 270 alpha=tau/delta; 271 272 if (! (breakFlag = (ABS(delta) <= TOLERANCE_FOR_SCALARS))) { 273 /* smoother */ 274 sum_3 = 0; 275 sum_4 = 0; 276 #pragma omp parallel private(i0, istart, iend, ipp,d, ss, ss1) 277 { 278 ss=0; 279 ss1=0; 280 #ifdef USE_DYNAMIC_SCHEDULING 281 #pragma omp for schedule(dynamic, 1) 282 for (ipp=0; ipp < n_chunks; ++ipp) { 283 istart=chunk_size*ipp; 284 iend=MIN(istart+chunk_size,n); 285 #else 286 #pragma omp for schedule(static) 287 for (ipp=0; ipp mpi_info->comm); 313 sum_3=sum[0]; 314 sum_4=sum[1]; 315 #endif 316 sum_5 = 0; 317 #pragma omp parallel private(i0, istart, iend, ipp, ss, gamma_1,gamma_2) 318 { 319 gamma_1= ( (ABS(sum_3)<= ZERO) ? 0 : -sum_4/sum_3) ; 320 gamma_2= ONE-gamma_1; 321 ss=0; 322 #ifdef USE_DYNAMIC_SCHEDULING 323 #pragma omp for schedule(dynamic, 1) 324 for (ipp=0; ipp < n_chunks; ++ipp) { 325 istart=chunk_size*ipp; 326 iend=MIN(istart+chunk_size,n); 327 #else 328 #pragma omp for schedule(static) 329 for (ipp=0; ipp mpi_info->comm); 353 #endif 354 norm_of_residual=sqrt(sum_5); 355 convergeFlag = norm_of_residual <= tol; 356 maxIterFlag = num_iter == maxit; 357 breakFlag = (ABS(tau) <= TOLERANCE_FOR_SCALARS); 358 } 359 } 360 /* end of iteration */ 361 num_iter_global=num_iter; 362 norm_of_residual_global=norm_of_residual; 363 if (maxIterFlag) { 364 status = SOLVER_MAXITER_REACHED; 365 } else if (breakFlag) { 366 status = SOLVER_BREAKDOWN; 367 } 368 Performance_stopMonitor(pp,PERFORMANCE_SOLVER); 369 TMPMEMFREE(rs); 370 TMPMEMFREE(x2); 371 TMPMEMFREE(v); 372 TMPMEMFREE(p); 373 *iter=num_iter_global; 374 *resid=norm_of_residual_global; 375 } 376 /* End of PCG */ 377 return status; 378 }

Properties

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