Actual source code: mumps.c

  2: /* 
  3:     Provides an interface to the MUMPS sparse solver
  4: */

  6: #include <../src/mat/impls/aij/mpi/mpiaij.h> /*I  "petscmat.h"  I*/
  7: #include <../src/mat/impls/sbaij/mpi/mpisbaij.h>

  9: EXTERN_C_BEGIN
 10: #if defined(PETSC_USE_COMPLEX)
 11: #include <zmumps_c.h>
 12: #else
 13: #include <dmumps_c.h> 
 14: #endif
 15: EXTERN_C_END
 16: #define JOB_INIT -1
 17: #define JOB_FACTSYMBOLIC 1
 18: #define JOB_FACTNUMERIC 2
 19: #define JOB_SOLVE 3
 20: #define JOB_END -2


 23: /* macros s.t. indices match MUMPS documentation */
 24: #define ICNTL(I) icntl[(I)-1]
 25: #define CNTL(I) cntl[(I)-1] 
 26: #define INFOG(I) infog[(I)-1]
 27: #define INFO(I) info[(I)-1]
 28: #define RINFOG(I) rinfog[(I)-1]
 29: #define RINFO(I) rinfo[(I)-1]

 31: typedef struct {
 32: #if defined(PETSC_USE_COMPLEX)
 33:   ZMUMPS_STRUC_C id;
 34: #else
 35:   DMUMPS_STRUC_C id;
 36: #endif
 37:   MatStructure   matstruc;
 38:   PetscMPIInt    myid,size;
 39:   PetscInt       *irn,*jcn,nz,sym,nSolve;
 40:   PetscScalar    *val;
 41:   MPI_Comm       comm_mumps;
 42:   VecScatter     scat_rhs, scat_sol;
 43:   PetscBool      isAIJ,CleanUpMUMPS;
 44:   Vec            b_seq,x_seq;
 45:   PetscErrorCode (*Destroy)(Mat);
 46:   PetscErrorCode (*ConvertToTriples)(Mat, int, MatReuse, int*, int**, int**, PetscScalar**);
 47: } Mat_MUMPS;

 49: extern PetscErrorCode MatDuplicate_MUMPS(Mat,MatDuplicateOption,Mat*);


 52: /* MatConvertToTriples_A_B */
 53: /*convert Petsc matrix to triples: row[nz], col[nz], val[nz] */
 54: /*
 55:   input: 
 56:     A       - matrix in aij,baij or sbaij (bs=1) format
 57:     shift   - 0: C style output triple; 1: Fortran style output triple.
 58:     reuse   - MAT_INITIAL_MATRIX: spaces are allocated and values are set for the triple  
 59:               MAT_REUSE_MATRIX:   only the values in v array are updated
 60:   output:     
 61:     nnz     - dim of r, c, and v (number of local nonzero entries of A)
 62:     r, c, v - row and col index, matrix values (matrix triples) 
 63:  */

 67: PetscErrorCode MatConvertToTriples_seqaij_seqaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
 68: {
 69:   const PetscInt   *ai,*aj,*ajj,M=A->rmap->n;
 70:   PetscInt         nz,rnz,i,j;
 71:   PetscErrorCode   ierr;
 72:   PetscInt         *row,*col;
 73:   Mat_SeqAIJ       *aa=(Mat_SeqAIJ*)A->data;

 76:   *v=aa->a;
 77:   if (reuse == MAT_INITIAL_MATRIX){
 78:     nz = aa->nz; ai = aa->i; aj = aa->j;
 79:     *nnz = nz;
 80:     PetscMalloc(2*nz*sizeof(PetscInt), &row);
 81:     col  = row + nz;

 83:     nz = 0;
 84:     for(i=0; i<M; i++) {
 85:       rnz = ai[i+1] - ai[i];
 86:       ajj = aj + ai[i];
 87:       for(j=0; j<rnz; j++) {
 88:         row[nz] = i+shift; col[nz++] = ajj[j] + shift;
 89:       }
 90:     }
 91:     *r = row; *c = col;
 92:   }
 93:   return(0);
 94: }

 98: PetscErrorCode MatConvertToTriples_seqbaij_seqaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
 99: {
100:   Mat_SeqBAIJ        *aa=(Mat_SeqBAIJ*)A->data;
101:   const PetscInt     *ai,*aj,*ajj,bs=A->rmap->bs,bs2=aa->bs2,M=A->rmap->N/bs;
102:   PetscInt           nz,idx=0,rnz,i,j,k,m;
103:   PetscErrorCode     ierr;
104:   PetscInt           *row,*col;

107:   *v = aa->a;
108:   if (reuse == MAT_INITIAL_MATRIX){
109:     ai = aa->i; aj = aa->j;
110:     nz = bs2*aa->nz;
111:     *nnz = nz;
112:     PetscMalloc(2*nz*sizeof(PetscInt), &row);
113:     col  = row + nz;

115:     for(i=0; i<M; i++) {
116:       ajj = aj + ai[i];
117:       rnz = ai[i+1] - ai[i];
118:       for(k=0; k<rnz; k++) {
119:         for(j=0; j<bs; j++) {
120:           for(m=0; m<bs; m++) {
121:             row[idx]     = i*bs + m + shift;
122:             col[idx++]   = bs*(ajj[k]) + j + shift;
123:           }
124:         }
125:       }
126:     }
127:     *r = row; *c = col;
128:   }
129:   return(0);
130: }

134: PetscErrorCode MatConvertToTriples_seqsbaij_seqsbaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
135: {
136:   const PetscInt   *ai, *aj,*ajj,M=A->rmap->n;
137:   PetscInt         nz,rnz,i,j;
138:   PetscErrorCode   ierr;
139:   PetscInt         *row,*col;
140:   Mat_SeqSBAIJ     *aa=(Mat_SeqSBAIJ*)A->data;

143:   if (reuse == MAT_INITIAL_MATRIX){
144:     nz = aa->nz;ai=aa->i; aj=aa->j;*v=aa->a;
145:     *nnz = nz;
146:     PetscMalloc(2*nz*sizeof(PetscInt), &row);
147:     col  = row + nz;

149:     nz = 0;
150:     for(i=0; i<M; i++) {
151:       rnz = ai[i+1] - ai[i];
152:       ajj = aj + ai[i];
153:       for(j=0; j<rnz; j++) {
154:         row[nz] = i+shift; col[nz++] = ajj[j] + shift;
155:       }
156:     }
157:     *r = row; *c = col;
158:   }
159:   return(0);
160: }

164: PetscErrorCode MatConvertToTriples_seqaij_seqsbaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
165: {
166:   const PetscInt     *ai,*aj,*ajj,*adiag,M=A->rmap->n;
167:   PetscInt           nz,rnz,i,j;
168:   const PetscScalar  *av,*v1;
169:   PetscScalar        *val;
170:   PetscErrorCode     ierr;
171:   PetscInt           *row,*col;
172:   Mat_SeqSBAIJ       *aa=(Mat_SeqSBAIJ*)A->data;

175:   ai=aa->i; aj=aa->j;av=aa->a;
176:   adiag=aa->diag;
177:   if (reuse == MAT_INITIAL_MATRIX){
178:     nz = M + (aa->nz-M)/2;
179:     *nnz = nz;
180:     PetscMalloc((2*nz*sizeof(PetscInt)+nz*sizeof(PetscScalar)), &row);
181:     col  = row + nz;
182:     val  = (PetscScalar*)(col + nz);

184:     nz = 0;
185:     for(i=0; i<M; i++) {
186:       rnz = ai[i+1] - adiag[i];
187:       ajj  = aj + adiag[i];
188:       v1   = av + adiag[i];
189:       for(j=0; j<rnz; j++) {
190:         row[nz] = i+shift; col[nz] = ajj[j] + shift; val[nz++] = v1[j];
191:       }
192:     }
193:     *r = row; *c = col; *v = val;
194:   } else {
195:     nz = 0; val = *v;
196:     for(i=0; i <M; i++) {
197:       rnz = ai[i+1] - adiag[i];
198:       ajj = aj + adiag[i];
199:       v1  = av + adiag[i];
200:       for(j=0; j<rnz; j++) {
201:         val[nz++] = v1[j];
202:       }
203:     }
204:   }
205:   return(0);
206: }

210: PetscErrorCode MatConvertToTriples_mpisbaij_mpisbaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
211: {
212:   const PetscInt     *ai, *aj, *bi, *bj,*garray,m=A->rmap->n,*ajj,*bjj;
213:   PetscErrorCode     ierr;
214:   PetscInt           rstart,nz,i,j,jj,irow,countA,countB;
215:   PetscInt           *row,*col;
216:   const PetscScalar  *av, *bv,*v1,*v2;
217:   PetscScalar        *val;
218:   Mat_MPISBAIJ       *mat =  (Mat_MPISBAIJ*)A->data;
219:   Mat_SeqSBAIJ       *aa=(Mat_SeqSBAIJ*)(mat->A)->data;
220:   Mat_SeqBAIJ        *bb=(Mat_SeqBAIJ*)(mat->B)->data;

223:   ai=aa->i; aj=aa->j; bi=bb->i; bj=bb->j; rstart= A->rmap->rstart;
224:   garray = mat->garray;
225:   av=aa->a; bv=bb->a;

227:   if (reuse == MAT_INITIAL_MATRIX){
228:     nz = aa->nz + bb->nz;
229:     *nnz = nz;
230:     PetscMalloc((2*nz*sizeof(PetscInt)+nz*sizeof(PetscScalar)), &row);
231:     col  = row + nz;
232:     val  = (PetscScalar*)(col + nz);

234:     *r = row; *c = col; *v = val;
235:   } else {
236:     row = *r; col = *c; val = *v;
237:   }

239:   jj = 0; irow = rstart;
240:   for ( i=0; i<m; i++ ) {
241:     ajj    = aj + ai[i];                 /* ptr to the beginning of this row */
242:     countA = ai[i+1] - ai[i];
243:     countB = bi[i+1] - bi[i];
244:     bjj    = bj + bi[i];
245:     v1     = av + ai[i];
246:     v2     = bv + bi[i];

248:     /* A-part */
249:     for (j=0; j<countA; j++){
250:       if (reuse == MAT_INITIAL_MATRIX) {
251:         row[jj] = irow + shift; col[jj] = rstart + ajj[j] + shift;
252:       }
253:       val[jj++] = v1[j];
254:     }

256:     /* B-part */
257:     for(j=0; j < countB; j++){
258:       if (reuse == MAT_INITIAL_MATRIX) {
259:         row[jj] = irow + shift; col[jj] = garray[bjj[j]] + shift;
260:       }
261:       val[jj++] = v2[j];
262:     }
263:     irow++;
264:   }
265:   return(0);
266: }

270: PetscErrorCode MatConvertToTriples_mpiaij_mpiaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
271: {
272:   const PetscInt     *ai, *aj, *bi, *bj,*garray,m=A->rmap->n,*ajj,*bjj;
273:   PetscErrorCode     ierr;
274:   PetscInt           rstart,nz,i,j,jj,irow,countA,countB;
275:   PetscInt           *row,*col;
276:   const PetscScalar  *av, *bv,*v1,*v2;
277:   PetscScalar        *val;
278:   Mat_MPIAIJ         *mat =  (Mat_MPIAIJ*)A->data;
279:   Mat_SeqAIJ         *aa=(Mat_SeqAIJ*)(mat->A)->data;
280:   Mat_SeqAIJ         *bb=(Mat_SeqAIJ*)(mat->B)->data;

283:   ai=aa->i; aj=aa->j; bi=bb->i; bj=bb->j; rstart= A->rmap->rstart;
284:   garray = mat->garray;
285:   av=aa->a; bv=bb->a;

287:   if (reuse == MAT_INITIAL_MATRIX){
288:     nz = aa->nz + bb->nz;
289:     *nnz = nz;
290:     PetscMalloc((2*nz*sizeof(PetscInt)+nz*sizeof(PetscScalar)), &row);
291:     col  = row + nz;
292:     val  = (PetscScalar*)(col + nz);

294:     *r = row; *c = col; *v = val;
295:   } else {
296:     row = *r; col = *c; val = *v;
297:   }

299:   jj = 0; irow = rstart;
300:   for ( i=0; i<m; i++ ) {
301:     ajj    = aj + ai[i];                 /* ptr to the beginning of this row */
302:     countA = ai[i+1] - ai[i];
303:     countB = bi[i+1] - bi[i];
304:     bjj    = bj + bi[i];
305:     v1     = av + ai[i];
306:     v2     = bv + bi[i];

308:     /* A-part */
309:     for (j=0; j<countA; j++){
310:       if (reuse == MAT_INITIAL_MATRIX){
311:         row[jj] = irow + shift; col[jj] = rstart + ajj[j] + shift;
312:       }
313:       val[jj++] = v1[j];
314:     }

316:     /* B-part */
317:     for(j=0; j < countB; j++){
318:       if (reuse == MAT_INITIAL_MATRIX){
319:         row[jj] = irow + shift; col[jj] = garray[bjj[j]] + shift;
320:       }
321:       val[jj++] = v2[j];
322:     }
323:     irow++;
324:   }
325:   return(0);
326: }

330: PetscErrorCode MatConvertToTriples_mpibaij_mpiaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
331: {
332:   Mat_MPIBAIJ        *mat =  (Mat_MPIBAIJ*)A->data;
333:   Mat_SeqBAIJ        *aa=(Mat_SeqBAIJ*)(mat->A)->data;
334:   Mat_SeqBAIJ        *bb=(Mat_SeqBAIJ*)(mat->B)->data;
335:   const PetscInt     *ai = aa->i, *bi = bb->i, *aj = aa->j, *bj = bb->j,*ajj, *bjj;
336:   const PetscInt     *garray = mat->garray,mbs=mat->mbs,rstart=A->rmap->rstart;
337:   const PetscInt     bs = A->rmap->bs,bs2=mat->bs2;
338:   PetscErrorCode     ierr;
339:   PetscInt           nz,i,j,k,n,jj,irow,countA,countB,idx;
340:   PetscInt           *row,*col;
341:   const PetscScalar  *av=aa->a, *bv=bb->a,*v1,*v2;
342:   PetscScalar        *val;


346:   if (reuse == MAT_INITIAL_MATRIX) {
347:     nz = bs2*(aa->nz + bb->nz);
348:     *nnz = nz;
349:     PetscMalloc((2*nz*sizeof(PetscInt)+nz*sizeof(PetscScalar)), &row);
350:     col  = row + nz;
351:     val  = (PetscScalar*)(col + nz);

353:     *r = row; *c = col; *v = val;
354:   } else {
355:     row = *r; col = *c; val = *v;
356:   }

358:   jj = 0; irow = rstart;
359:   for ( i=0; i<mbs; i++ ) {
360:     countA = ai[i+1] - ai[i];
361:     countB = bi[i+1] - bi[i];
362:     ajj    = aj + ai[i];
363:     bjj    = bj + bi[i];
364:     v1     = av + bs2*ai[i];
365:     v2     = bv + bs2*bi[i];

367:     idx = 0;
368:     /* A-part */
369:     for (k=0; k<countA; k++){
370:       for (j=0; j<bs; j++) {
371:         for (n=0; n<bs; n++) {
372:           if (reuse == MAT_INITIAL_MATRIX){
373:             row[jj] = irow + n + shift;
374:             col[jj] = rstart + bs*ajj[k] + j + shift;
375:           }
376:           val[jj++] = v1[idx++];
377:         }
378:       }
379:     }

381:     idx = 0;
382:     /* B-part */
383:     for(k=0; k<countB; k++){
384:       for (j=0; j<bs; j++) {
385:         for (n=0; n<bs; n++) {
386:           if (reuse == MAT_INITIAL_MATRIX){
387:             row[jj] = irow + n + shift;
388:             col[jj] = bs*garray[bjj[k]] + j + shift;
389:           }
390:           val[jj++] = v2[idx++];
391:         }
392:       }
393:     }
394:     irow += bs;
395:   }
396:   return(0);
397: }

401: PetscErrorCode MatConvertToTriples_mpiaij_mpisbaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
402: {
403:   const PetscInt     *ai, *aj,*adiag, *bi, *bj,*garray,m=A->rmap->n,*ajj,*bjj;
404:   PetscErrorCode     ierr;
405:   PetscInt           rstart,nz,nza,nzb,i,j,jj,irow,countA,countB;
406:   PetscInt           *row,*col;
407:   const PetscScalar  *av, *bv,*v1,*v2;
408:   PetscScalar        *val;
409:   Mat_MPIAIJ         *mat =  (Mat_MPIAIJ*)A->data;
410:   Mat_SeqAIJ         *aa=(Mat_SeqAIJ*)(mat->A)->data;
411:   Mat_SeqAIJ         *bb=(Mat_SeqAIJ*)(mat->B)->data;

414:   ai=aa->i; aj=aa->j; adiag=aa->diag;
415:   bi=bb->i; bj=bb->j; garray = mat->garray;
416:   av=aa->a; bv=bb->a;
417:   rstart = A->rmap->rstart;

419:   if (reuse == MAT_INITIAL_MATRIX) {
420:     nza = 0;    /* num of upper triangular entries in mat->A, including diagonals */
421:     nzb = 0;    /* num of upper triangular entries in mat->B */
422:     for(i=0; i<m; i++){
423:       nza    += (ai[i+1] - adiag[i]);
424:       countB  = bi[i+1] - bi[i];
425:       bjj     = bj + bi[i];
426:       for (j=0; j<countB; j++){
427:         if (garray[bjj[j]] > rstart) nzb++;
428:       }
429:     }
430: 
431:     nz = nza + nzb; /* total nz of upper triangular part of mat */
432:     *nnz = nz;
433:     PetscMalloc((2*nz*sizeof(PetscInt)+nz*sizeof(PetscScalar)), &row);
434:     col  = row + nz;
435:     val  = (PetscScalar*)(col + nz);

437:     *r = row; *c = col; *v = val;
438:   } else {
439:     row = *r; col = *c; val = *v;
440:   }

442:   jj = 0; irow = rstart;
443:   for ( i=0; i<m; i++ ) {
444:     ajj    = aj + adiag[i];                 /* ptr to the beginning of the diagonal of this row */
445:     v1     = av + adiag[i];
446:     countA = ai[i+1] - adiag[i];
447:     countB = bi[i+1] - bi[i];
448:     bjj    = bj + bi[i];
449:     v2     = bv + bi[i];

451:      /* A-part */
452:     for (j=0; j<countA; j++){
453:       if (reuse == MAT_INITIAL_MATRIX) {
454:         row[jj] = irow + shift; col[jj] = rstart + ajj[j] + shift;
455:       }
456:       val[jj++] = v1[j];
457:     }

459:     /* B-part */
460:     for(j=0; j < countB; j++){
461:       if (garray[bjj[j]] > rstart) {
462:         if (reuse == MAT_INITIAL_MATRIX) {
463:           row[jj] = irow + shift; col[jj] = garray[bjj[j]] + shift;
464:         }
465:         val[jj++] = v2[j];
466:       }
467:     }
468:     irow++;
469:   }
470:   return(0);
471: }

475: PetscErrorCode MatDestroy_MUMPS(Mat A)
476: {
477:   Mat_MUMPS      *lu=(Mat_MUMPS*)A->spptr;

481:   if (lu && lu->CleanUpMUMPS) {
482:     /* Terminate instance, deallocate memories */
483:     PetscFree2(lu->id.sol_loc,lu->id.isol_loc);
484:     VecScatterDestroy(&lu->scat_rhs);
485:     VecDestroy(&lu->b_seq);
486:     VecScatterDestroy(&lu->scat_sol);
487:     VecDestroy(&lu->x_seq);
488:     ierr=PetscFree(lu->id.perm_in);
489:     PetscFree(lu->irn);
490:     lu->id.job=JOB_END;
491: #if defined(PETSC_USE_COMPLEX)
492:     zmumps_c(&lu->id);
493: #else
494:     dmumps_c(&lu->id);
495: #endif
496:     MPI_Comm_free(&(lu->comm_mumps));
497:   }
498:   if (lu && lu->Destroy) {
499:     (lu->Destroy)(A);
500:   }
501:   PetscFree(A->spptr);

503:   /* clear composed functions */
504:   PetscObjectComposeFunctionDynamic((PetscObject)A,"MatFactorGetSolverPackage_C","",PETSC_NULL);
505:   PetscObjectComposeFunctionDynamic((PetscObject)A,"MatMumpsSetIcntl_C","",PETSC_NULL);
506:   return(0);
507: }

511: PetscErrorCode MatSolve_MUMPS(Mat A,Vec b,Vec x)
512: {
513:   Mat_MUMPS      *lu=(Mat_MUMPS*)A->spptr;
514:   PetscScalar    *array;
515:   Vec            b_seq;
516:   IS             is_iden,is_petsc;
518:   PetscInt       i;

521:   lu->id.nrhs = 1;
522:   b_seq = lu->b_seq;
523:   if (lu->size > 1){
524:     /* MUMPS only supports centralized rhs. Scatter b into a seqential rhs vector */
525:     VecScatterBegin(lu->scat_rhs,b,b_seq,INSERT_VALUES,SCATTER_FORWARD);
526:     VecScatterEnd(lu->scat_rhs,b,b_seq,INSERT_VALUES,SCATTER_FORWARD);
527:     if (!lu->myid) {VecGetArray(b_seq,&array);}
528:   } else {  /* size == 1 */
529:     VecCopy(b,x);
530:     VecGetArray(x,&array);
531:   }
532:   if (!lu->myid) { /* define rhs on the host */
533:     lu->id.nrhs = 1;
534: #if defined(PETSC_USE_COMPLEX)
535:     lu->id.rhs = (mumps_double_complex*)array;
536: #else
537:     lu->id.rhs = array;
538: #endif
539:   }

541:   /* solve phase */
542:   /*-------------*/
543:   lu->id.job = JOB_SOLVE;
544: #if defined(PETSC_USE_COMPLEX)
545:   zmumps_c(&lu->id);
546: #else
547:   dmumps_c(&lu->id);
548: #endif
549:   if (lu->id.INFOG(1) < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by MUMPS in solve phase: INFOG(1)=%d\n",lu->id.INFOG(1));

551:   if (lu->size > 1) { /* convert mumps distributed solution to petsc mpi x */
552:     if (!lu->nSolve){ /* create scatter scat_sol */
553:       ISCreateStride(PETSC_COMM_SELF,lu->id.lsol_loc,0,1,&is_iden); /* from */
554:       for (i=0; i<lu->id.lsol_loc; i++){
555:         lu->id.isol_loc[i] -= 1; /* change Fortran style to C style */
556:       }
557:       ISCreateGeneral(PETSC_COMM_SELF,lu->id.lsol_loc,lu->id.isol_loc,PETSC_COPY_VALUES,&is_petsc);  /* to */
558:       VecScatterCreate(lu->x_seq,is_iden,x,is_petsc,&lu->scat_sol);
559:       ISDestroy(&is_iden);
560:       ISDestroy(&is_petsc);
561:     }
562:     VecScatterBegin(lu->scat_sol,lu->x_seq,x,INSERT_VALUES,SCATTER_FORWARD);
563:     VecScatterEnd(lu->scat_sol,lu->x_seq,x,INSERT_VALUES,SCATTER_FORWARD);
564:   }
565:   lu->nSolve++;
566:   return(0);
567: }

571: PetscErrorCode MatSolveTranspose_MUMPS(Mat A,Vec b,Vec x)
572: {
573:   Mat_MUMPS      *lu=(Mat_MUMPS*)A->spptr;

577:   lu->id.ICNTL(9) = 0;
578:   MatSolve_MUMPS(A,b,x);
579:   lu->id.ICNTL(9) = 1;
580:   return(0);
581: }

585: PetscErrorCode MatMatSolve_MUMPS(Mat A,Mat B,Mat X)
586: {
588:   PetscBool      flg;

591:   PetscTypeCompareAny((PetscObject)B,&flg,MATSEQDENSE,MATMPIDENSE,PETSC_NULL);
592:   if (!flg) SETERRQ(((PetscObject)A)->comm,PETSC_ERR_ARG_WRONG,"Matrix B must be MATDENSE matrix");
593:   PetscTypeCompareAny((PetscObject)X,&flg,MATSEQDENSE,MATMPIDENSE,PETSC_NULL);
594:   if (!flg) SETERRQ(((PetscObject)A)->comm,PETSC_ERR_ARG_WRONG,"Matrix X must be MATDENSE matrix");  SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"MatMatSolve_MUMPS() is not implemented yet");
595:   return(0);
596: }

598: #if !defined(PETSC_USE_COMPLEX)
599: /* 
600:   input:
601:    F:        numeric factor
602:   output:
603:    nneg:     total number of negative pivots
604:    nzero:    0
605:    npos:     (global dimension of F) - nneg
606: */

610: PetscErrorCode MatGetInertia_SBAIJMUMPS(Mat F,int *nneg,int *nzero,int *npos)
611: {
612:   Mat_MUMPS      *lu =(Mat_MUMPS*)F->spptr;
614:   PetscMPIInt    size;

617:   MPI_Comm_size(((PetscObject)F)->comm,&size);
618:   /* 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 */
619:   if (size > 1 && lu->id.ICNTL(13) != 1) SETERRQ1(PETSC_COMM_SELF,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));
620:   if (nneg){
621:     if (!lu->myid){
622:       *nneg = lu->id.INFOG(12);
623:     }
624:     MPI_Bcast(nneg,1,MPI_INT,0,lu->comm_mumps);
625:   }
626:   if (nzero) *nzero = 0;
627:   if (npos)  *npos  = F->rmap->N - (*nneg);
628:   return(0);
629: }
630: #endif /* !defined(PETSC_USE_COMPLEX) */

634: PetscErrorCode MatFactorNumeric_MUMPS(Mat F,Mat A,const MatFactorInfo *info)
635: {
636:   Mat_MUMPS       *lu =(Mat_MUMPS*)(F)->spptr;
637:   PetscErrorCode  ierr;
638:   MatReuse        reuse;
639:   Mat             F_diag;
640:   PetscBool       isMPIAIJ;

643:   reuse = MAT_REUSE_MATRIX;
644:   (*lu->ConvertToTriples)(A, 1, reuse, &lu->nz, &lu->irn, &lu->jcn, &lu->val);

646:   /* numerical factorization phase */
647:   /*-------------------------------*/
648:   lu->id.job = JOB_FACTNUMERIC;
649:   if(!lu->id.ICNTL(18)) {
650:     if (!lu->myid) {
651: #if defined(PETSC_USE_COMPLEX)
652:       lu->id.a = (mumps_double_complex*)lu->val;
653: #else
654:       lu->id.a = lu->val;
655: #endif
656:     }
657:   } else {
658: #if defined(PETSC_USE_COMPLEX)
659:     lu->id.a_loc = (mumps_double_complex*)lu->val;
660: #else
661:     lu->id.a_loc = lu->val;
662: #endif
663:   }
664: #if defined(PETSC_USE_COMPLEX)
665:   zmumps_c(&lu->id);
666: #else
667:   dmumps_c(&lu->id);
668: #endif
669:   if (lu->id.INFOG(1) < 0) {
670:     if (lu->id.INFO(1) == -13) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by MUMPS in numerical factorization phase: Cannot allocate required memory %d megabytes\n",lu->id.INFO(2));
671:     else SETERRQ2(PETSC_COMM_SELF,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));
672:   }
673:   if (!lu->myid && lu->id.ICNTL(16) > 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"  lu->id.ICNTL(16):=%d\n",lu->id.INFOG(16));

675:   if (lu->size > 1){
676:     PetscTypeCompare((PetscObject)A,MATMPIAIJ,&isMPIAIJ);
677:     if(isMPIAIJ) {
678:       F_diag = ((Mat_MPIAIJ *)(F)->data)->A;
679:     } else {
680:       F_diag = ((Mat_MPISBAIJ *)(F)->data)->A;
681:     }
682:     F_diag->assembled = PETSC_TRUE;
683:     if (lu->nSolve){
684:       VecScatterDestroy(&lu->scat_sol);
685:       PetscFree2(lu->id.sol_loc,lu->id.isol_loc);
686:       VecDestroy(&lu->x_seq);
687:     }
688:   }
689:   (F)->assembled   = PETSC_TRUE;
690:   lu->matstruc     = SAME_NONZERO_PATTERN;
691:   lu->CleanUpMUMPS = PETSC_TRUE;
692:   lu->nSolve       = 0;
693: 
694:   if (lu->size > 1){
695:     /* distributed solution */
696:     if (!lu->nSolve){
697:       /* Create x_seq=sol_loc for repeated use */
698:       PetscInt    lsol_loc;
699:       PetscScalar *sol_loc;
700:       lsol_loc = lu->id.INFO(23); /* length of sol_loc */
701:       PetscMalloc2(lsol_loc,PetscScalar,&sol_loc,lsol_loc,PetscInt,&lu->id.isol_loc);
702:       lu->id.lsol_loc = lsol_loc;
703: #if defined(PETSC_USE_COMPLEX)
704:       lu->id.sol_loc  = (mumps_double_complex*)sol_loc;
705: #else
706:       lu->id.sol_loc  = sol_loc;
707: #endif
708:       VecCreateSeqWithArray(PETSC_COMM_SELF,lsol_loc,sol_loc,&lu->x_seq);
709:     }
710:   }
711:   return(0);
712: }

714: /* Sets MUMPS options from the options database */
717: PetscErrorCode PetscSetMUMPSFromOptions(Mat F, Mat A)
718: {
719:   Mat_MUMPS        *mumps = (Mat_MUMPS*)F->spptr;
720:   PetscErrorCode   ierr;
721:   PetscInt         icntl;
722:   PetscBool        flg;

725:   PetscOptionsBegin(((PetscObject)A)->comm,((PetscObject)A)->prefix,"MUMPS Options","Mat");
726:   PetscOptionsInt("-mat_mumps_icntl_1","ICNTL(1): output stream for error messages","None",mumps->id.ICNTL(1),&icntl,&flg);
727:   if (flg) mumps->id.ICNTL(1) = icntl;
728:   PetscOptionsInt("-mat_mumps_icntl_2","ICNTL(2): output stream for diagnostic printing, statistics, and warning","None",mumps->id.ICNTL(2),&icntl,&flg);
729:   if (flg) mumps->id.ICNTL(2) = icntl;
730:   PetscOptionsInt("-mat_mumps_icntl_3","ICNTL(3): output stream for global information, collected on the host","None",mumps->id.ICNTL(3),&icntl,&flg);
731:   if (flg) mumps->id.ICNTL(3) = icntl;

733:   PetscOptionsInt("-mat_mumps_icntl_4","ICNTL(4): level of printing (0 to 4)","None",mumps->id.ICNTL(4),&icntl,&flg);
734:   if (flg) mumps->id.ICNTL(4) = icntl;
735:   if (mumps->id.ICNTL(4) || PetscLogPrintInfo ) mumps->id.ICNTL(3) = 6; /* resume MUMPS default id.ICNTL(3) = 6 */
736: 
737:   PetscOptionsInt("-mat_mumps_icntl_6","ICNTL(6): permuting and/or scaling the matrix (0 to 7)","None",mumps->id.ICNTL(6),&icntl,&flg);
738:   if (flg) mumps->id.ICNTL(6) = icntl;

740:   PetscOptionsInt("-mat_mumps_icntl_7","ICNTL(7): matrix ordering (0 to 7). 3=Scotch, 4=PORD, 5=Metis","None",mumps->id.ICNTL(7),&icntl,&flg);
741:   if (flg) {
742:     if (icntl== 1 && mumps->size > 1){
743:       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"pivot order be set by the user in PERM_IN -- not supported by the PETSc/MUMPS interface\n");
744:     } else {
745:       mumps->id.ICNTL(7) = icntl;
746:     }
747:   }
748: 
749:   PetscOptionsInt("-mat_mumps_icntl_8","ICNTL(8): scaling strategy (-2 to 8 or 77)","None",mumps->id.ICNTL(8),&mumps->id.ICNTL(8),PETSC_NULL);
750:   PetscOptionsInt("-mat_mumps_icntl_10","ICNTL(10): max num of refinements","None",mumps->id.ICNTL(10),&mumps->id.ICNTL(10),PETSC_NULL);
751:   PetscOptionsInt("-mat_mumps_icntl_11","ICNTL(11): statistics related to the linear system solved (via -ksp_view)","None",mumps->id.ICNTL(11),&mumps->id.ICNTL(11),PETSC_NULL);
752:   PetscOptionsInt("-mat_mumps_icntl_12","ICNTL(12): efficiency control: defines the ordering strategy with scaling constraints (0 to 3)","None",mumps->id.ICNTL(12),&mumps->id.ICNTL(12),PETSC_NULL);
753:   PetscOptionsInt("-mat_mumps_icntl_13","ICNTL(13): efficiency control: with or without ScaLAPACK","None",mumps->id.ICNTL(13),&mumps->id.ICNTL(13),PETSC_NULL);
754:   PetscOptionsInt("-mat_mumps_icntl_14","ICNTL(14): percentage of estimated workspace increase","None",mumps->id.ICNTL(14),&mumps->id.ICNTL(14),PETSC_NULL);
755:   PetscOptionsInt("-mat_mumps_icntl_19","ICNTL(19): Schur complement","None",mumps->id.ICNTL(19),&mumps->id.ICNTL(19),PETSC_NULL);

757:   PetscOptionsInt("-mat_mumps_icntl_22","ICNTL(22): in-core/out-of-core facility (0 or 1)","None",mumps->id.ICNTL(22),&mumps->id.ICNTL(22),PETSC_NULL);
758:   PetscOptionsInt("-mat_mumps_icntl_23","ICNTL(23): max size of the working memory (MB) that can allocate per processor","None",mumps->id.ICNTL(23),&mumps->id.ICNTL(23),PETSC_NULL);
759:   PetscOptionsInt("-mat_mumps_icntl_24","ICNTL(24): detection of null pivot rows (0 or 1)","None",mumps->id.ICNTL(24),&mumps->id.ICNTL(24),PETSC_NULL);
760:   if (mumps->id.ICNTL(24)){
761:     mumps->id.ICNTL(13) = 1; /* turn-off ScaLAPACK to help with the correct detection of null pivots */
762:   }

764:   PetscOptionsInt("-mat_mumps_icntl_25","ICNTL(25): computation of a null space basis","None",mumps->id.ICNTL(25),&mumps->id.ICNTL(25),PETSC_NULL);
765:   PetscOptionsInt("-mat_mumps_icntl_26","ICNTL(26): Schur options for right-hand side or solution vector","None",mumps->id.ICNTL(26),&mumps->id.ICNTL(26),PETSC_NULL);
766:   PetscOptionsInt("-mat_mumps_icntl_27","ICNTL(27): experimental parameter","None",mumps->id.ICNTL(27),&mumps->id.ICNTL(27),PETSC_NULL);
767:   PetscOptionsInt("-mat_mumps_icntl_28","ICNTL(28): use 1 for sequential analysis and ictnl(7) ordering, or 2 for parallel analysis and ictnl(29) ordering","None",mumps->id.ICNTL(28),&mumps->id.ICNTL(28),PETSC_NULL);
768:   PetscOptionsInt("-mat_mumps_icntl_29","ICNTL(29): parallel ordering 1 = ptscotch 2 = parmetis","None",mumps->id.ICNTL(29),&mumps->id.ICNTL(29),PETSC_NULL);
769:   PetscOptionsInt("-mat_mumps_icntl_30","ICNTL(30): compute user-specified set of entries in inv(A)","None",mumps->id.ICNTL(30),&mumps->id.ICNTL(30),PETSC_NULL);
770:   PetscOptionsInt("-mat_mumps_icntl_31","ICNTL(31): factors can be discarded in the solve phase","None",mumps->id.ICNTL(31),&mumps->id.ICNTL(31),PETSC_NULL);
771:   PetscOptionsInt("-mat_mumps_icntl_33","ICNTL(33): compute determinant","None",mumps->id.ICNTL(33),&mumps->id.ICNTL(33),PETSC_NULL);

773:   PetscOptionsReal("-mat_mumps_cntl_1","CNTL(1): relative pivoting threshold","None",mumps->id.CNTL(1),&mumps->id.CNTL(1),PETSC_NULL);
774:   PetscOptionsReal("-mat_mumps_cntl_2","CNTL(2): stopping criterion of refinement","None",mumps->id.CNTL(2),&mumps->id.CNTL(2),PETSC_NULL);
775:   PetscOptionsReal("-mat_mumps_cntl_3","CNTL(3): absolute pivoting threshold","None",mumps->id.CNTL(3),&mumps->id.CNTL(3),PETSC_NULL);
776:   PetscOptionsReal("-mat_mumps_cntl_4","CNTL(4): value for static pivoting","None",mumps->id.CNTL(4),&mumps->id.CNTL(4),PETSC_NULL);
777:   PetscOptionsReal("-mat_mumps_cntl_5","CNTL(5): fixation for null pivots","None",mumps->id.CNTL(5),&mumps->id.CNTL(5),PETSC_NULL);
778:   PetscOptionsEnd();
779:   return(0);
780: }
781: 
784: PetscErrorCode PetscInitializeMUMPS(Mat A,Mat_MUMPS* mumps)
785: {
786:   PetscErrorCode  ierr;

789:   MPI_Comm_rank(((PetscObject)A)->comm, &mumps->myid);
790:   MPI_Comm_size(((PetscObject)A)->comm,&mumps->size);
791:   MPI_Comm_dup(((PetscObject)A)->comm,&(mumps->comm_mumps));
792:   mumps->id.comm_fortran = MPI_Comm_c2f(mumps->comm_mumps);

794:   mumps->id.job = JOB_INIT;
795:   mumps->id.par = 1;  /* host participates factorizaton and solve */
796:   mumps->id.sym = mumps->sym;
797: #if defined(PETSC_USE_COMPLEX)
798:   zmumps_c(&mumps->id);
799: #else
800:   dmumps_c(&mumps->id);
801: #endif

803:   mumps->CleanUpMUMPS = PETSC_FALSE;
804:   mumps->scat_rhs     = PETSC_NULL;
805:   mumps->scat_sol     = PETSC_NULL;
806:   mumps->nSolve       = 0;

808:   /* set PETSc-MUMPS default options - override MUMPS default */
809:   mumps->id.ICNTL(3) = 0;
810:   mumps->id.ICNTL(4) = 0;
811:   if (mumps->size == 1){
812:     mumps->id.ICNTL(18) = 0;   /* centralized assembled matrix input */
813:   } else {
814:     mumps->id.ICNTL(18) = 3;   /* distributed assembled matrix input */
815:     mumps->id.ICNTL(21) = 1;   /* distributed solution */
816:   }
817:   return(0);
818: }
819: 
820: /* Note the Petsc r and c permutations are ignored */
823: PetscErrorCode MatLUFactorSymbolic_AIJMUMPS(Mat F,Mat A,IS r,IS c,const MatFactorInfo *info)
824: {
825:   Mat_MUMPS          *lu = (Mat_MUMPS*)F->spptr;
826:   PetscErrorCode     ierr;
827:   MatReuse           reuse;
828:   Vec                b;
829:   IS                 is_iden;
830:   const PetscInt     M = A->rmap->N;

833:   lu->matstruc = DIFFERENT_NONZERO_PATTERN;

835:   /* Set MUMPS options from the options database */
836:   PetscSetMUMPSFromOptions(F,A);
837: 
838:   reuse = MAT_INITIAL_MATRIX;
839:   (*lu->ConvertToTriples)(A, 1, reuse, &lu->nz, &lu->irn, &lu->jcn, &lu->val);

841:   /* analysis phase */
842:   /*----------------*/
843:   lu->id.job = JOB_FACTSYMBOLIC;
844:   lu->id.n = M;
845:   switch (lu->id.ICNTL(18)){
846:   case 0:  /* centralized assembled matrix input */
847:     if (!lu->myid) {
848:       lu->id.nz =lu->nz; lu->id.irn=lu->irn; lu->id.jcn=lu->jcn;
849:       if (lu->id.ICNTL(6)>1){
850: #if defined(PETSC_USE_COMPLEX)
851:         lu->id.a = (mumps_double_complex*)lu->val;
852: #else
853:         lu->id.a = lu->val;
854: #endif
855:       }
856:       if (lu->id.ICNTL(7) == 1){ /* use user-provide matrix ordering */
857:         if (!lu->myid) {
858:           const PetscInt *idx;
859:           PetscInt i,*perm_in;
860:           PetscMalloc(M*sizeof(PetscInt),&perm_in);
861:           ISGetIndices(r,&idx);
862:           lu->id.perm_in = perm_in;
863:           for (i=0; i<M; i++) perm_in[i] = idx[i]+1; /* perm_in[]: start from 1, not 0! */
864:           ISRestoreIndices(r,&idx);
865:         }
866:       }
867:     }
868:     break;
869:   case 3:  /* distributed assembled matrix input (size>1) */
870:     lu->id.nz_loc = lu->nz;
871:     lu->id.irn_loc=lu->irn; lu->id.jcn_loc=lu->jcn;
872:     if (lu->id.ICNTL(6)>1) {
873: #if defined(PETSC_USE_COMPLEX)
874:       lu->id.a_loc = (mumps_double_complex*)lu->val;
875: #else
876:       lu->id.a_loc = lu->val;
877: #endif
878:     }
879:     /* MUMPS only supports centralized rhs. Create scatter scat_rhs for repeated use in MatSolve() */
880:     if (!lu->myid){
881:       VecCreateSeq(PETSC_COMM_SELF,A->cmap->N,&lu->b_seq);
882:       ISCreateStride(PETSC_COMM_SELF,A->cmap->N,0,1,&is_iden);
883:     } else {
884:       VecCreateSeq(PETSC_COMM_SELF,0,&lu->b_seq);
885:       ISCreateStride(PETSC_COMM_SELF,0,0,1,&is_iden);
886:     }
887:     VecCreate(((PetscObject)A)->comm,&b);
888:     VecSetSizes(b,A->rmap->n,PETSC_DECIDE);
889:     VecSetFromOptions(b);

891:     VecScatterCreate(b,is_iden,lu->b_seq,is_iden,&lu->scat_rhs);
892:     ISDestroy(&is_iden);
893:     VecDestroy(&b);
894:     break;
895:     }
896: #if defined(PETSC_USE_COMPLEX)
897:   zmumps_c(&lu->id);
898: #else
899:   dmumps_c(&lu->id);
900: #endif
901:   if (lu->id.INFOG(1) < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by MUMPS in analysis phase: INFOG(1)=%d\n",lu->id.INFOG(1));
902: 
903:   F->ops->lufactornumeric  = MatFactorNumeric_MUMPS;
904:   F->ops->solve            = MatSolve_MUMPS;
905:   F->ops->solvetranspose   = MatSolveTranspose_MUMPS;
906:   F->ops->matsolve         = MatMatSolve_MUMPS;
907:   return(0);
908: }

910: /* Note the Petsc r and c permutations are ignored */
913: PetscErrorCode MatLUFactorSymbolic_BAIJMUMPS(Mat F,Mat A,IS r,IS c,const MatFactorInfo *info)
914: {

916:   Mat_MUMPS       *lu = (Mat_MUMPS*)F->spptr;
917:   PetscErrorCode  ierr;
918:   MatReuse        reuse;
919:   Vec             b;
920:   IS              is_iden;
921:   const PetscInt  M = A->rmap->N;

924:   lu->matstruc = DIFFERENT_NONZERO_PATTERN;

926:   /* Set MUMPS options from the options database */
927:   PetscSetMUMPSFromOptions(F,A);

929:   reuse = MAT_INITIAL_MATRIX;
930:   (*lu->ConvertToTriples)(A, 1, reuse, &lu->nz, &lu->irn, &lu->jcn, &lu->val);

932:   /* analysis phase */
933:   /*----------------*/
934:   lu->id.job = JOB_FACTSYMBOLIC;
935:   lu->id.n = M;
936:   switch (lu->id.ICNTL(18)){
937:   case 0:  /* centralized assembled matrix input */
938:     if (!lu->myid) {
939:       lu->id.nz =lu->nz; lu->id.irn=lu->irn; lu->id.jcn=lu->jcn;
940:       if (lu->id.ICNTL(6)>1){
941: #if defined(PETSC_USE_COMPLEX)
942:         lu->id.a = (mumps_double_complex*)lu->val;
943: #else
944:         lu->id.a = lu->val;
945: #endif
946:       }
947:     }
948:     break;
949:   case 3:  /* distributed assembled matrix input (size>1) */
950:     lu->id.nz_loc = lu->nz;
951:     lu->id.irn_loc=lu->irn; lu->id.jcn_loc=lu->jcn;
952:     if (lu->id.ICNTL(6)>1) {
953: #if defined(PETSC_USE_COMPLEX)
954:       lu->id.a_loc = (mumps_double_complex*)lu->val;
955: #else
956:       lu->id.a_loc = lu->val;
957: #endif
958:     }
959:     /* MUMPS only supports centralized rhs. Create scatter scat_rhs for repeated use in MatSolve() */
960:     if (!lu->myid){
961:       VecCreateSeq(PETSC_COMM_SELF,A->cmap->N,&lu->b_seq);
962:       ISCreateStride(PETSC_COMM_SELF,A->cmap->N,0,1,&is_iden);
963:     } else {
964:       VecCreateSeq(PETSC_COMM_SELF,0,&lu->b_seq);
965:       ISCreateStride(PETSC_COMM_SELF,0,0,1,&is_iden);
966:     }
967:     VecCreate(((PetscObject)A)->comm,&b);
968:     VecSetSizes(b,A->rmap->n,PETSC_DECIDE);
969:     VecSetFromOptions(b);

971:     VecScatterCreate(b,is_iden,lu->b_seq,is_iden,&lu->scat_rhs);
972:     ISDestroy(&is_iden);
973:     VecDestroy(&b);
974:     break;
975:     }
976: #if defined(PETSC_USE_COMPLEX)
977:   zmumps_c(&lu->id);
978: #else
979:   dmumps_c(&lu->id);
980: #endif
981:   if (lu->id.INFOG(1) < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by MUMPS in analysis phase: INFOG(1)=%d\n",lu->id.INFOG(1));
982: 
983:   F->ops->lufactornumeric  = MatFactorNumeric_MUMPS;
984:   F->ops->solve            = MatSolve_MUMPS;
985:   F->ops->solvetranspose   = MatSolveTranspose_MUMPS;
986:   return(0);
987: }

989: /* Note the Petsc r permutation and factor info are ignored */
992: PetscErrorCode MatCholeskyFactorSymbolic_MUMPS(Mat F,Mat A,IS r,const MatFactorInfo *info)
993: {
994:   Mat_MUMPS          *lu = (Mat_MUMPS*)F->spptr;
995:   PetscErrorCode     ierr;
996:   MatReuse           reuse;
997:   Vec                b;
998:   IS                 is_iden;
999:   const PetscInt     M = A->rmap->N;

1002:   lu->matstruc = DIFFERENT_NONZERO_PATTERN;

1004:   /* Set MUMPS options from the options database */
1005:   PetscSetMUMPSFromOptions(F,A);

1007:   reuse = MAT_INITIAL_MATRIX;
1008:   (*lu->ConvertToTriples)(A, 1 , reuse, &lu->nz, &lu->irn, &lu->jcn, &lu->val);

1010:   /* analysis phase */
1011:   /*----------------*/
1012:   lu->id.job = JOB_FACTSYMBOLIC;
1013:   lu->id.n = M;
1014:   switch (lu->id.ICNTL(18)){
1015:   case 0:  /* centralized assembled matrix input */
1016:     if (!lu->myid) {
1017:       lu->id.nz =lu->nz; lu->id.irn=lu->irn; lu->id.jcn=lu->jcn;
1018:       if (lu->id.ICNTL(6)>1){
1019: #if defined(PETSC_USE_COMPLEX)
1020:         lu->id.a = (mumps_double_complex*)lu->val;
1021: #else
1022:         lu->id.a = lu->val;
1023: #endif
1024:       }
1025:     }
1026:     break;
1027:   case 3:  /* distributed assembled matrix input (size>1) */
1028:     lu->id.nz_loc = lu->nz;
1029:     lu->id.irn_loc=lu->irn; lu->id.jcn_loc=lu->jcn;
1030:     if (lu->id.ICNTL(6)>1) {
1031: #if defined(PETSC_USE_COMPLEX)
1032:       lu->id.a_loc = (mumps_double_complex*)lu->val;
1033: #else
1034:       lu->id.a_loc = lu->val;
1035: #endif
1036:     }
1037:     /* MUMPS only supports centralized rhs. Create scatter scat_rhs for repeated use in MatSolve() */
1038:     if (!lu->myid){
1039:       VecCreateSeq(PETSC_COMM_SELF,A->cmap->N,&lu->b_seq);
1040:       ISCreateStride(PETSC_COMM_SELF,A->cmap->N,0,1,&is_iden);
1041:     } else {
1042:       VecCreateSeq(PETSC_COMM_SELF,0,&lu->b_seq);
1043:       ISCreateStride(PETSC_COMM_SELF,0,0,1,&is_iden);
1044:     }
1045:     VecCreate(((PetscObject)A)->comm,&b);
1046:     VecSetSizes(b,A->rmap->n,PETSC_DECIDE);
1047:     VecSetFromOptions(b);

1049:     VecScatterCreate(b,is_iden,lu->b_seq,is_iden,&lu->scat_rhs);
1050:     ISDestroy(&is_iden);
1051:     VecDestroy(&b);
1052:     break;
1053:     }
1054: #if defined(PETSC_USE_COMPLEX)
1055:   zmumps_c(&lu->id);
1056: #else
1057:   dmumps_c(&lu->id);
1058: #endif
1059:   if (lu->id.INFOG(1) < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by MUMPS in analysis phase: INFOG(1)=%d\n",lu->id.INFOG(1));

1061:   F->ops->choleskyfactornumeric = MatFactorNumeric_MUMPS;
1062:   F->ops->solve                 = MatSolve_MUMPS;
1063:   F->ops->solvetranspose        = MatSolve_MUMPS;
1064: #if !defined(PETSC_USE_COMPLEX)
1065:   F->ops->getinertia            = MatGetInertia_SBAIJMUMPS;
1066: #else
1067:   F->ops->getinertia            = PETSC_NULL;
1068: #endif
1069:   return(0);
1070: }

1074: PetscErrorCode MatView_MUMPS(Mat A,PetscViewer viewer)
1075: {
1076:   PetscErrorCode    ierr;
1077:   PetscBool         iascii;
1078:   PetscViewerFormat format;
1079:   Mat_MUMPS         *lu=(Mat_MUMPS*)A->spptr;

1082:   /* check if matrix is mumps type */
1083:   if (A->ops->solve != MatSolve_MUMPS) return(0);

1085:   PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);
1086:   if (iascii) {
1087:     PetscViewerGetFormat(viewer,&format);
1088:     if (format == PETSC_VIEWER_ASCII_INFO){
1089:       PetscViewerASCIIPrintf(viewer,"MUMPS run parameters:\n");
1090:       PetscViewerASCIIPrintf(viewer,"  SYM (matrix type):                   %d \n",lu->id.sym);
1091:       PetscViewerASCIIPrintf(viewer,"  PAR (host participation):            %d \n",lu->id.par);
1092:       PetscViewerASCIIPrintf(viewer,"  ICNTL(1) (output for error):         %d \n",lu->id.ICNTL(1));
1093:       PetscViewerASCIIPrintf(viewer,"  ICNTL(2) (output of diagnostic msg): %d \n",lu->id.ICNTL(2));
1094:       PetscViewerASCIIPrintf(viewer,"  ICNTL(3) (output for global info):   %d \n",lu->id.ICNTL(3));
1095:       PetscViewerASCIIPrintf(viewer,"  ICNTL(4) (level of printing):        %d \n",lu->id.ICNTL(4));
1096:       PetscViewerASCIIPrintf(viewer,"  ICNTL(5) (input mat struct):         %d \n",lu->id.ICNTL(5));
1097:       PetscViewerASCIIPrintf(viewer,"  ICNTL(6) (matrix prescaling):        %d \n",lu->id.ICNTL(6));
1098:       PetscViewerASCIIPrintf(viewer,"  ICNTL(7) (sequentia matrix ordering):%d \n",lu->id.ICNTL(7));
1099:       PetscViewerASCIIPrintf(viewer,"  ICNTL(8) (scalling strategy):        %d \n",lu->id.ICNTL(8));
1100:       PetscViewerASCIIPrintf(viewer,"  ICNTL(10) (max num of refinements):  %d \n",lu->id.ICNTL(10));
1101:       PetscViewerASCIIPrintf(viewer,"  ICNTL(11) (error analysis):          %d \n",lu->id.ICNTL(11));
1102:       if (lu->id.ICNTL(11)>0) {
1103:         PetscViewerASCIIPrintf(viewer,"    RINFOG(4) (inf norm of input mat):        %g\n",lu->id.RINFOG(4));
1104:         PetscViewerASCIIPrintf(viewer,"    RINFOG(5) (inf norm of solution):         %g\n",lu->id.RINFOG(5));
1105:         PetscViewerASCIIPrintf(viewer,"    RINFOG(6) (inf norm of residual):         %g\n",lu->id.RINFOG(6));
1106:         PetscViewerASCIIPrintf(viewer,"    RINFOG(7),RINFOG(8) (backward error est): %g, %g\n",lu->id.RINFOG(7),lu->id.RINFOG(8));
1107:         PetscViewerASCIIPrintf(viewer,"    RINFOG(9) (error estimate):               %g \n",lu->id.RINFOG(9));
1108:         PetscViewerASCIIPrintf(viewer,"    RINFOG(10),RINFOG(11)(condition numbers): %g, %g\n",lu->id.RINFOG(10),lu->id.RINFOG(11));
1109:       }
1110:       PetscViewerASCIIPrintf(viewer,"  ICNTL(12) (efficiency control):                         %d \n",lu->id.ICNTL(12));
1111:       PetscViewerASCIIPrintf(viewer,"  ICNTL(13) (efficiency control):                         %d \n",lu->id.ICNTL(13));
1112:       PetscViewerASCIIPrintf(viewer,"  ICNTL(14) (percentage of estimated workspace increase): %d \n",lu->id.ICNTL(14));
1113:       /* ICNTL(15-17) not used */
1114:       PetscViewerASCIIPrintf(viewer,"  ICNTL(18) (input mat struct):                           %d \n",lu->id.ICNTL(18));
1115:       PetscViewerASCIIPrintf(viewer,"  ICNTL(19) (Shur complement info):                       %d \n",lu->id.ICNTL(19));
1116:       PetscViewerASCIIPrintf(viewer,"  ICNTL(20) (rhs sparse pattern):                         %d \n",lu->id.ICNTL(20));
1117:       PetscViewerASCIIPrintf(viewer,"  ICNTL(21) (solution struct):                            %d \n",lu->id.ICNTL(21));
1118:       PetscViewerASCIIPrintf(viewer,"  ICNTL(22) (in-core/out-of-core facility):               %d \n",lu->id.ICNTL(22));
1119:       PetscViewerASCIIPrintf(viewer,"  ICNTL(23) (max size of memory can be allocated locally):%d \n",lu->id.ICNTL(23));
1120: 
1121:       PetscViewerASCIIPrintf(viewer,"  ICNTL(24) (detection of null pivot rows):               %d \n",lu->id.ICNTL(24));
1122:       PetscViewerASCIIPrintf(viewer,"  ICNTL(25) (computation of a null space basis):          %d \n",lu->id.ICNTL(25));
1123:       PetscViewerASCIIPrintf(viewer,"  ICNTL(26) (Schur options for rhs or solution):          %d \n",lu->id.ICNTL(26));
1124:       PetscViewerASCIIPrintf(viewer,"  ICNTL(27) (experimental parameter):                     %d \n",lu->id.ICNTL(27));
1125:       PetscViewerASCIIPrintf(viewer,"  ICNTL(28) (use parallel or sequential ordering):        %d \n",lu->id.ICNTL(28));
1126:       PetscViewerASCIIPrintf(viewer,"  ICNTL(29) (parallel ordering):                          %d \n",lu->id.ICNTL(29));
1127: 
1128:       PetscViewerASCIIPrintf(viewer,"  ICNTL(30) (user-specified set of entries in inv(A)):    %d \n",lu->id.ICNTL(30));
1129:       PetscViewerASCIIPrintf(viewer,"  ICNTL(31) (factors is discarded in the solve phase):    %d \n",lu->id.ICNTL(31));
1130:       PetscViewerASCIIPrintf(viewer,"  ICNTL(33) (compute determinant):                        %d \n",lu->id.ICNTL(33));
1131: 
1132:       PetscViewerASCIIPrintf(viewer,"  CNTL(1) (relative pivoting threshold):      %g \n",lu->id.CNTL(1));
1133:       PetscViewerASCIIPrintf(viewer,"  CNTL(2) (stopping criterion of refinement): %g \n",lu->id.CNTL(2));
1134:       PetscViewerASCIIPrintf(viewer,"  CNTL(3) (absolute pivoting threshold):      %g \n",lu->id.CNTL(3));
1135:       PetscViewerASCIIPrintf(viewer,"  CNTL(4) (value of static pivoting):         %g \n",lu->id.CNTL(4));
1136:       PetscViewerASCIIPrintf(viewer,"  CNTL(5) (fixation for null pivots):         %g \n",lu->id.CNTL(5));
1137: 
1138:       /* infomation local to each processor */
1139:       PetscViewerASCIIPrintf(viewer, "  RINFO(1) (local estimated flops for the elimination after analysis): \n");
1140:       PetscViewerASCIISynchronizedAllow(viewer,PETSC_TRUE);
1141:       PetscViewerASCIISynchronizedPrintf(viewer,"    [%d] %g \n",lu->myid,lu->id.RINFO(1));
1142:       PetscViewerFlush(viewer);
1143:       PetscViewerASCIIPrintf(viewer, "  RINFO(2) (local estimated flops for the assembly after factorization): \n");
1144:       PetscViewerASCIISynchronizedPrintf(viewer,"    [%d]  %g \n",lu->myid,lu->id.RINFO(2));
1145:       PetscViewerFlush(viewer);
1146:       PetscViewerASCIIPrintf(viewer, "  RINFO(3) (local estimated flops for the elimination after factorization): \n");
1147:       PetscViewerASCIISynchronizedPrintf(viewer,"    [%d]  %g \n",lu->myid,lu->id.RINFO(3));
1148:       PetscViewerFlush(viewer);
1149: 
1150:       PetscViewerASCIIPrintf(viewer, "  INFO(15) (estimated size of (in MB) MUMPS internal data for running numerical factorization): \n");
1151:       PetscViewerASCIISynchronizedPrintf(viewer,"  [%d] %d \n",lu->myid,lu->id.INFO(15));
1152:       PetscViewerFlush(viewer);
1153: 
1154:       PetscViewerASCIIPrintf(viewer, "  INFO(16) (size of (in MB) MUMPS internal data used during numerical factorization): \n");
1155:       PetscViewerASCIISynchronizedPrintf(viewer,"    [%d] %d \n",lu->myid,lu->id.INFO(16));
1156:       PetscViewerFlush(viewer);
1157: 
1158:       PetscViewerASCIIPrintf(viewer, "  INFO(23) (num of pivots eliminated on this processor after factorization): \n");
1159:       PetscViewerASCIISynchronizedPrintf(viewer,"    [%d] %d \n",lu->myid,lu->id.INFO(23));
1160:       PetscViewerFlush(viewer);
1161:       PetscViewerASCIISynchronizedAllow(viewer,PETSC_FALSE);

1163:       if (!lu->myid){ /* information from the host */
1164:         PetscViewerASCIIPrintf(viewer,"  RINFOG(1) (global estimated flops for the elimination after analysis): %g \n",lu->id.RINFOG(1));
1165:         PetscViewerASCIIPrintf(viewer,"  RINFOG(2) (global estimated flops for the assembly after factorization): %g \n",lu->id.RINFOG(2));
1166:         PetscViewerASCIIPrintf(viewer,"  RINFOG(3) (global estimated flops for the elimination after factorization): %g \n",lu->id.RINFOG(3));
1167:         PetscViewerASCIIPrintf(viewer,"  (RINFOG(12) RINFOG(13))*2^INFOG(34) (determinant): (%g,%g)*(2^%d)\n",lu->id.RINFOG(12),lu->id.RINFOG(13),lu->id.INFOG(34));
1168: 
1169:         PetscViewerASCIIPrintf(viewer,"  INFOG(3) (estimated real workspace for factors on all processors after analysis): %d \n",lu->id.INFOG(3));
1170:         PetscViewerASCIIPrintf(viewer,"  INFOG(4) (estimated integer workspace for factors on all processors after analysis): %d \n",lu->id.INFOG(4));
1171:         PetscViewerASCIIPrintf(viewer,"  INFOG(5) (estimated maximum front size in the complete tree): %d \n",lu->id.INFOG(5));
1172:         PetscViewerASCIIPrintf(viewer,"  INFOG(6) (number of nodes in the complete tree): %d \n",lu->id.INFOG(6));
1173:         PetscViewerASCIIPrintf(viewer,"  INFOG(7) (ordering option effectively use after analysis): %d \n",lu->id.INFOG(7));
1174:         PetscViewerASCIIPrintf(viewer,"  INFOG(8) (structural symmetry in percent of the permuted matrix after analysis): %d \n",lu->id.INFOG(8));
1175:         PetscViewerASCIIPrintf(viewer,"  INFOG(9) (total real/complex workspace to store the matrix factors after factorization): %d \n",lu->id.INFOG(9));
1176:         PetscViewerASCIIPrintf(viewer,"  INFOG(10) (total integer space store the matrix factors after factorization): %d \n",lu->id.INFOG(10));
1177:         PetscViewerASCIIPrintf(viewer,"  INFOG(11) (order of largest frontal matrix after factorization): %d \n",lu->id.INFOG(11));
1178:         PetscViewerASCIIPrintf(viewer,"  INFOG(12) (number of off-diagonal pivots): %d \n",lu->id.INFOG(12));
1179:         PetscViewerASCIIPrintf(viewer,"  INFOG(13) (number of delayed pivots after factorization): %d \n",lu->id.INFOG(13));
1180:         PetscViewerASCIIPrintf(viewer,"  INFOG(14) (number of memory compress after factorization): %d \n",lu->id.INFOG(14));
1181:         PetscViewerASCIIPrintf(viewer,"  INFOG(15) (number of steps of iterative refinement after solution): %d \n",lu->id.INFOG(15));
1182:         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));
1183:         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));
1184:         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));
1185:         PetscViewerASCIIPrintf(viewer,"  INFOG(19) (size of all MUMPS internal data allocated during factorization: sum over all processors): %d \n",lu->id.INFOG(19));
1186:         PetscViewerASCIIPrintf(viewer,"  INFOG(20) (estimated number of entries in the factors): %d \n",lu->id.INFOG(20));
1187:         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));
1188:         PetscViewerASCIIPrintf(viewer,"  INFOG(22) (size in MB of memory effectively used during factorization - sum over all processors): %d \n",lu->id.INFOG(22));
1189:         PetscViewerASCIIPrintf(viewer,"  INFOG(23) (after analysis: value of ICNTL(6) effectively used): %d \n",lu->id.INFOG(23));
1190:         PetscViewerASCIIPrintf(viewer,"  INFOG(24) (after analysis: value of ICNTL(12) effectively used): %d \n",lu->id.INFOG(24));
1191:         PetscViewerASCIIPrintf(viewer,"  INFOG(25) (after factorization: number of pivots modified by static pivoting): %d \n",lu->id.INFOG(25));
1192:       }
1193:     }
1194:   }
1195:   return(0);
1196: }

1200: PetscErrorCode MatGetInfo_MUMPS(Mat A,MatInfoType flag,MatInfo *info)
1201: {
1202:   Mat_MUMPS  *mumps =(Mat_MUMPS*)A->spptr;

1205:   info->block_size        = 1.0;
1206:   info->nz_allocated      = mumps->id.INFOG(20);
1207:   info->nz_used           = mumps->id.INFOG(20);
1208:   info->nz_unneeded       = 0.0;
1209:   info->assemblies        = 0.0;
1210:   info->mallocs           = 0.0;
1211:   info->memory            = 0.0;
1212:   info->fill_ratio_given  = 0;
1213:   info->fill_ratio_needed = 0;
1214:   info->factor_mallocs    = 0;
1215:   return(0);
1216: }

1218: /* -------------------------------------------------------------------------------------------*/
1221: PetscErrorCode MatMumpsSetIcntl_MUMPS(Mat F,PetscInt icntl,PetscInt ival)
1222: {
1223:   Mat_MUMPS *lu =(Mat_MUMPS*)F->spptr;

1226:   lu->id.ICNTL(icntl) = ival;
1227:   return(0);
1228: }

1232: /*@
1233:   MatMumpsSetIcntl - Set MUMPS parameter ICNTL()

1235:    Logically Collective on Mat

1237:    Input Parameters:
1238: +  F - the factored matrix obtained by calling MatGetFactor() from PETSc-MUMPS interface
1239: .  icntl - index of MUMPS parameter array ICNTL()
1240: -  ival - value of MUMPS ICNTL(icntl)

1242:   Options Database:
1243: .   -mat_mumps_icntl_<icntl> <ival>

1245:    Level: beginner

1247:    References: MUMPS Users' Guide 

1249: .seealso: MatGetFactor()
1250: @*/
1251: PetscErrorCode MatMumpsSetIcntl(Mat F,PetscInt icntl,PetscInt ival)
1252: {

1258:   PetscTryMethod(F,"MatMumpsSetIcntl_C",(Mat,PetscInt,PetscInt),(F,icntl,ival));
1259:   return(0);
1260: }

1262: /*MC
1263:   MATSOLVERMUMPS -  A matrix type providing direct solvers (LU and Cholesky) for
1264:   distributed and sequential matrices via the external package MUMPS. 

1266:   Works with MATAIJ and MATSBAIJ matrices

1268:   Options Database Keys:
1269: + -mat_mumps_icntl_4 <0,...,4> - print level
1270: . -mat_mumps_icntl_6 <0,...,7> - matrix prescaling options (see MUMPS User's Guide)
1271: . -mat_mumps_icntl_7 <0,...,7> - matrix orderings (see MUMPS User's Guidec)
1272: . -mat_mumps_icntl_9 <1,2> - A or A^T x=b to be solved: 1 denotes A, 2 denotes A^T
1273: . -mat_mumps_icntl_10 <n> - maximum number of iterative refinements
1274: . -mat_mumps_icntl_11 <n> - error analysis, a positive value returns statistics during -ksp_view
1275: . -mat_mumps_icntl_12 <n> - efficiency control (see MUMPS User's Guide)
1276: . -mat_mumps_icntl_13 <n> - efficiency control (see MUMPS User's Guide)
1277: . -mat_mumps_icntl_14 <n> - efficiency control (see MUMPS User's Guide)
1278: . -mat_mumps_icntl_15 <n> - efficiency control (see MUMPS User's Guide)
1279: . -mat_mumps_cntl_1 <delta> - relative pivoting threshold
1280: . -mat_mumps_cntl_2 <tol> - stopping criterion for refinement
1281: - -mat_mumps_cntl_3 <adelta> - absolute pivoting threshold

1283:   Level: beginner

1285: .seealso: PCFactorSetMatSolverPackage(), MatSolverPackage

1287: M*/

1289: EXTERN_C_BEGIN
1292: PetscErrorCode MatFactorGetSolverPackage_mumps(Mat A,const MatSolverPackage *type)
1293: {
1295:   *type = MATSOLVERMUMPS;
1296:   return(0);
1297: }
1298: EXTERN_C_END

1300: EXTERN_C_BEGIN
1301: /* MatGetFactor for Seq and MPI AIJ matrices */
1304: PetscErrorCode MatGetFactor_aij_mumps(Mat A,MatFactorType ftype,Mat *F)
1305: {
1306:   Mat            B;
1308:   Mat_MUMPS      *mumps;
1309:   PetscBool      isSeqAIJ;

1312:   /* Create the factorization matrix */
1313:   PetscTypeCompare((PetscObject)A,MATSEQAIJ,&isSeqAIJ);
1314:   MatCreate(((PetscObject)A)->comm,&B);
1315:   MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);
1316:   MatSetType(B,((PetscObject)A)->type_name);
1317:   if (isSeqAIJ) {
1318:     MatSeqAIJSetPreallocation(B,0,PETSC_NULL);
1319:   } else {
1320:     MatMPIAIJSetPreallocation(B,0,PETSC_NULL,0,PETSC_NULL);
1321:   }

1323:   PetscNewLog(B,Mat_MUMPS,&mumps);
1324:   B->ops->view             = MatView_MUMPS;
1325:   B->ops->getinfo          = MatGetInfo_MUMPS;
1326:   PetscObjectComposeFunctionDynamic((PetscObject)B,"MatFactorGetSolverPackage_C","MatFactorGetSolverPackage_mumps",MatFactorGetSolverPackage_mumps);
1327:   PetscObjectComposeFunctionDynamic((PetscObject)B,"MatMumpsSetIcntl_C","MatMumpsSetIcntl_MUMPS",MatMumpsSetIcntl_MUMPS);
1328:   if (ftype == MAT_FACTOR_LU) {
1329:     B->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJMUMPS;
1330:     B->factortype = MAT_FACTOR_LU;
1331:     if (isSeqAIJ) mumps->ConvertToTriples = MatConvertToTriples_seqaij_seqaij;
1332:     else mumps->ConvertToTriples = MatConvertToTriples_mpiaij_mpiaij;
1333:     mumps->sym = 0;
1334:   } else {
1335:     B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_MUMPS;
1336:     B->factortype = MAT_FACTOR_CHOLESKY;
1337:     if (isSeqAIJ) mumps->ConvertToTriples = MatConvertToTriples_seqaij_seqsbaij;
1338:     else mumps->ConvertToTriples = MatConvertToTriples_mpiaij_mpisbaij;
1339:     if (A->spd_set && A->spd) mumps->sym = 1;
1340:     else                      mumps->sym = 2;
1341:   }

1343:   mumps->isAIJ        = PETSC_TRUE;
1344:   mumps->Destroy      = B->ops->destroy;
1345:   B->ops->destroy     = MatDestroy_MUMPS;
1346:   B->spptr            = (void*)mumps;
1347:   PetscInitializeMUMPS(A,mumps);

1349:   *F = B;
1350:   return(0);
1351: }
1352: EXTERN_C_END


1355: EXTERN_C_BEGIN
1356: /* MatGetFactor for Seq and MPI SBAIJ matrices */
1359: PetscErrorCode MatGetFactor_sbaij_mumps(Mat A,MatFactorType ftype,Mat *F)
1360: {
1361:   Mat            B;
1363:   Mat_MUMPS      *mumps;
1364:   PetscBool      isSeqSBAIJ;

1367:   if (ftype != MAT_FACTOR_CHOLESKY) SETERRQ(((PetscObject)A)->comm,PETSC_ERR_SUP,"Cannot use PETSc SBAIJ matrices with MUMPS LU, use AIJ matrix");
1368:   if(A->rmap->bs > 1) SETERRQ(((PetscObject)A)->comm,PETSC_ERR_SUP,"Cannot use PETSc SBAIJ matrices with block size > 1 with MUMPS Cholesky, use AIJ matrix instead");
1369:   PetscTypeCompare((PetscObject)A,MATSEQSBAIJ,&isSeqSBAIJ);
1370:   /* Create the factorization matrix */
1371:   MatCreate(((PetscObject)A)->comm,&B);
1372:   MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);
1373:   MatSetType(B,((PetscObject)A)->type_name);
1374:   PetscNewLog(B,Mat_MUMPS,&mumps);
1375:   if (isSeqSBAIJ) {
1376:     MatSeqSBAIJSetPreallocation(B,1,0,PETSC_NULL);
1377:     mumps->ConvertToTriples = MatConvertToTriples_seqsbaij_seqsbaij;
1378:   } else {
1379:     MatMPISBAIJSetPreallocation(B,1,0,PETSC_NULL,0,PETSC_NULL);
1380:     mumps->ConvertToTriples = MatConvertToTriples_mpisbaij_mpisbaij;
1381:   }

1383:   B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_MUMPS;
1384:   B->ops->view                   = MatView_MUMPS;
1385:   PetscObjectComposeFunctionDynamic((PetscObject)B,"MatFactorGetSolverPackage_C","MatFactorGetSolverPackage_mumps",MatFactorGetSolverPackage_mumps);
1386:   PetscObjectComposeFunctionDynamic((PetscObject)B,"MatMumpsSetIcntl_C","MatMumpsSetIcntl",MatMumpsSetIcntl);
1387:   B->factortype                  = MAT_FACTOR_CHOLESKY;
1388:   if (A->spd_set && A->spd) mumps->sym = 1;
1389:   else                      mumps->sym = 2;

1391:   mumps->isAIJ        = PETSC_FALSE;
1392:   mumps->Destroy      = B->ops->destroy;
1393:   B->ops->destroy     = MatDestroy_MUMPS;
1394:   B->spptr            = (void*)mumps;
1395:   PetscInitializeMUMPS(A,mumps);

1397:   *F = B;
1398:   return(0);
1399: }
1400: EXTERN_C_END

1402: EXTERN_C_BEGIN
1405: PetscErrorCode MatGetFactor_baij_mumps(Mat A,MatFactorType ftype,Mat *F)
1406: {
1407:   Mat            B;
1409:   Mat_MUMPS      *mumps;
1410:   PetscBool      isSeqBAIJ;

1413:   /* Create the factorization matrix */
1414:   PetscTypeCompare((PetscObject)A,MATSEQBAIJ,&isSeqBAIJ);
1415:   MatCreate(((PetscObject)A)->comm,&B);
1416:   MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);
1417:   MatSetType(B,((PetscObject)A)->type_name);
1418:   if (isSeqBAIJ) {
1419:     MatSeqBAIJSetPreallocation(B,A->rmap->bs,0,PETSC_NULL);
1420:   } else {
1421:     MatMPIBAIJSetPreallocation(B,A->rmap->bs,0,PETSC_NULL,0,PETSC_NULL);
1422:   }

1424:   PetscNewLog(B,Mat_MUMPS,&mumps);
1425:   if (ftype == MAT_FACTOR_LU) {
1426:     B->ops->lufactorsymbolic = MatLUFactorSymbolic_BAIJMUMPS;
1427:     B->factortype = MAT_FACTOR_LU;
1428:     if (isSeqBAIJ) mumps->ConvertToTriples = MatConvertToTriples_seqbaij_seqaij;
1429:     else mumps->ConvertToTriples = MatConvertToTriples_mpibaij_mpiaij;
1430:     mumps->sym = 0;
1431:   } else {
1432:     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc BAIJ matrices with MUMPS Cholesky, use SBAIJ or AIJ matrix instead\n");
1433:   }

1435:   B->ops->view             = MatView_MUMPS;
1436:   PetscObjectComposeFunctionDynamic((PetscObject)B,"MatFactorGetSolverPackage_C","MatFactorGetSolverPackage_mumps",MatFactorGetSolverPackage_mumps);
1437:   PetscObjectComposeFunctionDynamic((PetscObject)B,"MatMumpsSetIcntl_C","MatMumpsSetIcntl_MUMPS",MatMumpsSetIcntl_MUMPS);

1439:   mumps->isAIJ        = PETSC_TRUE;
1440:   mumps->Destroy      = B->ops->destroy;
1441:   B->ops->destroy     = MatDestroy_MUMPS;
1442:   B->spptr            = (void*)mumps;
1443:   PetscInitializeMUMPS(A,mumps);

1445:   *F = B;
1446:   return(0);
1447: }
1448: EXTERN_C_END