Actual source code: mumps.c
1: #define PETSCMAT_DLL
3: /*
4: Provides an interface to the MUMPS sparse solver
5: */
6: #include src/mat/impls/aij/seq/aij.h
7: #include src/mat/impls/aij/mpi/mpiaij.h
8: #include src/mat/impls/sbaij/seq/sbaij.h
9: #include src/mat/impls/sbaij/mpi/mpisbaij.h
12: #if defined(PETSC_USE_COMPLEX)
13: #include "zmumps_c.h"
14: #else
15: #include "dmumps_c.h"
16: #endif
18: #define JOB_INIT -1
19: #define JOB_END -2
20: /* macros s.t. indices match MUMPS documentation */
21: #define ICNTL(I) icntl[(I)-1]
22: #define CNTL(I) cntl[(I)-1]
23: #define INFOG(I) infog[(I)-1]
24: #define INFO(I) info[(I)-1]
25: #define RINFOG(I) rinfog[(I)-1]
26: #define RINFO(I) rinfo[(I)-1]
28: typedef struct {
29: #if defined(PETSC_USE_COMPLEX)
30: ZMUMPS_STRUC_C id;
31: #else
32: DMUMPS_STRUC_C id;
33: #endif
34: MatStructure matstruc;
35: PetscMPIInt myid,size;
36: PetscInt *irn,*jcn,sym,nSolve;
37: PetscScalar *val;
38: MPI_Comm comm_mumps;
39: VecScatter scat_rhs, scat_sol;
40: PetscTruth isAIJ,CleanUpMUMPS;
41: Vec b_seq,x_seq;
42: PetscErrorCode (*MatDuplicate)(Mat,MatDuplicateOption,Mat*);
43: PetscErrorCode (*MatView)(Mat,PetscViewer);
44: PetscErrorCode (*MatAssemblyEnd)(Mat,MatAssemblyType);
45: PetscErrorCode (*MatLUFactorSymbolic)(Mat,IS,IS,MatFactorInfo*,Mat*);
46: PetscErrorCode (*MatCholeskyFactorSymbolic)(Mat,IS,MatFactorInfo*,Mat*);
47: PetscErrorCode (*MatDestroy)(Mat);
48: PetscErrorCode (*specialdestroy)(Mat);
49: PetscErrorCode (*MatPreallocate)(Mat,int,int,int*,int,int*);
50: } Mat_MUMPS;
52: EXTERN PetscErrorCode MatDuplicate_MUMPS(Mat,MatDuplicateOption,Mat*);
54: PetscErrorCode MatConvert_SBAIJ_SBAIJMUMPS(Mat,MatType,MatReuse,Mat*);
56: /* convert Petsc mpiaij matrix to triples: row[nz], col[nz], val[nz] */
57: /*
58: input:
59: A - matrix in mpiaij or mpisbaij (bs=1) format
60: shift - 0: C style output triple; 1: Fortran style output triple.
61: valOnly - FALSE: spaces are allocated and values are set for the triple
62: TRUE: only the values in v array are updated
63: output:
64: nnz - dim of r, c, and v (number of local nonzero entries of A)
65: r, c, v - row and col index, matrix values (matrix triples)
66: */
67: PetscErrorCode MatConvertToTriples(Mat A,int shift,PetscTruth valOnly,int *nnz,int **r, int **c, PetscScalar **v) {
68: PetscInt *ai, *aj, *bi, *bj, rstart,nz, *garray;
70: PetscInt i,j,jj,jB,irow,m=A->rmap.n,*ajj,*bjj,countA,countB,colA_start,jcol;
71: PetscInt *row,*col;
72: PetscScalar *av, *bv,*val;
73: Mat_MUMPS *mumps=(Mat_MUMPS*)A->spptr;
76: if (mumps->isAIJ){
77: Mat_MPIAIJ *mat = (Mat_MPIAIJ*)A->data;
78: Mat_SeqAIJ *aa=(Mat_SeqAIJ*)(mat->A)->data;
79: Mat_SeqAIJ *bb=(Mat_SeqAIJ*)(mat->B)->data;
80: nz = aa->nz + bb->nz;
81: ai=aa->i; aj=aa->j; bi=bb->i; bj=bb->j; rstart= A->rmap.rstart;
82: garray = mat->garray;
83: av=aa->a; bv=bb->a;
84:
85: } else {
86: Mat_MPISBAIJ *mat = (Mat_MPISBAIJ*)A->data;
87: Mat_SeqSBAIJ *aa=(Mat_SeqSBAIJ*)(mat->A)->data;
88: Mat_SeqBAIJ *bb=(Mat_SeqBAIJ*)(mat->B)->data;
89: if (A->rmap.bs > 1) SETERRQ1(PETSC_ERR_SUP," bs=%d is not supported yet\n", A->rmap.bs);
90: nz = aa->nz + bb->nz;
91: ai=aa->i; aj=aa->j; bi=bb->i; bj=bb->j; rstart= A->rmap.rstart;
92: garray = mat->garray;
93: av=aa->a; bv=bb->a;
94: }
96: if (!valOnly){
97: PetscMalloc(nz*sizeof(PetscInt) ,&row);
98: PetscMalloc(nz*sizeof(PetscInt),&col);
99: PetscMalloc(nz*sizeof(PetscScalar),&val);
100: *r = row; *c = col; *v = val;
101: } else {
102: row = *r; col = *c; val = *v;
103: }
104: *nnz = nz;
106: jj = 0; irow = rstart;
107: for ( i=0; i<m; i++ ) {
108: ajj = aj + ai[i]; /* ptr to the beginning of this row */
109: countA = ai[i+1] - ai[i];
110: countB = bi[i+1] - bi[i];
111: bjj = bj + bi[i];
113: /* get jB, the starting local col index for the 2nd B-part */
114: colA_start = rstart + ajj[0]; /* the smallest col index for A */
115: j=-1;
116: do {
117: j++;
118: if (j == countB) break;
119: jcol = garray[bjj[j]];
120: } while (jcol < colA_start);
121: jB = j;
122:
123: /* B-part, smaller col index */
124: colA_start = rstart + ajj[0]; /* the smallest col index for A */
125: for (j=0; j<jB; j++){
126: jcol = garray[bjj[j]];
127: if (!valOnly){
128: row[jj] = irow + shift; col[jj] = jcol + shift;
130: }
131: val[jj++] = *bv++;
132: }
133: /* A-part */
134: for (j=0; j<countA; j++){
135: if (!valOnly){
136: row[jj] = irow + shift; col[jj] = rstart + ajj[j] + shift;
137: }
138: val[jj++] = *av++;
139: }
140: /* B-part, larger col index */
141: for (j=jB; j<countB; j++){
142: if (!valOnly){
143: row[jj] = irow + shift; col[jj] = garray[bjj[j]] + shift;
144: }
145: val[jj++] = *bv++;
146: }
147: irow++;
148: }
149:
150: return(0);
151: }
156: PetscErrorCode MatConvert_MUMPS_Base(Mat A,MatType type,MatReuse reuse,Mat *newmat)
157: {
159: Mat B=*newmat;
160: Mat_MUMPS *mumps=(Mat_MUMPS*)A->spptr;
161: void (*f)(void);
164: if (reuse == MAT_INITIAL_MATRIX) {
165: MatDuplicate(A,MAT_COPY_VALUES,&B);
166: }
167: B->ops->duplicate = mumps->MatDuplicate;
168: B->ops->view = mumps->MatView;
169: B->ops->assemblyend = mumps->MatAssemblyEnd;
170: B->ops->lufactorsymbolic = mumps->MatLUFactorSymbolic;
171: B->ops->choleskyfactorsymbolic = mumps->MatCholeskyFactorSymbolic;
172: B->ops->destroy = mumps->MatDestroy;
174: /* put back original composed preallocation function */
175: PetscObjectQueryFunction((PetscObject)B,"MatMPISBAIJSetPreallocation_C",(PetscVoidStarFunction)&f);
176: if (f) {
177: PetscObjectComposeFunction((PetscObject)B,"MatMPISBAIJSetPreallocation_C","",(PetscVoidFunction)mumps->MatPreallocate);
178: }
180: PetscObjectComposeFunction((PetscObject)B,"MatConvert_seqaij_aijmumps_C","",PETSC_NULL);
181: PetscObjectComposeFunction((PetscObject)B,"MatConvert_aijmumps_seqaij_C","",PETSC_NULL);
182: PetscObjectComposeFunction((PetscObject)B,"MatConvert_mpiaij_aijmumps_C","",PETSC_NULL);
183: PetscObjectComposeFunction((PetscObject)B,"MatConvert_aijmumps_mpiaij_C","",PETSC_NULL);
184: PetscObjectComposeFunction((PetscObject)B,"MatConvert_seqsbaij_sbaijmumps_C","",PETSC_NULL);
185: PetscObjectComposeFunction((PetscObject)B,"MatConvert_sbaijmumps_seqsbaij_C","",PETSC_NULL);
186: PetscObjectComposeFunction((PetscObject)B,"MatConvert_mpisbaij_sbaijmumps_C","",PETSC_NULL);
187: PetscObjectComposeFunction((PetscObject)B,"MatConvert_sbaijmumps_mpisbaij_C","",PETSC_NULL);
189: PetscObjectChangeTypeName((PetscObject)B,type);
190: *newmat = B;
191: return(0);
192: }
197: PetscErrorCode MatDestroy_MUMPS(Mat A)
198: {
199: Mat_MUMPS *lu=(Mat_MUMPS*)A->spptr;
201: PetscMPIInt size=lu->size;
202: PetscErrorCode (*specialdestroy)(Mat);
204: if (lu->CleanUpMUMPS) {
205: /* Terminate instance, deallocate memories */
206: if (size > 1){
207: PetscFree(lu->id.sol_loc);
208: VecScatterDestroy(lu->scat_rhs);
209: VecDestroy(lu->b_seq);
210: VecScatterDestroy(lu->scat_sol);
211: VecDestroy(lu->x_seq);
212: PetscFree(lu->val);
213: }
214: lu->id.job=JOB_END;
215: #if defined(PETSC_USE_COMPLEX)
216: zmumps_c(&lu->id);
217: #else
218: dmumps_c(&lu->id);
219: #endif
220: PetscFree(lu->irn);
221: PetscFree(lu->jcn);
222: MPI_Comm_free(&(lu->comm_mumps));
223: }
224: specialdestroy = lu->specialdestroy;
225: (*specialdestroy)(A);
226: (*A->ops->destroy)(A);
227: return(0);
228: }
232: PetscErrorCode MatDestroy_AIJMUMPS(Mat A)
233: {
235: PetscMPIInt size;
238: MPI_Comm_size(A->comm,&size);
239: if (size==1) {
240: MatConvert_MUMPS_Base(A,MATSEQAIJ,MAT_REUSE_MATRIX,&A);
241: } else {
242: MatConvert_MUMPS_Base(A,MATMPIAIJ,MAT_REUSE_MATRIX,&A);
243: }
244: return(0);
245: }
249: PetscErrorCode MatDestroy_SBAIJMUMPS(Mat A)
250: {
252: PetscMPIInt size;
255: MPI_Comm_size(A->comm,&size);
256: if (size==1) {
257: MatConvert_MUMPS_Base(A,MATSEQSBAIJ,MAT_REUSE_MATRIX,&A);
258: } else {
259: MatConvert_MUMPS_Base(A,MATMPISBAIJ,MAT_REUSE_MATRIX,&A);
260: }
261: return(0);
262: }
266: PetscErrorCode MatFactorInfo_MUMPS(Mat A,PetscViewer viewer) {
267: Mat_MUMPS *lu=(Mat_MUMPS*)A->spptr;
271: PetscViewerASCIIPrintf(viewer,"MUMPS run parameters:\n");
272: PetscViewerASCIIPrintf(viewer," SYM (matrix type): %d \n",lu->id.sym);
273: PetscViewerASCIIPrintf(viewer," PAR (host participation): %d \n",lu->id.par);
274: PetscViewerASCIIPrintf(viewer," ICNTL(1) (output for error): %d \n",lu->id.ICNTL(1));
275: PetscViewerASCIIPrintf(viewer," ICNTL(2) (output of diagnostic msg):%d \n",lu->id.ICNTL(2));
276: PetscViewerASCIIPrintf(viewer," ICNTL(3) (output for global info): %d \n",lu->id.ICNTL(3));
277: PetscViewerASCIIPrintf(viewer," ICNTL(4) (level of printing): %d \n",lu->id.ICNTL(4));
278: PetscViewerASCIIPrintf(viewer," ICNTL(5) (input mat struct): %d \n",lu->id.ICNTL(5));
279: PetscViewerASCIIPrintf(viewer," ICNTL(6) (matrix prescaling): %d \n",lu->id.ICNTL(6));
280: PetscViewerASCIIPrintf(viewer," ICNTL(7) (matrix ordering): %d \n",lu->id.ICNTL(7));
281: PetscViewerASCIIPrintf(viewer," ICNTL(8) (scalling strategy): %d \n",lu->id.ICNTL(8));
282: PetscViewerASCIIPrintf(viewer," ICNTL(9) (A/A^T x=b is solved): %d \n",lu->id.ICNTL(9));
283: PetscViewerASCIIPrintf(viewer," ICNTL(10) (max num of refinements): %d \n",lu->id.ICNTL(10));
284: PetscViewerASCIIPrintf(viewer," ICNTL(11) (error analysis): %d \n",lu->id.ICNTL(11));
285: if (!lu->myid && lu->id.ICNTL(11)>0) {
286: PetscPrintf(PETSC_COMM_SELF," RINFOG(4) (inf norm of input mat): %g\n",lu->id.RINFOG(4));
287: PetscPrintf(PETSC_COMM_SELF," RINFOG(5) (inf norm of solution): %g\n",lu->id.RINFOG(5));
288: PetscPrintf(PETSC_COMM_SELF," RINFOG(6) (inf norm of residual): %g\n",lu->id.RINFOG(6));
289: PetscPrintf(PETSC_COMM_SELF," RINFOG(7),RINFOG(8) (backward error est): %g, %g\n",lu->id.RINFOG(7),lu->id.RINFOG(8));
290: PetscPrintf(PETSC_COMM_SELF," RINFOG(9) (error estimate): %g \n",lu->id.RINFOG(9));
291: PetscPrintf(PETSC_COMM_SELF," RINFOG(10),RINFOG(11)(condition numbers): %g, %g\n",lu->id.RINFOG(10),lu->id.RINFOG(11));
292:
293: }
294: PetscViewerASCIIPrintf(viewer," ICNTL(12) (efficiency control): %d \n",lu->id.ICNTL(12));
295: PetscViewerASCIIPrintf(viewer," ICNTL(13) (efficiency control): %d \n",lu->id.ICNTL(13));
296: PetscViewerASCIIPrintf(viewer," ICNTL(14) (percentage of estimated workspace increase): %d \n",lu->id.ICNTL(14));
297: /* ICNTL(15-17) not used */
298: PetscViewerASCIIPrintf(viewer," ICNTL(18) (input mat struct): %d \n",lu->id.ICNTL(18));
299: PetscViewerASCIIPrintf(viewer," ICNTL(19) (Shur complement info): %d \n",lu->id.ICNTL(19));
300: PetscViewerASCIIPrintf(viewer," ICNTL(20) (rhs sparse pattern): %d \n",lu->id.ICNTL(20));
301: PetscViewerASCIIPrintf(viewer," ICNTL(21) (solution struct): %d \n",lu->id.ICNTL(21));
303: PetscViewerASCIIPrintf(viewer," CNTL(1) (relative pivoting threshold): %g \n",lu->id.CNTL(1));
304: PetscViewerASCIIPrintf(viewer," CNTL(2) (stopping criterion of refinement): %g \n",lu->id.CNTL(2));
305: PetscViewerASCIIPrintf(viewer," CNTL(3) (absolute pivoting threshold): %g \n",lu->id.CNTL(3));
306: PetscViewerASCIIPrintf(viewer," CNTL(4) (value of static pivoting): %g \n",lu->id.CNTL(4));
308: /* infomation local to each processor */
309: if (!lu->myid) {PetscPrintf(PETSC_COMM_SELF, " RINFO(1) (local estimated flops for the elimination after analysis): \n");}
310: PetscSynchronizedPrintf(A->comm," [%d] %g \n",lu->myid,lu->id.RINFO(1));
311: PetscSynchronizedFlush(A->comm);
312: if (!lu->myid) {PetscPrintf(PETSC_COMM_SELF, " RINFO(2) (local estimated flops for the assembly after factorization): \n");}
313: PetscSynchronizedPrintf(A->comm," [%d] %g \n",lu->myid,lu->id.RINFO(2));
314: PetscSynchronizedFlush(A->comm);
315: if (!lu->myid) {PetscPrintf(PETSC_COMM_SELF, " RINFO(3) (local estimated flops for the elimination after factorization): \n");}
316: PetscSynchronizedPrintf(A->comm," [%d] %g \n",lu->myid,lu->id.RINFO(3));
317: PetscSynchronizedFlush(A->comm);
318: /*
319: if (!lu->myid) {PetscPrintf(PETSC_COMM_SELF, " INFO(2) (info about error or warning ): \n");}
320: PetscSynchronizedPrintf(A->comm," [%d] %d \n",lu->myid,lu->id.INFO(2));
321: PetscSynchronizedFlush(A->comm);
322: */
324: if (!lu->myid) {PetscPrintf(PETSC_COMM_SELF, " INFO(15) (estimated size of (in MB) MUMPS internal data for running numerical factorization): \n");}
325: PetscSynchronizedPrintf(A->comm," [%d] %d \n",lu->myid,lu->id.INFO(15));
326: PetscSynchronizedFlush(A->comm);
328: if (!lu->myid) {PetscPrintf(PETSC_COMM_SELF, " INFO(16) (size of (in MB) MUMPS internal data used during numerical factorization): \n");}
329: PetscSynchronizedPrintf(A->comm," [%d] %d \n",lu->myid,lu->id.INFO(16));
330: PetscSynchronizedFlush(A->comm);
332: if (!lu->myid) {PetscPrintf(PETSC_COMM_SELF, " INFO(23) (num of pivots eliminated on this processor after factorization): \n");}
333: PetscSynchronizedPrintf(A->comm," [%d] %d \n",lu->myid,lu->id.INFO(23));
334: PetscSynchronizedFlush(A->comm);
336: if (!lu->myid){ /* information from the host */
337: PetscViewerASCIIPrintf(viewer," RINFOG(1) (global estimated flops for the elimination after analysis): %g \n",lu->id.RINFOG(1));
338: PetscViewerASCIIPrintf(viewer," RINFOG(2) (global estimated flops for the assembly after factorization): %g \n",lu->id.RINFOG(2));
339: PetscViewerASCIIPrintf(viewer," RINFOG(3) (global estimated flops for the elimination after factorization): %g \n",lu->id.RINFOG(3));
341: PetscViewerASCIIPrintf(viewer," INFOG(3) (estimated real workspace for factors on all processors after analysis): %d \n",lu->id.INFOG(3));
342: PetscViewerASCIIPrintf(viewer," INFOG(4) (estimated integer workspace for factors on all processors after analysis): %d \n",lu->id.INFOG(4));
343: PetscViewerASCIIPrintf(viewer," INFOG(5) (estimated maximum front size in the complete tree): %d \n",lu->id.INFOG(5));
344: PetscViewerASCIIPrintf(viewer," INFOG(6) (number of nodes in the complete tree): %d \n",lu->id.INFOG(6));
345: PetscViewerASCIIPrintf(viewer," INFOG(7) (ordering option effectively uese after analysis): %d \n",lu->id.INFOG(7));
346: PetscViewerASCIIPrintf(viewer," INFOG(8) (structural symmetry in percent of the permuted matrix after analysis): %d \n",lu->id.INFOG(8));
347: PetscViewerASCIIPrintf(viewer," INFOG(9) (total real/complex workspace to store the matrix factors after factorization): %d \n",lu->id.INFOG(9));
348: PetscViewerASCIIPrintf(viewer," INFOG(10) (total integer space store the matrix factors after factorization): %d \n",lu->id.INFOG(10));
349: PetscViewerASCIIPrintf(viewer," INFOG(11) (order of largest frontal matrix after factorization): %d \n",lu->id.INFOG(11));
350: PetscViewerASCIIPrintf(viewer," INFOG(12) (number of off-diagonal pivots): %d \n",lu->id.INFOG(12));
351: PetscViewerASCIIPrintf(viewer," INFOG(13) (number of delayed pivots after factorization): %d \n",lu->id.INFOG(13));
352: PetscViewerASCIIPrintf(viewer," INFOG(14) (number of memory compress after factorization): %d \n",lu->id.INFOG(14));
353: PetscViewerASCIIPrintf(viewer," INFOG(15) (number of steps of iterative refinement after solution): %d \n",lu->id.INFOG(15));
354: PetscViewerASCIIPrintf(viewer," INFOG(16) (estimated size (in MB) of all MUMPS internal data for factorization after analysis: value on the most memory consuming processor): %d \n",lu->id.INFOG(16));
355: PetscViewerASCIIPrintf(viewer," INFOG(17) (estimated size of all MUMPS internal data for factorization after analysis: sum over all processors): %d \n",lu->id.INFOG(17));
356: PetscViewerASCIIPrintf(viewer," INFOG(18) (size of all MUMPS internal data allocated during factorization: value on the most memory consuming processor): %d \n",lu->id.INFOG(18));
357: PetscViewerASCIIPrintf(viewer," INFOG(19) (size of all MUMPS internal data allocated during factorization: sum over all processors): %d \n",lu->id.INFOG(19));
358: PetscViewerASCIIPrintf(viewer," INFOG(20) (estimated number of entries in the factors): %d \n",lu->id.INFOG(20));
359: PetscViewerASCIIPrintf(viewer," INFOG(21) (size in MB of memory effectively used during factorization - value on the most memory consuming processor): %d \n",lu->id.INFOG(21));
360: PetscViewerASCIIPrintf(viewer," INFOG(22) (size in MB of memory effectively used during factorization - sum over all processors): %d \n",lu->id.INFOG(22));
361: PetscViewerASCIIPrintf(viewer," INFOG(23) (after analysis: value of ICNTL(6) effectively used): %d \n",lu->id.INFOG(23));
362: PetscViewerASCIIPrintf(viewer," INFOG(24) (after analysis: value of ICNTL(12) effectively used): %d \n",lu->id.INFOG(24));
363: PetscViewerASCIIPrintf(viewer," INFOG(25) (after factorization: number of pivots modified by static pivoting): %d \n",lu->id.INFOG(25));
364: }
366: return(0);
367: }
371: PetscErrorCode MatView_MUMPS(Mat A,PetscViewer viewer) {
372: PetscErrorCode ierr;
373: PetscTruth iascii;
374: PetscViewerFormat format;
375: Mat_MUMPS *mumps=(Mat_MUMPS*)(A->spptr);
378: (*mumps->MatView)(A,viewer);
380: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
381: if (iascii) {
382: PetscViewerGetFormat(viewer,&format);
383: if (format == PETSC_VIEWER_ASCII_INFO){
384: MatFactorInfo_MUMPS(A,viewer);
385: }
386: }
387: return(0);
388: }
392: PetscErrorCode MatSolve_AIJMUMPS(Mat A,Vec b,Vec x) {
393: Mat_MUMPS *lu=(Mat_MUMPS*)A->spptr;
394: PetscScalar *array;
395: Vec x_seq;
396: IS is_iden,is_petsc;
397: VecScatter scat_rhs=lu->scat_rhs,scat_sol=lu->scat_sol;
399: PetscInt i;
402: lu->id.nrhs = 1;
403: x_seq = lu->b_seq;
404: if (lu->size > 1){
405: /* MUMPS only supports centralized rhs. Scatter b into a seqential rhs vector */
406: VecScatterBegin(b,x_seq,INSERT_VALUES,SCATTER_FORWARD,scat_rhs);
407: VecScatterEnd(b,x_seq,INSERT_VALUES,SCATTER_FORWARD,scat_rhs);
408: if (!lu->myid) {VecGetArray(x_seq,&array);}
409: } else { /* size == 1 */
410: VecCopy(b,x);
411: VecGetArray(x,&array);
412: }
413: if (!lu->myid) { /* define rhs on the host */
414: #if defined(PETSC_USE_COMPLEX)
415: lu->id.rhs = (mumps_double_complex*)array;
416: #else
417: lu->id.rhs = array;
418: #endif
419: }
420: if (lu->size == 1){
421: VecRestoreArray(x,&array);
422: } else if (!lu->myid){
423: VecRestoreArray(x_seq,&array);
424: }
426: if (lu->size > 1){
427: /* distributed solution */
428: lu->id.ICNTL(21) = 1;
429: if (!lu->nSolve){
430: /* Create x_seq=sol_loc for repeated use */
431: PetscInt lsol_loc;
432: PetscScalar *sol_loc;
433: lsol_loc = lu->id.INFO(23); /* length of sol_loc */
434: PetscMalloc((1+lsol_loc)*(sizeof(PetscScalar)+sizeof(PetscInt)),&sol_loc);
435: lu->id.isol_loc = (PetscInt *)(sol_loc + lsol_loc);
436: lu->id.lsol_loc = lsol_loc;
437: lu->id.sol_loc = (F_DOUBLE *)sol_loc;
438: VecCreateSeqWithArray(PETSC_COMM_SELF,lsol_loc,sol_loc,&lu->x_seq);
439: }
440: }
442: /* solve phase */
443: /*-------------*/
444: lu->id.job = 3;
445: #if defined(PETSC_USE_COMPLEX)
446: zmumps_c(&lu->id);
447: #else
448: dmumps_c(&lu->id);
449: #endif
450: if (lu->id.INFOG(1) < 0) {
451: SETERRQ1(PETSC_ERR_LIB,"Error reported by MUMPS in solve phase: INFOG(1)=%d\n",lu->id.INFOG(1));
452: }
454: if (lu->size > 1) { /* convert mumps distributed solution to petsc mpi x */
455: if (!lu->nSolve){ /* create scatter scat_sol */
456: ISCreateStride(PETSC_COMM_SELF,lu->id.lsol_loc,0,1,&is_iden); /* from */
457: for (i=0; i<lu->id.lsol_loc; i++){
458: lu->id.isol_loc[i] -= 1; /* change Fortran style to C style */
459: }
460: ISCreateGeneral(PETSC_COMM_SELF,lu->id.lsol_loc,lu->id.isol_loc,&is_petsc); /* to */
461: VecScatterCreate(lu->x_seq,is_iden,x,is_petsc,&lu->scat_sol);
462: ISDestroy(is_iden);
463: ISDestroy(is_petsc);
464: }
465: VecScatterBegin(lu->x_seq,x,INSERT_VALUES,SCATTER_FORWARD,lu->scat_sol);
466: VecScatterEnd(lu->x_seq,x,INSERT_VALUES,SCATTER_FORWARD,lu->scat_sol);
467: }
468: lu->nSolve++;
469: return(0);
470: }
472: /*
473: input:
474: F: numeric factor
475: output:
476: nneg: total number of negative pivots
477: nzero: 0
478: npos: (global dimension of F) - nneg
479: */
483: PetscErrorCode MatGetInertia_SBAIJMUMPS(Mat F,int *nneg,int *nzero,int *npos)
484: {
485: Mat_MUMPS *lu =(Mat_MUMPS*)F->spptr;
487: PetscMPIInt size;
490: MPI_Comm_size(F->comm,&size);
491: /* MUMPS 4.3.1 calls ScaLAPACK when ICNTL(13)=0 (default), which does not offer the possibility to compute the inertia of a dense matrix. Set ICNTL(13)=1 to skip ScaLAPACK */
492: if (size > 1 && lu->id.ICNTL(13) != 1){
493: SETERRQ1(PETSC_ERR_ARG_WRONG,"ICNTL(13)=%d. -mat_mumps_icntl_13 must be set as 1 for correct global matrix inertia\n",lu->id.INFOG(13));
494: }
495: if (nneg){
496: if (!lu->myid){
497: *nneg = lu->id.INFOG(12);
498: }
499: MPI_Bcast(nneg,1,MPI_INT,0,lu->comm_mumps);
500: }
501: if (nzero) *nzero = 0;
502: if (npos) *npos = F->rmap.N - (*nneg);
503: return(0);
504: }
508: PetscErrorCode MatFactorNumeric_AIJMUMPS(Mat A,MatFactorInfo *info,Mat *F)
509: {
510: Mat_MUMPS *lu =(Mat_MUMPS*)(*F)->spptr;
511: Mat_MUMPS *lua=(Mat_MUMPS*)(A)->spptr;
513: PetscInt rnz,nnz,nz=0,i,M=A->rmap.N,*ai,*aj,icntl;
514: PetscTruth valOnly,flg;
515: Mat F_diag;
518: if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){
519: (*F)->ops->solve = MatSolve_AIJMUMPS;
521: /* Initialize a MUMPS instance */
522: MPI_Comm_rank(A->comm, &lu->myid);
523: MPI_Comm_size(A->comm,&lu->size);
524: lua->myid = lu->myid; lua->size = lu->size;
525: lu->id.job = JOB_INIT;
526: MPI_Comm_dup(A->comm,&(lu->comm_mumps));
527: MPICCommToFortranComm(lu->comm_mumps,&(lu->id.comm_fortran));
529: /* Set mumps options */
530: PetscOptionsBegin(A->comm,A->prefix,"MUMPS Options","Mat");
531: lu->id.par=1; /* host participates factorizaton and solve */
532: lu->id.sym=lu->sym;
533: if (lu->sym == 2){
534: PetscOptionsInt("-mat_mumps_sym","SYM: (1,2)","None",lu->id.sym,&icntl,&flg);
535: if (flg && icntl == 1) lu->id.sym=icntl; /* matrix is spd */
536: }
537: #if defined(PETSC_USE_COMPLEX)
538: zmumps_c(&lu->id);
539: #else
540: dmumps_c(&lu->id);
541: #endif
542:
543: if (lu->size == 1){
544: lu->id.ICNTL(18) = 0; /* centralized assembled matrix input */
545: } else {
546: lu->id.ICNTL(18) = 3; /* distributed assembled matrix input */
547: }
549: icntl=-1;
550: PetscOptionsInt("-mat_mumps_icntl_4","ICNTL(4): level of printing (0 to 4)","None",lu->id.ICNTL(4),&icntl,&flg);
551: if ((flg && icntl > 0) || PetscLogPrintInfo) {
552: lu->id.ICNTL(4)=icntl; /* and use mumps default icntl(i), i=1,2,3 */
553: } else { /* no output */
554: lu->id.ICNTL(1) = 0; /* error message, default= 6 */
555: lu->id.ICNTL(2) = -1; /* output stream for diagnostic printing, statistics, and warning. default=0 */
556: lu->id.ICNTL(3) = -1; /* output stream for global information, default=6 */
557: lu->id.ICNTL(4) = 0; /* level of printing, 0,1,2,3,4, default=2 */
558: }
559: PetscOptionsInt("-mat_mumps_icntl_6","ICNTL(6): matrix prescaling (0 to 7)","None",lu->id.ICNTL(6),&lu->id.ICNTL(6),PETSC_NULL);
560: icntl=-1;
561: PetscOptionsInt("-mat_mumps_icntl_7","ICNTL(7): matrix ordering (0 to 7)","None",lu->id.ICNTL(7),&icntl,&flg);
562: if (flg) {
563: if (icntl== 1){
564: SETERRQ(PETSC_ERR_SUP,"pivot order be set by the user in PERM_IN -- not supported by the PETSc/MUMPS interface\n");
565: } else {
566: lu->id.ICNTL(7) = icntl;
567: }
568: }
569: PetscOptionsInt("-mat_mumps_icntl_9","ICNTL(9): A or A^T x=b to be solved. 1: A; otherwise: A^T","None",lu->id.ICNTL(9),&lu->id.ICNTL(9),PETSC_NULL);
570: PetscOptionsInt("-mat_mumps_icntl_10","ICNTL(10): max num of refinements","None",lu->id.ICNTL(10),&lu->id.ICNTL(10),PETSC_NULL);
571: PetscOptionsInt("-mat_mumps_icntl_11","ICNTL(11): error analysis, a positive value returns statistics (by -ksp_view)","None",lu->id.ICNTL(11),&lu->id.ICNTL(11),PETSC_NULL);
572: PetscOptionsInt("-mat_mumps_icntl_12","ICNTL(12): efficiency control","None",lu->id.ICNTL(12),&lu->id.ICNTL(12),PETSC_NULL);
573: PetscOptionsInt("-mat_mumps_icntl_13","ICNTL(13): efficiency control","None",lu->id.ICNTL(13),&lu->id.ICNTL(13),PETSC_NULL);
574: PetscOptionsInt("-mat_mumps_icntl_14","ICNTL(14): percentage of estimated workspace increase","None",lu->id.ICNTL(14),&lu->id.ICNTL(14),PETSC_NULL);
575: PetscOptionsInt("-mat_mumps_icntl_15","ICNTL(15): efficiency control","None",lu->id.ICNTL(15),&lu->id.ICNTL(15),PETSC_NULL);
577: PetscOptionsReal("-mat_mumps_cntl_1","CNTL(1): relative pivoting threshold","None",lu->id.CNTL(1),&lu->id.CNTL(1),PETSC_NULL);
578: PetscOptionsReal("-mat_mumps_cntl_2","CNTL(2): stopping criterion of refinement","None",lu->id.CNTL(2),&lu->id.CNTL(2),PETSC_NULL);
579: PetscOptionsReal("-mat_mumps_cntl_3","CNTL(3): absolute pivoting threshold","None",lu->id.CNTL(3),&lu->id.CNTL(3),PETSC_NULL);
580: PetscOptionsEnd();
581: }
583: /* define matrix A */
584: switch (lu->id.ICNTL(18)){
585: case 0: /* centralized assembled matrix input (size=1) */
586: if (!lu->myid) {
587: if (lua->isAIJ){
588: Mat_SeqAIJ *aa = (Mat_SeqAIJ*)A->data;
589: nz = aa->nz;
590: ai = aa->i; aj = aa->j; lu->val = aa->a;
591: } else {
592: Mat_SeqSBAIJ *aa = (Mat_SeqSBAIJ*)A->data;
593: nz = aa->nz;
594: ai = aa->i; aj = aa->j; lu->val = aa->a;
595: }
596: if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){ /* first numeric factorization, get irn and jcn */
597: PetscMalloc(nz*sizeof(PetscInt),&lu->irn);
598: PetscMalloc(nz*sizeof(PetscInt),&lu->jcn);
599: nz = 0;
600: for (i=0; i<M; i++){
601: rnz = ai[i+1] - ai[i];
602: while (rnz--) { /* Fortran row/col index! */
603: lu->irn[nz] = i+1; lu->jcn[nz] = (*aj)+1; aj++; nz++;
604: }
605: }
606: }
607: }
608: break;
609: case 3: /* distributed assembled matrix input (size>1) */
610: if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){
611: valOnly = PETSC_FALSE;
612: } else {
613: valOnly = PETSC_TRUE; /* only update mat values, not row and col index */
614: }
615: MatConvertToTriples(A,1,valOnly, &nnz, &lu->irn, &lu->jcn, &lu->val);
616: break;
617: default: SETERRQ(PETSC_ERR_SUP,"Matrix input format is not supported by MUMPS.");
618: }
620: /* analysis phase */
621: /*----------------*/
622: if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){
623: lu->id.job = 1;
625: lu->id.n = M;
626: switch (lu->id.ICNTL(18)){
627: case 0: /* centralized assembled matrix input */
628: if (!lu->myid) {
629: lu->id.nz =nz; lu->id.irn=lu->irn; lu->id.jcn=lu->jcn;
630: if (lu->id.ICNTL(6)>1){
631: #if defined(PETSC_USE_COMPLEX)
632: lu->id.a = (mumps_double_complex*)lu->val;
633: #else
634: lu->id.a = lu->val;
635: #endif
636: }
637: }
638: break;
639: case 3: /* distributed assembled matrix input (size>1) */
640: lu->id.nz_loc = nnz;
641: lu->id.irn_loc=lu->irn; lu->id.jcn_loc=lu->jcn;
642: if (lu->id.ICNTL(6)>1) {
643: #if defined(PETSC_USE_COMPLEX)
644: lu->id.a_loc = (mumps_double_complex*)lu->val;
645: #else
646: lu->id.a_loc = lu->val;
647: #endif
648: }
649: /* MUMPS only supports centralized rhs. Create scatter scat_rhs for repeated use in MatSolve() */
650: IS is_iden;
651: Vec b;
652: if (!lu->myid){
653: VecCreateSeq(PETSC_COMM_SELF,A->cmap.N,&lu->b_seq);
654: ISCreateStride(PETSC_COMM_SELF,A->cmap.N,0,1,&is_iden);
655: } else {
656: VecCreateSeq(PETSC_COMM_SELF,0,&lu->b_seq);
657: ISCreateStride(PETSC_COMM_SELF,0,0,1,&is_iden);
658: }
659: VecCreate(A->comm,&b);
660: VecSetSizes(b,A->rmap.n,PETSC_DECIDE);
661: VecSetFromOptions(b);
663: VecScatterCreate(b,is_iden,lu->b_seq,is_iden,&lu->scat_rhs);
664: ISDestroy(is_iden);
665: VecDestroy(b);
666: break;
667: }
668: #if defined(PETSC_USE_COMPLEX)
669: zmumps_c(&lu->id);
670: #else
671: dmumps_c(&lu->id);
672: #endif
673: if (lu->id.INFOG(1) < 0) {
674: SETERRQ1(PETSC_ERR_LIB,"Error reported by MUMPS in analysis phase: INFOG(1)=%d\n",lu->id.INFOG(1));
675: }
676: }
678: /* numerical factorization phase */
679: /*-------------------------------*/
680: lu->id.job = 2;
681: if(!lu->id.ICNTL(18)) {
682: if (!lu->myid) {
683: #if defined(PETSC_USE_COMPLEX)
684: lu->id.a = (mumps_double_complex*)lu->val;
685: #else
686: lu->id.a = lu->val;
687: #endif
688: }
689: } else {
690: #if defined(PETSC_USE_COMPLEX)
691: lu->id.a_loc = (mumps_double_complex*)lu->val;
692: #else
693: lu->id.a_loc = lu->val;
694: #endif
695: }
696: #if defined(PETSC_USE_COMPLEX)
697: zmumps_c(&lu->id);
698: #else
699: dmumps_c(&lu->id);
700: #endif
701: if (lu->id.INFOG(1) < 0) {
702: if (lu->id.INFO(1) == -13) {
703: SETERRQ1(PETSC_ERR_LIB,"Error reported by MUMPS in numerical factorization phase: Cannot allocate required memory %d megabytes\n",lu->id.INFO(2));
704: } else {
705: SETERRQ2(PETSC_ERR_LIB,"Error reported by MUMPS in numerical factorization phase: INFO(1)=%d, INFO(2)=%d\n",lu->id.INFO(1),lu->id.INFO(2));
706: }
707: }
709: if (!lu->myid && lu->id.ICNTL(16) > 0){
710: SETERRQ1(PETSC_ERR_LIB," lu->id.ICNTL(16):=%d\n",lu->id.INFOG(16));
711: }
713: if (lu->size > 1){
714: if ((*F)->factor == FACTOR_LU){
715: F_diag = ((Mat_MPIAIJ *)(*F)->data)->A;
716: } else {
717: F_diag = ((Mat_MPISBAIJ *)(*F)->data)->A;
718: }
719: F_diag->assembled = PETSC_TRUE;
720: if (lu->nSolve){
721: VecScatterDestroy(lu->scat_sol);
722: PetscFree(lu->id.sol_loc);
723: VecDestroy(lu->x_seq);
724: }
725: }
726: (*F)->assembled = PETSC_TRUE;
727: lu->matstruc = SAME_NONZERO_PATTERN;
728: lu->CleanUpMUMPS = PETSC_TRUE;
729: lu->nSolve = 0;
730: return(0);
731: }
733: /* Note the Petsc r and c permutations are ignored */
736: PetscErrorCode MatLUFactorSymbolic_AIJMUMPS(Mat A,IS r,IS c,MatFactorInfo *info,Mat *F) {
737: Mat B;
738: Mat_MUMPS *lu;
742: /* Create the factorization matrix */
743: MatCreate(A->comm,&B);
744: MatSetSizes(B,A->rmap.n,A->cmap.n,A->rmap.N,A->cmap.N);
745: MatSetType(B,A->type_name);
746: MatSeqAIJSetPreallocation(B,0,PETSC_NULL);
747: MatMPIAIJSetPreallocation(B,0,PETSC_NULL,0,PETSC_NULL);
749: B->ops->lufactornumeric = MatFactorNumeric_AIJMUMPS;
750: B->factor = FACTOR_LU;
751: lu = (Mat_MUMPS*)B->spptr;
752: lu->sym = 0;
753: lu->matstruc = DIFFERENT_NONZERO_PATTERN;
755: *F = B;
756: return(0);
757: }
759: /* Note the Petsc r permutation is ignored */
762: PetscErrorCode MatCholeskyFactorSymbolic_SBAIJMUMPS(Mat A,IS r,MatFactorInfo *info,Mat *F) {
763: Mat B;
764: Mat_MUMPS *lu;
768: /* Create the factorization matrix */
769: MatCreate(A->comm,&B);
770: MatSetSizes(B,A->rmap.n,A->cmap.n,A->rmap.N,A->cmap.N);
771: MatSetType(B,A->type_name);
772: MatSeqSBAIJSetPreallocation(B,1,0,PETSC_NULL);
773: MatMPISBAIJSetPreallocation(B,1,0,PETSC_NULL,0,PETSC_NULL);
775: B->ops->choleskyfactornumeric = MatFactorNumeric_AIJMUMPS;
776: B->ops->getinertia = MatGetInertia_SBAIJMUMPS;
777: B->factor = FACTOR_CHOLESKY;
778: lu = (Mat_MUMPS*)B->spptr;
779: lu->sym = 2;
780: lu->matstruc = DIFFERENT_NONZERO_PATTERN;
782: *F = B;
783: return(0);
784: }
788: PetscErrorCode MatAssemblyEnd_AIJMUMPS(Mat A,MatAssemblyType mode) {
790: Mat_MUMPS *mumps=(Mat_MUMPS*)A->spptr;
793: (*mumps->MatAssemblyEnd)(A,mode);
795: mumps->MatLUFactorSymbolic = A->ops->lufactorsymbolic;
796: mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
797: A->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJMUMPS;
798: return(0);
799: }
804: PetscErrorCode MatConvert_AIJ_AIJMUMPS(Mat A,MatType newtype,MatReuse reuse,Mat *newmat)
805: {
807: PetscMPIInt size;
808: MPI_Comm comm;
809: Mat B=*newmat;
810: Mat_MUMPS *mumps;
813: if (reuse == MAT_INITIAL_MATRIX) {
814: MatDuplicate(A,MAT_COPY_VALUES,&B);
815: }
817: PetscObjectGetComm((PetscObject)A,&comm);
818: PetscNew(Mat_MUMPS,&mumps);
820: mumps->MatDuplicate = A->ops->duplicate;
821: mumps->MatView = A->ops->view;
822: mumps->MatAssemblyEnd = A->ops->assemblyend;
823: mumps->MatLUFactorSymbolic = A->ops->lufactorsymbolic;
824: mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
825: mumps->MatDestroy = A->ops->destroy;
826: mumps->specialdestroy = MatDestroy_AIJMUMPS;
827: mumps->CleanUpMUMPS = PETSC_FALSE;
828: mumps->isAIJ = PETSC_TRUE;
830: B->spptr = (void*)mumps;
831: B->ops->duplicate = MatDuplicate_MUMPS;
832: B->ops->view = MatView_MUMPS;
833: B->ops->assemblyend = MatAssemblyEnd_AIJMUMPS;
834: B->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJMUMPS;
835: B->ops->destroy = MatDestroy_MUMPS;
837: MPI_Comm_size(comm,&size);
838: if (size == 1) {
839: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_seqaij_aijmumps_C",
840: "MatConvert_AIJ_AIJMUMPS",MatConvert_AIJ_AIJMUMPS);
841: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_aijmumps_seqaij_C",
842: "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);
843: } else {
844: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_mpiaij_aijmumps_C",
845: "MatConvert_AIJ_AIJMUMPS",MatConvert_AIJ_AIJMUMPS);
846: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_aijmumps_mpiaij_C",
847: "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);
848: }
850: PetscInfo(0,"Using MUMPS for LU factorization and solves.\n");
851: PetscObjectChangeTypeName((PetscObject)B,newtype);
852: *newmat = B;
853: return(0);
854: }
857: /*MC
858: MATAIJMUMPS - MATAIJMUMPS = "aijmumps" - A matrix type providing direct solvers (LU) for distributed
859: and sequential matrices via the external package MUMPS.
861: If MUMPS is installed (see the manual for instructions
862: on how to declare the existence of external packages),
863: a matrix type can be constructed which invokes MUMPS solvers.
864: After calling MatCreate(...,A), simply call MatSetType(A,MATAIJMUMPS).
866: If created with a single process communicator, this matrix type inherits from MATSEQAIJ.
867: Otherwise, this matrix type inherits from MATMPIAIJ. Hence for single process communicators,
868: MatSeqAIJSetPreallocation is supported, and similarly MatMPIAIJSetPreallocation is supported
869: for communicators controlling multiple processes. It is recommended that you call both of
870: the above preallocation routines for simplicity. One can also call MatConvert for an inplace
871: conversion to or from the MATSEQAIJ or MATMPIAIJ type (depending on the communicator size)
872: without data copy.
874: Options Database Keys:
875: + -mat_type aijmumps - sets the matrix type to "aijmumps" during a call to MatSetFromOptions()
876: . -mat_mumps_sym <0,1,2> - 0 the matrix is unsymmetric, 1 symmetric positive definite, 2 symmetric
877: . -mat_mumps_icntl_4 <0,1,2,3,4> - print level
878: . -mat_mumps_icntl_6 <0,...,7> - matrix prescaling options (see MUMPS User's Guide)
879: . -mat_mumps_icntl_7 <0,...,7> - matrix orderings (see MUMPS User's Guide)
880: . -mat_mumps_icntl_9 <1,2> - A or A^T x=b to be solved: 1 denotes A, 2 denotes A^T
881: . -mat_mumps_icntl_10 <n> - maximum number of iterative refinements
882: . -mat_mumps_icntl_11 <n> - error analysis, a positive value returns statistics during -ksp_view
883: . -mat_mumps_icntl_12 <n> - efficiency control (see MUMPS User's Guide)
884: . -mat_mumps_icntl_13 <n> - efficiency control (see MUMPS User's Guide)
885: . -mat_mumps_icntl_14 <n> - efficiency control (see MUMPS User's Guide)
886: . -mat_mumps_icntl_15 <n> - efficiency control (see MUMPS User's Guide)
887: . -mat_mumps_cntl_1 <delta> - relative pivoting threshold
888: . -mat_mumps_cntl_2 <tol> - stopping criterion for refinement
889: - -mat_mumps_cntl_3 <adelta> - absolute pivoting threshold
891: Level: beginner
893: .seealso: MATSBAIJMUMPS
894: M*/
899: PetscErrorCode MatCreate_AIJMUMPS(Mat A)
900: {
902: PetscMPIInt size;
903:
905: MPI_Comm_size(A->comm,&size);
906: if (size == 1) {
907: MatSetType(A,MATSEQAIJ);
908: } else {
909: MatSetType(A,MATMPIAIJ);
910: /*
911: Mat A_diag = ((Mat_MPIAIJ *)A->data)->A;
912: MatConvert_AIJ_AIJMUMPS(A_diag,MATAIJMUMPS,MAT_REUSE_MATRIX,&A_diag);
913: */
914: }
915: MatConvert_AIJ_AIJMUMPS(A,MATAIJMUMPS,MAT_REUSE_MATRIX,&A);
916: return(0);
917: }
922: PetscErrorCode MatAssemblyEnd_SBAIJMUMPS(Mat A,MatAssemblyType mode)
923: {
925: Mat_MUMPS *mumps=(Mat_MUMPS*)A->spptr;
928: (*mumps->MatAssemblyEnd)(A,mode);
929: mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
930: A->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SBAIJMUMPS;
931: return(0);
932: }
937: PetscErrorCode MatMPISBAIJSetPreallocation_MPISBAIJMUMPS(Mat B,PetscInt bs,PetscInt d_nz,PetscInt *d_nnz,PetscInt o_nz,PetscInt *o_nnz)
938: {
939: Mat A;
940: Mat_MUMPS *mumps=(Mat_MUMPS*)B->spptr;
944: /*
945: After performing the MPISBAIJ Preallocation, we need to convert the local diagonal block matrix
946: into MUMPS type so that the block jacobi preconditioner (for example) can use MUMPS. I would
947: like this to be done in the MatCreate routine, but the creation of this inner matrix requires
948: block size info so that PETSc can determine the local size properly. The block size info is set
949: in the preallocation routine.
950: */
951: (*mumps->MatPreallocate)(B,bs,d_nz,d_nnz,o_nz,o_nnz);
952: A = ((Mat_MPISBAIJ *)B->data)->A;
953: MatConvert_SBAIJ_SBAIJMUMPS(A,MATSBAIJMUMPS,MAT_REUSE_MATRIX,&A);
954: return(0);
955: }
961: PetscErrorCode MatConvert_SBAIJ_SBAIJMUMPS(Mat A,MatType newtype,MatReuse reuse,Mat *newmat)
962: {
964: PetscMPIInt size;
965: MPI_Comm comm;
966: Mat B=*newmat;
967: Mat_MUMPS *mumps;
968: void (*f)(void);
971: if (reuse == MAT_INITIAL_MATRIX) {
972: MatDuplicate(A,MAT_COPY_VALUES,&B);
973: }
975: PetscObjectGetComm((PetscObject)A,&comm);
976: PetscNew(Mat_MUMPS,&mumps);
978: mumps->MatDuplicate = A->ops->duplicate;
979: mumps->MatView = A->ops->view;
980: mumps->MatAssemblyEnd = A->ops->assemblyend;
981: mumps->MatLUFactorSymbolic = A->ops->lufactorsymbolic;
982: mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
983: mumps->MatDestroy = A->ops->destroy;
984: mumps->specialdestroy = MatDestroy_SBAIJMUMPS;
985: mumps->CleanUpMUMPS = PETSC_FALSE;
986: mumps->isAIJ = PETSC_FALSE;
987:
988: B->spptr = (void*)mumps;
989: B->ops->duplicate = MatDuplicate_MUMPS;
990: B->ops->view = MatView_MUMPS;
991: B->ops->assemblyend = MatAssemblyEnd_SBAIJMUMPS;
992: B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SBAIJMUMPS;
993: B->ops->destroy = MatDestroy_MUMPS;
995: MPI_Comm_size(comm,&size);
996: if (size == 1) {
997: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_seqsbaij_sbaijmumps_C",
998: "MatConvert_SBAIJ_SBAIJMUMPS",MatConvert_SBAIJ_SBAIJMUMPS);
999: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_sbaijmumps_seqsbaij_C",
1000: "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);
1001: } else {
1002: /* I really don't like needing to know the tag: MatMPISBAIJSetPreallocation_C */
1003: PetscObjectQueryFunction((PetscObject)B,"MatMPISBAIJSetPreallocation_C",(PetscVoidStarFunction)&f);
1004: if (f) { /* This case should always be true when this routine is called */
1005: mumps->MatPreallocate = (PetscErrorCode (*)(Mat,int,int,int*,int,int*))f;
1006: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatMPISBAIJSetPreallocation_C",
1007: "MatMPISBAIJSetPreallocation_MPISBAIJMUMPS",
1008: MatMPISBAIJSetPreallocation_MPISBAIJMUMPS);
1009: }
1010: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_mpisbaij_sbaijmumps_C",
1011: "MatConvert_SBAIJ_SBAIJMUMPS",MatConvert_SBAIJ_SBAIJMUMPS);
1012: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_sbaijmumps_mpisbaij_C",
1013: "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);
1014: }
1016: PetscInfo(0,"Using MUMPS for Cholesky factorization and solves.\n");
1017: PetscObjectChangeTypeName((PetscObject)B,newtype);
1018: *newmat = B;
1019: return(0);
1020: }
1025: PetscErrorCode MatDuplicate_MUMPS(Mat A, MatDuplicateOption op, Mat *M) {
1027: Mat_MUMPS *lu=(Mat_MUMPS *)A->spptr;
1030: (*lu->MatDuplicate)(A,op,M);
1031: PetscMemcpy((*M)->spptr,lu,sizeof(Mat_MUMPS));
1032: return(0);
1033: }
1035: /*MC
1036: MATSBAIJMUMPS - MATSBAIJMUMPS = "sbaijmumps" - A symmetric matrix type providing direct solvers (Cholesky) for
1037: distributed and sequential matrices via the external package MUMPS.
1039: If MUMPS is installed (see the manual for instructions
1040: on how to declare the existence of external packages),
1041: a matrix type can be constructed which invokes MUMPS solvers.
1042: After calling MatCreate(...,A), simply call MatSetType(A,MATSBAIJMUMPS).
1044: If created with a single process communicator, this matrix type inherits from MATSEQSBAIJ.
1045: Otherwise, this matrix type inherits from MATMPISBAIJ. Hence for single process communicators,
1046: MatSeqSBAIJSetPreallocation is supported, and similarly MatMPISBAIJSetPreallocation is supported
1047: for communicators controlling multiple processes. It is recommended that you call both of
1048: the above preallocation routines for simplicity. One can also call MatConvert for an inplace
1049: conversion to or from the MATSEQSBAIJ or MATMPISBAIJ type (depending on the communicator size)
1050: without data copy.
1052: Options Database Keys:
1053: + -mat_type sbaijmumps - sets the matrix type to "sbaijmumps" during a call to MatSetFromOptions()
1054: . -mat_mumps_sym <0,1,2> - 0 the matrix is unsymmetric, 1 symmetric positive definite, 2 symmetric
1055: . -mat_mumps_icntl_4 <0,...,4> - print level
1056: . -mat_mumps_icntl_6 <0,...,7> - matrix prescaling options (see MUMPS User's Guide)
1057: . -mat_mumps_icntl_7 <0,...,7> - matrix orderings (see MUMPS User's Guide)
1058: . -mat_mumps_icntl_9 <1,2> - A or A^T x=b to be solved: 1 denotes A, 2 denotes A^T
1059: . -mat_mumps_icntl_10 <n> - maximum number of iterative refinements
1060: . -mat_mumps_icntl_11 <n> - error analysis, a positive value returns statistics during -ksp_view
1061: . -mat_mumps_icntl_12 <n> - efficiency control (see MUMPS User's Guide)
1062: . -mat_mumps_icntl_13 <n> - efficiency control (see MUMPS User's Guide)
1063: . -mat_mumps_icntl_14 <n> - efficiency control (see MUMPS User's Guide)
1064: . -mat_mumps_icntl_15 <n> - efficiency control (see MUMPS User's Guide)
1065: . -mat_mumps_cntl_1 <delta> - relative pivoting threshold
1066: . -mat_mumps_cntl_2 <tol> - stopping criterion for refinement
1067: - -mat_mumps_cntl_3 <adelta> - absolute pivoting threshold
1069: Level: beginner
1071: .seealso: MATAIJMUMPS
1072: M*/
1077: PetscErrorCode MatCreate_SBAIJMUMPS(Mat A)
1078: {
1080: PetscMPIInt size;
1083: MPI_Comm_size(A->comm,&size);
1084: if (size == 1) {
1085: MatSetType(A,MATSEQSBAIJ);
1086: } else {
1087: MatSetType(A,MATMPISBAIJ);
1088: }
1089: MatConvert_SBAIJ_SBAIJMUMPS(A,MATSBAIJMUMPS,MAT_REUSE_MATRIX,&A);
1090: return(0);
1091: }