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(A->comm,&B);
78: MatSetSizes(B,m,n,m,n);
79: MatSetType(B,A->type_name);
80: MatSeqSBAIJSetPreallocation(B,1,PETSC_NULL,PETSC_NULL);
82: B->ops->choleskyfactornumeric = MatFactorNumeric_SeqAIJSpooles;
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: if (reuse == MAT_INITIAL_MATRIX) {
107: /* This routine is inherited, so we know the type is correct. */
108: MatDuplicate(A,MAT_COPY_VALUES,&B);
109: }
111: PetscNew(Mat_Spooles,&lu);
112: B->spptr = (void*)lu;
114: lu->basetype = MATSEQSBAIJ;
115: lu->CleanUpSpooles = PETSC_FALSE;
116: lu->MatDuplicate = A->ops->duplicate;
117: lu->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
118: lu->MatLUFactorSymbolic = A->ops->lufactorsymbolic;
119: lu->MatView = A->ops->view;
120: lu->MatAssemblyEnd = A->ops->assemblyend;
121: lu->MatDestroy = A->ops->destroy;
123: B->ops->duplicate = MatDuplicate_Spooles;
124: B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SeqSBAIJSpooles;
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).
146: This matrix inherits from MATSEQSBAIJ. As a result, MatSeqSBAIJSetPreallocation is
147: supported for this matrix type. One can also call MatConvert for an inplace conversion to or from
148: the MATSEQSBAIJ type without data copy.
150: Options Database Keys:
151: + -mat_type seqsbaijspooles - sets the matrix type to seqsbaijspooles during calls to MatSetFromOptions()
152: . -mat_spooles_tau <tau> - upper bound on the magnitude of the largest element in L or U
153: . -mat_spooles_seed <seed> - random number seed used for ordering
154: . -mat_spooles_msglvl <msglvl> - message output level
155: . -mat_spooles_ordering <BestOfNDandMS,MMD,MS,ND> - ordering used
156: . -mat_spooles_maxdomainsize <n> - maximum subgraph size used by Spooles orderings
157: . -mat_spooles_maxzeros <n> - maximum number of zeros inside a supernode
158: . -mat_spooles_maxsize <n> - maximum size of a supernode
159: . -mat_spooles_FrontMtxInfo <true,fase> - print Spooles information about the computed factorization
160: . -mat_spooles_symmetryflag <0,1,2> - 0: SPOOLES_SYMMETRIC, 1: SPOOLES_HERMITIAN, 2: SPOOLES_NONSYMMETRIC
161: . -mat_spooles_patchAndGoFlag <0,1,2> - 0: no patch, 1: use PatchAndGo strategy 1, 2: use PatchAndGo strategy 2
162: . -mat_spooles_toosmall <dt> - drop tolerance for PatchAndGo strategy 1
163: . -mat_spooles_storeids <bool integer> - if nonzero, stores row and col numbers where patches were applied in an IV object
164: . -mat_spooles_fudge <delta> - fudge factor for rescaling diagonals with PatchAndGo strategy 2
165: - -mat_spooles_storevalues <bool integer> - if nonzero and PatchAndGo strategy 2 is used, store change in diagonal value in a DV object
167: Level: beginner
169: .seealso: MATMPISBAIJSPOOLES, MATSEQAIJSPOOLES, MATMPIAIJSPOOLES, PCCHOLESKY
170: M*/
175: PetscErrorCode MatCreate_SeqSBAIJSpooles(Mat A)
176: {
180: MatSetType(A,MATSEQSBAIJ);
181: MatConvert_SeqSBAIJ_SeqSBAIJSpooles(A,MATSEQSBAIJSPOOLES,MAT_REUSE_MATRIX,&A);
182: return(0);
183: }
186: /*MC
187: MATSBAIJSPOOLES - MATSBAIJSPOOLES = "sbaijspooles" - A matrix type providing direct solvers (Cholesky) for sequential and parallel symmetric matrices via the external package Spooles.
189: If Spooles is installed (see the manual for
190: instructions on how to declare the existence of external packages),
191: a matrix type can be constructed which invokes Spooles solvers.
192: After calling MatCreate(...,A), simply call MatSetType(A,MATSBAIJSPOOLES).
194: This matrix inherits from MATSBAIJ. As a result, MatSeqSBAIJSetPreallocation and MatMPISBAIJSetPreallocation are
195: supported for this matrix type. One can also call MatConvert for an inplace conversion to or from
196: the MATSBAIJ type without data copy.
198: Options Database Keys:
199: + -mat_type sbaijspooles - sets the matrix type to sbaijspooles during calls to MatSetFromOptions()
200: . -mat_spooles_tau <tau> - upper bound on the magnitude of the largest element in L or U
201: . -mat_spooles_seed <seed> - random number seed used for ordering
202: . -mat_spooles_msglvl <msglvl> - message output level
203: . -mat_spooles_ordering <BestOfNDandMS,MMD,MS,ND> - ordering used
204: . -mat_spooles_maxdomainsize <n> - maximum subgraph size used by Spooles orderings
205: . -mat_spooles_maxzeros <n> - maximum number of zeros inside a supernode
206: . -mat_spooles_maxsize <n> - maximum size of a supernode
207: . -mat_spooles_FrontMtxInfo <true,fase> - print Spooles information about the computed factorization
208: . -mat_spooles_symmetryflag <0,1,2> - 0: SPOOLES_SYMMETRIC, 1: SPOOLES_HERMITIAN, 2: SPOOLES_NONSYMMETRIC
209: . -mat_spooles_patchAndGoFlag <0,1,2> - 0: no patch, 1: use PatchAndGo strategy 1, 2: use PatchAndGo strategy 2
210: . -mat_spooles_toosmall <dt> - drop tolerance for PatchAndGo strategy 1
211: . -mat_spooles_storeids <bool integer> - if nonzero, stores row and col numbers where patches were applied in an IV object
212: . -mat_spooles_fudge <delta> - fudge factor for rescaling diagonals with PatchAndGo strategy 2
213: - -mat_spooles_storevalues <bool integer> - if nonzero and PatchAndGo strategy 2 is used, store change in diagonal value in a DV object
215: Level: beginner
217: .seealso: MATMPISBAIJSPOOLES, MATSEQAIJSPOOLES, MATMPIAIJSPOOLES, PCCHOLESKY
218: M*/
223: PetscErrorCode MatCreate_SBAIJSpooles(Mat A)
224: {
226: int size;
229: MPI_Comm_size(A->comm,&size);
230: if (size == 1) {
231: MatSetType(A,MATSEQSBAIJ);
232: MatConvert_SeqSBAIJ_SeqSBAIJSpooles(A,MATSEQSBAIJSPOOLES,MAT_REUSE_MATRIX,&A);
233: } else {
234: MatSetType(A,MATMPISBAIJ);
235: MatConvert_MPISBAIJ_MPISBAIJSpooles(A,MATMPISBAIJSPOOLES,MAT_REUSE_MATRIX,&A);
236: }
237:
238: return(0);
239: }