Actual source code: sbaijspooles.c

  1: /*$Id: sbaijspooles.c,v 1.10 2001/08/15 15:56:50 bsmith Exp $*/
  2: /* 
  3:    Provides an interface to the Spooles serial sparse solver
  4: */

 6:  #include src/mat/impls/aij/seq/spooles/spooles.h

 10: int MatDestroy_SeqSBAIJSpooles(Mat A) {
 11:   int         ierr;
 12: 
 14:   /* SeqSBAIJ_Spooles isn't really the matrix that USES spooles, */
 15:   /* rather it is a factory class for creating a symmetric matrix that can */
 16:   /* invoke Spooles' sequential cholesky solver. */
 17:   /* As a result, we don't have to clean up the stuff set by spooles */
 18:   /* as in MatDestroy_SeqAIJ_Spooles. */
 19:   MatConvert_Spooles_Base(A,MATSEQSBAIJ,&A);
 20:   (*A->ops->destroy)(A);
 21:   return(0);
 22: }

 26: int MatAssemblyEnd_SeqSBAIJSpooles(Mat A,MatAssemblyType mode) {
 27:   int         ierr,bs;
 28:   Mat_Spooles *lu=(Mat_Spooles *)(A->spptr);

 31:   (*lu->MatAssemblyEnd)(A,mode);
 32:   MatGetBlockSize(A,&bs);
 33:   if (bs > 1) SETERRQ1(1,"Block size %d not supported by Spooles",bs);
 34:   lu->MatCholeskyFactorSymbolic  = A->ops->choleskyfactorsymbolic;
 35:   A->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SeqSBAIJSpooles;
 36:   return(0);
 37: }

 39: /* 
 40:   input:
 41:    F:                 numeric factor
 42:   output:
 43:    nneg, nzero, npos: matrix inertia 
 44: */

 48: int MatGetInertia_SeqSBAIJSpooles(Mat F,int *nneg,int *nzero,int *npos)
 49: {
 50:   Mat_Spooles *lu = (Mat_Spooles*)F->spptr;
 51:   int         neg,zero,pos;

 54:   FrontMtx_inertia(lu->frontmtx, &neg, &zero, &pos) ;
 55:   if(nneg)  *nneg  = neg;
 56:   if(nzero) *nzero = zero;
 57:   if(npos)  *npos  = pos;
 58:   return(0);
 59: }

 61: /* Note the Petsc r permutation is ignored */
 64: int MatCholeskyFactorSymbolic_SeqSBAIJSpooles(Mat A,IS r,MatFactorInfo *info,Mat *F)
 65: {
 66:   Mat         B;
 67:   Mat_Spooles *lu;
 68:   int         ierr,m=A->m,n=A->n;

 71:   /* Create the factorization matrix */
 72:   MatCreate(A->comm,m,n,m,n,&B);
 73:   MatSetType(B,A->type_name);
 74:   MatSeqAIJSetPreallocation(B,PETSC_NULL,PETSC_NULL);

 76:   B->ops->choleskyfactornumeric  = MatFactorNumeric_SeqAIJSpooles;
 77:   B->ops->getinertia             = MatGetInertia_SeqSBAIJSpooles;
 78:   B->factor                      = FACTOR_CHOLESKY;

 80:   lu                        = (Mat_Spooles *)(B->spptr);
 81:   lu->options.pivotingflag  = SPOOLES_NO_PIVOTING;
 82:   lu->options.symflag       = SPOOLES_SYMMETRIC;   /* default */
 83:   lu->flg                   = DIFFERENT_NONZERO_PATTERN;
 84:   lu->options.useQR         = PETSC_FALSE;

 86:   *F = B;
 87:   return(0);
 88: }

 90: EXTERN_C_BEGIN
 93: int MatConvert_SeqSBAIJ_SeqSBAIJSpooles(Mat A,const MatType type,Mat *newmat) {
 94:   /* This routine is only called to convert a MATSEQSBAIJ matrix */
 95:   /* to a MATSEQSBAIJSPOOLES matrix, so we will ignore 'MatType type'. */
 96:   int         ierr;
 97:   Mat         B=*newmat;
 98:   Mat_Spooles *lu;

101:   if (B != A) {
102:     /* This routine is inherited, so we know the type is correct. */
103:     MatDuplicate(A,MAT_COPY_VALUES,&B);
104:   }

106:   PetscNew(Mat_Spooles,&lu);
107:   B->spptr                       = (void*)lu;

109:   lu->basetype                   = MATSEQSBAIJ;
110:   lu->CleanUpSpooles             = PETSC_FALSE;
111:   lu->MatDuplicate               = A->ops->duplicate;
112:   lu->MatCholeskyFactorSymbolic  = A->ops->choleskyfactorsymbolic;
113:   lu->MatLUFactorSymbolic        = A->ops->lufactorsymbolic;
114:   lu->MatView                    = A->ops->view;
115:   lu->MatAssemblyEnd             = A->ops->assemblyend;
116:   lu->MatDestroy                 = A->ops->destroy;
117:   B->ops->duplicate              = MatDuplicate_SeqSBAIJSpooles;
118:   B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SeqSBAIJSpooles;
119:   B->ops->assemblyend            = MatAssemblyEnd_SeqSBAIJSpooles;
120:   B->ops->destroy                = MatDestroy_SeqSBAIJSpooles;
121:   PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_seqsbaijspooles_seqsbaij_C",
122:                                            "MatConvert_Spooles_Base",MatConvert_Spooles_Base);
123:   PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_seqsbaij_seqsbaijspooles_C",
124:                                            "MatConvert_SeqSBAIJ_SeqSBAIJSpooles",MatConvert_SeqSBAIJ_SeqSBAIJSpooles);
125:   PetscObjectChangeTypeName((PetscObject)B,MATSEQSBAIJSPOOLES);
126:   *newmat = B;
127:   return(0);
128: }
129: EXTERN_C_END

133: int MatDuplicate_SeqSBAIJSpooles(Mat A, MatDuplicateOption op, Mat *M) {
134:   int         ierr;
135:   Mat_Spooles *lu=(Mat_Spooles *)A->spptr;

138:   (*lu->MatDuplicate)(A,op,M);
139:   PetscMemcpy((*M)->spptr,lu,sizeof(Mat_Spooles));
140:   return(0);
141: }

143: /*MC
144:   MATSEQSBAIJSPOOLES - MATSEQSBAIJSPOOLES = "seqsbaijspooles" - A matrix type providing direct solvers (Cholesky) for sequential symmetric
145:   matrices via the external package Spooles.

147:   If Spooles is installed (see the manual for
148:   instructions on how to declare the existence of external packages),
149:   a matrix type can be constructed which invokes Spooles solvers.
150:   After calling MatCreate(...,A), simply call MatSetType(A,MATSEQSBAIJSPOOLES).
151:   This matrix type is only supported for double precision real.

153:   This matrix inherits from MATSEQSBAIJ.  As a result, MatSeqSBAIJSetPreallocation is 
154:   supported for this matrix type.  One can also call MatConvert for an inplace conversion to or from 
155:   the MATSEQSBAIJ type without data copy.

157:   Options Database Keys:
158: + -mat_type seqsbaijspooles - sets the matrix type to seqsbaijspooles during calls to MatSetFromOptions()
159: . -mat_spooles_tau <tau> - upper bound on the magnitude of the largest element in L or U
160: . -mat_spooles_seed <seed> - random number seed used for ordering
161: . -mat_spooles_msglvl <msglvl> - message output level
162: . -mat_spooles_ordering <BestOfNDandMS,MMD,MS,ND> - ordering used
163: . -mat_spooles_maxdomainsize <n> - maximum subgraph size used by Spooles orderings
164: . -mat_spooles_maxzeros <n> - maximum number of zeros inside a supernode
165: . -mat_spooles_maxsize <n> - maximum size of a supernode
166: . -mat_spooles_FrontMtxInfo <true,fase> - print Spooles information about the computed factorization
167: . -mat_spooles_symmetryflag <0,1,2> - 0: SPOOLES_SYMMETRIC, 1: SPOOLES_HERMITIAN, 2: SPOOLES_NONSYMMETRIC
168: . -mat_spooles_patchAndGoFlag <0,1,2> - 0: no patch, 1: use PatchAndGo strategy 1, 2: use PatchAndGo strategy 2
169: . -mat_spooles_toosmall <dt> - drop tolerance for PatchAndGo strategy 1
170: . -mat_spooles_storeids <bool integer> - if nonzero, stores row and col numbers where patches were applied in an IV object
171: . -mat_spooles_fudge <delta> - fudge factor for rescaling diagonals with PatchAndGo strategy 2
172: - -mat_spooles_storevalues <bool integer> - if nonzero and PatchAndGo strategy 2 is used, store change in diagonal value in a DV object

174:    Level: beginner

176: .seealso: MATMPISBAIJSPOOLES, MATSEQAIJSPOOLES, MATMPIAIJSPOOLES, PCCHOLESKY
177: M*/

179: EXTERN_C_BEGIN
182: int MatCreate_SeqSBAIJSpooles(Mat A) {

186:   /* Change type name before calling MatSetType to force proper construction of SeqSBAIJ */
187:   /*   and SeqSBAIJSpooles types */
188:   PetscObjectChangeTypeName((PetscObject)A,MATSEQSBAIJSPOOLES);
189:   MatSetType(A,MATSEQSBAIJ);
190:   MatConvert_SeqSBAIJ_SeqSBAIJSpooles(A,MATSEQSBAIJSPOOLES,&A);
191:   return(0);
192: }
193: EXTERN_C_END