Actual source code: sbaijspooles.c

  1: #define PETSCMAT_DLL

  3: /* 
  4:    Provides an interface to the Spooles serial sparse solver
  5: */

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

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

 28: PetscErrorCode MatAssemblyEnd_SeqSBAIJSpooles(Mat A,MatAssemblyType mode) \
 29: {
 31:   PetscInt       bs;
 32:   Mat_Spooles    *lu=(Mat_Spooles *)(A->spptr);

 35:   (*lu->MatAssemblyEnd)(A,mode);
 36:   MatGetBlockSize(A,&bs);
 37:   if (bs > 1) SETERRQ1(PETSC_ERR_SUP,"Block size %D not supported by Spooles",bs);
 38:   lu->MatCholeskyFactorSymbolic  = A->ops->choleskyfactorsymbolic;
 39:   A->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SeqSBAIJSpooles;
 40:   return(0);
 41: }

 43: /* 
 44:   input:
 45:    F:                 numeric factor
 46:   output:
 47:    nneg, nzero, npos: matrix inertia 
 48: */

 52: PetscErrorCode MatGetInertia_SeqSBAIJSpooles(Mat F,int *nneg,int *nzero,int *npos)
 53: {
 54:   Mat_Spooles *lu = (Mat_Spooles*)F->spptr;
 55:   int         neg,zero,pos;

 58:   FrontMtx_inertia(lu->frontmtx, &neg, &zero, &pos);
 59:   if(nneg)  *nneg  = neg;
 60:   if(nzero) *nzero = zero;
 61:   if(npos)  *npos  = pos;
 62:   return(0);
 63: }

 65: /* Note the Petsc r permutation is ignored */
 68: PetscErrorCode MatCholeskyFactorSymbolic_SeqSBAIJSpooles(Mat A,IS r,MatFactorInfo *info,Mat *F)
 69: {
 70:   Mat         B;
 71:   Mat_Spooles *lu;
 73:   int m=A->rmap.n,n=A->cmap.n;

 76:   /* Create the factorization matrix */
 77:   MatCreate(((PetscObject)A)->comm,&B);
 78:   MatSetSizes(B,m,n,m,n);
 79:   MatSetType(B,((PetscObject)A)->type_name);
 80:   MatSeqSBAIJSetPreallocation(B,1,PETSC_NULL,PETSC_NULL);

 82:   B->ops->choleskyfactornumeric  = MatFactorNumeric_SeqSpooles;
 83:   B->ops->getinertia             = MatGetInertia_SeqSBAIJSpooles;
 84:   B->factor                      = FACTOR_CHOLESKY;

 86:   lu                        = (Mat_Spooles *)(B->spptr);
 87:   lu->options.pivotingflag  = SPOOLES_NO_PIVOTING;
 88:   lu->options.symflag       = SPOOLES_SYMMETRIC;   /* default */
 89:   lu->flg                   = DIFFERENT_NONZERO_PATTERN;
 90:   lu->options.useQR         = PETSC_FALSE;

 92:   *F = B;
 93:   return(0);
 94: }

 99: PetscErrorCode  MatConvert_SeqSBAIJ_SeqSBAIJSpooles(Mat A,MatType type,MatReuse reuse,Mat *newmat)
100: {
102:   Mat            B=*newmat;
103:   Mat_Spooles    *lu;

106:   PetscNewLog(B,Mat_Spooles,&lu);
107:   if (reuse == MAT_INITIAL_MATRIX) {
108:     /* This routine is inherited, so we know the type is correct. */
109:     MatDuplicate(A,MAT_COPY_VALUES,&B);
110:   }
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;

118:   B->spptr                       = (void*)lu;
119:   lu->basetype                   = MATSEQSBAIJ;
120:   lu->CleanUpSpooles             = PETSC_FALSE;

122:   B->ops->duplicate              = MatDuplicate_Spooles;
123:   B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SeqSBAIJSpooles;
124:   B->ops->view                   = MatView_Spooles;
125:   B->ops->assemblyend            = MatAssemblyEnd_SeqSBAIJSpooles;
126:   B->ops->destroy                = MatDestroy_SeqSBAIJSpooles;
127:   PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_seqsbaijspooles_seqsbaij_C",
128:                                            "MatConvert_Spooles_Base",MatConvert_Spooles_Base);
129:   PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_seqsbaij_seqsbaijspooles_C",
130:                                            "MatConvert_SeqSBAIJ_SeqSBAIJSpooles",MatConvert_SeqSBAIJ_SeqSBAIJSpooles);
131:   PetscObjectChangeTypeName((PetscObject)B,MATSEQSBAIJSPOOLES);
132:   *newmat = B;
133:   return(0);
134: }

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

141:   If Spooles is installed (see the manual for
142:   instructions on how to declare the existence of external packages),
143:   a matrix type can be constructed which invokes Spooles solvers.
144:   After calling MatCreate(...,A), simply call MatSetType(A,MATSEQSBAIJSPOOLES), then 
145:   optionally call MatSeqSBAIJSetPreallocation() or MatMPISBAIJSetPreallocation() DO NOT
146:   call MatCreateSeqSBAIJ/MPISBAIJ() directly or the preallocation information will be LOST!

148:   This matrix inherits from MATSEQSBAIJ.  As a result, MatSeqSBAIJSetPreallocation() is 
149:   supported for this matrix type.  One can also call MatConvert() for an inplace conversion to or from 
150:   the MATSEQSBAIJ type without data copy, after the matrix values have been set.

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

169:    Level: beginner

171: .seealso: MATMPISBAIJSPOOLES, MATSEQAIJSPOOLES, MATMPIAIJSPOOLES, PCCHOLESKY
172: M*/

177: PetscErrorCode  MatCreate_SeqSBAIJSpooles(Mat A)
178: {

182:   MatSetType(A,MATSEQSBAIJ);
183:   MatConvert_SeqSBAIJ_SeqSBAIJSpooles(A,MATSEQSBAIJSPOOLES,MAT_REUSE_MATRIX,&A);
184:   return(0);
185: }

188: /*MC
189:   MATSBAIJSPOOLES - MATSBAIJSPOOLES = "sbaijspooles" - A matrix type providing direct solvers (Cholesky) for sequential and parallel symmetric matrices via the external package Spooles.

191:   If Spooles is installed (see the manual for
192:   instructions on how to declare the existence of external packages),
193:   a matrix type can be constructed which invokes Spooles solvers.
194:   After calling MatCreate(...,A), simply call MatSetType(A,MATSBAIJSPOOLES), then 
195:   optionally call MatSeqSBAIJSetPreallocation() or MatMPISBAIJSetPreallocation() DO NOT
196:   call MatCreateSeqSBAIJ/MPISBAIJ() directly or the preallocation information will be LOST!

198:   This matrix inherits from MATSBAIJ.  As a result, MatSeqSBAIJSetPreallocation() and MatMPISBAIJSetPreallocation() are 
199:   supported for this matrix type.  One can also call MatConvert for an inplace conversion to or from 
200:   the MATSBAIJ type without data copy after the matrix values have been set.

202:   Options Database Keys:
203: + -mat_type sbaijspooles - sets the matrix type to sbaijspooles during calls to MatSetFromOptions()
204: . -mat_spooles_tau <tau> - upper bound on the magnitude of the largest element in L or U
205: . -mat_spooles_seed <seed> - random number seed used for ordering
206: . -mat_spooles_msglvl <msglvl> - message output level
207: . -mat_spooles_ordering <BestOfNDandMS,MMD,MS,ND> - ordering used
208: . -mat_spooles_maxdomainsize <n> - maximum subgraph size used by Spooles orderings
209: . -mat_spooles_maxzeros <n> - maximum number of zeros inside a supernode
210: . -mat_spooles_maxsize <n> - maximum size of a supernode
211: . -mat_spooles_FrontMtxInfo <true,fase> - print Spooles information about the computed factorization
212: . -mat_spooles_symmetryflag <0,1,2> - 0: SPOOLES_SYMMETRIC, 1: SPOOLES_HERMITIAN, 2: SPOOLES_NONSYMMETRIC
213: . -mat_spooles_patchAndGoFlag <0,1,2> - 0: no patch, 1: use PatchAndGo strategy 1, 2: use PatchAndGo strategy 2
214: . -mat_spooles_toosmall <dt> - drop tolerance for PatchAndGo strategy 1
215: . -mat_spooles_storeids <bool integer> - if nonzero, stores row and col numbers where patches were applied in an IV object
216: . -mat_spooles_fudge <delta> - fudge factor for rescaling diagonals with PatchAndGo strategy 2
217: - -mat_spooles_storevalues <bool integer> - if nonzero and PatchAndGo strategy 2 is used, store change in diagonal value in a DV object

219:    Level: beginner

221: .seealso: MATMPISBAIJSPOOLES, MATSEQAIJSPOOLES, MATMPIAIJSPOOLES, PCCHOLESKY
222: M*/

227: PetscErrorCode  MatCreate_SBAIJSpooles(Mat A)
228: {
230:   int size;

233:   MPI_Comm_size(((PetscObject)A)->comm,&size);
234:   if (size == 1) {
235:     MatSetType(A,MATSEQSBAIJ);
236:     MatConvert_SeqSBAIJ_SeqSBAIJSpooles(A,MATSEQSBAIJSPOOLES,MAT_REUSE_MATRIX,&A);
237:   } else {
238:     MatSetType(A,MATMPISBAIJ);
239:     MatConvert_MPISBAIJ_MPISBAIJSpooles(A,MATMPISBAIJSPOOLES,MAT_REUSE_MATRIX,&A);
240:   }
241: 
242:   return(0);
243: }