Actual source code: mumps.c

petsc-master 2017-03-28
Report Typos and Errors

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

  6:  #include <../src/mat/impls/aij/mpi/mpiaij.h>
  7:  #include <../src/mat/impls/sbaij/mpi/mpisbaij.h>
  8:  #include <petscblaslapack.h>

 10: EXTERN_C_BEGIN
 11: #if defined(PETSC_USE_COMPLEX)
 12: #if defined(PETSC_USE_REAL_SINGLE)
 13: #include <cmumps_c.h>
 14: #else
 15: #include <zmumps_c.h>
 16: #endif
 17: #else
 18: #if defined(PETSC_USE_REAL_SINGLE)
 19: #include <smumps_c.h>
 20: #else
 21: #include <dmumps_c.h>
 22: #endif
 23: #endif
 24: EXTERN_C_END
 25: #define JOB_INIT -1
 26: #define JOB_FACTSYMBOLIC 1
 27: #define JOB_FACTNUMERIC 2
 28: #define JOB_SOLVE 3
 29: #define JOB_END -2

 31: /* calls to MUMPS */
 32: #if defined(PETSC_USE_COMPLEX)
 33: #if defined(PETSC_USE_REAL_SINGLE)
 34: #define PetscMUMPS_c cmumps_c
 35: #else
 36: #define PetscMUMPS_c zmumps_c
 37: #endif
 38: #else
 39: #if defined(PETSC_USE_REAL_SINGLE)
 40: #define PetscMUMPS_c smumps_c
 41: #else
 42: #define PetscMUMPS_c dmumps_c
 43: #endif
 44: #endif

 46: /* declare MumpsScalar */
 47: #if defined(PETSC_USE_COMPLEX)
 48: #if defined(PETSC_USE_REAL_SINGLE)
 49: #define MumpsScalar mumps_complex
 50: #else
 51: #define MumpsScalar mumps_double_complex
 52: #endif
 53: #else
 54: #define MumpsScalar PetscScalar
 55: #endif

 57: /* macros s.t. indices match MUMPS documentation */
 58: #define ICNTL(I) icntl[(I)-1]
 59: #define CNTL(I) cntl[(I)-1]
 60: #define INFOG(I) infog[(I)-1]
 61: #define INFO(I) info[(I)-1]
 62: #define RINFOG(I) rinfog[(I)-1]
 63: #define RINFO(I) rinfo[(I)-1]

 65: typedef struct {
 66: #if defined(PETSC_USE_COMPLEX)
 67: #if defined(PETSC_USE_REAL_SINGLE)
 68:   CMUMPS_STRUC_C id;
 69: #else
 70:   ZMUMPS_STRUC_C id;
 71: #endif
 72: #else
 73: #if defined(PETSC_USE_REAL_SINGLE)
 74:   SMUMPS_STRUC_C id;
 75: #else
 76:   DMUMPS_STRUC_C id;
 77: #endif
 78: #endif

 80:   MatStructure matstruc;
 81:   PetscMPIInt  myid,size;
 82:   PetscInt     *irn,*jcn,nz,sym;
 83:   PetscScalar  *val;
 84:   MPI_Comm     comm_mumps;
 85:   PetscBool    isAIJ;
 86:   PetscInt     ICNTL9_pre;           /* check if ICNTL(9) is changed from previous MatSolve */
 87:   VecScatter   scat_rhs, scat_sol;   /* used by MatSolve() */
 88:   Vec          b_seq,x_seq;
 89:   PetscInt     ninfo,*info;          /* display INFO */
 90:   PetscInt     sizeredrhs;
 91:   PetscInt     *schur_pivots;
 92:   PetscInt     schur_B_lwork;
 93:   PetscScalar  *schur_work;
 94:   PetscScalar  *schur_sol;
 95:   PetscInt     schur_sizesol;
 96:   PetscBool    schur_factored;
 97:   PetscBool    schur_inverted;
 98:   PetscInt     schur_sym;

100:   PetscErrorCode (*ConvertToTriples)(Mat, int, MatReuse, int*, int**, int**, PetscScalar**);
101: } Mat_MUMPS;

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

105: static PetscErrorCode MatMumpsResetSchur_Private(Mat_MUMPS* mumps)
106: {

110:   PetscFree2(mumps->id.listvar_schur,mumps->id.schur);
111:   PetscFree(mumps->id.redrhs);
112:   PetscFree(mumps->schur_sol);
113:   PetscFree(mumps->schur_pivots);
114:   PetscFree(mumps->schur_work);
115:   mumps->id.size_schur = 0;
116:   mumps->id.ICNTL(19) = 0;
117:   return(0);
118: }

120: static PetscErrorCode MatMumpsFactorSchur_Private(Mat_MUMPS* mumps)
121: {
122:   PetscBLASInt   B_N,B_ierr,B_slda;

126:   if (mumps->schur_factored) {
127:     return(0);
128:   }
129:   PetscBLASIntCast(mumps->id.size_schur,&B_N);
130:   PetscBLASIntCast(mumps->id.schur_lld,&B_slda);
131:   if (!mumps->sym) { /* MUMPS always return a full Schur matrix */
132:     if (!mumps->schur_pivots) {
133:       PetscMalloc1(B_N,&mumps->schur_pivots);
134:     }
135:     PetscFPTrapPush(PETSC_FP_TRAP_OFF);
136:     PetscStackCallBLAS("LAPACKgetrf",LAPACKgetrf_(&B_N,&B_N,(PetscScalar*)mumps->id.schur,&B_slda,mumps->schur_pivots,&B_ierr));
137:     PetscFPTrapPop();
138:     if (B_ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in GETRF Lapack routine %d",(int)B_ierr);
139:   } else { /* either full or lower-triangular (not packed) */
140:     char ord[2];
141:     if (mumps->id.ICNTL(19) == 2 || mumps->id.ICNTL(19) == 3) { /* lower triangular stored by columns or full matrix */
142:       sprintf(ord,"L");
143:     } else { /* ICNTL(19) == 1 lower triangular stored by rows */
144:       sprintf(ord,"U");
145:     }
146:     if (mumps->schur_sym == 2) {
147:       if (!mumps->schur_pivots) {
148:         PetscScalar  lwork;

150:         PetscMalloc1(B_N,&mumps->schur_pivots);
151:         mumps->schur_B_lwork=-1;
152:         PetscFPTrapPush(PETSC_FP_TRAP_OFF);
153:         PetscStackCallBLAS("LAPACKsytrf",LAPACKsytrf_(ord,&B_N,(PetscScalar*)mumps->id.schur,&B_slda,mumps->schur_pivots,&lwork,&mumps->schur_B_lwork,&B_ierr));
154:         PetscFPTrapPop();
155:         if (B_ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in query to SYTRF Lapack routine %d",(int)B_ierr);
156:         PetscBLASIntCast((PetscInt)PetscRealPart(lwork),&mumps->schur_B_lwork);
157:         PetscMalloc1(mumps->schur_B_lwork,&mumps->schur_work);
158:       }
159:       PetscFPTrapPush(PETSC_FP_TRAP_OFF);
160:       PetscStackCallBLAS("LAPACKsytrf",LAPACKsytrf_(ord,&B_N,(PetscScalar*)mumps->id.schur,&B_slda,mumps->schur_pivots,mumps->schur_work,&mumps->schur_B_lwork,&B_ierr));
161:       PetscFPTrapPop();
162:       if (B_ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in SYTRF Lapack routine %d",(int)B_ierr);
163:     } else {
164:       PetscFPTrapPush(PETSC_FP_TRAP_OFF);
165:       PetscStackCallBLAS("LAPACKpotrf",LAPACKpotrf_(ord,&B_N,(PetscScalar*)mumps->id.schur,&B_slda,&B_ierr));
166:       PetscFPTrapPop();
167:       if (B_ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in POTRF Lapack routine %d",(int)B_ierr);
168:     }
169:   }
170:   mumps->schur_factored = PETSC_TRUE;
171:   return(0);
172: }

174: static PetscErrorCode MatMumpsInvertSchur_Private(Mat_MUMPS* mumps)
175: {
176:   PetscBLASInt   B_N,B_ierr,B_slda;

180:   MatMumpsFactorSchur_Private(mumps);
181:   PetscBLASIntCast(mumps->id.size_schur,&B_N);
182:   PetscBLASIntCast(mumps->id.schur_lld,&B_slda);
183:   if (!mumps->sym) { /* MUMPS always return a full Schur matrix */
184:     if (!mumps->schur_work) {
185:       PetscScalar lwork;

187:       mumps->schur_B_lwork = -1;
188:       PetscFPTrapPush(PETSC_FP_TRAP_OFF);
189:       PetscStackCallBLAS("LAPACKgetri",LAPACKgetri_(&B_N,(PetscScalar*)mumps->id.schur,&B_N,mumps->schur_pivots,&lwork,&mumps->schur_B_lwork,&B_ierr));
190:       PetscFPTrapPop();
191:       if (B_ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in query to GETRI Lapack routine %d",(int)B_ierr);
192:       PetscBLASIntCast((PetscInt)PetscRealPart(lwork),&mumps->schur_B_lwork);
193:       PetscMalloc1(mumps->schur_B_lwork,&mumps->schur_work);
194:     }
195:     PetscFPTrapPush(PETSC_FP_TRAP_OFF);
196:     PetscStackCallBLAS("LAPACKgetri",LAPACKgetri_(&B_N,(PetscScalar*)mumps->id.schur,&B_N,mumps->schur_pivots,mumps->schur_work,&mumps->schur_B_lwork,&B_ierr));
197:     PetscFPTrapPop();
198:     if (B_ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in GETRI Lapack routine %d",(int)B_ierr);
199:   } else { /* either full or lower-triangular (not packed) */
200:     char ord[2];
201:     if (mumps->id.ICNTL(19) == 2 || mumps->id.ICNTL(19) == 3) { /* lower triangular stored by columns or full matrix */
202:       sprintf(ord,"L");
203:     } else { /* ICNTL(19) == 1 lower triangular stored by rows */
204:       sprintf(ord,"U");
205:     }
206:     if (mumps->schur_sym == 2) {
207:       PetscFPTrapPush(PETSC_FP_TRAP_OFF);
208:       PetscStackCallBLAS("LAPACKsytri",LAPACKsytri_(ord,&B_N,(PetscScalar*)mumps->id.schur,&B_N,mumps->schur_pivots,mumps->schur_work,&B_ierr));
209:       PetscFPTrapPop();
210:       if (B_ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in SYTRI Lapack routine %d",(int)B_ierr);
211:     } else {
212:       PetscFPTrapPush(PETSC_FP_TRAP_OFF);
213:       PetscStackCallBLAS("LAPACKpotri",LAPACKpotri_(ord,&B_N,(PetscScalar*)mumps->id.schur,&B_N,&B_ierr));
214:       PetscFPTrapPop();
215:       if (B_ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in POTRI Lapack routine %d",(int)B_ierr);
216:     }
217:   }
218:   mumps->schur_inverted = PETSC_TRUE;
219:   return(0);
220: }

222: static PetscErrorCode MatMumpsSolveSchur_Private(Mat_MUMPS* mumps, PetscBool sol_in_redrhs)
223: {
224:   PetscBLASInt   B_N,B_Nrhs,B_ierr,B_slda,B_rlda;
225:   PetscScalar    one=1.,zero=0.;

229:   MatMumpsFactorSchur_Private(mumps);
230:   PetscBLASIntCast(mumps->id.size_schur,&B_N);
231:   PetscBLASIntCast(mumps->id.schur_lld,&B_slda);
232:   PetscBLASIntCast(mumps->id.nrhs,&B_Nrhs);
233:   PetscBLASIntCast(mumps->id.lredrhs,&B_rlda);
234:   if (mumps->schur_inverted) {
235:     PetscInt sizesol = B_Nrhs*B_N;
236:     if (!mumps->schur_sol || sizesol > mumps->schur_sizesol) {
237:       PetscFree(mumps->schur_sol);
238:       PetscMalloc1(sizesol,&mumps->schur_sol);
239:       mumps->schur_sizesol = sizesol;
240:     }
241:     if (!mumps->sym) {
242:       char type[2];
243:       if (mumps->id.ICNTL(19) == 1) { /* stored by rows */
244:         if (!mumps->id.ICNTL(9)) { /* transpose solve */
245:           sprintf(type,"N");
246:         } else {
247:           sprintf(type,"T");
248:         }
249:       } else { /* stored by columns */
250:         if (!mumps->id.ICNTL(9)) { /* transpose solve */
251:           sprintf(type,"T");
252:         } else {
253:           sprintf(type,"N");
254:         }
255:       }
256:       PetscStackCallBLAS("BLASgemm",BLASgemm_(type,"N",&B_N,&B_Nrhs,&B_N,&one,(PetscScalar*)mumps->id.schur,&B_slda,(PetscScalar*)mumps->id.redrhs,&B_rlda,&zero,mumps->schur_sol,&B_rlda));
257:     } else {
258:       char ord[2];
259:       if (mumps->id.ICNTL(19) == 2 || mumps->id.ICNTL(19) == 3) { /* lower triangular stored by columns or full matrix */
260:         sprintf(ord,"L");
261:       } else { /* ICNTL(19) == 1 lower triangular stored by rows */
262:         sprintf(ord,"U");
263:       }
264:       PetscStackCallBLAS("BLASsymm",BLASsymm_("L",ord,&B_N,&B_Nrhs,&one,(PetscScalar*)mumps->id.schur,&B_slda,(PetscScalar*)mumps->id.redrhs,&B_rlda,&zero,mumps->schur_sol,&B_rlda));
265:     }
266:     if (sol_in_redrhs) {
267:       PetscMemcpy(mumps->id.redrhs,mumps->schur_sol,sizesol*sizeof(PetscScalar));
268:     }
269:   } else { /* Schur complement has not yet been inverted */
270:     MumpsScalar *orhs=NULL;

272:     if (!sol_in_redrhs) {
273:       PetscInt sizesol = B_Nrhs*B_N;
274:       if (!mumps->schur_sol || sizesol > mumps->schur_sizesol) {
275:         PetscFree(mumps->schur_sol);
276:         PetscMalloc1(sizesol,&mumps->schur_sol);
277:         mumps->schur_sizesol = sizesol;
278:       }
279:       orhs = mumps->id.redrhs;
280:       PetscMemcpy(mumps->schur_sol,mumps->id.redrhs,sizesol*sizeof(PetscScalar));
281:       mumps->id.redrhs = (MumpsScalar*)mumps->schur_sol;
282:     }
283:     if (!mumps->sym) { /* MUMPS always return a full Schur matrix */
284:       char type[2];
285:       if (mumps->id.ICNTL(19) == 1) { /* stored by rows */
286:         if (!mumps->id.ICNTL(9)) { /* transpose solve */
287:           sprintf(type,"N");
288:         } else {
289:           sprintf(type,"T");
290:         }
291:       } else { /* stored by columns */
292:         if (!mumps->id.ICNTL(9)) { /* transpose solve */
293:           sprintf(type,"T");
294:         } else {
295:           sprintf(type,"N");
296:         }
297:       }
298:       PetscFPTrapPush(PETSC_FP_TRAP_OFF);
299:       PetscStackCallBLAS("LAPACKgetrs",LAPACKgetrs_(type,&B_N,&B_Nrhs,(PetscScalar*)mumps->id.schur,&B_slda,mumps->schur_pivots,(PetscScalar*)mumps->id.redrhs,&B_rlda,&B_ierr));
300:       PetscFPTrapPop();
301:       if (B_ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in GETRS Lapack routine %d",(int)B_ierr);
302:     } else { /* either full or lower-triangular (not packed) */
303:       char ord[2];
304:       if (mumps->id.ICNTL(19) == 2 || mumps->id.ICNTL(19) == 3) { /* lower triangular stored by columns or full matrix */
305:         sprintf(ord,"L");
306:       } else { /* ICNTL(19) == 1 lower triangular stored by rows */
307:         sprintf(ord,"U");
308:       }
309:       if (mumps->schur_sym == 2) {
310:         PetscFPTrapPush(PETSC_FP_TRAP_OFF);
311:         PetscStackCallBLAS("LAPACKsytrs",LAPACKsytrs_(ord,&B_N,&B_Nrhs,(PetscScalar*)mumps->id.schur,&B_slda,mumps->schur_pivots,(PetscScalar*)mumps->id.redrhs,&B_rlda,&B_ierr));
312:         PetscFPTrapPop();
313:         if (B_ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in SYTRS Lapack routine %d",(int)B_ierr);
314:       } else {
315:         PetscFPTrapPush(PETSC_FP_TRAP_OFF);
316:         PetscStackCallBLAS("LAPACKpotrs",LAPACKpotrs_(ord,&B_N,&B_Nrhs,(PetscScalar*)mumps->id.schur,&B_slda,(PetscScalar*)mumps->id.redrhs,&B_rlda,&B_ierr));
317:         PetscFPTrapPop();
318:         if (B_ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in POTRS Lapack routine %d",(int)B_ierr);
319:       }
320:     }
321:     if (!sol_in_redrhs) {
322:       mumps->id.redrhs = orhs;
323:     }
324:   }
325:   return(0);
326: }

328: static PetscErrorCode MatMumpsHandleSchur_Private(Mat_MUMPS* mumps, PetscBool expansion)
329: {

333:   if (!mumps->id.ICNTL(19)) { /* do nothing when Schur complement has not been computed */
334:     return(0);
335:   }
336:   if (!expansion) { /* prepare for the condensation step */
337:     PetscInt sizeredrhs = mumps->id.nrhs*mumps->id.size_schur;
338:     /* allocate MUMPS internal array to store reduced right-hand sides */
339:     if (!mumps->id.redrhs || sizeredrhs > mumps->sizeredrhs) {
340:       PetscFree(mumps->id.redrhs);
341:       mumps->id.lredrhs = mumps->id.size_schur;
342:       PetscMalloc1(mumps->id.nrhs*mumps->id.lredrhs,&mumps->id.redrhs);
343:       mumps->sizeredrhs = mumps->id.nrhs*mumps->id.lredrhs;
344:     }
345:     mumps->id.ICNTL(26) = 1; /* condensation phase */
346:   } else { /* prepare for the expansion step */
347:     /* solve Schur complement (this has to be done by the MUMPS user, so basically us) */
348:     MatMumpsSolveSchur_Private(mumps,PETSC_TRUE);
349:     mumps->id.ICNTL(26) = 2; /* expansion phase */
350:     PetscMUMPS_c(&mumps->id);
351:     if (mumps->id.INFOG(1) < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by MUMPS in solve phase: INFOG(1)=%d\n",mumps->id.INFOG(1));
352:     /* restore defaults */
353:     mumps->id.ICNTL(26) = -1;
354:     /* free MUMPS internal array for redrhs if we have solved for multiple rhs in order to save memory space */
355:     if (mumps->id.nrhs > 1) {
356:       PetscFree(mumps->id.redrhs);
357:       mumps->id.lredrhs = 0;
358:       mumps->sizeredrhs = 0;
359:     }
360:   }
361:   return(0);
362: }

364: /*
365:   MatConvertToTriples_A_B - convert Petsc matrix to triples: row[nz], col[nz], val[nz] 

367:   input:
368:     A       - matrix in aij,baij or sbaij (bs=1) format
369:     shift   - 0: C style output triple; 1: Fortran style output triple.
370:     reuse   - MAT_INITIAL_MATRIX: spaces are allocated and values are set for the triple
371:               MAT_REUSE_MATRIX:   only the values in v array are updated
372:   output:
373:     nnz     - dim of r, c, and v (number of local nonzero entries of A)
374:     r, c, v - row and col index, matrix values (matrix triples)

376:   The returned values r, c, and sometimes v are obtained in a single PetscMalloc(). Then in MatDestroy_MUMPS() it is
377:   freed with PetscFree((mumps->irn);  This is not ideal code, the fact that v is ONLY sometimes part of mumps->irn means
378:   that the PetscMalloc() cannot easily be replaced with a PetscMalloc3(). 

380:  */

382: PetscErrorCode MatConvertToTriples_seqaij_seqaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
383: {
384:   const PetscInt *ai,*aj,*ajj,M=A->rmap->n;
385:   PetscInt       nz,rnz,i,j;
387:   PetscInt       *row,*col;
388:   Mat_SeqAIJ     *aa=(Mat_SeqAIJ*)A->data;

391:   *v=aa->a;
392:   if (reuse == MAT_INITIAL_MATRIX) {
393:     nz   = aa->nz;
394:     ai   = aa->i;
395:     aj   = aa->j;
396:     *nnz = nz;
397:     PetscMalloc1(2*nz, &row);
398:     col  = row + nz;

400:     nz = 0;
401:     for (i=0; i<M; i++) {
402:       rnz = ai[i+1] - ai[i];
403:       ajj = aj + ai[i];
404:       for (j=0; j<rnz; j++) {
405:         row[nz] = i+shift; col[nz++] = ajj[j] + shift;
406:       }
407:     }
408:     *r = row; *c = col;
409:   }
410:   return(0);
411: }

413: PetscErrorCode MatConvertToTriples_seqbaij_seqaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
414: {
415:   Mat_SeqBAIJ    *aa=(Mat_SeqBAIJ*)A->data;
416:   const PetscInt *ai,*aj,*ajj,bs2 = aa->bs2;
417:   PetscInt       bs,M,nz,idx=0,rnz,i,j,k,m;
419:   PetscInt       *row,*col;

422:   MatGetBlockSize(A,&bs);
423:   M = A->rmap->N/bs;
424:   *v = aa->a;
425:   if (reuse == MAT_INITIAL_MATRIX) {
426:     ai   = aa->i; aj = aa->j;
427:     nz   = bs2*aa->nz;
428:     *nnz = nz;
429:     PetscMalloc1(2*nz, &row);
430:     col  = row + nz;

432:     for (i=0; i<M; i++) {
433:       ajj = aj + ai[i];
434:       rnz = ai[i+1] - ai[i];
435:       for (k=0; k<rnz; k++) {
436:         for (j=0; j<bs; j++) {
437:           for (m=0; m<bs; m++) {
438:             row[idx]   = i*bs + m + shift;
439:             col[idx++] = bs*(ajj[k]) + j + shift;
440:           }
441:         }
442:       }
443:     }
444:     *r = row; *c = col;
445:   }
446:   return(0);
447: }

449: PetscErrorCode MatConvertToTriples_seqsbaij_seqsbaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
450: {
451:   const PetscInt *ai, *aj,*ajj,M=A->rmap->n;
452:   PetscInt       nz,rnz,i,j;
454:   PetscInt       *row,*col;
455:   Mat_SeqSBAIJ   *aa=(Mat_SeqSBAIJ*)A->data;

458:   *v = aa->a;
459:   if (reuse == MAT_INITIAL_MATRIX) {
460:     nz   = aa->nz;
461:     ai   = aa->i;
462:     aj   = aa->j;
463:     *v   = aa->a;
464:     *nnz = nz;
465:     PetscMalloc1(2*nz, &row);
466:     col  = row + nz;

468:     nz = 0;
469:     for (i=0; i<M; i++) {
470:       rnz = ai[i+1] - ai[i];
471:       ajj = aj + ai[i];
472:       for (j=0; j<rnz; j++) {
473:         row[nz] = i+shift; col[nz++] = ajj[j] + shift;
474:       }
475:     }
476:     *r = row; *c = col;
477:   }
478:   return(0);
479: }

481: PetscErrorCode MatConvertToTriples_seqaij_seqsbaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
482: {
483:   const PetscInt    *ai,*aj,*ajj,*adiag,M=A->rmap->n;
484:   PetscInt          nz,rnz,i,j;
485:   const PetscScalar *av,*v1;
486:   PetscScalar       *val;
487:   PetscErrorCode    ierr;
488:   PetscInt          *row,*col;
489:   Mat_SeqAIJ        *aa=(Mat_SeqAIJ*)A->data;
490:   PetscBool         missing;

493:   ai   =aa->i; aj=aa->j;av=aa->a;
494:   adiag=aa->diag;
495:   MatMissingDiagonal_SeqAIJ(A,&missing,&i);
496:   if (reuse == MAT_INITIAL_MATRIX) {
497:     /* count nz in the uppper triangular part of A */
498:     nz = 0;
499:     if (missing) {
500:       for (i=0; i<M; i++) {
501:         if (PetscUnlikely(adiag[i] >= ai[i+1])) {
502:           for (j=ai[i];j<ai[i+1];j++) {
503:             if (aj[j] < i) continue;
504:             nz++;
505:           }
506:         } else {
507:           nz += ai[i+1] - adiag[i];
508:         }
509:       }
510:     } else {
511:       for (i=0; i<M; i++) nz += ai[i+1] - adiag[i];
512:     }
513:     *nnz = nz;

515:     PetscMalloc((2*nz*sizeof(PetscInt)+nz*sizeof(PetscScalar)), &row);
516:     col  = row + nz;
517:     val  = (PetscScalar*)(col + nz);

519:     nz = 0;
520:     if (missing) {
521:       for (i=0; i<M; i++) {
522:         if (PetscUnlikely(adiag[i] >= ai[i+1])) {
523:           for (j=ai[i];j<ai[i+1];j++) {
524:             if (aj[j] < i) continue;
525:             row[nz] = i+shift;
526:             col[nz] = aj[j]+shift;
527:             val[nz] = av[j];
528:             nz++;
529:           }
530:         } else {
531:           rnz = ai[i+1] - adiag[i];
532:           ajj = aj + adiag[i];
533:           v1  = av + adiag[i];
534:           for (j=0; j<rnz; j++) {
535:             row[nz] = i+shift; col[nz] = ajj[j] + shift; val[nz++] = v1[j];
536:           }
537:         }
538:       }
539:     } else {
540:       for (i=0; i<M; i++) {
541:         rnz = ai[i+1] - adiag[i];
542:         ajj = aj + adiag[i];
543:         v1  = av + adiag[i];
544:         for (j=0; j<rnz; j++) {
545:           row[nz] = i+shift; col[nz] = ajj[j] + shift; val[nz++] = v1[j];
546:         }
547:       }
548:     }
549:     *r = row; *c = col; *v = val;
550:   } else {
551:     nz = 0; val = *v;
552:     if (missing) {
553:       for (i=0; i <M; i++) {
554:         if (PetscUnlikely(adiag[i] >= ai[i+1])) {
555:           for (j=ai[i];j<ai[i+1];j++) {
556:             if (aj[j] < i) continue;
557:             val[nz++] = av[j];
558:           }
559:         } else {
560:           rnz = ai[i+1] - adiag[i];
561:           v1  = av + adiag[i];
562:           for (j=0; j<rnz; j++) {
563:             val[nz++] = v1[j];
564:           }
565:         }
566:       }
567:     } else {
568:       for (i=0; i <M; i++) {
569:         rnz = ai[i+1] - adiag[i];
570:         v1  = av + adiag[i];
571:         for (j=0; j<rnz; j++) {
572:           val[nz++] = v1[j];
573:         }
574:       }
575:     }
576:   }
577:   return(0);
578: }

580: PetscErrorCode MatConvertToTriples_mpisbaij_mpisbaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
581: {
582:   const PetscInt    *ai, *aj, *bi, *bj,*garray,m=A->rmap->n,*ajj,*bjj;
583:   PetscErrorCode    ierr;
584:   PetscInt          rstart,nz,i,j,jj,irow,countA,countB;
585:   PetscInt          *row,*col;
586:   const PetscScalar *av, *bv,*v1,*v2;
587:   PetscScalar       *val;
588:   Mat_MPISBAIJ      *mat = (Mat_MPISBAIJ*)A->data;
589:   Mat_SeqSBAIJ      *aa  = (Mat_SeqSBAIJ*)(mat->A)->data;
590:   Mat_SeqBAIJ       *bb  = (Mat_SeqBAIJ*)(mat->B)->data;

593:   ai=aa->i; aj=aa->j; bi=bb->i; bj=bb->j; rstart= A->rmap->rstart;
594:   av=aa->a; bv=bb->a;

596:   garray = mat->garray;

598:   if (reuse == MAT_INITIAL_MATRIX) {
599:     nz   = aa->nz + bb->nz;
600:     *nnz = nz;
601:     PetscMalloc((2*nz*sizeof(PetscInt)+nz*sizeof(PetscScalar)), &row);
602:     col  = row + nz;
603:     val  = (PetscScalar*)(col + nz);

605:     *r = row; *c = col; *v = val;
606:   } else {
607:     row = *r; col = *c; val = *v;
608:   }

610:   jj = 0; irow = rstart;
611:   for (i=0; i<m; i++) {
612:     ajj    = aj + ai[i];                 /* ptr to the beginning of this row */
613:     countA = ai[i+1] - ai[i];
614:     countB = bi[i+1] - bi[i];
615:     bjj    = bj + bi[i];
616:     v1     = av + ai[i];
617:     v2     = bv + bi[i];

619:     /* A-part */
620:     for (j=0; j<countA; j++) {
621:       if (reuse == MAT_INITIAL_MATRIX) {
622:         row[jj] = irow + shift; col[jj] = rstart + ajj[j] + shift;
623:       }
624:       val[jj++] = v1[j];
625:     }

627:     /* B-part */
628:     for (j=0; j < countB; j++) {
629:       if (reuse == MAT_INITIAL_MATRIX) {
630:         row[jj] = irow + shift; col[jj] = garray[bjj[j]] + shift;
631:       }
632:       val[jj++] = v2[j];
633:     }
634:     irow++;
635:   }
636:   return(0);
637: }

639: PetscErrorCode MatConvertToTriples_mpiaij_mpiaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
640: {
641:   const PetscInt    *ai, *aj, *bi, *bj,*garray,m=A->rmap->n,*ajj,*bjj;
642:   PetscErrorCode    ierr;
643:   PetscInt          rstart,nz,i,j,jj,irow,countA,countB;
644:   PetscInt          *row,*col;
645:   const PetscScalar *av, *bv,*v1,*v2;
646:   PetscScalar       *val;
647:   Mat_MPIAIJ        *mat = (Mat_MPIAIJ*)A->data;
648:   Mat_SeqAIJ        *aa  = (Mat_SeqAIJ*)(mat->A)->data;
649:   Mat_SeqAIJ        *bb  = (Mat_SeqAIJ*)(mat->B)->data;

652:   ai=aa->i; aj=aa->j; bi=bb->i; bj=bb->j; rstart= A->rmap->rstart;
653:   av=aa->a; bv=bb->a;

655:   garray = mat->garray;

657:   if (reuse == MAT_INITIAL_MATRIX) {
658:     nz   = aa->nz + bb->nz;
659:     *nnz = nz;
660:     PetscMalloc((2*nz*sizeof(PetscInt)+nz*sizeof(PetscScalar)), &row);
661:     col  = row + nz;
662:     val  = (PetscScalar*)(col + nz);

664:     *r = row; *c = col; *v = val;
665:   } else {
666:     row = *r; col = *c; val = *v;
667:   }

669:   jj = 0; irow = rstart;
670:   for (i=0; i<m; i++) {
671:     ajj    = aj + ai[i];                 /* ptr to the beginning of this row */
672:     countA = ai[i+1] - ai[i];
673:     countB = bi[i+1] - bi[i];
674:     bjj    = bj + bi[i];
675:     v1     = av + ai[i];
676:     v2     = bv + bi[i];

678:     /* A-part */
679:     for (j=0; j<countA; j++) {
680:       if (reuse == MAT_INITIAL_MATRIX) {
681:         row[jj] = irow + shift; col[jj] = rstart + ajj[j] + shift;
682:       }
683:       val[jj++] = v1[j];
684:     }

686:     /* B-part */
687:     for (j=0; j < countB; j++) {
688:       if (reuse == MAT_INITIAL_MATRIX) {
689:         row[jj] = irow + shift; col[jj] = garray[bjj[j]] + shift;
690:       }
691:       val[jj++] = v2[j];
692:     }
693:     irow++;
694:   }
695:   return(0);
696: }

698: PetscErrorCode MatConvertToTriples_mpibaij_mpiaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
699: {
700:   Mat_MPIBAIJ       *mat    = (Mat_MPIBAIJ*)A->data;
701:   Mat_SeqBAIJ       *aa     = (Mat_SeqBAIJ*)(mat->A)->data;
702:   Mat_SeqBAIJ       *bb     = (Mat_SeqBAIJ*)(mat->B)->data;
703:   const PetscInt    *ai     = aa->i, *bi = bb->i, *aj = aa->j, *bj = bb->j,*ajj, *bjj;
704:   const PetscInt    *garray = mat->garray,mbs=mat->mbs,rstart=A->rmap->rstart;
705:   const PetscInt    bs2=mat->bs2;
706:   PetscErrorCode    ierr;
707:   PetscInt          bs,nz,i,j,k,n,jj,irow,countA,countB,idx;
708:   PetscInt          *row,*col;
709:   const PetscScalar *av=aa->a, *bv=bb->a,*v1,*v2;
710:   PetscScalar       *val;

713:   MatGetBlockSize(A,&bs);
714:   if (reuse == MAT_INITIAL_MATRIX) {
715:     nz   = bs2*(aa->nz + bb->nz);
716:     *nnz = nz;
717:     PetscMalloc((2*nz*sizeof(PetscInt)+nz*sizeof(PetscScalar)), &row);
718:     col  = row + nz;
719:     val  = (PetscScalar*)(col + nz);

721:     *r = row; *c = col; *v = val;
722:   } else {
723:     row = *r; col = *c; val = *v;
724:   }

726:   jj = 0; irow = rstart;
727:   for (i=0; i<mbs; i++) {
728:     countA = ai[i+1] - ai[i];
729:     countB = bi[i+1] - bi[i];
730:     ajj    = aj + ai[i];
731:     bjj    = bj + bi[i];
732:     v1     = av + bs2*ai[i];
733:     v2     = bv + bs2*bi[i];

735:     idx = 0;
736:     /* A-part */
737:     for (k=0; k<countA; k++) {
738:       for (j=0; j<bs; j++) {
739:         for (n=0; n<bs; n++) {
740:           if (reuse == MAT_INITIAL_MATRIX) {
741:             row[jj] = irow + n + shift;
742:             col[jj] = rstart + bs*ajj[k] + j + shift;
743:           }
744:           val[jj++] = v1[idx++];
745:         }
746:       }
747:     }

749:     idx = 0;
750:     /* B-part */
751:     for (k=0; k<countB; k++) {
752:       for (j=0; j<bs; j++) {
753:         for (n=0; n<bs; n++) {
754:           if (reuse == MAT_INITIAL_MATRIX) {
755:             row[jj] = irow + n + shift;
756:             col[jj] = bs*garray[bjj[k]] + j + shift;
757:           }
758:           val[jj++] = v2[idx++];
759:         }
760:       }
761:     }
762:     irow += bs;
763:   }
764:   return(0);
765: }

767: PetscErrorCode MatConvertToTriples_mpiaij_mpisbaij(Mat A,int shift,MatReuse reuse,int *nnz,int **r, int **c, PetscScalar **v)
768: {
769:   const PetscInt    *ai, *aj,*adiag, *bi, *bj,*garray,m=A->rmap->n,*ajj,*bjj;
770:   PetscErrorCode    ierr;
771:   PetscInt          rstart,nz,nza,nzb,i,j,jj,irow,countA,countB;
772:   PetscInt          *row,*col;
773:   const PetscScalar *av, *bv,*v1,*v2;
774:   PetscScalar       *val;
775:   Mat_MPIAIJ        *mat =  (Mat_MPIAIJ*)A->data;
776:   Mat_SeqAIJ        *aa  =(Mat_SeqAIJ*)(mat->A)->data;
777:   Mat_SeqAIJ        *bb  =(Mat_SeqAIJ*)(mat->B)->data;

780:   ai=aa->i; aj=aa->j; adiag=aa->diag;
781:   bi=bb->i; bj=bb->j; garray = mat->garray;
782:   av=aa->a; bv=bb->a;

784:   rstart = A->rmap->rstart;

786:   if (reuse == MAT_INITIAL_MATRIX) {
787:     nza = 0;    /* num of upper triangular entries in mat->A, including diagonals */
788:     nzb = 0;    /* num of upper triangular entries in mat->B */
789:     for (i=0; i<m; i++) {
790:       nza   += (ai[i+1] - adiag[i]);
791:       countB = bi[i+1] - bi[i];
792:       bjj    = bj + bi[i];
793:       for (j=0; j<countB; j++) {
794:         if (garray[bjj[j]] > rstart) nzb++;
795:       }
796:     }

798:     nz   = nza + nzb; /* total nz of upper triangular part of mat */
799:     *nnz = nz;
800:     PetscMalloc((2*nz*sizeof(PetscInt)+nz*sizeof(PetscScalar)), &row);
801:     col  = row + nz;
802:     val  = (PetscScalar*)(col + nz);

804:     *r = row; *c = col; *v = val;
805:   } else {
806:     row = *r; col = *c; val = *v;
807:   }

809:   jj = 0; irow = rstart;
810:   for (i=0; i<m; i++) {
811:     ajj    = aj + adiag[i];                 /* ptr to the beginning of the diagonal of this row */
812:     v1     = av + adiag[i];
813:     countA = ai[i+1] - adiag[i];
814:     countB = bi[i+1] - bi[i];
815:     bjj    = bj + bi[i];
816:     v2     = bv + bi[i];

818:     /* A-part */
819:     for (j=0; j<countA; j++) {
820:       if (reuse == MAT_INITIAL_MATRIX) {
821:         row[jj] = irow + shift; col[jj] = rstart + ajj[j] + shift;
822:       }
823:       val[jj++] = v1[j];
824:     }

826:     /* B-part */
827:     for (j=0; j < countB; j++) {
828:       if (garray[bjj[j]] > rstart) {
829:         if (reuse == MAT_INITIAL_MATRIX) {
830:           row[jj] = irow + shift; col[jj] = garray[bjj[j]] + shift;
831:         }
832:         val[jj++] = v2[j];
833:       }
834:     }
835:     irow++;
836:   }
837:   return(0);
838: }

840: PetscErrorCode MatDestroy_MUMPS(Mat A)
841: {
842:   Mat_MUMPS      *mumps=(Mat_MUMPS*)A->data;

846:   PetscFree2(mumps->id.sol_loc,mumps->id.isol_loc);
847:   VecScatterDestroy(&mumps->scat_rhs);
848:   VecScatterDestroy(&mumps->scat_sol);
849:   VecDestroy(&mumps->b_seq);
850:   VecDestroy(&mumps->x_seq);
851:   PetscFree(mumps->id.perm_in);
852:   PetscFree(mumps->irn);
853:   PetscFree(mumps->info);
854:   MatMumpsResetSchur_Private(mumps);
855:   mumps->id.job = JOB_END;
856:   PetscMUMPS_c(&mumps->id);
857:   MPI_Comm_free(&mumps->comm_mumps);
858:   PetscFree(A->data);

860:   /* clear composed functions */
861:   PetscObjectComposeFunction((PetscObject)A,"MatFactorGetSolverPackage_C",NULL);
862:   PetscObjectComposeFunction((PetscObject)A,"MatFactorSetSchurIS_C",NULL);
863:   PetscObjectComposeFunction((PetscObject)A,"MatFactorInvertSchurComplement_C",NULL);
864:   PetscObjectComposeFunction((PetscObject)A,"MatFactorCreateSchurComplement_C",NULL);
865:   PetscObjectComposeFunction((PetscObject)A,"MatFactorGetSchurComplement_C",NULL);
866:   PetscObjectComposeFunction((PetscObject)A,"MatFactorSolveSchurComplement_C",NULL);
867:   PetscObjectComposeFunction((PetscObject)A,"MatFactorSolveSchurComplementTranspose_C",NULL);
868:   PetscObjectComposeFunction((PetscObject)A,"MatFactorFactorizeSchurComplement_C",NULL);
869:   PetscObjectComposeFunction((PetscObject)A,"MatFactorSetSchurComplementSolverType_C",NULL);
870:   PetscObjectComposeFunction((PetscObject)A,"MatMumpsSetIcntl_C",NULL);
871:   PetscObjectComposeFunction((PetscObject)A,"MatMumpsGetIcntl_C",NULL);
872:   PetscObjectComposeFunction((PetscObject)A,"MatMumpsSetCntl_C",NULL);
873:   PetscObjectComposeFunction((PetscObject)A,"MatMumpsGetCntl_C",NULL);
874:   PetscObjectComposeFunction((PetscObject)A,"MatMumpsGetInfo_C",NULL);
875:   PetscObjectComposeFunction((PetscObject)A,"MatMumpsGetInfog_C",NULL);
876:   PetscObjectComposeFunction((PetscObject)A,"MatMumpsGetRinfo_C",NULL);
877:   PetscObjectComposeFunction((PetscObject)A,"MatMumpsGetRinfog_C",NULL);
878:   return(0);
879: }

881: PetscErrorCode MatSolve_MUMPS(Mat A,Vec b,Vec x)
882: {
883:   Mat_MUMPS        *mumps=(Mat_MUMPS*)A->data;
884:   PetscScalar      *array;
885:   Vec              b_seq;
886:   IS               is_iden,is_petsc;
887:   PetscErrorCode   ierr;
888:   PetscInt         i;
889:   PetscBool        second_solve = PETSC_FALSE;
890:   static PetscBool cite1 = PETSC_FALSE,cite2 = PETSC_FALSE;

893:   PetscCitationsRegister("@article{MUMPS01,\n  author = {P.~R. Amestoy and I.~S. Duff and J.-Y. L'Excellent and J. Koster},\n  title = {A fully asynchronous multifrontal solver using distributed dynamic scheduling},\n  journal = {SIAM Journal on Matrix Analysis and Applications},\n  volume = {23},\n  number = {1},\n  pages = {15--41},\n  year = {2001}\n}\n",&cite1);
894:   PetscCitationsRegister("@article{MUMPS02,\n  author = {P.~R. Amestoy and A. Guermouche and J.-Y. L'Excellent and S. Pralet},\n  title = {Hybrid scheduling for the parallel solution of linear systems},\n  journal = {Parallel Computing},\n  volume = {32},\n  number = {2},\n  pages = {136--156},\n  year = {2006}\n}\n",&cite2);

896:   if (A->factorerrortype) {
897:     PetscInfo2(A,"MatSolve is called with singular matrix factor, INFOG(1)=%d, INFO(2)=%d\n",mumps->id.INFOG(1),mumps->id.INFO(2));
898:     VecSetInf(x);
899:     return(0);
900:   }

902:   mumps->id.nrhs = 1;
903:   b_seq          = mumps->b_seq;
904:   if (mumps->size > 1) {
905:     /* MUMPS only supports centralized rhs. Scatter b into a seqential rhs vector */
906:     VecScatterBegin(mumps->scat_rhs,b,b_seq,INSERT_VALUES,SCATTER_FORWARD);
907:     VecScatterEnd(mumps->scat_rhs,b,b_seq,INSERT_VALUES,SCATTER_FORWARD);
908:     if (!mumps->myid) {VecGetArray(b_seq,&array);}
909:   } else {  /* size == 1 */
910:     VecCopy(b,x);
911:     VecGetArray(x,&array);
912:   }
913:   if (!mumps->myid) { /* define rhs on the host */
914:     mumps->id.nrhs = 1;
915:     mumps->id.rhs = (MumpsScalar*)array;
916:   }

918:   /*
919:      handle condensation step of Schur complement (if any)
920:      We set by default ICNTL(26) == -1 when Schur indices have been provided by the user.
921:      According to MUMPS (5.0.0) manual, any value should be harmful during the factorization phase
922:      Unless the user provides a valid value for ICNTL(26), MatSolve and MatMatSolve routines solve the full system.
923:      This requires an extra call to PetscMUMPS_c and the computation of the factors for S
924:   */
925:   if (mumps->id.ICNTL(26) < 0 || mumps->id.ICNTL(26) > 2) {
926:     if (mumps->size > 1) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_SUP,"Parallel Schur complements not yet supported from PETSc\n");
927:     second_solve = PETSC_TRUE;
928:     MatMumpsHandleSchur_Private(mumps,PETSC_FALSE);
929:   }
930:   /* solve phase */
931:   /*-------------*/
932:   mumps->id.job = JOB_SOLVE;
933:   PetscMUMPS_c(&mumps->id);
934:   if (mumps->id.INFOG(1) < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by MUMPS in solve phase: INFOG(1)=%d\n",mumps->id.INFOG(1));

936:   /* handle expansion step of Schur complement (if any) */
937:   if (second_solve) {
938:     MatMumpsHandleSchur_Private(mumps,PETSC_TRUE);
939:   }

941:   if (mumps->size > 1) { /* convert mumps distributed solution to petsc mpi x */
942:     if (mumps->scat_sol && mumps->ICNTL9_pre != mumps->id.ICNTL(9)) {
943:       /* when id.ICNTL(9) changes, the contents of lsol_loc may change (not its size, lsol_loc), recreates scat_sol */
944:       VecScatterDestroy(&mumps->scat_sol);
945:     }
946:     if (!mumps->scat_sol) { /* create scatter scat_sol */
947:       ISCreateStride(PETSC_COMM_SELF,mumps->id.lsol_loc,0,1,&is_iden); /* from */
948:       for (i=0; i<mumps->id.lsol_loc; i++) {
949:         mumps->id.isol_loc[i] -= 1; /* change Fortran style to C style */
950:       }
951:       ISCreateGeneral(PETSC_COMM_SELF,mumps->id.lsol_loc,mumps->id.isol_loc,PETSC_COPY_VALUES,&is_petsc);  /* to */
952:       VecScatterCreate(mumps->x_seq,is_iden,x,is_petsc,&mumps->scat_sol);
953:       ISDestroy(&is_iden);
954:       ISDestroy(&is_petsc);

956:       mumps->ICNTL9_pre = mumps->id.ICNTL(9); /* save current value of id.ICNTL(9) */
957:     }

959:     VecScatterBegin(mumps->scat_sol,mumps->x_seq,x,INSERT_VALUES,SCATTER_FORWARD);
960:     VecScatterEnd(mumps->scat_sol,mumps->x_seq,x,INSERT_VALUES,SCATTER_FORWARD);
961:   }
962:   return(0);
963: }

965: PetscErrorCode MatSolveTranspose_MUMPS(Mat A,Vec b,Vec x)
966: {
967:   Mat_MUMPS      *mumps=(Mat_MUMPS*)A->data;

971:   mumps->id.ICNTL(9) = 0;
972:   MatSolve_MUMPS(A,b,x);
973:   mumps->id.ICNTL(9) = 1;
974:   return(0);
975: }

977: PetscErrorCode MatMatSolve_MUMPS(Mat A,Mat B,Mat X)
978: {
980:   PetscBool      flg;
981:   Mat_MUMPS      *mumps=(Mat_MUMPS*)A->data;
982:   PetscInt       i,nrhs,M;
983:   PetscScalar    *array,*bray;

986:   PetscObjectTypeCompareAny((PetscObject)B,&flg,MATSEQDENSE,MATMPIDENSE,NULL);
987:   if (!flg) SETERRQ(PetscObjectComm((PetscObject)B),PETSC_ERR_ARG_WRONG,"Matrix B must be MATDENSE matrix");
988:   PetscObjectTypeCompareAny((PetscObject)X,&flg,MATSEQDENSE,MATMPIDENSE,NULL);
989:   if (!flg) SETERRQ(PetscObjectComm((PetscObject)X),PETSC_ERR_ARG_WRONG,"Matrix X must be MATDENSE matrix");
990:   if (B->rmap->n != X->rmap->n) SETERRQ(PetscObjectComm((PetscObject)B),PETSC_ERR_ARG_WRONG,"Matrix B and X must have same row distribution");

992:   MatGetSize(B,&M,&nrhs);
993:   mumps->id.nrhs = nrhs;
994:   mumps->id.lrhs = M;

996:   if (mumps->size == 1) {
997:     PetscBool second_solve = PETSC_FALSE;
998:     /* copy B to X */
999:     MatDenseGetArray(B,&bray);
1000:     MatDenseGetArray(X,&array);
1001:     PetscMemcpy(array,bray,M*nrhs*sizeof(PetscScalar));
1002:     MatDenseRestoreArray(B,&bray);
1003:     mumps->id.rhs = (MumpsScalar*)array;

1005:     /* handle condensation step of Schur complement (if any) */
1006:     if (mumps->id.ICNTL(26) < 0 || mumps->id.ICNTL(26) > 2) {
1007:       second_solve = PETSC_TRUE;
1008:       MatMumpsHandleSchur_Private(mumps,PETSC_FALSE);
1009:     }
1010:     /* solve phase */
1011:     /*-------------*/
1012:     mumps->id.job = JOB_SOLVE;
1013:     PetscMUMPS_c(&mumps->id);
1014:     if (mumps->id.INFOG(1) < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by MUMPS in solve phase: INFOG(1)=%d\n",mumps->id.INFOG(1));

1016:     /* handle expansion step of Schur complement (if any) */
1017:     if (second_solve) {
1018:       MatMumpsHandleSchur_Private(mumps,PETSC_TRUE);
1019:     }
1020:     MatDenseRestoreArray(X,&array);
1021:   } else {  /*--------- parallel case --------*/
1022:     PetscInt       lsol_loc,nlsol_loc,*isol_loc,*idx,*iidx,*idxx,*isol_loc_save;
1023:     MumpsScalar    *sol_loc,*sol_loc_save;
1024:     IS             is_to,is_from;
1025:     PetscInt       k,proc,j,m;
1026:     const PetscInt *rstart;
1027:     Vec            v_mpi,b_seq,x_seq;
1028:     VecScatter     scat_rhs,scat_sol;

1030:     if (mumps->size > 1 && mumps->id.ICNTL(19)) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_SUP,"Parallel Schur complements not yet supported from PETSc\n");

1032:     /* create x_seq to hold local solution */
1033:     isol_loc_save = mumps->id.isol_loc; /* save it for MatSovle() */
1034:     sol_loc_save  = mumps->id.sol_loc;

1036:     lsol_loc  = mumps->id.INFO(23);
1037:     nlsol_loc = nrhs*lsol_loc;     /* length of sol_loc */
1038:     PetscMalloc2(nlsol_loc,&sol_loc,nlsol_loc,&isol_loc);
1039:     mumps->id.sol_loc = (MumpsScalar*)sol_loc;
1040:     mumps->id.isol_loc = isol_loc;

1042:     VecCreateSeqWithArray(PETSC_COMM_SELF,1,nlsol_loc,(PetscScalar*)sol_loc,&x_seq);

1044:     /* copy rhs matrix B into vector v_mpi */
1045:     MatGetLocalSize(B,&m,NULL);
1046:     MatDenseGetArray(B,&bray);
1047:     VecCreateMPIWithArray(PetscObjectComm((PetscObject)B),1,nrhs*m,nrhs*M,(const PetscScalar*)bray,&v_mpi);
1048:     MatDenseRestoreArray(B,&bray);

1050:     /* scatter v_mpi to b_seq because MUMPS only supports centralized rhs */
1051:     /* idx: maps from k-th index of v_mpi to (i,j)-th global entry of B;
1052:       iidx: inverse of idx, will be used by scattering xx_seq -> X       */
1053:     PetscMalloc2(nrhs*M,&idx,nrhs*M,&iidx);
1054:     MatGetOwnershipRanges(B,&rstart);
1055:     k = 0;
1056:     for (proc=0; proc<mumps->size; proc++){
1057:       for (j=0; j<nrhs; j++){
1058:         for (i=rstart[proc]; i<rstart[proc+1]; i++){
1059:           iidx[j*M + i] = k;
1060:           idx[k++]      = j*M + i;
1061:         }
1062:       }
1063:     }

1065:     if (!mumps->myid) {
1066:       VecCreateSeq(PETSC_COMM_SELF,nrhs*M,&b_seq);
1067:       ISCreateGeneral(PETSC_COMM_SELF,nrhs*M,idx,PETSC_COPY_VALUES,&is_to);
1068:       ISCreateStride(PETSC_COMM_SELF,nrhs*M,0,1,&is_from);
1069:     } else {
1070:       VecCreateSeq(PETSC_COMM_SELF,0,&b_seq);
1071:       ISCreateStride(PETSC_COMM_SELF,0,0,1,&is_to);
1072:       ISCreateStride(PETSC_COMM_SELF,0,0,1,&is_from);
1073:     }
1074:     VecScatterCreate(v_mpi,is_from,b_seq,is_to,&scat_rhs);
1075:     VecScatterBegin(scat_rhs,v_mpi,b_seq,INSERT_VALUES,SCATTER_FORWARD);
1076:     ISDestroy(&is_to);
1077:     ISDestroy(&is_from);
1078:     VecScatterEnd(scat_rhs,v_mpi,b_seq,INSERT_VALUES,SCATTER_FORWARD);

1080:     if (!mumps->myid) { /* define rhs on the host */
1081:       VecGetArray(b_seq,&bray);
1082:       mumps->id.rhs = (MumpsScalar*)bray;
1083:       VecRestoreArray(b_seq,&bray);
1084:     }

1086:     /* solve phase */
1087:     /*-------------*/
1088:     mumps->id.job = JOB_SOLVE;
1089:     PetscMUMPS_c(&mumps->id);
1090:     if (mumps->id.INFOG(1) < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by MUMPS in solve phase: INFOG(1)=%d\n",mumps->id.INFOG(1));

1092:     /* scatter mumps distributed solution to petsc vector v_mpi, which shares local arrays with solution matrix X */
1093:     MatDenseGetArray(X,&array);
1094:     VecPlaceArray(v_mpi,array);
1095: 
1096:     /* create scatter scat_sol */
1097:     PetscMalloc1(nlsol_loc,&idxx);
1098:     ISCreateStride(PETSC_COMM_SELF,nlsol_loc,0,1,&is_from);
1099:     for (i=0; i<lsol_loc; i++) {
1100:       isol_loc[i] -= 1; /* change Fortran style to C style */
1101:       idxx[i] = iidx[isol_loc[i]];
1102:       for (j=1; j<nrhs; j++){
1103:         idxx[j*lsol_loc+i] = iidx[isol_loc[i]+j*M];
1104:       }
1105:     }
1106:     ISCreateGeneral(PETSC_COMM_SELF,nlsol_loc,idxx,PETSC_COPY_VALUES,&is_to);
1107:     VecScatterCreate(x_seq,is_from,v_mpi,is_to,&scat_sol);
1108:     VecScatterBegin(scat_sol,x_seq,v_mpi,INSERT_VALUES,SCATTER_FORWARD);
1109:     ISDestroy(&is_from);
1110:     ISDestroy(&is_to);
1111:     VecScatterEnd(scat_sol,x_seq,v_mpi,INSERT_VALUES,SCATTER_FORWARD);
1112:     MatDenseRestoreArray(X,&array);

1114:     /* free spaces */
1115:     mumps->id.sol_loc = sol_loc_save;
1116:     mumps->id.isol_loc = isol_loc_save;

1118:     PetscFree2(sol_loc,isol_loc);
1119:     PetscFree2(idx,iidx);
1120:     PetscFree(idxx);
1121:     VecDestroy(&x_seq);
1122:     VecDestroy(&v_mpi);
1123:     VecDestroy(&b_seq);
1124:     VecScatterDestroy(&scat_rhs);
1125:     VecScatterDestroy(&scat_sol);
1126:   }
1127:   return(0);
1128: }

1130: #if !defined(PETSC_USE_COMPLEX)
1131: /*
1132:   input:
1133:    F:        numeric factor
1134:   output:
1135:    nneg:     total number of negative pivots
1136:    nzero:    total number of zero pivots
1137:    npos:     (global dimension of F) - nneg - nzero
1138: */
1139: PetscErrorCode MatGetInertia_SBAIJMUMPS(Mat F,int *nneg,int *nzero,int *npos)
1140: {
1141:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;
1143:   PetscMPIInt    size;

1146:   MPI_Comm_size(PetscObjectComm((PetscObject)F),&size);
1147:   /* 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 */
1148:   if (size > 1 && mumps->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",mumps->id.INFOG(13));

1150:   if (nneg) *nneg = mumps->id.INFOG(12);
1151:   if (nzero || npos) {
1152:     if (mumps->id.ICNTL(24) != 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"-mat_mumps_icntl_24 must be set as 1 for null pivot row detection");
1153:     if (nzero) *nzero = mumps->id.INFOG(28);
1154:     if (npos) *npos   = F->rmap->N - (mumps->id.INFOG(12) + mumps->id.INFOG(28));
1155:   }
1156:   return(0);
1157: }
1158: #endif

1160: PetscErrorCode MatFactorNumeric_MUMPS(Mat F,Mat A,const MatFactorInfo *info)
1161: {
1162:   Mat_MUMPS      *mumps =(Mat_MUMPS*)(F)->data;
1164:   PetscBool      isMPIAIJ;

1167:   if (mumps->id.INFOG(1) < 0) {
1168:     if (mumps->id.INFOG(1) == -6) {
1169:       PetscInfo2(A,"MatFactorNumeric is called with singular matrix structure, INFOG(1)=%d, INFO(2)=%d\n",mumps->id.INFOG(1),mumps->id.INFO(2));
1170:     }
1171:     PetscInfo2(A,"MatFactorNumeric is called after analysis phase fails, INFOG(1)=%d, INFO(2)=%d\n",mumps->id.INFOG(1),mumps->id.INFO(2));
1172:     return(0);
1173:   }

1175:   (*mumps->ConvertToTriples)(A, 1, MAT_REUSE_MATRIX, &mumps->nz, &mumps->irn, &mumps->jcn, &mumps->val);

1177:   /* numerical factorization phase */
1178:   /*-------------------------------*/
1179:   mumps->id.job = JOB_FACTNUMERIC;
1180:   if (!mumps->id.ICNTL(18)) { /* A is centralized */
1181:     if (!mumps->myid) {
1182:       mumps->id.a = (MumpsScalar*)mumps->val;
1183:     }
1184:   } else {
1185:     mumps->id.a_loc = (MumpsScalar*)mumps->val;
1186:   }
1187:   PetscMUMPS_c(&mumps->id);
1188:   if (mumps->id.INFOG(1) < 0) {
1189:     if (A->erroriffailure) {
1190:       SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by MUMPS in numerical factorization phase: INFOG(1)=%d, INFO(2)=%d\n",mumps->id.INFOG(1),mumps->id.INFO(2));
1191:     } else {
1192:       if (mumps->id.INFOG(1) == -10) { /* numerically singular matrix */
1193:         PetscInfo2(F,"matrix is numerically singular, INFOG(1)=%d, INFO(2)=%d\n",mumps->id.INFOG(1),mumps->id.INFO(2));
1194:         F->factorerrortype = MAT_FACTOR_NUMERIC_ZEROPIVOT;
1195:       } else if (mumps->id.INFOG(1) == -13) {
1196:         PetscInfo2(F,"MUMPS in numerical factorization phase: INFOG(1)=%d, cannot allocate required memory %d megabytes\n",mumps->id.INFOG(1),mumps->id.INFO(2));
1197:         F->factorerrortype = MAT_FACTOR_OUTMEMORY;
1198:       } else if (mumps->id.INFOG(1) == -8 || mumps->id.INFOG(1) == -9 || (-16 < mumps->id.INFOG(1) && mumps->id.INFOG(1) < -10) ) {
1199:         PetscInfo2(F,"MUMPS in numerical factorization phase: INFOG(1)=%d, INFO(2)=%d, problem with workarray \n",mumps->id.INFOG(1),mumps->id.INFO(2));
1200:         F->factorerrortype = MAT_FACTOR_OUTMEMORY;
1201:       } else {
1202:         PetscInfo2(F,"MUMPS in numerical factorization phase: INFOG(1)=%d, INFO(2)=%d\n",mumps->id.INFOG(1),mumps->id.INFO(2));
1203:         F->factorerrortype = MAT_FACTOR_OTHER;
1204:       }
1205:     }
1206:   }
1207:   if (!mumps->myid && mumps->id.ICNTL(16) > 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"  mumps->id.ICNTL(16):=%d\n",mumps->id.INFOG(16));

1209:   (F)->assembled        = PETSC_TRUE;
1210:   mumps->matstruc       = SAME_NONZERO_PATTERN;
1211:   mumps->schur_factored = PETSC_FALSE;
1212:   mumps->schur_inverted = PETSC_FALSE;

1214:   /* just to be sure that ICNTL(19) value returned by a call from MatMumpsGetIcntl is always consistent */
1215:   if (!mumps->sym && mumps->id.ICNTL(19) && mumps->id.ICNTL(19) != 1) mumps->id.ICNTL(19) = 3;

1217:   if (mumps->size > 1) {
1218:     PetscInt    lsol_loc;
1219:     PetscScalar *sol_loc;

1221:     PetscObjectTypeCompare((PetscObject)A,MATMPIAIJ,&isMPIAIJ);

1223:     /* distributed solution; Create x_seq=sol_loc for repeated use */
1224:     if (mumps->x_seq) {
1225:       VecScatterDestroy(&mumps->scat_sol);
1226:       PetscFree2(mumps->id.sol_loc,mumps->id.isol_loc);
1227:       VecDestroy(&mumps->x_seq);
1228:     }
1229:     lsol_loc = mumps->id.INFO(23); /* length of sol_loc */
1230:     PetscMalloc2(lsol_loc,&sol_loc,lsol_loc,&mumps->id.isol_loc);
1231:     mumps->id.lsol_loc = lsol_loc;
1232:     mumps->id.sol_loc = (MumpsScalar*)sol_loc;
1233:     VecCreateSeqWithArray(PETSC_COMM_SELF,1,lsol_loc,sol_loc,&mumps->x_seq);
1234:   }
1235:   return(0);
1236: }

1238: /* Sets MUMPS options from the options database */
1239: PetscErrorCode PetscSetMUMPSFromOptions(Mat F, Mat A)
1240: {
1241:   Mat_MUMPS      *mumps = (Mat_MUMPS*)F->data;
1243:   PetscInt       icntl,info[40],i,ninfo=40;
1244:   PetscBool      flg;

1247:   PetscOptionsBegin(PetscObjectComm((PetscObject)A),((PetscObject)A)->prefix,"MUMPS Options","Mat");
1248:   PetscOptionsInt("-mat_mumps_icntl_1","ICNTL(1): output stream for error messages","None",mumps->id.ICNTL(1),&icntl,&flg);
1249:   if (flg) mumps->id.ICNTL(1) = icntl;
1250:   PetscOptionsInt("-mat_mumps_icntl_2","ICNTL(2): output stream for diagnostic printing, statistics, and warning","None",mumps->id.ICNTL(2),&icntl,&flg);
1251:   if (flg) mumps->id.ICNTL(2) = icntl;
1252:   PetscOptionsInt("-mat_mumps_icntl_3","ICNTL(3): output stream for global information, collected on the host","None",mumps->id.ICNTL(3),&icntl,&flg);
1253:   if (flg) mumps->id.ICNTL(3) = icntl;

1255:   PetscOptionsInt("-mat_mumps_icntl_4","ICNTL(4): level of printing (0 to 4)","None",mumps->id.ICNTL(4),&icntl,&flg);
1256:   if (flg) mumps->id.ICNTL(4) = icntl;
1257:   if (mumps->id.ICNTL(4) || PetscLogPrintInfo) mumps->id.ICNTL(3) = 6; /* resume MUMPS default id.ICNTL(3) = 6 */

1259:   PetscOptionsInt("-mat_mumps_icntl_6","ICNTL(6): permutes to a zero-free diagonal and/or scale the matrix (0 to 7)","None",mumps->id.ICNTL(6),&icntl,&flg);
1260:   if (flg) mumps->id.ICNTL(6) = icntl;

1262:   PetscOptionsInt("-mat_mumps_icntl_7","ICNTL(7): computes a symmetric permutation in sequential analysis (0 to 7). 3=Scotch, 4=PORD, 5=Metis","None",mumps->id.ICNTL(7),&icntl,&flg);
1263:   if (flg) {
1264:     if (icntl== 1 && mumps->size > 1) 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");
1265:     else mumps->id.ICNTL(7) = icntl;
1266:   }

1268:   PetscOptionsInt("-mat_mumps_icntl_8","ICNTL(8): scaling strategy (-2 to 8 or 77)","None",mumps->id.ICNTL(8),&mumps->id.ICNTL(8),NULL);
1269:   /* PetscOptionsInt("-mat_mumps_icntl_9","ICNTL(9): computes the solution using A or A^T","None",mumps->id.ICNTL(9),&mumps->id.ICNTL(9),NULL); handled by MatSolveTranspose_MUMPS() */
1270:   PetscOptionsInt("-mat_mumps_icntl_10","ICNTL(10): max num of refinements","None",mumps->id.ICNTL(10),&mumps->id.ICNTL(10),NULL);
1271:   PetscOptionsInt("-mat_mumps_icntl_11","ICNTL(11): statistics related to an error analysis (via -ksp_view)","None",mumps->id.ICNTL(11),&mumps->id.ICNTL(11),NULL);
1272:   PetscOptionsInt("-mat_mumps_icntl_12","ICNTL(12): an ordering strategy for symmetric matrices (0 to 3)","None",mumps->id.ICNTL(12),&mumps->id.ICNTL(12),NULL);
1273:   PetscOptionsInt("-mat_mumps_icntl_13","ICNTL(13): parallelism of the root node (enable ScaLAPACK) and its splitting","None",mumps->id.ICNTL(13),&mumps->id.ICNTL(13),NULL);
1274:   PetscOptionsInt("-mat_mumps_icntl_14","ICNTL(14): percentage increase in the estimated working space","None",mumps->id.ICNTL(14),&mumps->id.ICNTL(14),NULL);
1275:   PetscOptionsInt("-mat_mumps_icntl_19","ICNTL(19): computes the Schur complement","None",mumps->id.ICNTL(19),&mumps->id.ICNTL(19),NULL);
1276:   if (mumps->id.ICNTL(19) <= 0 || mumps->id.ICNTL(19) > 3) { /* reset any schur data (if any) */
1277:     MatMumpsResetSchur_Private(mumps);
1278:   }
1279:   /* PetscOptionsInt("-mat_mumps_icntl_20","ICNTL(20): the format (dense or sparse) of the right-hand sides","None",mumps->id.ICNTL(20),&mumps->id.ICNTL(20),NULL); -- sparse rhs is not supported in PETSc API */
1280:   /* PetscOptionsInt("-mat_mumps_icntl_21","ICNTL(21): the distribution (centralized or distributed) of the solution vectors","None",mumps->id.ICNTL(21),&mumps->id.ICNTL(21),NULL); we only use distributed solution vector */

1282:   PetscOptionsInt("-mat_mumps_icntl_22","ICNTL(22): in-core/out-of-core factorization and solve (0 or 1)","None",mumps->id.ICNTL(22),&mumps->id.ICNTL(22),NULL);
1283:   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),NULL);
1284:   PetscOptionsInt("-mat_mumps_icntl_24","ICNTL(24): detection of null pivot rows (0 or 1)","None",mumps->id.ICNTL(24),&mumps->id.ICNTL(24),NULL);
1285:   if (mumps->id.ICNTL(24)) {
1286:     mumps->id.ICNTL(13) = 1; /* turn-off ScaLAPACK to help with the correct detection of null pivots */
1287:   }

1289:   PetscOptionsInt("-mat_mumps_icntl_25","ICNTL(25): compute a solution of a deficient matrix and a null space basis","None",mumps->id.ICNTL(25),&mumps->id.ICNTL(25),NULL);
1290:   PetscOptionsInt("-mat_mumps_icntl_26","ICNTL(26): drives the solution phase if a Schur complement matrix","None",mumps->id.ICNTL(26),&mumps->id.ICNTL(26),NULL);
1291:   PetscOptionsInt("-mat_mumps_icntl_27","ICNTL(27): the blocking size for multiple right-hand sides","None",mumps->id.ICNTL(27),&mumps->id.ICNTL(27),NULL);
1292:   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),NULL);
1293:   PetscOptionsInt("-mat_mumps_icntl_29","ICNTL(29): parallel ordering 1 = ptscotch, 2 = parmetis","None",mumps->id.ICNTL(29),&mumps->id.ICNTL(29),NULL);
1294:   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),NULL);
1295:   PetscOptionsInt("-mat_mumps_icntl_31","ICNTL(31): indicates which factors may be discarded during factorization","None",mumps->id.ICNTL(31),&mumps->id.ICNTL(31),NULL);
1296:   /* PetscOptionsInt("-mat_mumps_icntl_32","ICNTL(32): performs the forward elemination of the right-hand sides during factorization","None",mumps->id.ICNTL(32),&mumps->id.ICNTL(32),NULL);  -- not supported by PETSc API */
1297:   PetscOptionsInt("-mat_mumps_icntl_33","ICNTL(33): compute determinant","None",mumps->id.ICNTL(33),&mumps->id.ICNTL(33),NULL);

1299:   PetscOptionsReal("-mat_mumps_cntl_1","CNTL(1): relative pivoting threshold","None",mumps->id.CNTL(1),&mumps->id.CNTL(1),NULL);
1300:   PetscOptionsReal("-mat_mumps_cntl_2","CNTL(2): stopping criterion of refinement","None",mumps->id.CNTL(2),&mumps->id.CNTL(2),NULL);
1301:   PetscOptionsReal("-mat_mumps_cntl_3","CNTL(3): absolute pivoting threshold","None",mumps->id.CNTL(3),&mumps->id.CNTL(3),NULL);
1302:   PetscOptionsReal("-mat_mumps_cntl_4","CNTL(4): value for static pivoting","None",mumps->id.CNTL(4),&mumps->id.CNTL(4),NULL);
1303:   PetscOptionsReal("-mat_mumps_cntl_5","CNTL(5): fixation for null pivots","None",mumps->id.CNTL(5),&mumps->id.CNTL(5),NULL);

1305:   PetscOptionsString("-mat_mumps_ooc_tmpdir", "out of core directory", "None", mumps->id.ooc_tmpdir, mumps->id.ooc_tmpdir, 256, NULL);

1307:   PetscOptionsIntArray("-mat_mumps_view_info","request INFO local to each processor","",info,&ninfo,NULL);
1308:   if (ninfo) {
1309:     if (ninfo > 40) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_USER,"number of INFO %d must <= 40\n",ninfo);
1310:     PetscMalloc1(ninfo,&mumps->info);
1311:     mumps->ninfo = ninfo;
1312:     for (i=0; i<ninfo; i++) {
1313:       if (info[i] < 0 || info[i]>40) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_USER,"index of INFO %d must between 1 and 40\n",ninfo);
1314:       else  mumps->info[i] = info[i];
1315:     }
1316:   }

1318:   PetscOptionsEnd();
1319:   return(0);
1320: }

1322: PetscErrorCode PetscInitializeMUMPS(Mat A,Mat_MUMPS *mumps)
1323: {

1327:   MPI_Comm_rank(PetscObjectComm((PetscObject)A), &mumps->myid);
1328:   MPI_Comm_size(PetscObjectComm((PetscObject)A),&mumps->size);
1329:   MPI_Comm_dup(PetscObjectComm((PetscObject)A),&(mumps->comm_mumps));

1331:   mumps->id.comm_fortran = MPI_Comm_c2f(mumps->comm_mumps);

1333:   mumps->id.job = JOB_INIT;
1334:   mumps->id.par = 1;  /* host participates factorizaton and solve */
1335:   mumps->id.sym = mumps->sym;
1336:   PetscMUMPS_c(&mumps->id);

1338:   mumps->scat_rhs     = NULL;
1339:   mumps->scat_sol     = NULL;

1341:   /* set PETSc-MUMPS default options - override MUMPS default */
1342:   mumps->id.ICNTL(3) = 0;
1343:   mumps->id.ICNTL(4) = 0;
1344:   if (mumps->size == 1) {
1345:     mumps->id.ICNTL(18) = 0;   /* centralized assembled matrix input */
1346:   } else {
1347:     mumps->id.ICNTL(18) = 3;   /* distributed assembled matrix input */
1348:     mumps->id.ICNTL(20) = 0;   /* rhs is in dense format */
1349:     mumps->id.ICNTL(21) = 1;   /* distributed solution */
1350:   }

1352:   /* schur */
1353:   mumps->id.size_schur      = 0;
1354:   mumps->id.listvar_schur   = NULL;
1355:   mumps->id.schur           = NULL;
1356:   mumps->sizeredrhs         = 0;
1357:   mumps->schur_pivots       = NULL;
1358:   mumps->schur_work         = NULL;
1359:   mumps->schur_sol          = NULL;
1360:   mumps->schur_sizesol      = 0;
1361:   mumps->schur_factored     = PETSC_FALSE;
1362:   mumps->schur_inverted     = PETSC_FALSE;
1363:   mumps->schur_sym          = mumps->id.sym;
1364:   return(0);
1365: }

1367: PetscErrorCode MatFactorSymbolic_MUMPS_ReportIfError(Mat F,Mat A,const MatFactorInfo *info,Mat_MUMPS *mumps)
1368: {

1372:   if (mumps->id.INFOG(1) < 0) {
1373:     if (A->erroriffailure) {
1374:       SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error reported by MUMPS in analysis phase: INFOG(1)=%d\n",mumps->id.INFOG(1));
1375:     } else {
1376:       if (mumps->id.INFOG(1) == -6) {
1377:         PetscInfo2(F,"matrix is singular in structure, INFOG(1)=%d, INFO(2)=%d\n",mumps->id.INFOG(1),mumps->id.INFO(2));
1378:         F->factorerrortype = MAT_FACTOR_STRUCT_ZEROPIVOT;
1379:       } else if (mumps->id.INFOG(1) == -5 || mumps->id.INFOG(1) == -7) {
1380:         PetscInfo2(F,"problem of workspace, INFOG(1)=%d, INFO(2)=%d\n",mumps->id.INFOG(1),mumps->id.INFO(2));
1381:         F->factorerrortype = MAT_FACTOR_OUTMEMORY;
1382:       } else {
1383:         PetscInfo2(F,"Error reported by MUMPS in analysis phase: INFOG(1)=%d, INFO(2)=%d\n",mumps->id.INFOG(1),mumps->id.INFO(2));
1384:         F->factorerrortype = MAT_FACTOR_OTHER;
1385:       }
1386:     }
1387:   }
1388:   return(0);
1389: }

1391: /* Note Petsc r(=c) permutation is used when mumps->id.ICNTL(7)==1 with centralized assembled matrix input; otherwise r and c are ignored */
1392: PetscErrorCode MatLUFactorSymbolic_AIJMUMPS(Mat F,Mat A,IS r,IS c,const MatFactorInfo *info)
1393: {
1394:   Mat_MUMPS      *mumps = (Mat_MUMPS*)F->data;
1396:   Vec            b;
1397:   IS             is_iden;
1398:   const PetscInt M = A->rmap->N;

1401:   mumps->matstruc = DIFFERENT_NONZERO_PATTERN;

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

1406:   (*mumps->ConvertToTriples)(A, 1, MAT_INITIAL_MATRIX, &mumps->nz, &mumps->irn, &mumps->jcn, &mumps->val);

1408:   /* analysis phase */
1409:   /*----------------*/
1410:   mumps->id.job = JOB_FACTSYMBOLIC;
1411:   mumps->id.n   = M;
1412:   switch (mumps->id.ICNTL(18)) {
1413:   case 0:  /* centralized assembled matrix input */
1414:     if (!mumps->myid) {
1415:       mumps->id.nz =mumps->nz; mumps->id.irn=mumps->irn; mumps->id.jcn=mumps->jcn;
1416:       if (mumps->id.ICNTL(6)>1) {
1417:         mumps->id.a = (MumpsScalar*)mumps->val;
1418:       }
1419:       if (mumps->id.ICNTL(7) == 1) { /* use user-provide matrix ordering - assuming r = c ordering */
1420:         /*
1421:         PetscBool      flag;
1422:         ISEqual(r,c,&flag);
1423:         if (!flag) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"row_perm != col_perm");
1424:         ISView(r,PETSC_VIEWER_STDOUT_SELF);
1425:          */
1426:         if (!mumps->myid) {
1427:           const PetscInt *idx;
1428:           PetscInt       i,*perm_in;

1430:           PetscMalloc1(M,&perm_in);
1431:           ISGetIndices(r,&idx);

1433:           mumps->id.perm_in = perm_in;
1434:           for (i=0; i<M; i++) perm_in[i] = idx[i]+1; /* perm_in[]: start from 1, not 0! */
1435:           ISRestoreIndices(r,&idx);
1436:         }
1437:       }
1438:     }
1439:     break;
1440:   case 3:  /* distributed assembled matrix input (size>1) */
1441:     mumps->id.nz_loc = mumps->nz;
1442:     mumps->id.irn_loc=mumps->irn; mumps->id.jcn_loc=mumps->jcn;
1443:     if (mumps->id.ICNTL(6)>1) {
1444:       mumps->id.a_loc = (MumpsScalar*)mumps->val;
1445:     }
1446:     /* MUMPS only supports centralized rhs. Create scatter scat_rhs for repeated use in MatSolve() */
1447:     if (!mumps->myid) {
1448:       VecCreateSeq(PETSC_COMM_SELF,A->rmap->N,&mumps->b_seq);
1449:       ISCreateStride(PETSC_COMM_SELF,A->rmap->N,0,1,&is_iden);
1450:     } else {
1451:       VecCreateSeq(PETSC_COMM_SELF,0,&mumps->b_seq);
1452:       ISCreateStride(PETSC_COMM_SELF,0,0,1,&is_iden);
1453:     }
1454:     MatCreateVecs(A,NULL,&b);
1455:     VecScatterCreate(b,is_iden,mumps->b_seq,is_iden,&mumps->scat_rhs);
1456:     ISDestroy(&is_iden);
1457:     VecDestroy(&b);
1458:     break;
1459:   }
1460:   PetscMUMPS_c(&mumps->id);
1461:   MatFactorSymbolic_MUMPS_ReportIfError(F,A,info,mumps);

1463:   F->ops->lufactornumeric = MatFactorNumeric_MUMPS;
1464:   F->ops->solve           = MatSolve_MUMPS;
1465:   F->ops->solvetranspose  = MatSolveTranspose_MUMPS;
1466:   F->ops->matsolve        = MatMatSolve_MUMPS;
1467:   return(0);
1468: }

1470: /* Note the Petsc r and c permutations are ignored */
1471: PetscErrorCode MatLUFactorSymbolic_BAIJMUMPS(Mat F,Mat A,IS r,IS c,const MatFactorInfo *info)
1472: {
1473:   Mat_MUMPS      *mumps = (Mat_MUMPS*)F->data;
1475:   Vec            b;
1476:   IS             is_iden;
1477:   const PetscInt M = A->rmap->N;

1480:   mumps->matstruc = DIFFERENT_NONZERO_PATTERN;

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

1485:   (*mumps->ConvertToTriples)(A, 1, MAT_INITIAL_MATRIX, &mumps->nz, &mumps->irn, &mumps->jcn, &mumps->val);

1487:   /* analysis phase */
1488:   /*----------------*/
1489:   mumps->id.job = JOB_FACTSYMBOLIC;
1490:   mumps->id.n   = M;
1491:   switch (mumps->id.ICNTL(18)) {
1492:   case 0:  /* centralized assembled matrix input */
1493:     if (!mumps->myid) {
1494:       mumps->id.nz =mumps->nz; mumps->id.irn=mumps->irn; mumps->id.jcn=mumps->jcn;
1495:       if (mumps->id.ICNTL(6)>1) {
1496:         mumps->id.a = (MumpsScalar*)mumps->val;
1497:       }
1498:     }
1499:     break;
1500:   case 3:  /* distributed assembled matrix input (size>1) */
1501:     mumps->id.nz_loc = mumps->nz;
1502:     mumps->id.irn_loc=mumps->irn; mumps->id.jcn_loc=mumps->jcn;
1503:     if (mumps->id.ICNTL(6)>1) {
1504:       mumps->id.a_loc = (MumpsScalar*)mumps->val;
1505:     }
1506:     /* MUMPS only supports centralized rhs. Create scatter scat_rhs for repeated use in MatSolve() */
1507:     if (!mumps->myid) {
1508:       VecCreateSeq(PETSC_COMM_SELF,A->cmap->N,&mumps->b_seq);
1509:       ISCreateStride(PETSC_COMM_SELF,A->cmap->N,0,1,&is_iden);
1510:     } else {
1511:       VecCreateSeq(PETSC_COMM_SELF,0,&mumps->b_seq);
1512:       ISCreateStride(PETSC_COMM_SELF,0,0,1,&is_iden);
1513:     }
1514:     MatCreateVecs(A,NULL,&b);
1515:     VecScatterCreate(b,is_iden,mumps->b_seq,is_iden,&mumps->scat_rhs);
1516:     ISDestroy(&is_iden);
1517:     VecDestroy(&b);
1518:     break;
1519:   }
1520:   PetscMUMPS_c(&mumps->id);
1521:   MatFactorSymbolic_MUMPS_ReportIfError(F,A,info,mumps);

1523:   F->ops->lufactornumeric = MatFactorNumeric_MUMPS;
1524:   F->ops->solve           = MatSolve_MUMPS;
1525:   F->ops->solvetranspose  = MatSolveTranspose_MUMPS;
1526:   return(0);
1527: }

1529: /* Note the Petsc r permutation and factor info are ignored */
1530: PetscErrorCode MatCholeskyFactorSymbolic_MUMPS(Mat F,Mat A,IS r,const MatFactorInfo *info)
1531: {
1532:   Mat_MUMPS      *mumps = (Mat_MUMPS*)F->data;
1534:   Vec            b;
1535:   IS             is_iden;
1536:   const PetscInt M = A->rmap->N;

1539:   mumps->matstruc = DIFFERENT_NONZERO_PATTERN;

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

1544:   (*mumps->ConvertToTriples)(A, 1, MAT_INITIAL_MATRIX, &mumps->nz, &mumps->irn, &mumps->jcn, &mumps->val);

1546:   /* analysis phase */
1547:   /*----------------*/
1548:   mumps->id.job = JOB_FACTSYMBOLIC;
1549:   mumps->id.n   = M;
1550:   switch (mumps->id.ICNTL(18)) {
1551:   case 0:  /* centralized assembled matrix input */
1552:     if (!mumps->myid) {
1553:       mumps->id.nz =mumps->nz; mumps->id.irn=mumps->irn; mumps->id.jcn=mumps->jcn;
1554:       if (mumps->id.ICNTL(6)>1) {
1555:         mumps->id.a = (MumpsScalar*)mumps->val;
1556:       }
1557:     }
1558:     break;
1559:   case 3:  /* distributed assembled matrix input (size>1) */
1560:     mumps->id.nz_loc = mumps->nz;
1561:     mumps->id.irn_loc=mumps->irn; mumps->id.jcn_loc=mumps->jcn;
1562:     if (mumps->id.ICNTL(6)>1) {
1563:       mumps->id.a_loc = (MumpsScalar*)mumps->val;
1564:     }
1565:     /* MUMPS only supports centralized rhs. Create scatter scat_rhs for repeated use in MatSolve() */
1566:     if (!mumps->myid) {
1567:       VecCreateSeq(PETSC_COMM_SELF,A->cmap->N,&mumps->b_seq);
1568:       ISCreateStride(PETSC_COMM_SELF,A->cmap->N,0,1,&is_iden);
1569:     } else {
1570:       VecCreateSeq(PETSC_COMM_SELF,0,&mumps->b_seq);
1571:       ISCreateStride(PETSC_COMM_SELF,0,0,1,&is_iden);
1572:     }
1573:     MatCreateVecs(A,NULL,&b);
1574:     VecScatterCreate(b,is_iden,mumps->b_seq,is_iden,&mumps->scat_rhs);
1575:     ISDestroy(&is_iden);
1576:     VecDestroy(&b);
1577:     break;
1578:   }
1579:   PetscMUMPS_c(&mumps->id);
1580:   MatFactorSymbolic_MUMPS_ReportIfError(F,A,info,mumps);

1582:   F->ops->choleskyfactornumeric = MatFactorNumeric_MUMPS;
1583:   F->ops->solve                 = MatSolve_MUMPS;
1584:   F->ops->solvetranspose        = MatSolve_MUMPS;
1585:   F->ops->matsolve              = MatMatSolve_MUMPS;
1586: #if defined(PETSC_USE_COMPLEX)
1587:   F->ops->getinertia = NULL;
1588: #else
1589:   F->ops->getinertia = MatGetInertia_SBAIJMUMPS;
1590: #endif
1591:   return(0);
1592: }

1594: PetscErrorCode MatView_MUMPS(Mat A,PetscViewer viewer)
1595: {
1596:   PetscErrorCode    ierr;
1597:   PetscBool         iascii;
1598:   PetscViewerFormat format;
1599:   Mat_MUMPS         *mumps=(Mat_MUMPS*)A->data;

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

1605:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);
1606:   if (iascii) {
1607:     PetscViewerGetFormat(viewer,&format);
1608:     if (format == PETSC_VIEWER_ASCII_INFO) {
1609:       PetscViewerASCIIPrintf(viewer,"MUMPS run parameters:\n");
1610:       PetscViewerASCIIPrintf(viewer,"  SYM (matrix type):                   %d \n",mumps->id.sym);
1611:       PetscViewerASCIIPrintf(viewer,"  PAR (host participation):            %d \n",mumps->id.par);
1612:       PetscViewerASCIIPrintf(viewer,"  ICNTL(1) (output for error):         %d \n",mumps->id.ICNTL(1));
1613:       PetscViewerASCIIPrintf(viewer,"  ICNTL(2) (output of diagnostic msg): %d \n",mumps->id.ICNTL(2));
1614:       PetscViewerASCIIPrintf(viewer,"  ICNTL(3) (output for global info):   %d \n",mumps->id.ICNTL(3));
1615:       PetscViewerASCIIPrintf(viewer,"  ICNTL(4) (level of printing):        %d \n",mumps->id.ICNTL(4));
1616:       PetscViewerASCIIPrintf(viewer,"  ICNTL(5) (input mat struct):         %d \n",mumps->id.ICNTL(5));
1617:       PetscViewerASCIIPrintf(viewer,"  ICNTL(6) (matrix prescaling):        %d \n",mumps->id.ICNTL(6));
1618:       PetscViewerASCIIPrintf(viewer,"  ICNTL(7) (sequential matrix ordering):%d \n",mumps->id.ICNTL(7));
1619:       PetscViewerASCIIPrintf(viewer,"  ICNTL(8) (scaling strategy):        %d \n",mumps->id.ICNTL(8));
1620:       PetscViewerASCIIPrintf(viewer,"  ICNTL(10) (max num of refinements):  %d \n",mumps->id.ICNTL(10));
1621:       PetscViewerASCIIPrintf(viewer,"  ICNTL(11) (error analysis):          %d \n",mumps->id.ICNTL(11));
1622:       if (mumps->id.ICNTL(11)>0) {
1623:         PetscViewerASCIIPrintf(viewer,"    RINFOG(4) (inf norm of input mat):        %g\n",mumps->id.RINFOG(4));
1624:         PetscViewerASCIIPrintf(viewer,"    RINFOG(5) (inf norm of solution):         %g\n",mumps->id.RINFOG(5));
1625:         PetscViewerASCIIPrintf(viewer,"    RINFOG(6) (inf norm of residual):         %g\n",mumps->id.RINFOG(6));
1626:         PetscViewerASCIIPrintf(viewer,"    RINFOG(7),RINFOG(8) (backward error est): %g, %g\n",mumps->id.RINFOG(7),mumps->id.RINFOG(8));
1627:         PetscViewerASCIIPrintf(viewer,"    RINFOG(9) (error estimate):               %g \n",mumps->id.RINFOG(9));
1628:         PetscViewerASCIIPrintf(viewer,"    RINFOG(10),RINFOG(11)(condition numbers): %g, %g\n",mumps->id.RINFOG(10),mumps->id.RINFOG(11));
1629:       }
1630:       PetscViewerASCIIPrintf(viewer,"  ICNTL(12) (efficiency control):                         %d \n",mumps->id.ICNTL(12));
1631:       PetscViewerASCIIPrintf(viewer,"  ICNTL(13) (efficiency control):                         %d \n",mumps->id.ICNTL(13));
1632:       PetscViewerASCIIPrintf(viewer,"  ICNTL(14) (percentage of estimated workspace increase): %d \n",mumps->id.ICNTL(14));
1633:       /* ICNTL(15-17) not used */
1634:       PetscViewerASCIIPrintf(viewer,"  ICNTL(18) (input mat struct):                           %d \n",mumps->id.ICNTL(18));
1635:       PetscViewerASCIIPrintf(viewer,"  ICNTL(19) (Schur complement info):                       %d \n",mumps->id.ICNTL(19));
1636:       PetscViewerASCIIPrintf(viewer,"  ICNTL(20) (rhs sparse pattern):                         %d \n",mumps->id.ICNTL(20));
1637:       PetscViewerASCIIPrintf(viewer,"  ICNTL(21) (solution struct):                            %d \n",mumps->id.ICNTL(21));
1638:       PetscViewerASCIIPrintf(viewer,"  ICNTL(22) (in-core/out-of-core facility):               %d \n",mumps->id.ICNTL(22));
1639:       PetscViewerASCIIPrintf(viewer,"  ICNTL(23) (max size of memory can be allocated locally):%d \n",mumps->id.ICNTL(23));

1641:       PetscViewerASCIIPrintf(viewer,"  ICNTL(24) (detection of null pivot rows):               %d \n",mumps->id.ICNTL(24));
1642:       PetscViewerASCIIPrintf(viewer,"  ICNTL(25) (computation of a null space basis):          %d \n",mumps->id.ICNTL(25));
1643:       PetscViewerASCIIPrintf(viewer,"  ICNTL(26) (Schur options for rhs or solution):          %d \n",mumps->id.ICNTL(26));
1644:       PetscViewerASCIIPrintf(viewer,"  ICNTL(27) (experimental parameter):                     %d \n",mumps->id.ICNTL(27));
1645:       PetscViewerASCIIPrintf(viewer,"  ICNTL(28) (use parallel or sequential ordering):        %d \n",mumps->id.ICNTL(28));
1646:       PetscViewerASCIIPrintf(viewer,"  ICNTL(29) (parallel ordering):                          %d \n",mumps->id.ICNTL(29));

1648:       PetscViewerASCIIPrintf(viewer,"  ICNTL(30) (user-specified set of entries in inv(A)):    %d \n",mumps->id.ICNTL(30));
1649:       PetscViewerASCIIPrintf(viewer,"  ICNTL(31) (factors is discarded in the solve phase):    %d \n",mumps->id.ICNTL(31));
1650:       PetscViewerASCIIPrintf(viewer,"  ICNTL(33) (compute determinant):                        %d \n",mumps->id.ICNTL(33));

1652:       PetscViewerASCIIPrintf(viewer,"  CNTL(1) (relative pivoting threshold):      %g \n",mumps->id.CNTL(1));
1653:       PetscViewerASCIIPrintf(viewer,"  CNTL(2) (stopping criterion of refinement): %g \n",mumps->id.CNTL(2));
1654:       PetscViewerASCIIPrintf(viewer,"  CNTL(3) (absolute pivoting threshold):      %g \n",mumps->id.CNTL(3));
1655:       PetscViewerASCIIPrintf(viewer,"  CNTL(4) (value of static pivoting):         %g \n",mumps->id.CNTL(4));
1656:       PetscViewerASCIIPrintf(viewer,"  CNTL(5) (fixation for null pivots):         %g \n",mumps->id.CNTL(5));

1658:       /* infomation local to each processor */
1659:       PetscViewerASCIIPrintf(viewer, "  RINFO(1) (local estimated flops for the elimination after analysis): \n");
1660:       PetscViewerASCIIPushSynchronized(viewer);
1661:       PetscViewerASCIISynchronizedPrintf(viewer,"    [%d] %g \n",mumps->myid,mumps->id.RINFO(1));
1662:       PetscViewerFlush(viewer);
1663:       PetscViewerASCIIPrintf(viewer, "  RINFO(2) (local estimated flops for the assembly after factorization): \n");
1664:       PetscViewerASCIISynchronizedPrintf(viewer,"    [%d]  %g \n",mumps->myid,mumps->id.RINFO(2));
1665:       PetscViewerFlush(viewer);
1666:       PetscViewerASCIIPrintf(viewer, "  RINFO(3) (local estimated flops for the elimination after factorization): \n");
1667:       PetscViewerASCIISynchronizedPrintf(viewer,"    [%d]  %g \n",mumps->myid,mumps->id.RINFO(3));
1668:       PetscViewerFlush(viewer);

1670:       PetscViewerASCIIPrintf(viewer, "  INFO(15) (estimated size of (in MB) MUMPS internal data for running numerical factorization): \n");
1671:       PetscViewerASCIISynchronizedPrintf(viewer,"  [%d] %d \n",mumps->myid,mumps->id.INFO(15));
1672:       PetscViewerFlush(viewer);

1674:       PetscViewerASCIIPrintf(viewer, "  INFO(16) (size of (in MB) MUMPS internal data used during numerical factorization): \n");
1675:       PetscViewerASCIISynchronizedPrintf(viewer,"    [%d] %d \n",mumps->myid,mumps->id.INFO(16));
1676:       PetscViewerFlush(viewer);

1678:       PetscViewerASCIIPrintf(viewer, "  INFO(23) (num of pivots eliminated on this processor after factorization): \n");
1679:       PetscViewerASCIISynchronizedPrintf(viewer,"    [%d] %d \n",mumps->myid,mumps->id.INFO(23));
1680:       PetscViewerFlush(viewer);

1682:       if (mumps->ninfo && mumps->ninfo <= 40){
1683:         PetscInt i;
1684:         for (i=0; i<mumps->ninfo; i++){
1685:           PetscViewerASCIIPrintf(viewer, "  INFO(%d): \n",mumps->info[i]);
1686:           PetscViewerASCIISynchronizedPrintf(viewer,"    [%d] %d \n",mumps->myid,mumps->id.INFO(mumps->info[i]));
1687:           PetscViewerFlush(viewer);
1688:         }
1689:       }


1692:       PetscViewerASCIIPopSynchronized(viewer);

1694:       if (!mumps->myid) { /* information from the host */
1695:         PetscViewerASCIIPrintf(viewer,"  RINFOG(1) (global estimated flops for the elimination after analysis): %g \n",mumps->id.RINFOG(1));
1696:         PetscViewerASCIIPrintf(viewer,"  RINFOG(2) (global estimated flops for the assembly after factorization): %g \n",mumps->id.RINFOG(2));
1697:         PetscViewerASCIIPrintf(viewer,"  RINFOG(3) (global estimated flops for the elimination after factorization): %g \n",mumps->id.RINFOG(3));
1698:         PetscViewerASCIIPrintf(viewer,"  (RINFOG(12) RINFOG(13))*2^INFOG(34) (determinant): (%g,%g)*(2^%d)\n",mumps->id.RINFOG(12),mumps->id.RINFOG(13),mumps->id.INFOG(34));

1700:         PetscViewerASCIIPrintf(viewer,"  INFOG(3) (estimated real workspace for factors on all processors after analysis): %d \n",mumps->id.INFOG(3));
1701:         PetscViewerASCIIPrintf(viewer,"  INFOG(4) (estimated integer workspace for factors on all processors after analysis): %d \n",mumps->id.INFOG(4));
1702:         PetscViewerASCIIPrintf(viewer,"  INFOG(5) (estimated maximum front size in the complete tree): %d \n",mumps->id.INFOG(5));
1703:         PetscViewerASCIIPrintf(viewer,"  INFOG(6) (number of nodes in the complete tree): %d \n",mumps->id.INFOG(6));
1704:         PetscViewerASCIIPrintf(viewer,"  INFOG(7) (ordering option effectively use after analysis): %d \n",mumps->id.INFOG(7));
1705:         PetscViewerASCIIPrintf(viewer,"  INFOG(8) (structural symmetry in percent of the permuted matrix after analysis): %d \n",mumps->id.INFOG(8));
1706:         PetscViewerASCIIPrintf(viewer,"  INFOG(9) (total real/complex workspace to store the matrix factors after factorization): %d \n",mumps->id.INFOG(9));
1707:         PetscViewerASCIIPrintf(viewer,"  INFOG(10) (total integer space store the matrix factors after factorization): %d \n",mumps->id.INFOG(10));
1708:         PetscViewerASCIIPrintf(viewer,"  INFOG(11) (order of largest frontal matrix after factorization): %d \n",mumps->id.INFOG(11));
1709:         PetscViewerASCIIPrintf(viewer,"  INFOG(12) (number of off-diagonal pivots): %d \n",mumps->id.INFOG(12));
1710:         PetscViewerASCIIPrintf(viewer,"  INFOG(13) (number of delayed pivots after factorization): %d \n",mumps->id.INFOG(13));
1711:         PetscViewerASCIIPrintf(viewer,"  INFOG(14) (number of memory compress after factorization): %d \n",mumps->id.INFOG(14));
1712:         PetscViewerASCIIPrintf(viewer,"  INFOG(15) (number of steps of iterative refinement after solution): %d \n",mumps->id.INFOG(15));
1713:         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",mumps->id.INFOG(16));
1714:         PetscViewerASCIIPrintf(viewer,"  INFOG(17) (estimated size of all MUMPS internal data for factorization after analysis: sum over all processors): %d \n",mumps->id.INFOG(17));
1715:         PetscViewerASCIIPrintf(viewer,"  INFOG(18) (size of all MUMPS internal data allocated during factorization: value on the most memory consuming processor): %d \n",mumps->id.INFOG(18));
1716:         PetscViewerASCIIPrintf(viewer,"  INFOG(19) (size of all MUMPS internal data allocated during factorization: sum over all processors): %d \n",mumps->id.INFOG(19));
1717:         PetscViewerASCIIPrintf(viewer,"  INFOG(20) (estimated number of entries in the factors): %d \n",mumps->id.INFOG(20));
1718:         PetscViewerASCIIPrintf(viewer,"  INFOG(21) (size in MB of memory effectively used during factorization - value on the most memory consuming processor): %d \n",mumps->id.INFOG(21));
1719:         PetscViewerASCIIPrintf(viewer,"  INFOG(22) (size in MB of memory effectively used during factorization - sum over all processors): %d \n",mumps->id.INFOG(22));
1720:         PetscViewerASCIIPrintf(viewer,"  INFOG(23) (after analysis: value of ICNTL(6) effectively used): %d \n",mumps->id.INFOG(23));
1721:         PetscViewerASCIIPrintf(viewer,"  INFOG(24) (after analysis: value of ICNTL(12) effectively used): %d \n",mumps->id.INFOG(24));
1722:         PetscViewerASCIIPrintf(viewer,"  INFOG(25) (after factorization: number of pivots modified by static pivoting): %d \n",mumps->id.INFOG(25));
1723:         PetscViewerASCIIPrintf(viewer,"  INFOG(28) (after factorization: number of null pivots encountered): %d\n",mumps->id.INFOG(28));
1724:         PetscViewerASCIIPrintf(viewer,"  INFOG(29) (after factorization: effective number of entries in the factors (sum over all processors)): %d\n",mumps->id.INFOG(29));
1725:         PetscViewerASCIIPrintf(viewer,"  INFOG(30, 31) (after solution: size in Mbytes of memory used during solution phase): %d, %d\n",mumps->id.INFOG(30),mumps->id.INFOG(31));
1726:         PetscViewerASCIIPrintf(viewer,"  INFOG(32) (after analysis: type of analysis done): %d\n",mumps->id.INFOG(32));
1727:         PetscViewerASCIIPrintf(viewer,"  INFOG(33) (value used for ICNTL(8)): %d\n",mumps->id.INFOG(33));
1728:         PetscViewerASCIIPrintf(viewer,"  INFOG(34) (exponent of the determinant if determinant is requested): %d\n",mumps->id.INFOG(34));
1729:       }
1730:     }
1731:   }
1732:   return(0);
1733: }

1735: PetscErrorCode MatGetInfo_MUMPS(Mat A,MatInfoType flag,MatInfo *info)
1736: {
1737:   Mat_MUMPS *mumps =(Mat_MUMPS*)A->data;

1740:   info->block_size        = 1.0;
1741:   info->nz_allocated      = mumps->id.INFOG(20);
1742:   info->nz_used           = mumps->id.INFOG(20);
1743:   info->nz_unneeded       = 0.0;
1744:   info->assemblies        = 0.0;
1745:   info->mallocs           = 0.0;
1746:   info->memory            = 0.0;
1747:   info->fill_ratio_given  = 0;
1748:   info->fill_ratio_needed = 0;
1749:   info->factor_mallocs    = 0;
1750:   return(0);
1751: }

1753: /* -------------------------------------------------------------------------------------------*/
1754: PetscErrorCode MatFactorSetSchurIS_MUMPS(Mat F, IS is)
1755: {
1756:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;
1757:   const PetscInt *idxs;
1758:   PetscInt       size,i;

1762:   if (mumps->size > 1) {
1763:     PetscBool ls,gs;

1765:     ISGetLocalSize(is,&size);
1766:     ls   = mumps->myid ? (size ? PETSC_FALSE : PETSC_TRUE) : PETSC_TRUE;
1767:     MPI_Allreduce(&ls,&gs,1,MPIU_BOOL,MPI_LAND,mumps->comm_mumps);
1768:     if (!gs) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"MUMPS distributed parallel Schur complements not yet supported from PETSc\n");
1769:   }
1770:   ISGetLocalSize(is,&size);
1771:   if (mumps->id.size_schur != size) {
1772:     PetscFree2(mumps->id.listvar_schur,mumps->id.schur);
1773:     mumps->id.size_schur = size;
1774:     mumps->id.schur_lld = size;
1775:     PetscMalloc2(size,&mumps->id.listvar_schur,size*size,&mumps->id.schur);
1776:   }
1777:   ISGetIndices(is,&idxs);
1778:   PetscMemcpy(mumps->id.listvar_schur,idxs,size*sizeof(PetscInt));
1779:   /* MUMPS expects Fortran style indices */
1780:   for (i=0;i<size;i++) mumps->id.listvar_schur[i]++;
1781:   ISRestoreIndices(is,&idxs);
1782:   if (mumps->size > 1) {
1783:     mumps->id.ICNTL(19) = 1; /* MUMPS returns Schur centralized on the host */
1784:   } else {
1785:     if (F->factortype == MAT_FACTOR_LU) {
1786:       mumps->id.ICNTL(19) = 3; /* MUMPS returns full matrix */
1787:     } else {
1788:       mumps->id.ICNTL(19) = 2; /* MUMPS returns lower triangular part */
1789:     }
1790:   }
1791:   /* set a special value of ICNTL (not handled my MUMPS) to be used in the solve phase by PETSc */
1792:   mumps->id.ICNTL(26) = -1;
1793:   return(0);
1794: }

1796: /* -------------------------------------------------------------------------------------------*/
1797: PetscErrorCode MatFactorCreateSchurComplement_MUMPS(Mat F,Mat* S)
1798: {
1799:   Mat            St;
1800:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;
1801:   PetscScalar    *array;
1802: #if defined(PETSC_USE_COMPLEX)
1803:   PetscScalar    im = PetscSqrtScalar((PetscScalar)-1.0);
1804: #endif

1808:   if (!mumps->id.ICNTL(19)) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur complement mode not selected! You should call MatFactorSetSchurIS to enable it");
1809:   MatCreate(PETSC_COMM_SELF,&St);
1810:   MatSetSizes(St,PETSC_DECIDE,PETSC_DECIDE,mumps->id.size_schur,mumps->id.size_schur);
1811:   MatSetType(St,MATDENSE);
1812:   MatSetUp(St);
1813:   MatDenseGetArray(St,&array);
1814:   if (!mumps->sym) { /* MUMPS always return a full matrix */
1815:     if (mumps->id.ICNTL(19) == 1) { /* stored by rows */
1816:       PetscInt i,j,N=mumps->id.size_schur;
1817:       for (i=0;i<N;i++) {
1818:         for (j=0;j<N;j++) {
1819: #if !defined(PETSC_USE_COMPLEX)
1820:           PetscScalar val = mumps->id.schur[i*N+j];
1821: #else
1822:           PetscScalar val = mumps->id.schur[i*N+j].r + im*mumps->id.schur[i*N+j].i;
1823: #endif
1824:           array[j*N+i] = val;
1825:         }
1826:       }
1827:     } else { /* stored by columns */
1828:       PetscMemcpy(array,mumps->id.schur,mumps->id.size_schur*mumps->id.size_schur*sizeof(PetscScalar));
1829:     }
1830:   } else { /* either full or lower-triangular (not packed) */
1831:     if (mumps->id.ICNTL(19) == 2) { /* lower triangular stored by columns */
1832:       PetscInt i,j,N=mumps->id.size_schur;
1833:       for (i=0;i<N;i++) {
1834:         for (j=i;j<N;j++) {
1835: #if !defined(PETSC_USE_COMPLEX)
1836:           PetscScalar val = mumps->id.schur[i*N+j];
1837: #else
1838:           PetscScalar val = mumps->id.schur[i*N+j].r + im*mumps->id.schur[i*N+j].i;
1839: #endif
1840:           array[i*N+j] = val;
1841:           array[j*N+i] = val;
1842:         }
1843:       }
1844:     } else if (mumps->id.ICNTL(19) == 3) { /* full matrix */
1845:       PetscMemcpy(array,mumps->id.schur,mumps->id.size_schur*mumps->id.size_schur*sizeof(PetscScalar));
1846:     } else { /* ICNTL(19) == 1 lower triangular stored by rows */
1847:       PetscInt i,j,N=mumps->id.size_schur;
1848:       for (i=0;i<N;i++) {
1849:         for (j=0;j<i+1;j++) {
1850: #if !defined(PETSC_USE_COMPLEX)
1851:           PetscScalar val = mumps->id.schur[i*N+j];
1852: #else
1853:           PetscScalar val = mumps->id.schur[i*N+j].r + im*mumps->id.schur[i*N+j].i;
1854: #endif
1855:           array[i*N+j] = val;
1856:           array[j*N+i] = val;
1857:         }
1858:       }
1859:     }
1860:   }
1861:   MatDenseRestoreArray(St,&array);
1862:   *S = St;
1863:   return(0);
1864: }

1866: /* -------------------------------------------------------------------------------------------*/
1867: PetscErrorCode MatFactorGetSchurComplement_MUMPS(Mat F,Mat* S)
1868: {
1869:   Mat            St;
1870:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;

1874:   if (!mumps->id.ICNTL(19)) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur complement mode not selected! You should call MatFactorSetSchurIS to enable it");
1875:   /* It should be the responsibility of the user to handle different ICNTL(19) cases and factorization stages if they want to work with the raw data */
1876:   MatCreateSeqDense(PETSC_COMM_SELF,mumps->id.size_schur,mumps->id.size_schur,(PetscScalar*)mumps->id.schur,&St);
1877:   *S = St;
1878:   return(0);
1879: }

1881: /* -------------------------------------------------------------------------------------------*/
1882: PetscErrorCode MatFactorFactorizeSchurComplement_MUMPS(Mat F)
1883: {
1884:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;

1888:   if (!mumps->id.ICNTL(19)) { /* do nothing */
1889:     return(0);
1890:   }
1891:   if (mumps->size > 1) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_SUP,"Parallel Schur complement not yet supported from PETSc");
1892:   MatMumpsFactorSchur_Private(mumps);
1893:   return(0);
1894: }

1896: PetscErrorCode MatFactorInvertSchurComplement_MUMPS(Mat F)
1897: {
1898:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;

1902:   if (!mumps->id.ICNTL(19)) { /* do nothing */
1903:     return(0);
1904:   }
1905:   if (mumps->size > 1) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_SUP,"Parallel Schur complement not yet supported from PETSc");
1906:   MatMumpsInvertSchur_Private(mumps);
1907:   return(0);
1908: }

1910: /* -------------------------------------------------------------------------------------------*/
1911: PetscErrorCode MatFactorSolveSchurComplement_MUMPS(Mat F, Vec rhs, Vec sol)
1912: {
1913:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;
1914:   MumpsScalar    *orhs;
1915:   PetscScalar    *osol,*nrhs,*nsol;
1916:   PetscInt       orhs_size,osol_size,olrhs_size;

1920:   if (!mumps->id.ICNTL(19)) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur complement mode not selected! You should call MatFactorSetSchurIS to enable it");
1921:   if (mumps->size > 1) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_SUP,"Parallel Schur complement not yet supported from PETSc");

1923:   /* swap pointers */
1924:   orhs = mumps->id.redrhs;
1925:   olrhs_size = mumps->id.lredrhs;
1926:   orhs_size = mumps->sizeredrhs;
1927:   osol = mumps->schur_sol;
1928:   osol_size = mumps->schur_sizesol;
1929:   VecGetArray(rhs,&nrhs);
1930:   VecGetArray(sol,&nsol);
1931:   mumps->id.redrhs = (MumpsScalar*)nrhs;
1932:   VecGetLocalSize(rhs,&mumps->sizeredrhs);
1933:   mumps->id.lredrhs = mumps->sizeredrhs;
1934:   mumps->schur_sol = nsol;
1935:   VecGetLocalSize(sol,&mumps->schur_sizesol);

1937:   /* solve Schur complement */
1938:   mumps->id.nrhs = 1;
1939:   MatMumpsSolveSchur_Private(mumps,PETSC_FALSE);
1940:   /* restore pointers */
1941:   VecRestoreArray(rhs,&nrhs);
1942:   VecRestoreArray(sol,&nsol);
1943:   mumps->id.redrhs = orhs;
1944:   mumps->id.lredrhs = olrhs_size;
1945:   mumps->sizeredrhs = orhs_size;
1946:   mumps->schur_sol = osol;
1947:   mumps->schur_sizesol = osol_size;
1948:   return(0);
1949: }

1951: /* -------------------------------------------------------------------------------------------*/
1952: PetscErrorCode MatFactorSolveSchurComplementTranspose_MUMPS(Mat F, Vec rhs, Vec sol)
1953: {
1954:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;
1955:   MumpsScalar    *orhs;
1956:   PetscScalar    *osol,*nrhs,*nsol;
1957:   PetscInt       orhs_size,osol_size;

1961:   if (!mumps->id.ICNTL(19)) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur complement mode not selected! You should call MatFactorSetSchurIS to enable it");
1962:   if (mumps->size > 1) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_SUP,"Parallel Schur complement not yet supported from PETSc");

1964:   /* swap pointers */
1965:   orhs = mumps->id.redrhs;
1966:   orhs_size = mumps->sizeredrhs;
1967:   osol = mumps->schur_sol;
1968:   osol_size = mumps->schur_sizesol;
1969:   VecGetArray(rhs,&nrhs);
1970:   VecGetArray(sol,&nsol);
1971:   mumps->id.redrhs = (MumpsScalar*)nrhs;
1972:   VecGetLocalSize(rhs,&mumps->sizeredrhs);
1973:   mumps->schur_sol = nsol;
1974:   VecGetLocalSize(sol,&mumps->schur_sizesol);

1976:   /* solve Schur complement */
1977:   mumps->id.nrhs = 1;
1978:   mumps->id.ICNTL(9) = 0;
1979:   MatMumpsSolveSchur_Private(mumps,PETSC_FALSE);
1980:   mumps->id.ICNTL(9) = 1;
1981:   /* restore pointers */
1982:   VecRestoreArray(rhs,&nrhs);
1983:   VecRestoreArray(sol,&nsol);
1984:   mumps->id.redrhs = orhs;
1985:   mumps->sizeredrhs = orhs_size;
1986:   mumps->schur_sol = osol;
1987:   mumps->schur_sizesol = osol_size;
1988:   return(0);
1989: }

1991: /* -------------------------------------------------------------------------------------------*/
1992: PetscErrorCode MatFactorSetSchurComplementSolverType_MUMPS(Mat F, PetscInt sym)
1993: {
1994:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

1997:   if (mumps->schur_factored && mumps->sym != mumps->schur_sym) {
1998:     SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONG,"Cannot change the Schur solver! Schur complement data has been already factored");
1999:   }
2000:   mumps->schur_sym = sym;
2001:   return(0);
2002: }

2004: /* -------------------------------------------------------------------------------------------*/
2005: PetscErrorCode MatMumpsSetIcntl_MUMPS(Mat F,PetscInt icntl,PetscInt ival)
2006: {
2007:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2010:   mumps->id.ICNTL(icntl) = ival;
2011:   return(0);
2012: }

2014: PetscErrorCode MatMumpsGetIcntl_MUMPS(Mat F,PetscInt icntl,PetscInt *ival)
2015: {
2016:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2019:   *ival = mumps->id.ICNTL(icntl);
2020:   return(0);
2021: }

2023: /*@
2024:   MatMumpsSetIcntl - Set MUMPS parameter ICNTL()

2026:    Logically Collective on Mat

2028:    Input Parameters:
2029: +  F - the factored matrix obtained by calling MatGetFactor() from PETSc-MUMPS interface
2030: .  icntl - index of MUMPS parameter array ICNTL()
2031: -  ival - value of MUMPS ICNTL(icntl)

2033:   Options Database:
2034: .   -mat_mumps_icntl_<icntl> <ival>

2036:    Level: beginner

2038:    References:
2039: .     MUMPS Users' Guide

2041: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2042:  @*/
2043: PetscErrorCode MatMumpsSetIcntl(Mat F,PetscInt icntl,PetscInt ival)
2044: {
2046: 
2049:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2052:   PetscTryMethod(F,"MatMumpsSetIcntl_C",(Mat,PetscInt,PetscInt),(F,icntl,ival));
2053:   return(0);
2054: }

2056: /*@
2057:   MatMumpsGetIcntl - Get MUMPS parameter ICNTL()

2059:    Logically Collective on Mat

2061:    Input Parameters:
2062: +  F - the factored matrix obtained by calling MatGetFactor() from PETSc-MUMPS interface
2063: -  icntl - index of MUMPS parameter array ICNTL()

2065:   Output Parameter:
2066: .  ival - value of MUMPS ICNTL(icntl)

2068:    Level: beginner

2070:    References:
2071: .     MUMPS Users' Guide

2073: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2074: @*/
2075: PetscErrorCode MatMumpsGetIcntl(Mat F,PetscInt icntl,PetscInt *ival)
2076: {

2081:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2084:   PetscUseMethod(F,"MatMumpsGetIcntl_C",(Mat,PetscInt,PetscInt*),(F,icntl,ival));
2085:   return(0);
2086: }

2088: /* -------------------------------------------------------------------------------------------*/
2089: PetscErrorCode MatMumpsSetCntl_MUMPS(Mat F,PetscInt icntl,PetscReal val)
2090: {
2091:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2094:   mumps->id.CNTL(icntl) = val;
2095:   return(0);
2096: }

2098: PetscErrorCode MatMumpsGetCntl_MUMPS(Mat F,PetscInt icntl,PetscReal *val)
2099: {
2100:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2103:   *val = mumps->id.CNTL(icntl);
2104:   return(0);
2105: }

2107: /*@
2108:   MatMumpsSetCntl - Set MUMPS parameter CNTL()

2110:    Logically Collective on Mat

2112:    Input Parameters:
2113: +  F - the factored matrix obtained by calling MatGetFactor() from PETSc-MUMPS interface
2114: .  icntl - index of MUMPS parameter array CNTL()
2115: -  val - value of MUMPS CNTL(icntl)

2117:   Options Database:
2118: .   -mat_mumps_cntl_<icntl> <val>

2120:    Level: beginner

2122:    References:
2123: .     MUMPS Users' Guide

2125: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2126: @*/
2127: PetscErrorCode MatMumpsSetCntl(Mat F,PetscInt icntl,PetscReal val)
2128: {

2133:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2136:   PetscTryMethod(F,"MatMumpsSetCntl_C",(Mat,PetscInt,PetscReal),(F,icntl,val));
2137:   return(0);
2138: }

2140: /*@
2141:   MatMumpsGetCntl - Get MUMPS parameter CNTL()

2143:    Logically Collective on Mat

2145:    Input Parameters:
2146: +  F - the factored matrix obtained by calling MatGetFactor() from PETSc-MUMPS interface
2147: -  icntl - index of MUMPS parameter array CNTL()

2149:   Output Parameter:
2150: .  val - value of MUMPS CNTL(icntl)

2152:    Level: beginner

2154:    References:
2155: .      MUMPS Users' Guide

2157: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2158: @*/
2159: PetscErrorCode MatMumpsGetCntl(Mat F,PetscInt icntl,PetscReal *val)
2160: {

2165:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2168:   PetscUseMethod(F,"MatMumpsGetCntl_C",(Mat,PetscInt,PetscReal*),(F,icntl,val));
2169:   return(0);
2170: }

2172: PetscErrorCode MatMumpsGetInfo_MUMPS(Mat F,PetscInt icntl,PetscInt *info)
2173: {
2174:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2177:   *info = mumps->id.INFO(icntl);
2178:   return(0);
2179: }

2181: PetscErrorCode MatMumpsGetInfog_MUMPS(Mat F,PetscInt icntl,PetscInt *infog)
2182: {
2183:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2186:   *infog = mumps->id.INFOG(icntl);
2187:   return(0);
2188: }

2190: PetscErrorCode MatMumpsGetRinfo_MUMPS(Mat F,PetscInt icntl,PetscReal *rinfo)
2191: {
2192:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2195:   *rinfo = mumps->id.RINFO(icntl);
2196:   return(0);
2197: }

2199: PetscErrorCode MatMumpsGetRinfog_MUMPS(Mat F,PetscInt icntl,PetscReal *rinfog)
2200: {
2201:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2204:   *rinfog = mumps->id.RINFOG(icntl);
2205:   return(0);
2206: }

2208: /*@
2209:   MatMumpsGetInfo - Get MUMPS parameter INFO()

2211:    Logically Collective on Mat

2213:    Input Parameters:
2214: +  F - the factored matrix obtained by calling MatGetFactor() from PETSc-MUMPS interface
2215: -  icntl - index of MUMPS parameter array INFO()

2217:   Output Parameter:
2218: .  ival - value of MUMPS INFO(icntl)

2220:    Level: beginner

2222:    References:
2223: .      MUMPS Users' Guide

2225: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2226: @*/
2227: PetscErrorCode MatMumpsGetInfo(Mat F,PetscInt icntl,PetscInt *ival)
2228: {

2233:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2235:   PetscUseMethod(F,"MatMumpsGetInfo_C",(Mat,PetscInt,PetscInt*),(F,icntl,ival));
2236:   return(0);
2237: }

2239: /*@
2240:   MatMumpsGetInfog - Get MUMPS parameter INFOG()

2242:    Logically Collective on Mat

2244:    Input Parameters:
2245: +  F - the factored matrix obtained by calling MatGetFactor() from PETSc-MUMPS interface
2246: -  icntl - index of MUMPS parameter array INFOG()

2248:   Output Parameter:
2249: .  ival - value of MUMPS INFOG(icntl)

2251:    Level: beginner

2253:    References:
2254: .      MUMPS Users' Guide

2256: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2257: @*/
2258: PetscErrorCode MatMumpsGetInfog(Mat F,PetscInt icntl,PetscInt *ival)
2259: {

2264:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2266:   PetscUseMethod(F,"MatMumpsGetInfog_C",(Mat,PetscInt,PetscInt*),(F,icntl,ival));
2267:   return(0);
2268: }

2270: /*@
2271:   MatMumpsGetRinfo - Get MUMPS parameter RINFO()

2273:    Logically Collective on Mat

2275:    Input Parameters:
2276: +  F - the factored matrix obtained by calling MatGetFactor() from PETSc-MUMPS interface
2277: -  icntl - index of MUMPS parameter array RINFO()

2279:   Output Parameter:
2280: .  val - value of MUMPS RINFO(icntl)

2282:    Level: beginner

2284:    References:
2285: .       MUMPS Users' Guide

2287: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2288: @*/
2289: PetscErrorCode MatMumpsGetRinfo(Mat F,PetscInt icntl,PetscReal *val)
2290: {

2295:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2297:   PetscUseMethod(F,"MatMumpsGetRinfo_C",(Mat,PetscInt,PetscReal*),(F,icntl,val));
2298:   return(0);
2299: }

2301: /*@
2302:   MatMumpsGetRinfog - Get MUMPS parameter RINFOG()

2304:    Logically Collective on Mat

2306:    Input Parameters:
2307: +  F - the factored matrix obtained by calling MatGetFactor() from PETSc-MUMPS interface
2308: -  icntl - index of MUMPS parameter array RINFOG()

2310:   Output Parameter:
2311: .  val - value of MUMPS RINFOG(icntl)

2313:    Level: beginner

2315:    References:
2316: .      MUMPS Users' Guide

2318: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2319: @*/
2320: PetscErrorCode MatMumpsGetRinfog(Mat F,PetscInt icntl,PetscReal *val)
2321: {

2326:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2328:   PetscUseMethod(F,"MatMumpsGetRinfog_C",(Mat,PetscInt,PetscReal*),(F,icntl,val));
2329:   return(0);
2330: }

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

2336:   Works with MATAIJ and MATSBAIJ matrices

2338:   Use ./configure --download-mumps --download-scalapack --download-parmetis --download-metis --download-ptscotch  to have PETSc installed with MUMPS

2340:   Use -pc_type cholesky or lu -pc_factor_mat_solver_package mumps to us this direct solver

2342:   Options Database Keys:
2343: +  -mat_mumps_icntl_1 - ICNTL(1): output stream for error messages 
2344: .  -mat_mumps_icntl_2 - ICNTL(2): output stream for diagnostic printing, statistics, and warning 
2345: .  -mat_mumps_icntl_3 -  ICNTL(3): output stream for global information, collected on the host 
2346: .  -mat_mumps_icntl_4 -  ICNTL(4): level of printing (0 to 4) 
2347: .  -mat_mumps_icntl_6 - ICNTL(6): permutes to a zero-free diagonal and/or scale the matrix (0 to 7) 
2348: .  -mat_mumps_icntl_7 - ICNTL(7): computes a symmetric permutation in sequential analysis (0 to 7). 3=Scotch, 4=PORD, 5=Metis 
2349: .  -mat_mumps_icntl_8  - ICNTL(8): scaling strategy (-2 to 8 or 77) 
2350: .  -mat_mumps_icntl_10  - ICNTL(10): max num of refinements 
2351: .  -mat_mumps_icntl_11  - ICNTL(11): statistics related to an error analysis (via -ksp_view) 
2352: .  -mat_mumps_icntl_12  - ICNTL(12): an ordering strategy for symmetric matrices (0 to 3) 
2353: .  -mat_mumps_icntl_13  - ICNTL(13): parallelism of the root node (enable ScaLAPACK) and its splitting 
2354: .  -mat_mumps_icntl_14  - ICNTL(14): percentage increase in the estimated working space 
2355: .  -mat_mumps_icntl_19  - ICNTL(19): computes the Schur complement 
2356: .  -mat_mumps_icntl_22  - ICNTL(22): in-core/out-of-core factorization and solve (0 or 1) 
2357: .  -mat_mumps_icntl_23  - ICNTL(23): max size of the working memory (MB) that can allocate per processor 
2358: .  -mat_mumps_icntl_24  - ICNTL(24): detection of null pivot rows (0 or 1) 
2359: .  -mat_mumps_icntl_25  - ICNTL(25): compute a solution of a deficient matrix and a null space basis 
2360: .  -mat_mumps_icntl_26  - ICNTL(26): drives the solution phase if a Schur complement matrix 
2361: .  -mat_mumps_icntl_28  - ICNTL(28): use 1 for sequential analysis and ictnl(7) ordering, or 2 for parallel analysis and ictnl(29) ordering 
2362: .  -mat_mumps_icntl_29 - ICNTL(29): parallel ordering 1 = ptscotch, 2 = parmetis 
2363: .  -mat_mumps_icntl_30 - ICNTL(30): compute user-specified set of entries in inv(A) 
2364: .  -mat_mumps_icntl_31 - ICNTL(31): indicates which factors may be discarded during factorization 
2365: .  -mat_mumps_icntl_33 - ICNTL(33): compute determinant 
2366: .  -mat_mumps_cntl_1  - CNTL(1): relative pivoting threshold 
2367: .  -mat_mumps_cntl_2  -  CNTL(2): stopping criterion of refinement 
2368: .  -mat_mumps_cntl_3 - CNTL(3): absolute pivoting threshold 
2369: .  -mat_mumps_cntl_4 - CNTL(4): value for static pivoting 
2370: -  -mat_mumps_cntl_5 - CNTL(5): fixation for null pivots 

2372:   Level: beginner

2374:     Notes: When a MUMPS factorization fails inside a KSP solve, for example with a KSP_DIVERGED_PCSETUP_FAILED, one can find the MUMPS information about the failure by calling 
2375: $          KSPGetPC(ksp,&pc);
2376: $          PCFactorGetMatrix(pc,&mat);
2377: $          MatMumpsGetInfo(mat,....);
2378: $          MatMumpsGetInfog(mat,....); etc.
2379:            Or you can run with -ksp_error_if_not_converged and the program will be stopped and the information printed in the error message.

2381: .seealso: PCFactorSetMatSolverPackage(), MatSolverPackage, MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog(), KSPGetPC(), PCGetFactor(), PCFactorGetMatrix()

2383: M*/

2385: static PetscErrorCode MatFactorGetSolverPackage_mumps(Mat A,const MatSolverPackage *type)
2386: {
2388:   *type = MATSOLVERMUMPS;
2389:   return(0);
2390: }

2392: /* MatGetFactor for Seq and MPI AIJ matrices */
2393: static PetscErrorCode MatGetFactor_aij_mumps(Mat A,MatFactorType ftype,Mat *F)
2394: {
2395:   Mat            B;
2397:   Mat_MUMPS      *mumps;
2398:   PetscBool      isSeqAIJ;

2401:   /* Create the factorization matrix */
2402:   PetscObjectTypeCompare((PetscObject)A,MATSEQAIJ,&isSeqAIJ);
2403:   MatCreate(PetscObjectComm((PetscObject)A),&B);
2404:   MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);
2405:   PetscStrallocpy("mumps",&((PetscObject)B)->type_name);
2406:   MatSetUp(B);

2408:   PetscNewLog(B,&mumps);

2410:   B->ops->view        = MatView_MUMPS;
2411:   B->ops->getinfo     = MatGetInfo_MUMPS;

2413:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_mumps);
2414:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurIS_C",MatFactorSetSchurIS_MUMPS);
2415:   PetscObjectComposeFunction((PetscObject)B,"MatFactorInvertSchurComplement_C",MatFactorInvertSchurComplement_MUMPS);
2416:   PetscObjectComposeFunction((PetscObject)B,"MatFactorCreateSchurComplement_C",MatFactorCreateSchurComplement_MUMPS);
2417:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSchurComplement_C",MatFactorGetSchurComplement_MUMPS);
2418:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplement_C",MatFactorSolveSchurComplement_MUMPS);
2419:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplementTranspose_C",MatFactorSolveSchurComplementTranspose_MUMPS);
2420:   PetscObjectComposeFunction((PetscObject)B,"MatFactorFactorizeSchurComplement_C",MatFactorFactorizeSchurComplement_MUMPS);
2421:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurComplementSolverType_C",MatFactorSetSchurComplementSolverType_MUMPS);
2422:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetIcntl_C",MatMumpsSetIcntl_MUMPS);
2423:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetIcntl_C",MatMumpsGetIcntl_MUMPS);
2424:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetCntl_C",MatMumpsSetCntl_MUMPS);
2425:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetCntl_C",MatMumpsGetCntl_MUMPS);
2426:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfo_C",MatMumpsGetInfo_MUMPS);
2427:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfog_C",MatMumpsGetInfog_MUMPS);
2428:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfo_C",MatMumpsGetRinfo_MUMPS);
2429:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfog_C",MatMumpsGetRinfog_MUMPS);

2431:   if (ftype == MAT_FACTOR_LU) {
2432:     B->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJMUMPS;
2433:     B->factortype            = MAT_FACTOR_LU;
2434:     if (isSeqAIJ) mumps->ConvertToTriples = MatConvertToTriples_seqaij_seqaij;
2435:     else mumps->ConvertToTriples = MatConvertToTriples_mpiaij_mpiaij;
2436:     mumps->sym = 0;
2437:   } else {
2438:     B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_MUMPS;
2439:     B->factortype                  = MAT_FACTOR_CHOLESKY;
2440:     if (isSeqAIJ) mumps->ConvertToTriples = MatConvertToTriples_seqaij_seqsbaij;
2441:     else mumps->ConvertToTriples = MatConvertToTriples_mpiaij_mpisbaij;
2442: #if defined(PETSC_USE_COMPLEX)
2443:     mumps->sym = 2;
2444: #else
2445:     if (A->spd_set && A->spd) mumps->sym = 1;
2446:     else                      mumps->sym = 2;
2447: #endif
2448:   }

2450:   /* set solvertype */
2451:   PetscFree(B->solvertype);
2452:   PetscStrallocpy(MATSOLVERMUMPS,&B->solvertype);

2454:   mumps->isAIJ    = PETSC_TRUE;
2455:   B->ops->destroy = MatDestroy_MUMPS;
2456:   B->data        = (void*)mumps;

2458:   PetscInitializeMUMPS(A,mumps);

2460:   *F = B;
2461:   return(0);
2462: }

2464: /* MatGetFactor for Seq and MPI SBAIJ matrices */
2465: static PetscErrorCode MatGetFactor_sbaij_mumps(Mat A,MatFactorType ftype,Mat *F)
2466: {
2467:   Mat            B;
2469:   Mat_MUMPS      *mumps;
2470:   PetscBool      isSeqSBAIJ;

2473:   if (ftype != MAT_FACTOR_CHOLESKY) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_SUP,"Cannot use PETSc SBAIJ matrices with MUMPS LU, use AIJ matrix");
2474:   if (A->rmap->bs > 1) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_SUP,"Cannot use PETSc SBAIJ matrices with block size > 1 with MUMPS Cholesky, use AIJ matrix instead");
2475:   PetscObjectTypeCompare((PetscObject)A,MATSEQSBAIJ,&isSeqSBAIJ);
2476:   /* Create the factorization matrix */
2477:   MatCreate(PetscObjectComm((PetscObject)A),&B);
2478:   MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);
2479:   PetscStrallocpy("mumps",&((PetscObject)B)->type_name);
2480:   MatSetUp(B);

2482:   PetscNewLog(B,&mumps);
2483:   if (isSeqSBAIJ) {
2484:     mumps->ConvertToTriples = MatConvertToTriples_seqsbaij_seqsbaij;
2485:   } else {
2486:     mumps->ConvertToTriples = MatConvertToTriples_mpisbaij_mpisbaij;
2487:   }

2489:   B->ops->getinfo                = MatGetInfo_External;
2490:   B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_MUMPS;
2491:   B->ops->view                   = MatView_MUMPS;

2493:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_mumps);
2494:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurIS_C",MatFactorSetSchurIS_MUMPS);
2495:   PetscObjectComposeFunction((PetscObject)B,"MatFactorInvertSchurComplement_C",MatFactorInvertSchurComplement_MUMPS);
2496:   PetscObjectComposeFunction((PetscObject)B,"MatFactorCreateSchurComplement_C",MatFactorCreateSchurComplement_MUMPS);
2497:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSchurComplement_C",MatFactorGetSchurComplement_MUMPS);
2498:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplement_C",MatFactorSolveSchurComplement_MUMPS);
2499:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplementTranspose_C",MatFactorSolveSchurComplementTranspose_MUMPS);
2500:   PetscObjectComposeFunction((PetscObject)B,"MatFactorFactorizeSchurComplement_C",MatFactorFactorizeSchurComplement_MUMPS);
2501:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurComplementSolverType_C",MatFactorSetSchurComplementSolverType_MUMPS);
2502:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetIcntl_C",MatMumpsSetIcntl_MUMPS);
2503:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetIcntl_C",MatMumpsGetIcntl_MUMPS);
2504:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetCntl_C",MatMumpsSetCntl_MUMPS);
2505:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetCntl_C",MatMumpsGetCntl_MUMPS);
2506:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfo_C",MatMumpsGetInfo_MUMPS);
2507:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfog_C",MatMumpsGetInfog_MUMPS);
2508:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfo_C",MatMumpsGetRinfo_MUMPS);
2509:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfog_C",MatMumpsGetRinfog_MUMPS);

2511:   B->factortype = MAT_FACTOR_CHOLESKY;
2512: #if defined(PETSC_USE_COMPLEX)
2513:   mumps->sym = 2;
2514: #else
2515:   if (A->spd_set && A->spd) mumps->sym = 1;
2516:   else                      mumps->sym = 2;
2517: #endif

2519:   /* set solvertype */
2520:   PetscFree(B->solvertype);
2521:   PetscStrallocpy(MATSOLVERMUMPS,&B->solvertype);

2523:   mumps->isAIJ    = PETSC_FALSE;
2524:   B->ops->destroy = MatDestroy_MUMPS;
2525:   B->data        = (void*)mumps;

2527:   PetscInitializeMUMPS(A,mumps);

2529:   *F = B;
2530:   return(0);
2531: }

2533: static PetscErrorCode MatGetFactor_baij_mumps(Mat A,MatFactorType ftype,Mat *F)
2534: {
2535:   Mat            B;
2537:   Mat_MUMPS      *mumps;
2538:   PetscBool      isSeqBAIJ;

2541:   /* Create the factorization matrix */
2542:   PetscObjectTypeCompare((PetscObject)A,MATSEQBAIJ,&isSeqBAIJ);
2543:   MatCreate(PetscObjectComm((PetscObject)A),&B);
2544:   MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);
2545:   PetscStrallocpy("mumps",&((PetscObject)B)->type_name);
2546:   MatSetUp(B);

2548:   PetscNewLog(B,&mumps);
2549:   if (ftype == MAT_FACTOR_LU) {
2550:     B->ops->lufactorsymbolic = MatLUFactorSymbolic_BAIJMUMPS;
2551:     B->factortype            = MAT_FACTOR_LU;
2552:     if (isSeqBAIJ) mumps->ConvertToTriples = MatConvertToTriples_seqbaij_seqaij;
2553:     else mumps->ConvertToTriples = MatConvertToTriples_mpibaij_mpiaij;
2554:     mumps->sym = 0;
2555:   } else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc BAIJ matrices with MUMPS Cholesky, use SBAIJ or AIJ matrix instead\n");

2557:   B->ops->getinfo     = MatGetInfo_External;
2558:   B->ops->view        = MatView_MUMPS;

2560:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_mumps);
2561:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurIS_C",MatFactorSetSchurIS_MUMPS);
2562:   PetscObjectComposeFunction((PetscObject)B,"MatFactorInvertSchurComplement_C",MatFactorInvertSchurComplement_MUMPS);
2563:   PetscObjectComposeFunction((PetscObject)B,"MatFactorCreateSchurComplement_C",MatFactorCreateSchurComplement_MUMPS);
2564:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSchurComplement_C",MatFactorGetSchurComplement_MUMPS);
2565:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplement_C",MatFactorSolveSchurComplement_MUMPS);
2566:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplementTranspose_C",MatFactorSolveSchurComplementTranspose_MUMPS);
2567:   PetscObjectComposeFunction((PetscObject)B,"MatFactorFactorizeSchurComplement_C",MatFactorFactorizeSchurComplement_MUMPS);
2568:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurComplementSolverType_C",MatFactorSetSchurComplementSolverType_MUMPS);
2569:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetIcntl_C",MatMumpsSetIcntl_MUMPS);
2570:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetIcntl_C",MatMumpsGetIcntl_MUMPS);
2571:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetCntl_C",MatMumpsSetCntl_MUMPS);
2572:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetCntl_C",MatMumpsGetCntl_MUMPS);
2573:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfo_C",MatMumpsGetInfo_MUMPS);
2574:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfog_C",MatMumpsGetInfog_MUMPS);
2575:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfo_C",MatMumpsGetRinfo_MUMPS);
2576:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfog_C",MatMumpsGetRinfog_MUMPS);

2578:   /* set solvertype */
2579:   PetscFree(B->solvertype);
2580:   PetscStrallocpy(MATSOLVERMUMPS,&B->solvertype);

2582:   mumps->isAIJ    = PETSC_TRUE;
2583:   B->ops->destroy = MatDestroy_MUMPS;
2584:   B->data        = (void*)mumps;

2586:   PetscInitializeMUMPS(A,mumps);

2588:   *F = B;
2589:   return(0);
2590: }

2592: PETSC_EXTERN PetscErrorCode MatSolverPackageRegister_MUMPS(void)
2593: {

2597:   MatSolverPackageRegister(MATSOLVERMUMPS,MATMPIAIJ,MAT_FACTOR_LU,MatGetFactor_aij_mumps);
2598:   MatSolverPackageRegister(MATSOLVERMUMPS,MATMPIAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_aij_mumps);
2599:   MatSolverPackageRegister(MATSOLVERMUMPS,MATMPIBAIJ,MAT_FACTOR_LU,MatGetFactor_baij_mumps);
2600:   MatSolverPackageRegister(MATSOLVERMUMPS,MATMPIBAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_baij_mumps);
2601:   MatSolverPackageRegister(MATSOLVERMUMPS,MATMPISBAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_sbaij_mumps);
2602:   MatSolverPackageRegister(MATSOLVERMUMPS,MATSEQAIJ,MAT_FACTOR_LU,MatGetFactor_aij_mumps);
2603:   MatSolverPackageRegister(MATSOLVERMUMPS,MATSEQAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_aij_mumps);
2604:   MatSolverPackageRegister(MATSOLVERMUMPS,MATSEQBAIJ,MAT_FACTOR_LU,MatGetFactor_baij_mumps);
2605:   MatSolverPackageRegister(MATSOLVERMUMPS,MATSEQBAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_baij_mumps);
2606:   MatSolverPackageRegister(MATSOLVERMUMPS,MATSEQSBAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_sbaij_mumps);
2607:   return(0);
2608: }