Actual source code: borthog3.c
1: /*$Id: borthog3.c,v 1.25 2001/08/07 03:03:51 balay Exp $*/
2: /*
3: Routines used for the orthogonalization of the Hessenberg matrix.
5: Note that for the complex numbers version, the VecDot() and
6: VecMDot() arguments within the code MUST remain in the order
7: given for correct computation of inner products.
8: */
9: #include src/sles/ksp/impls/gmres/gmresp.h
11: /*
12: This version uses 1 iteration of iterative refinement of UNMODIFIED Gram-Schmidt.
13: It can give better performance when running in a parallel
14: environment and in some cases even in a sequential environment (because
15: MAXPY has more data reuse).
17: Care is taken to accumulate the updated HH/HES values.
18: */
19: #undef __FUNCT__
21: int KSPGMRESIROrthogonalization(KSP ksp,int it)
22: {
23: KSP_GMRES *gmres = (KSP_GMRES *)(ksp->data);
24: int j,ncnt,ierr;
25: PetscScalar *hh,*hes,shh[100],*lhh;
28: PetscLogEventBegin(KSP_GMRESOrthogonalization,ksp,0,0,0);
29: /* Don't allocate small arrays */
30: if (it < 100) lhh = shh;
31: else {
32: PetscMalloc((it+1) * sizeof(PetscScalar),&lhh);
33: }
34:
35: /* update Hessenberg matrix and do unmodified Gram-Schmidt */
36: hh = HH(0,it);
37: hes = HES(0,it);
39: /* Clear hh and hes since we will accumulate values into them */
40: for (j=0; j<=it; j++) {
41: hh[j] = 0.0;
42: hes[j] = 0.0;
43: }
45: ncnt = 0;
46: do {
47: /*
48: This is really a matrix-vector product, with the matrix stored
49: as pointer to rows
50: */
51: VecMDot(it+1,VEC_VV(it+1),&(VEC_VV(0)),lhh); /* <v,vnew> */
53: /*
54: This is really a matrix vector product:
55: [h[0],h[1],...]*[ v[0]; v[1]; ...] subtracted from v[it+1].
56: */
57: for (j=0; j<=it; j++) lhh[j] = - lhh[j];
58: VecMAXPY(it+1,lhh,VEC_VV(it+1),&VEC_VV(0));
59: for (j=0; j<=it; j++) {
60: hh[j] -= lhh[j]; /* hh += <v,vnew> */
61: hes[j] += lhh[j]; /* hes += - <v,vnew> */
62: }
63: } while (ncnt++ < 2);
65: if (it >= 100) {PetscFree(lhh);}
66: PetscLogEventEnd(KSP_GMRESOrthogonalization,ksp,0,0,0);
67: return(0);
68: }