Actual source code: mumps.c
1: /*$Id: mumps.c,v 1.10 2001/08/15 15:56:50 bsmith Exp $*/
2: /*
3: Provides an interface to the MUMPS_4.3 sparse solver
4: */
5: #include src/mat/impls/aij/seq/aij.h
6: #include src/mat/impls/aij/mpi/mpiaij.h
7: #include src/mat/impls/sbaij/seq/sbaij.h
8: #include src/mat/impls/sbaij/mpi/mpisbaij.h
10: EXTERN_C_BEGIN
11: #if defined(PETSC_USE_COMPLEX)
12: #include "zmumps_c.h"
13: #else
14: #include "dmumps_c.h"
15: #endif
16: EXTERN_C_END
17: #define JOB_INIT -1
18: #define JOB_END -2
19: /* macros s.t. indices match MUMPS documentation */
20: #define ICNTL(I) icntl[(I)-1]
21: #define CNTL(I) cntl[(I)-1]
22: #define INFOG(I) infog[(I)-1]
23: #define RINFOG(I) rinfog[(I)-1]
25: typedef struct {
26: #if defined(PETSC_USE_COMPLEX)
27: ZMUMPS_STRUC_C id;
28: #else
29: DMUMPS_STRUC_C id;
30: #endif
31: MatStructure matstruc;
32: int myid,size,*irn,*jcn,sym;
33: PetscScalar *val;
34: MPI_Comm comm_mumps;
36: MatType basetype;
37: PetscTruth isAIJ,CleanUpMUMPS;
38: int (*MatDuplicate)(Mat,MatDuplicateOption,Mat*);
39: int (*MatView)(Mat,PetscViewer);
40: int (*MatAssemblyEnd)(Mat,MatAssemblyType);
41: int (*MatLUFactorSymbolic)(Mat,IS,IS,MatFactorInfo*,Mat*);
42: int (*MatCholeskyFactorSymbolic)(Mat,IS,MatFactorInfo*,Mat*);
43: int (*MatDestroy)(Mat);
44: } Mat_MUMPS;
46: EXTERN int MatDuplicate_AIJMUMPS(Mat,MatDuplicateOption,Mat*);
47: EXTERN int MatDuplicate_SBAIJMUMPS(Mat,MatDuplicateOption,Mat*);
49: /* convert Petsc mpiaij matrix to triples: row[nz], col[nz], val[nz] */
50: /*
51: input:
52: A - matrix in mpiaij or mpisbaij (bs=1) format
53: shift - 0: C style output triple; 1: Fortran style output triple.
54: valOnly - FALSE: spaces are allocated and values are set for the triple
55: TRUE: only the values in v array are updated
56: output:
57: nnz - dim of r, c, and v (number of local nonzero entries of A)
58: r, c, v - row and col index, matrix values (matrix triples)
59: */
60: int MatConvertToTriples(Mat A,int shift,PetscTruth valOnly,int *nnz,int **r, int **c, PetscScalar **v) {
61: int *ai, *aj, *bi, *bj, rstart,nz, *garray;
62: int ierr,i,j,jj,jB,irow,m=A->m,*ajj,*bjj,countA,countB,colA_start,jcol;
63: int *row,*col;
64: PetscScalar *av, *bv,*val;
65: Mat_MUMPS *mumps=(Mat_MUMPS*)A->spptr;
68: if (mumps->isAIJ){
69: Mat_MPIAIJ *mat = (Mat_MPIAIJ*)A->data;
70: Mat_SeqAIJ *aa=(Mat_SeqAIJ*)(mat->A)->data;
71: Mat_SeqAIJ *bb=(Mat_SeqAIJ*)(mat->B)->data;
72: nz = aa->nz + bb->nz;
73: ai=aa->i; aj=aa->j; bi=bb->i; bj=bb->j; rstart= mat->rstart;
74: garray = mat->garray;
75: av=aa->a; bv=bb->a;
76:
77: } else {
78: Mat_MPISBAIJ *mat = (Mat_MPISBAIJ*)A->data;
79: Mat_SeqSBAIJ *aa=(Mat_SeqSBAIJ*)(mat->A)->data;
80: Mat_SeqBAIJ *bb=(Mat_SeqBAIJ*)(mat->B)->data;
81: if (mat->bs > 1) SETERRQ1(PETSC_ERR_SUP," bs=%d is not supported yet\n", mat->bs);
82: nz = aa->s_nz + bb->nz;
83: ai=aa->i; aj=aa->j; bi=bb->i; bj=bb->j; rstart= mat->rstart;
84: garray = mat->garray;
85: av=aa->a; bv=bb->a;
86: }
88: if (!valOnly){
89: PetscMalloc(nz*sizeof(int),&row);
90: PetscMalloc(nz*sizeof(int),&col);
91: PetscMalloc(nz*sizeof(PetscScalar),&val);
92: *r = row; *c = col; *v = val;
93: } else {
94: row = *r; col = *c; val = *v;
95: }
96: *nnz = nz;
98: jj = 0; irow = rstart;
99: for ( i=0; i<m; i++ ) {
100: ajj = aj + ai[i]; /* ptr to the beginning of this row */
101: countA = ai[i+1] - ai[i];
102: countB = bi[i+1] - bi[i];
103: bjj = bj + bi[i];
105: /* get jB, the starting local col index for the 2nd B-part */
106: colA_start = rstart + ajj[0]; /* the smallest col index for A */
107: j=-1;
108: do {
109: j++;
110: if (j == countB) break;
111: jcol = garray[bjj[j]];
112: } while (jcol < colA_start);
113: jB = j;
114:
115: /* B-part, smaller col index */
116: colA_start = rstart + ajj[0]; /* the smallest col index for A */
117: for (j=0; j<jB; j++){
118: jcol = garray[bjj[j]];
119: if (!valOnly){
120: row[jj] = irow + shift; col[jj] = jcol + shift;
122: }
123: val[jj++] = *bv++;
124: }
125: /* A-part */
126: for (j=0; j<countA; j++){
127: if (!valOnly){
128: row[jj] = irow + shift; col[jj] = rstart + ajj[j] + shift;
129: }
130: val[jj++] = *av++;
131: }
132: /* B-part, larger col index */
133: for (j=jB; j<countB; j++){
134: if (!valOnly){
135: row[jj] = irow + shift; col[jj] = garray[bjj[j]] + shift;
136: }
137: val[jj++] = *bv++;
138: }
139: irow++;
140: }
141:
142: return(0);
143: }
145: EXTERN_C_BEGIN
148: int MatConvert_MUMPS_Base(Mat A,MatType type,Mat *newmat) {
149: int ierr;
150: Mat B=*newmat;
151: Mat_MUMPS *mumps=(Mat_MUMPS*)A->spptr;
154: if (B != A) {
155: MatDuplicate(A,MAT_COPY_VALUES,&B);
156: }
157: B->ops->duplicate = mumps->MatDuplicate;
158: B->ops->view = mumps->MatView;
159: B->ops->assemblyend = mumps->MatAssemblyEnd;
160: B->ops->lufactorsymbolic = mumps->MatLUFactorSymbolic;
161: B->ops->choleskyfactorsymbolic = mumps->MatCholeskyFactorSymbolic;
162: B->ops->destroy = mumps->MatDestroy;
163: PetscObjectChangeTypeName((PetscObject)B,type);
164: PetscStrfree(mumps->basetype);
165: PetscFree(mumps);
166: *newmat = B;
167: return(0);
168: }
169: EXTERN_C_END
173: int MatDestroy_MUMPS(Mat A) {
174: Mat_MUMPS *lu=(Mat_MUMPS*)A->spptr;
175: int ierr,size=lu->size;
178: if (lu->CleanUpMUMPS) {
179: /* Terminate instance, deallocate memories */
180: lu->id.job=JOB_END;
181: #if defined(PETSC_USE_COMPLEX)
182: zmumps_c(&lu->id);
183: #else
184: dmumps_c(&lu->id);
185: #endif
186: if (lu->irn) {
187: PetscFree(lu->irn);
188: }
189: if (lu->jcn) {
190: PetscFree(lu->jcn);
191: }
192: if (size>1 && lu->val) {
193: PetscFree(lu->val);
194: }
195: MPI_Comm_free(&(lu->comm_mumps));
196: }
197: MatConvert_MUMPS_Base(A,lu->basetype,&A);
198: (*A->ops->destroy)(A);
199: return(0);
200: }
204: int MatFactorInfo_MUMPS(Mat A,PetscViewer viewer) {
205: Mat_MUMPS *lu=(Mat_MUMPS*)A->spptr;
206: int ierr;
209: PetscViewerASCIIPrintf(viewer,"MUMPS run parameters:\n");
210: PetscViewerASCIIPrintf(viewer," SYM (matrix type): %d \n",lu->id.sym);
211: PetscViewerASCIIPrintf(viewer," PAR (host participation): %d \n",lu->id.par);
212: PetscViewerASCIIPrintf(viewer," ICNTL(4) (level of printing): %d \n",lu->id.ICNTL(4));
213: PetscViewerASCIIPrintf(viewer," ICNTL(5) (input mat struct): %d \n",lu->id.ICNTL(5));
214: PetscViewerASCIIPrintf(viewer," ICNTL(6) (matrix prescaling): %d \n",lu->id.ICNTL(6));
215: PetscViewerASCIIPrintf(viewer," ICNTL(7) (matrix ordering): %d \n",lu->id.ICNTL(7));
216: PetscViewerASCIIPrintf(viewer," ICNTL(9) (A/A^T x=b is solved): %d \n",lu->id.ICNTL(9));
217: PetscViewerASCIIPrintf(viewer," ICNTL(10) (max num of refinements): %d \n",lu->id.ICNTL(10));
218: PetscViewerASCIIPrintf(viewer," ICNTL(11) (error analysis): %d \n",lu->id.ICNTL(11));
219: if (lu->myid == 0 && lu->id.ICNTL(11)>0) {
220: PetscPrintf(PETSC_COMM_SELF," RINFOG(4) (inf norm of input mat): %g\n",lu->id.RINFOG(4));
221: PetscPrintf(PETSC_COMM_SELF," RINFOG(5) (inf norm of solution): %g\n",lu->id.RINFOG(5));
222: PetscPrintf(PETSC_COMM_SELF," RINFOG(6) (inf norm of residual): %g\n",lu->id.RINFOG(6));
223: PetscPrintf(PETSC_COMM_SELF," RINFOG(7),RINFOG(8) (backward error est): %g, %g\n",lu->id.RINFOG(7),lu->id.RINFOG(8));
224: PetscPrintf(PETSC_COMM_SELF," RINFOG(9) (error estimate): %g \n",lu->id.RINFOG(9));
225: PetscPrintf(PETSC_COMM_SELF," RINFOG(10),RINFOG(11)(condition numbers): %g, %g\n",lu->id.RINFOG(10),lu->id.RINFOG(11));
226:
227: }
228: PetscViewerASCIIPrintf(viewer," ICNTL(12) (efficiency control): %d \n",lu->id.ICNTL(12));
229: PetscViewerASCIIPrintf(viewer," ICNTL(13) (efficiency control): %d \n",lu->id.ICNTL(13));
230: PetscViewerASCIIPrintf(viewer," ICNTL(14) (efficiency control): %d \n",lu->id.ICNTL(14));
231: PetscViewerASCIIPrintf(viewer," ICNTL(15) (efficiency control): %d \n",lu->id.ICNTL(15));
232: PetscViewerASCIIPrintf(viewer," ICNTL(18) (input mat struct): %d \n",lu->id.ICNTL(18));
234: PetscViewerASCIIPrintf(viewer," CNTL(1) (relative pivoting threshold): %g \n",lu->id.CNTL(1));
235: PetscViewerASCIIPrintf(viewer," CNTL(2) (stopping criterion of refinement): %g \n",lu->id.CNTL(2));
236: PetscViewerASCIIPrintf(viewer," CNTL(3) (absolute pivoting threshold): %g \n",lu->id.CNTL(3));
237: return(0);
238: }
242: int MatView_AIJMUMPS(Mat A,PetscViewer viewer) {
243: int ierr;
244: PetscTruth isascii;
245: PetscViewerFormat format;
246: Mat_MUMPS *mumps=(Mat_MUMPS*)(A->spptr);
249: (*mumps->MatView)(A,viewer);
251: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&isascii);
252: if (isascii) {
253: PetscViewerGetFormat(viewer,&format);
254: if (format == PETSC_VIEWER_ASCII_FACTOR_INFO) {
255: MatFactorInfo_MUMPS(A,viewer);
256: }
257: }
258: return(0);
259: }
263: int MatSolve_AIJMUMPS(Mat A,Vec b,Vec x) {
264: Mat_MUMPS *lu=(Mat_MUMPS*)A->spptr;
265: PetscScalar *array;
266: Vec x_seq;
267: IS iden;
268: VecScatter scat;
269: int ierr;
272: if (lu->size > 1){
273: if (!lu->myid){
274: VecCreateSeq(PETSC_COMM_SELF,A->N,&x_seq);
275: ISCreateStride(PETSC_COMM_SELF,A->N,0,1,&iden);
276: } else {
277: VecCreateSeq(PETSC_COMM_SELF,0,&x_seq);
278: ISCreateStride(PETSC_COMM_SELF,0,0,1,&iden);
279: }
280: VecScatterCreate(b,iden,x_seq,iden,&scat);
281: ISDestroy(iden);
283: VecScatterBegin(b,x_seq,INSERT_VALUES,SCATTER_FORWARD,scat);
284: VecScatterEnd(b,x_seq,INSERT_VALUES,SCATTER_FORWARD,scat);
285: if (!lu->myid) {VecGetArray(x_seq,&array);}
286: } else { /* size == 1 */
287: VecCopy(b,x);
288: VecGetArray(x,&array);
289: }
290: if (!lu->myid) { /* define rhs on the host */
291: #if defined(PETSC_USE_COMPLEX)
292: lu->id.rhs = (mumps_double_complex*)array;
293: #else
294: lu->id.rhs = array;
295: #endif
296: }
298: /* solve phase */
299: lu->id.job=3;
300: #if defined(PETSC_USE_COMPLEX)
301: zmumps_c(&lu->id);
302: #else
303: dmumps_c(&lu->id);
304: #endif
305: if (lu->id.INFOG(1) < 0) {
306: SETERRQ1(1,"Error reported by MUMPS in solve phase: INFOG(1)=%d\n",lu->id.INFOG(1));
307: }
309: /* convert mumps solution x_seq to petsc mpi x */
310: if (lu->size > 1) {
311: if (!lu->myid){
312: VecRestoreArray(x_seq,&array);
313: }
314: VecScatterBegin(x_seq,x,INSERT_VALUES,SCATTER_REVERSE,scat);
315: VecScatterEnd(x_seq,x,INSERT_VALUES,SCATTER_REVERSE,scat);
316: VecScatterDestroy(scat);
317: VecDestroy(x_seq);
318: } else {
319: VecRestoreArray(x,&array);
320: }
321:
322: return(0);
323: }
327: int MatFactorNumeric_AIJMUMPS(Mat A,Mat *F) {
328: Mat_MUMPS *lu =(Mat_MUMPS*)(*F)->spptr;
329: Mat_MUMPS *lua=(Mat_MUMPS*)(A)->spptr;
330: int rnz,nnz,ierr,nz,i,M=A->M,*ai,*aj,icntl;
331: PetscTruth valOnly,flg;
334: if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){
335: (*F)->ops->solve = MatSolve_AIJMUMPS;
337: /* Initialize a MUMPS instance */
338: MPI_Comm_rank(A->comm, &lu->myid);
339: MPI_Comm_size(A->comm,&lu->size);
340: lua->myid = lu->myid; lua->size = lu->size;
341: lu->id.job = JOB_INIT;
342: MPI_Comm_dup(A->comm,&(lu->comm_mumps));
343: lu->id.comm_fortran = lu->comm_mumps;
345: /* Set mumps options */
346: PetscOptionsBegin(A->comm,A->prefix,"MUMPS Options","Mat");
347: lu->id.par=1; /* host participates factorizaton and solve */
348: lu->id.sym=lu->sym;
349: if (lu->sym == 2){
350: PetscOptionsInt("-mat_mumps_sym","SYM: (1,2)","None",lu->id.sym,&icntl,&flg);
351: if (flg && icntl == 1) lu->id.sym=icntl; /* matrix is spd */
352: }
353: #if defined(PETSC_USE_COMPLEX)
354: zmumps_c(&lu->id);
355: #else
356: dmumps_c(&lu->id);
357: #endif
358:
359: if (lu->size == 1){
360: lu->id.ICNTL(18) = 0; /* centralized assembled matrix input */
361: } else {
362: lu->id.ICNTL(18) = 3; /* distributed assembled matrix input */
363: }
365: icntl=-1;
366: PetscOptionsInt("-mat_mumps_icntl_4","ICNTL(4): level of printing (0 to 4)","None",lu->id.ICNTL(4),&icntl,&flg);
367: if (flg && icntl > 0) {
368: lu->id.ICNTL(4)=icntl; /* and use mumps default icntl(i), i=1,2,3 */
369: } else { /* no output */
370: lu->id.ICNTL(1) = 0; /* error message, default= 6 */
371: lu->id.ICNTL(2) = -1; /* output stream for diagnostic printing, statistics, and warning. default=0 */
372: lu->id.ICNTL(3) = -1; /* output stream for global information, default=6 */
373: lu->id.ICNTL(4) = 0; /* level of printing, 0,1,2,3,4, default=2 */
374: }
375: PetscOptionsInt("-mat_mumps_icntl_6","ICNTL(6): matrix prescaling (0 to 7)","None",lu->id.ICNTL(6),&lu->id.ICNTL(6),PETSC_NULL);
376: icntl=-1;
377: PetscOptionsInt("-mat_mumps_icntl_7","ICNTL(7): matrix ordering (0 to 7)","None",lu->id.ICNTL(7),&icntl,&flg);
378: if (flg) {
379: if (icntl== 1){
380: SETERRQ(PETSC_ERR_SUP,"pivot order be set by the user in PERM_IN -- not supported by the PETSc/MUMPS interface\n");
381: } else {
382: lu->id.ICNTL(7) = icntl;
383: }
384: }
385: 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);
386: PetscOptionsInt("-mat_mumps_icntl_10","ICNTL(10): max num of refinements","None",lu->id.ICNTL(10),&lu->id.ICNTL(10),PETSC_NULL);
387: PetscOptionsInt("-mat_mumps_icntl_11","ICNTL(11): error analysis, a positive value returns statistics (by -sles_view)","None",lu->id.ICNTL(11),&lu->id.ICNTL(11),PETSC_NULL);
388: PetscOptionsInt("-mat_mumps_icntl_12","ICNTL(12): efficiency control","None",lu->id.ICNTL(12),&lu->id.ICNTL(12),PETSC_NULL);
389: PetscOptionsInt("-mat_mumps_icntl_13","ICNTL(13): efficiency control","None",lu->id.ICNTL(13),&lu->id.ICNTL(13),PETSC_NULL);
390: PetscOptionsInt("-mat_mumps_icntl_14","ICNTL(14): efficiency control","None",lu->id.ICNTL(14),&lu->id.ICNTL(14),PETSC_NULL);
391: PetscOptionsInt("-mat_mumps_icntl_15","ICNTL(15): efficiency control","None",lu->id.ICNTL(15),&lu->id.ICNTL(15),PETSC_NULL);
393: /*
394: PetscOptionsInt("-mat_mumps_icntl_16","ICNTL(16): 1: rank detection; 2: rank detection and nullspace","None",lu->id.ICNTL(16),&icntl,&flg);
395: if (flg){
396: if (icntl >-1 && icntl <3 ){
397: if (lu->myid==0) lu->id.ICNTL(16) = icntl;
398: } else {
399: SETERRQ1(PETSC_ERR_SUP,"ICNTL(16)=%d -- not supported\n",icntl);
400: }
401: }
402: */
404: PetscOptionsReal("-mat_mumps_cntl_1","CNTL(1): relative pivoting threshold","None",lu->id.CNTL(1),&lu->id.CNTL(1),PETSC_NULL);
405: PetscOptionsReal("-mat_mumps_cntl_2","CNTL(2): stopping criterion of refinement","None",lu->id.CNTL(2),&lu->id.CNTL(2),PETSC_NULL);
406: PetscOptionsReal("-mat_mumps_cntl_3","CNTL(3): absolute pivoting threshold","None",lu->id.CNTL(3),&lu->id.CNTL(3),PETSC_NULL);
407: PetscOptionsEnd();
408: }
410: /* define matrix A */
411: switch (lu->id.ICNTL(18)){
412: case 0: /* centralized assembled matrix input (size=1) */
413: if (!lu->myid) {
414: if (lua->isAIJ){
415: Mat_SeqAIJ *aa = (Mat_SeqAIJ*)A->data;
416: nz = aa->nz;
417: ai = aa->i; aj = aa->j; lu->val = aa->a;
418: } else {
419: Mat_SeqSBAIJ *aa = (Mat_SeqSBAIJ*)A->data;
420: nz = aa->s_nz;
421: ai = aa->i; aj = aa->j; lu->val = aa->a;
422: }
423: if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){ /* first numeric factorization, get irn and jcn */
424: PetscMalloc(nz*sizeof(int),&lu->irn);
425: PetscMalloc(nz*sizeof(int),&lu->jcn);
426: nz = 0;
427: for (i=0; i<M; i++){
428: rnz = ai[i+1] - ai[i];
429: while (rnz--) { /* Fortran row/col index! */
430: lu->irn[nz] = i+1; lu->jcn[nz] = (*aj)+1; aj++; nz++;
431: }
432: }
433: }
434: }
435: break;
436: case 3: /* distributed assembled matrix input (size>1) */
437: if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){
438: valOnly = PETSC_FALSE;
439: } else {
440: valOnly = PETSC_TRUE; /* only update mat values, not row and col index */
441: }
442: MatConvertToTriples(A,1,valOnly, &nnz, &lu->irn, &lu->jcn, &lu->val);
443: break;
444: default: SETERRQ(PETSC_ERR_SUP,"Matrix input format is not supported by MUMPS.");
445: }
447: /* analysis phase */
448: if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){
449: lu->id.n = M;
450: switch (lu->id.ICNTL(18)){
451: case 0: /* centralized assembled matrix input */
452: if (!lu->myid) {
453: lu->id.nz =nz; lu->id.irn=lu->irn; lu->id.jcn=lu->jcn;
454: if (lu->id.ICNTL(6)>1){
455: #if defined(PETSC_USE_COMPLEX)
456: lu->id.a = (mumps_double_complex*)lu->val;
457: #else
458: lu->id.a = lu->val;
459: #endif
460: }
461: }
462: break;
463: case 3: /* distributed assembled matrix input (size>1) */
464: lu->id.nz_loc = nnz;
465: lu->id.irn_loc=lu->irn; lu->id.jcn_loc=lu->jcn;
466: if (lu->id.ICNTL(6)>1) {
467: #if defined(PETSC_USE_COMPLEX)
468: lu->id.a_loc = (mumps_double_complex*)lu->val;
469: #else
470: lu->id.a_loc = lu->val;
471: #endif
472: }
473: break;
474: }
475: lu->id.job=1;
476: #if defined(PETSC_USE_COMPLEX)
477: zmumps_c(&lu->id);
478: #else
479: dmumps_c(&lu->id);
480: #endif
481: if (lu->id.INFOG(1) < 0) {
482: SETERRQ1(1,"Error reported by MUMPS in analysis phase: INFOG(1)=%d\n",lu->id.INFOG(1));
483: }
484: }
486: /* numerical factorization phase */
487: if(lu->id.ICNTL(18) == 0) {
488: if (lu->myid == 0) {
489: #if defined(PETSC_USE_COMPLEX)
490: lu->id.a = (mumps_double_complex*)lu->val;
491: #else
492: lu->id.a = lu->val;
493: #endif
494: }
495: } else {
496: #if defined(PETSC_USE_COMPLEX)
497: lu->id.a_loc = (mumps_double_complex*)lu->val;
498: #else
499: lu->id.a_loc = lu->val;
500: #endif
501: }
502: lu->id.job=2;
503: #if defined(PETSC_USE_COMPLEX)
504: zmumps_c(&lu->id);
505: #else
506: dmumps_c(&lu->id);
507: #endif
508: if (lu->id.INFOG(1) < 0) {
509: SETERRQ1(1,"1, Error reported by MUMPS in numerical factorization phase: INFOG(1)=%d\n",lu->id.INFOG(1));
510: }
512: if (lu->myid==0 && lu->id.ICNTL(16) > 0){
513: SETERRQ1(1," lu->id.ICNTL(16):=%d\n",lu->id.INFOG(16));
514: }
515:
516: (*F)->assembled = PETSC_TRUE;
517: lu->matstruc = SAME_NONZERO_PATTERN;
518: lu->CleanUpMUMPS = PETSC_TRUE;
519: return(0);
520: }
522: /* Note the Petsc r and c permutations are ignored */
525: int MatLUFactorSymbolic_AIJMUMPS(Mat A,IS r,IS c,MatFactorInfo *info,Mat *F) {
526: Mat B;
527: Mat_MUMPS *lu;
528: int ierr;
532: /* Create the factorization matrix */
533: MatCreate(A->comm,A->m,A->n,A->M,A->N,&B);
534: MatSetType(B,MATAIJMUMPS);
535: MatSeqAIJSetPreallocation(B,0,PETSC_NULL);
536: MatMPIAIJSetPreallocation(B,0,PETSC_NULL,0,PETSC_NULL);
538: B->ops->lufactornumeric = MatFactorNumeric_AIJMUMPS;
539: B->factor = FACTOR_LU;
540: lu = (Mat_MUMPS*)B->spptr;
541: lu->sym = 0;
542: lu->matstruc = DIFFERENT_NONZERO_PATTERN;
544: *F = B;
545: return(0);
546: }
548: /* Note the Petsc r permutation is ignored */
551: int MatCholeskyFactorSymbolic_SBAIJMUMPS(Mat A,IS r,MatFactorInfo *info,Mat *F) {
552: Mat B;
553: Mat_MUMPS *lu;
554: int ierr;
558: /* Create the factorization matrix */
559: MatCreate(A->comm,A->m,A->n,A->M,A->N,&B);
560: MatSetType(B,MATAIJMUMPS);
561: MatSeqAIJSetPreallocation(B,0,PETSC_NULL);
562: MatMPIAIJSetPreallocation(B,0,PETSC_NULL,0,PETSC_NULL);
564: B->ops->choleskyfactornumeric = MatFactorNumeric_AIJMUMPS;
565: B->factor = FACTOR_CHOLESKY;
566: lu = (Mat_MUMPS*)B->spptr;
567: lu->sym = 2;
568: lu->matstruc = DIFFERENT_NONZERO_PATTERN;
570: *F = B;
571: return(0);
572: }
576: int MatAssemblyEnd_AIJMUMPS(Mat A,MatAssemblyType mode) {
577: int ierr;
578: Mat_MUMPS *mumps=(Mat_MUMPS*)A->spptr;
581: (*mumps->MatAssemblyEnd)(A,mode);
583: mumps->MatLUFactorSymbolic = A->ops->lufactorsymbolic;
584: mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
585: A->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJMUMPS;
586: return(0);
587: }
589: EXTERN_C_BEGIN
592: int MatConvert_AIJ_AIJMUMPS(Mat A,MatType newtype,Mat *newmat) {
593: int ierr,size;
594: MPI_Comm comm;
595: Mat B=*newmat;
596: Mat_MUMPS *mumps;
599: if (B != A) {
600: MatDuplicate(A,MAT_COPY_VALUES,&B);
601: }
603: PetscObjectGetComm((PetscObject)A,&comm);
604: PetscNew(Mat_MUMPS,&mumps);
606: mumps->MatDuplicate = A->ops->duplicate;
607: mumps->MatView = A->ops->view;
608: mumps->MatAssemblyEnd = A->ops->assemblyend;
609: mumps->MatLUFactorSymbolic = A->ops->lufactorsymbolic;
610: mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
611: mumps->MatDestroy = A->ops->destroy;
612: mumps->CleanUpMUMPS = PETSC_FALSE;
613: mumps->isAIJ = PETSC_TRUE;
615: B->spptr = (void *)mumps;
616: B->ops->duplicate = MatDuplicate_AIJMUMPS;
617: B->ops->view = MatView_AIJMUMPS;
618: B->ops->assemblyend = MatAssemblyEnd_AIJMUMPS;
619: B->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJMUMPS;
620: B->ops->destroy = MatDestroy_MUMPS;
622: MPI_Comm_size(comm,&size);
623: if (size == 1) {
624: PetscStrallocpy(MATSEQAIJ,&(mumps->basetype));
625: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_seqaij_aijmumps_C",
626: "MatConvert_AIJ_AIJMUMPS",MatConvert_AIJ_AIJMUMPS);
627: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_aijmumps_seqaij_C",
628: "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);
629: } else {
630: PetscStrallocpy(MATMPIAIJ,&(mumps->basetype));
631: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_mpiaij_aijmumps_C",
632: "MatConvert_AIJ_AIJMUMPS",MatConvert_AIJ_AIJMUMPS);
633: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_aijmumps_mpiaij_C",
634: "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);
635: }
637: PetscLogInfo(0,"Using MUMPS for LU factorization and solves.");
638: PetscObjectChangeTypeName((PetscObject)B,newtype);
639: *newmat = B;
640: return(0);
641: }
642: EXTERN_C_END
646: int MatDuplicate_AIJMUMPS(Mat A, MatDuplicateOption op, Mat *M) {
649: (*A->ops->duplicate)(A,op,M);
650: MatConvert_AIJ_AIJMUMPS(*M,MATAIJMUMPS,M);
651: return(0);
652: }
654: /*MC
655: MATAIJMUMPS - MATAIJMUMPS = "aijmumps" - A matrix type providing direct solvers (LU) for distributed
656: and sequential matrices via the external package MUMPS.
658: If MUMPS is installed (see the manual for instructions
659: on how to declare the existence of external packages),
660: a matrix type can be constructed which invokes MUMPS solvers.
661: After calling MatCreate(...,A), simply call MatSetType(A,MATAIJMUMPS).
662: This matrix type is only supported for double precision real.
664: If created with a single process communicator, this matrix type inherits from MATSEQAIJ.
665: Otherwise, this matrix type inherits from MATMPIAIJ. Hence for single process communicators,
666: MatSeqAIJSetPreallocation is supported, and similarly MatMPIAIJSetPreallocation is supported
667: for communicators controlling multiple processes. It is recommended that you call both of
668: the above preallocation routines for simplicity. One can also call MatConvert for an inplace
669: conversion to or from the MATSEQAIJ or MATMPIAIJ type (depending on the communicator size)
670: without data copy.
672: Options Database Keys:
673: + -mat_type aijmumps - sets the matrix type to "aijmumps" during a call to MatSetFromOptions()
674: . -mat_mumps_sym <0,1,2> - 0 the matrix is unsymmetric, 1 symmetric positive definite, 2 symmetric
675: . -mat_mumps_icntl_4 <0,1,2,3,4> - print level
676: . -mat_mumps_icntl_6 <0,...,7> - matrix prescaling options (see MUMPS User's Guide)
677: . -mat_mumps_icntl_7 <0,...,7> - matrix orderings (see MUMPS User's Guide)
678: . -mat_mumps_icntl_9 <1,2> - A or A^T x=b to be solved: 1 denotes A, 2 denotes A^T
679: . -mat_mumps_icntl_10 <n> - maximum number of iterative refinements
680: . -mat_mumps_icntl_11 <n> - error analysis, a positive value returns statistics during -sles_view
681: . -mat_mumps_icntl_12 <n> - efficiency control (see MUMPS User's Guide)
682: . -mat_mumps_icntl_13 <n> - efficiency control (see MUMPS User's Guide)
683: . -mat_mumps_icntl_14 <n> - efficiency control (see MUMPS User's Guide)
684: . -mat_mumps_icntl_15 <n> - efficiency control (see MUMPS User's Guide)
685: . -mat_mumps_cntl_1 <delta> - relative pivoting threshold
686: . -mat_mumps_cntl_2 <tol> - stopping criterion for refinement
687: - -mat_mumps_cntl_3 <adelta> - absolute pivoting threshold
689: Level: beginner
691: .seealso: MATSBAIJMUMPS
692: M*/
694: EXTERN_C_BEGIN
697: int MatCreate_AIJMUMPS(Mat A) {
698: int ierr,size;
699: MPI_Comm comm;
700:
702: /* Change type name before calling MatSetType to force proper construction of SeqAIJ or MPIAIJ */
703: /* and AIJMUMPS types */
704: PetscObjectChangeTypeName((PetscObject)A,MATAIJMUMPS);
705: PetscObjectGetComm((PetscObject)A,&comm);
706: MPI_Comm_size(comm,&size);
707: if (size == 1) {
708: MatSetType(A,MATSEQAIJ);
709: } else {
710: MatSetType(A,MATMPIAIJ);
711: }
712: MatConvert_AIJ_AIJMUMPS(A,MATAIJMUMPS,&A);
713: return(0);
714: }
715: EXTERN_C_END
719: int MatAssemblyEnd_SBAIJMUMPS(Mat A,MatAssemblyType mode) {
720: int ierr;
721: Mat_MUMPS *mumps=(Mat_MUMPS*)A->spptr;
724: (*mumps->MatAssemblyEnd)(A,mode);
725: mumps->MatLUFactorSymbolic = A->ops->lufactorsymbolic;
726: mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
727: A->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SBAIJMUMPS;
728: return(0);
729: }
731: EXTERN_C_BEGIN
734: int MatConvert_SBAIJ_SBAIJMUMPS(Mat A,MatType newtype,Mat *newmat) {
735: int ierr,size;
736: MPI_Comm comm;
737: Mat B=*newmat;
738: Mat_MUMPS *mumps;
741: if (B != A) {
742: MatDuplicate(A,MAT_COPY_VALUES,&B);
743: }
745: PetscObjectGetComm((PetscObject)A,&comm);
746: PetscNew(Mat_MUMPS,&mumps);
748: mumps->MatDuplicate = A->ops->duplicate;
749: mumps->MatView = A->ops->view;
750: mumps->MatAssemblyEnd = A->ops->assemblyend;
751: mumps->MatLUFactorSymbolic = A->ops->lufactorsymbolic;
752: mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
753: mumps->MatDestroy = A->ops->destroy;
754: mumps->CleanUpMUMPS = PETSC_FALSE;
755: mumps->isAIJ = PETSC_FALSE;
756:
757: B->spptr = (void *)mumps;
758: B->ops->duplicate = MatDuplicate_SBAIJMUMPS;
759: B->ops->view = MatView_AIJMUMPS;
760: B->ops->assemblyend = MatAssemblyEnd_SBAIJMUMPS;
761: B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SBAIJMUMPS;
762: B->ops->destroy = MatDestroy_MUMPS;
764: MPI_Comm_size(comm,&size);
765: if (size == 1) {
766: PetscStrallocpy(MATSEQSBAIJ,&(mumps->basetype));
767: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_seqsbaij_sbaijmumps_C",
768: "MatConvert_SBAIJ_SBAIJMUMPS",MatConvert_SBAIJ_SBAIJMUMPS);
769: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_sbaijmumps_seqsbaij_C",
770: "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);
771: } else {
772: PetscStrallocpy(MATMPISBAIJ,&(mumps->basetype));
773: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_mpisbaij_sbaijmumps_C",
774: "MatConvert_SBAIJ_SBAIJMUMPS",MatConvert_SBAIJ_SBAIJMUMPS);
775: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_sbaijmumps_mpisbaij_C",
776: "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);
777: }
779: PetscLogInfo(0,"Using MUMPS for Cholesky factorization and solves.");
780: PetscObjectChangeTypeName((PetscObject)B,newtype);
781: *newmat = B;
782: return(0);
783: }
784: EXTERN_C_END
788: int MatDuplicate_SBAIJMUMPS(Mat A, MatDuplicateOption op, Mat *M) {
791: (*A->ops->duplicate)(A,op,M);
792: MatConvert_SBAIJ_SBAIJMUMPS(*M,MATSBAIJMUMPS,M);
793: return(0);
794: }
796: /*MC
797: MATSBAIJMUMPS - MATSBAIJMUMPS = "sbaijmumps" - A symmetric matrix type providing direct solvers (Cholesky) for
798: distributed and sequential matrices via the external package MUMPS.
800: If MUMPS is installed (see the manual for instructions
801: on how to declare the existence of external packages),
802: a matrix type can be constructed which invokes MUMPS solvers.
803: After calling MatCreate(...,A), simply call MatSetType(A,MATSBAIJMUMPS).
804: This matrix type is only supported for double precision real.
806: If created with a single process communicator, this matrix type inherits from MATSEQSBAIJ.
807: Otherwise, this matrix type inherits from MATMPISBAIJ. Hence for single process communicators,
808: MatSeqSBAIJSetPreallocation is supported, and similarly MatMPISBAIJSetPreallocation is supported
809: for communicators controlling multiple processes. It is recommended that you call both of
810: the above preallocation routines for simplicity. One can also call MatConvert for an inplace
811: conversion to or from the MATSEQSBAIJ or MATMPISBAIJ type (depending on the communicator size)
812: without data copy.
814: Options Database Keys:
815: + -mat_type sbaijmumps - sets the matrix type to "sbaijmumps" during a call to MatSetFromOptions()
816: . -mat_mumps_sym <0,1,2> - 0 the matrix is unsymmetric, 1 symmetric positive definite, 2 symmetric
817: . -mat_mumps_icntl_4 <0,...,4> - print level
818: . -mat_mumps_icntl_6 <0,...,7> - matrix prescaling options (see MUMPS User's Guide)
819: . -mat_mumps_icntl_7 <0,...,7> - matrix orderings (see MUMPS User's Guide)
820: . -mat_mumps_icntl_9 <1,2> - A or A^T x=b to be solved: 1 denotes A, 2 denotes A^T
821: . -mat_mumps_icntl_10 <n> - maximum number of iterative refinements
822: . -mat_mumps_icntl_11 <n> - error analysis, a positive value returns statistics during -sles_view
823: . -mat_mumps_icntl_12 <n> - efficiency control (see MUMPS User's Guide)
824: . -mat_mumps_icntl_13 <n> - efficiency control (see MUMPS User's Guide)
825: . -mat_mumps_icntl_14 <n> - efficiency control (see MUMPS User's Guide)
826: . -mat_mumps_icntl_15 <n> - efficiency control (see MUMPS User's Guide)
827: . -mat_mumps_cntl_1 <delta> - relative pivoting threshold
828: . -mat_mumps_cntl_2 <tol> - stopping criterion for refinement
829: - -mat_mumps_cntl_3 <adelta> - absolute pivoting threshold
831: Level: beginner
833: .seealso: MATAIJMUMPS
834: M*/
836: EXTERN_C_BEGIN
839: int MatCreate_SBAIJMUMPS(Mat A) {
840: int ierr,size;
843: /* Change type name before calling MatSetType to force proper construction of SeqSBAIJ or MPISBAIJ */
844: /* and SBAIJMUMPS types */
845: PetscObjectChangeTypeName((PetscObject)A,MATSBAIJMUMPS);
846: MPI_Comm_size(A->comm,&size);
847: if (size == 1) {
848: MatSetType(A,MATSEQSBAIJ);
849: } else {
850: MatSetType(A,MATMPISBAIJ);
851: }
852: MatConvert_SBAIJ_SBAIJMUMPS(A,MATSBAIJMUMPS,&A);
853: return(0);
854: }
855: EXTERN_C_END