Actual source code: mumps.c

petsc-master 2017-02-19
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:     second_solve = PETSC_TRUE;
927:     MatMumpsHandleSchur_Private(mumps,PETSC_FALSE);
928:   }
929:   /* solve phase */
930:   /*-------------*/
931:   mumps->id.job = JOB_SOLVE;
932:   PetscMUMPS_c(&mumps->id);
933:   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));

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

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

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

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

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

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

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

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

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

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

1004:     /* handle condensation step of Schur complement (if any) */
1005:     if (mumps->id.ICNTL(26) < 0 || mumps->id.ICNTL(26) > 2) {
1006:       second_solve = PETSC_TRUE;
1007:       MatMumpsHandleSchur_Private(mumps,PETSC_FALSE);
1008:     }
1009:     /* solve phase */
1010:     /*-------------*/
1011:     mumps->id.job = JOB_SOLVE;
1012:     PetscMUMPS_c(&mumps->id);
1013:     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));

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

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

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

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

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

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

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

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

1083:     /* solve phase */
1084:     /*-------------*/
1085:     mumps->id.job = JOB_SOLVE;
1086:     PetscMUMPS_c(&mumps->id);
1087:     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));

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

1111:     /* free spaces */
1112:     mumps->id.sol_loc = sol_loc_save;
1113:     mumps->id.isol_loc = isol_loc_save;

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

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

1143:   MPI_Comm_size(PetscObjectComm((PetscObject)F),&size);
1144:   /* 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 */
1145:   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));

1147:   if (nneg) *nneg = mumps->id.INFOG(12);
1148:   if (nzero || npos) {
1149:     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");
1150:     if (nzero) *nzero = mumps->id.INFOG(28);
1151:     if (npos) *npos   = F->rmap->N - (mumps->id.INFOG(12) + mumps->id.INFOG(28));
1152:   }
1153:   return(0);
1154: }
1155: #endif

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

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

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

1174:   /* numerical factorization phase */
1175:   /*-------------------------------*/
1176:   mumps->id.job = JOB_FACTNUMERIC;
1177:   if (!mumps->id.ICNTL(18)) { /* A is centralized */
1178:     if (!mumps->myid) {
1179:       mumps->id.a = (MumpsScalar*)mumps->val;
1180:     }
1181:   } else {
1182:     mumps->id.a_loc = (MumpsScalar*)mumps->val;
1183:   }
1184:   PetscMUMPS_c(&mumps->id);
1185:   if (mumps->id.INFOG(1) < 0) {
1186:     if (A->erroriffailure) {
1187:       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));
1188:     } else {
1189:       if (mumps->id.INFOG(1) == -10) { /* numerically singular matrix */
1190:         PetscInfo2(F,"matrix is numerically singular, INFOG(1)=%d, INFO(2)=%d\n",mumps->id.INFOG(1),mumps->id.INFO(2));
1191:         F->factorerrortype = MAT_FACTOR_NUMERIC_ZEROPIVOT;
1192:       } else if (mumps->id.INFOG(1) == -13) {
1193:         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));
1194:         F->factorerrortype = MAT_FACTOR_OUTMEMORY;
1195:       } else if (mumps->id.INFOG(1) == -8 || mumps->id.INFOG(1) == -9 || (-16 < mumps->id.INFOG(1) && mumps->id.INFOG(1) < -10) ) {
1196:         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));
1197:         F->factorerrortype = MAT_FACTOR_OUTMEMORY;
1198:       } else {
1199:         PetscInfo2(F,"MUMPS in numerical factorization phase: INFOG(1)=%d, INFO(2)=%d\n",mumps->id.INFOG(1),mumps->id.INFO(2));
1200:         F->factorerrortype = MAT_FACTOR_OTHER;
1201:       }
1202:     }
1203:   }
1204:   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));

1206:   (F)->assembled        = PETSC_TRUE;
1207:   mumps->matstruc       = SAME_NONZERO_PATTERN;
1208:   mumps->schur_factored = PETSC_FALSE;
1209:   mumps->schur_inverted = PETSC_FALSE;

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

1214:   if (mumps->size > 1) {
1215:     PetscInt    lsol_loc;
1216:     PetscScalar *sol_loc;

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

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

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

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

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

1256:   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);
1257:   if (flg) mumps->id.ICNTL(6) = icntl;

1259:   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);
1260:   if (flg) {
1261:     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");
1262:     else mumps->id.ICNTL(7) = icntl;
1263:   }

1265:   PetscOptionsInt("-mat_mumps_icntl_8","ICNTL(8): scaling strategy (-2 to 8 or 77)","None",mumps->id.ICNTL(8),&mumps->id.ICNTL(8),NULL);
1266:   /* 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() */
1267:   PetscOptionsInt("-mat_mumps_icntl_10","ICNTL(10): max num of refinements","None",mumps->id.ICNTL(10),&mumps->id.ICNTL(10),NULL);
1268:   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);
1269:   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);
1270:   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);
1271:   PetscOptionsInt("-mat_mumps_icntl_14","ICNTL(14): percentage increase in the estimated working space","None",mumps->id.ICNTL(14),&mumps->id.ICNTL(14),NULL);
1272:   PetscOptionsInt("-mat_mumps_icntl_19","ICNTL(19): computes the Schur complement","None",mumps->id.ICNTL(19),&mumps->id.ICNTL(19),NULL);
1273:   if (mumps->id.ICNTL(19) <= 0 || mumps->id.ICNTL(19) > 3) { /* reset any schur data (if any) */
1274:     MatMumpsResetSchur_Private(mumps);
1275:   }
1276:   /* 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 */
1277:   /* 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 */

1279:   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);
1280:   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);
1281:   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);
1282:   if (mumps->id.ICNTL(24)) {
1283:     mumps->id.ICNTL(13) = 1; /* turn-off ScaLAPACK to help with the correct detection of null pivots */
1284:   }

1286:   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);
1287:   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);
1288:   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);
1289:   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);
1290:   PetscOptionsInt("-mat_mumps_icntl_29","ICNTL(29): parallel ordering 1 = ptscotch, 2 = parmetis","None",mumps->id.ICNTL(29),&mumps->id.ICNTL(29),NULL);
1291:   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);
1292:   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);
1293:   /* 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 */
1294:   PetscOptionsInt("-mat_mumps_icntl_33","ICNTL(33): compute determinant","None",mumps->id.ICNTL(33),&mumps->id.ICNTL(33),NULL);

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

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

1304:   PetscOptionsIntArray("-mat_mumps_view_info","request INFO local to each processor","",info,&ninfo,NULL);
1305:   if (ninfo) {
1306:     if (ninfo > 40) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_USER,"number of INFO %d must <= 40\n",ninfo);
1307:     PetscMalloc1(ninfo,&mumps->info);
1308:     mumps->ninfo = ninfo;
1309:     for (i=0; i<ninfo; i++) {
1310:       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);
1311:       else  mumps->info[i] = info[i];
1312:     }
1313:   }

1315:   PetscOptionsEnd();
1316:   return(0);
1317: }

1319: PetscErrorCode PetscInitializeMUMPS(Mat A,Mat_MUMPS *mumps)
1320: {

1324:   MPI_Comm_rank(PetscObjectComm((PetscObject)A), &mumps->myid);
1325:   MPI_Comm_size(PetscObjectComm((PetscObject)A),&mumps->size);
1326:   MPI_Comm_dup(PetscObjectComm((PetscObject)A),&(mumps->comm_mumps));

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

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

1335:   mumps->scat_rhs     = NULL;
1336:   mumps->scat_sol     = NULL;

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

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

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

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

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

1398:   mumps->matstruc = DIFFERENT_NONZERO_PATTERN;

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

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

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

1427:           PetscMalloc1(M,&perm_in);
1428:           ISGetIndices(r,&idx);

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

1460:   F->ops->lufactornumeric = MatFactorNumeric_MUMPS;
1461:   F->ops->solve           = MatSolve_MUMPS;
1462:   F->ops->solvetranspose  = MatSolveTranspose_MUMPS;
1463:   F->ops->matsolve        = MatMatSolve_MUMPS;
1464:   return(0);
1465: }

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

1477:   mumps->matstruc = DIFFERENT_NONZERO_PATTERN;

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

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

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

1520:   F->ops->lufactornumeric = MatFactorNumeric_MUMPS;
1521:   F->ops->solve           = MatSolve_MUMPS;
1522:   F->ops->solvetranspose  = MatSolveTranspose_MUMPS;
1523:   return(0);
1524: }

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

1536:   mumps->matstruc = DIFFERENT_NONZERO_PATTERN;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


1689:       PetscViewerASCIIPopSynchronized(viewer);

1691:       if (!mumps->myid) { /* information from the host */
1692:         PetscViewerASCIIPrintf(viewer,"  RINFOG(1) (global estimated flops for the elimination after analysis): %g \n",mumps->id.RINFOG(1));
1693:         PetscViewerASCIIPrintf(viewer,"  RINFOG(2) (global estimated flops for the assembly after factorization): %g \n",mumps->id.RINFOG(2));
1694:         PetscViewerASCIIPrintf(viewer,"  RINFOG(3) (global estimated flops for the elimination after factorization): %g \n",mumps->id.RINFOG(3));
1695:         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));

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

1732: PetscErrorCode MatGetInfo_MUMPS(Mat A,MatInfoType flag,MatInfo *info)
1733: {
1734:   Mat_MUMPS *mumps =(Mat_MUMPS*)A->data;

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

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

1759:   if (mumps->size > 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"MUMPS parallel Schur complements not yet supported from PETSc\n");
1760:   ISGetLocalSize(is,&size);
1761:   if (mumps->id.size_schur != size) {
1762:     PetscFree2(mumps->id.listvar_schur,mumps->id.schur);
1763:     mumps->id.size_schur = size;
1764:     mumps->id.schur_lld = size;
1765:     PetscMalloc2(size,&mumps->id.listvar_schur,size*size,&mumps->id.schur);
1766:   }
1767:   ISGetIndices(is,&idxs);
1768:   PetscMemcpy(mumps->id.listvar_schur,idxs,size*sizeof(PetscInt));
1769:   /* MUMPS expects Fortran style indices */
1770:   for (i=0;i<size;i++) mumps->id.listvar_schur[i]++;
1771:   ISRestoreIndices(is,&idxs);
1772:   if (size) { /* turn on Schur switch if we the set of indices is not empty */
1773:     if (F->factortype == MAT_FACTOR_LU) {
1774:       mumps->id.ICNTL(19) = 3; /* MUMPS returns full matrix */
1775:     } else {
1776:       mumps->id.ICNTL(19) = 2; /* MUMPS returns lower triangular part */
1777:     }
1778:     /* set a special value of ICNTL (not handled my MUMPS) to be used in the solve phase by PETSc */
1779:     mumps->id.ICNTL(26) = -1;
1780:   }
1781:   return(0);
1782: }

1784: /* -------------------------------------------------------------------------------------------*/
1785: PetscErrorCode MatFactorCreateSchurComplement_MUMPS(Mat F,Mat* S)
1786: {
1787:   Mat            St;
1788:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;
1789:   PetscScalar    *array;
1790: #if defined(PETSC_USE_COMPLEX)
1791:   PetscScalar    im = PetscSqrtScalar((PetscScalar)-1.0);
1792: #endif

1796:   if (!mumps->id.ICNTL(19)) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur complement mode not selected! You should call MatFactorSetSchurIS to enable it");
1797:   else if (!mumps->id.size_schur) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur indices not set! You should call MatFactorSetSchurIS before");

1799:   MatCreate(PetscObjectComm((PetscObject)F),&St);
1800:   MatSetSizes(St,PETSC_DECIDE,PETSC_DECIDE,mumps->id.size_schur,mumps->id.size_schur);
1801:   MatSetType(St,MATDENSE);
1802:   MatSetUp(St);
1803:   MatDenseGetArray(St,&array);
1804:   if (!mumps->sym) { /* MUMPS always return a full matrix */
1805:     if (mumps->id.ICNTL(19) == 1) { /* stored by rows */
1806:       PetscInt i,j,N=mumps->id.size_schur;
1807:       for (i=0;i<N;i++) {
1808:         for (j=0;j<N;j++) {
1809: #if !defined(PETSC_USE_COMPLEX)
1810:           PetscScalar val = mumps->id.schur[i*N+j];
1811: #else
1812:           PetscScalar val = mumps->id.schur[i*N+j].r + im*mumps->id.schur[i*N+j].i;
1813: #endif
1814:           array[j*N+i] = val;
1815:         }
1816:       }
1817:     } else { /* stored by columns */
1818:       PetscMemcpy(array,mumps->id.schur,mumps->id.size_schur*mumps->id.size_schur*sizeof(PetscScalar));
1819:     }
1820:   } else { /* either full or lower-triangular (not packed) */
1821:     if (mumps->id.ICNTL(19) == 2) { /* lower triangular stored by columns */
1822:       PetscInt i,j,N=mumps->id.size_schur;
1823:       for (i=0;i<N;i++) {
1824:         for (j=i;j<N;j++) {
1825: #if !defined(PETSC_USE_COMPLEX)
1826:           PetscScalar val = mumps->id.schur[i*N+j];
1827: #else
1828:           PetscScalar val = mumps->id.schur[i*N+j].r + im*mumps->id.schur[i*N+j].i;
1829: #endif
1830:           array[i*N+j] = val;
1831:           array[j*N+i] = val;
1832:         }
1833:       }
1834:     } else if (mumps->id.ICNTL(19) == 3) { /* full matrix */
1835:       PetscMemcpy(array,mumps->id.schur,mumps->id.size_schur*mumps->id.size_schur*sizeof(PetscScalar));
1836:     } else { /* ICNTL(19) == 1 lower triangular stored by rows */
1837:       PetscInt i,j,N=mumps->id.size_schur;
1838:       for (i=0;i<N;i++) {
1839:         for (j=0;j<i+1;j++) {
1840: #if !defined(PETSC_USE_COMPLEX)
1841:           PetscScalar val = mumps->id.schur[i*N+j];
1842: #else
1843:           PetscScalar val = mumps->id.schur[i*N+j].r + im*mumps->id.schur[i*N+j].i;
1844: #endif
1845:           array[i*N+j] = val;
1846:           array[j*N+i] = val;
1847:         }
1848:       }
1849:     }
1850:   }
1851:   MatDenseRestoreArray(St,&array);
1852:   *S = St;
1853:   return(0);
1854: }

1856: /* -------------------------------------------------------------------------------------------*/
1857: PetscErrorCode MatFactorGetSchurComplement_MUMPS(Mat F,Mat* S)
1858: {
1859:   Mat            St;
1860:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;

1864:   if (!mumps->id.ICNTL(19)) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur complement mode not selected! You should call MatFactorSetSchurIS to enable it");
1865:   else if (!mumps->id.size_schur) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur indices not set! You should call MatFactorSetSchurIS before");

1867:   /* 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 */
1868:   MatCreateSeqDense(PetscObjectComm((PetscObject)F),mumps->id.size_schur,mumps->id.size_schur,(PetscScalar*)mumps->id.schur,&St);
1869:   *S = St;
1870:   return(0);
1871: }

1873: /* -------------------------------------------------------------------------------------------*/
1874: PetscErrorCode MatFactorFactorizeSchurComplement_MUMPS(Mat F)
1875: {
1876:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;

1880:   if (!mumps->id.ICNTL(19)) { /* do nothing */
1881:     return(0);
1882:   }
1883:   if (!mumps->id.size_schur) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur indices not set! You should call MatMumpsSetSchurIndices before");
1884:   MatMumpsFactorSchur_Private(mumps);
1885:   return(0);
1886: }

1888: PetscErrorCode MatFactorInvertSchurComplement_MUMPS(Mat F)
1889: {
1890:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;

1894:   if (!mumps->id.ICNTL(19)) { /* do nothing */
1895:     return(0);
1896:   }
1897:   if (!mumps->id.size_schur) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur indices not set! You should call MatFactorSetSchurIS before");
1898:   MatMumpsInvertSchur_Private(mumps);
1899:   return(0);
1900: }

1902: /* -------------------------------------------------------------------------------------------*/
1903: PetscErrorCode MatFactorSolveSchurComplement_MUMPS(Mat F, Vec rhs, Vec sol)
1904: {
1905:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;
1906:   MumpsScalar    *orhs;
1907:   PetscScalar    *osol,*nrhs,*nsol;
1908:   PetscInt       orhs_size,osol_size,olrhs_size;

1912:   if (!mumps->id.ICNTL(19)) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur complement mode not selected! You should call MatFactorSetSchurIS to enable it");
1913:   if (!mumps->id.size_schur) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur indices not set! You should call MatFactorSetSchurIS before");

1915:   /* swap pointers */
1916:   orhs = mumps->id.redrhs;
1917:   olrhs_size = mumps->id.lredrhs;
1918:   orhs_size = mumps->sizeredrhs;
1919:   osol = mumps->schur_sol;
1920:   osol_size = mumps->schur_sizesol;
1921:   VecGetArray(rhs,&nrhs);
1922:   VecGetArray(sol,&nsol);
1923:   mumps->id.redrhs = (MumpsScalar*)nrhs;
1924:   VecGetLocalSize(rhs,&mumps->sizeredrhs);
1925:   mumps->id.lredrhs = mumps->sizeredrhs;
1926:   mumps->schur_sol = nsol;
1927:   VecGetLocalSize(sol,&mumps->schur_sizesol);

1929:   /* solve Schur complement */
1930:   mumps->id.nrhs = 1;
1931:   MatMumpsSolveSchur_Private(mumps,PETSC_FALSE);
1932:   /* restore pointers */
1933:   VecRestoreArray(rhs,&nrhs);
1934:   VecRestoreArray(sol,&nsol);
1935:   mumps->id.redrhs = orhs;
1936:   mumps->id.lredrhs = olrhs_size;
1937:   mumps->sizeredrhs = orhs_size;
1938:   mumps->schur_sol = osol;
1939:   mumps->schur_sizesol = osol_size;
1940:   return(0);
1941: }

1943: /* -------------------------------------------------------------------------------------------*/
1944: PetscErrorCode MatFactorSolveSchurComplementTranspose_MUMPS(Mat F, Vec rhs, Vec sol)
1945: {
1946:   Mat_MUMPS      *mumps =(Mat_MUMPS*)F->data;
1947:   MumpsScalar    *orhs;
1948:   PetscScalar    *osol,*nrhs,*nsol;
1949:   PetscInt       orhs_size,osol_size;

1953:   if (!mumps->id.ICNTL(19)) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur complement mode not selected! You should call MatFactorSetSchurIS to enable it");
1954:   else if (!mumps->id.size_schur) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ORDER,"Schur indices not set! You should call MatFactorSetSchurIS before");

1956:   /* swap pointers */
1957:   orhs = mumps->id.redrhs;
1958:   orhs_size = mumps->sizeredrhs;
1959:   osol = mumps->schur_sol;
1960:   osol_size = mumps->schur_sizesol;
1961:   VecGetArray(rhs,&nrhs);
1962:   VecGetArray(sol,&nsol);
1963:   mumps->id.redrhs = (MumpsScalar*)nrhs;
1964:   VecGetLocalSize(rhs,&mumps->sizeredrhs);
1965:   mumps->schur_sol = nsol;
1966:   VecGetLocalSize(sol,&mumps->schur_sizesol);

1968:   /* solve Schur complement */
1969:   mumps->id.nrhs = 1;
1970:   mumps->id.ICNTL(9) = 0;
1971:   MatMumpsSolveSchur_Private(mumps,PETSC_FALSE);
1972:   mumps->id.ICNTL(9) = 1;
1973:   /* restore pointers */
1974:   VecRestoreArray(rhs,&nrhs);
1975:   VecRestoreArray(sol,&nsol);
1976:   mumps->id.redrhs = orhs;
1977:   mumps->sizeredrhs = orhs_size;
1978:   mumps->schur_sol = osol;
1979:   mumps->schur_sizesol = osol_size;
1980:   return(0);
1981: }

1983: /* -------------------------------------------------------------------------------------------*/
1984: PetscErrorCode MatFactorSetSchurComplementSolverType_MUMPS(Mat F, PetscInt sym)
1985: {
1986:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

1989:   if (mumps->schur_factored && mumps->sym != mumps->schur_sym) {
1990:     SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONG,"Cannot change the Schur solver! Schur complement data has been already factored");
1991:   }
1992:   mumps->schur_sym = sym;
1993:   return(0);
1994: }

1996: /* -------------------------------------------------------------------------------------------*/
1997: PetscErrorCode MatMumpsSetIcntl_MUMPS(Mat F,PetscInt icntl,PetscInt ival)
1998: {
1999:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2002:   mumps->id.ICNTL(icntl) = ival;
2003:   return(0);
2004: }

2006: PetscErrorCode MatMumpsGetIcntl_MUMPS(Mat F,PetscInt icntl,PetscInt *ival)
2007: {
2008:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

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

2015: /*@
2016:   MatMumpsSetIcntl - Set MUMPS parameter ICNTL()

2018:    Logically Collective on Mat

2020:    Input Parameters:
2021: +  F - the factored matrix obtained by calling MatGetFactor() from PETSc-MUMPS interface
2022: .  icntl - index of MUMPS parameter array ICNTL()
2023: -  ival - value of MUMPS ICNTL(icntl)

2025:   Options Database:
2026: .   -mat_mumps_icntl_<icntl> <ival>

2028:    Level: beginner

2030:    References:
2031: .     MUMPS Users' Guide

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

2048: /*@
2049:   MatMumpsGetIcntl - Get MUMPS parameter ICNTL()

2051:    Logically Collective on Mat

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

2057:   Output Parameter:
2058: .  ival - value of MUMPS ICNTL(icntl)

2060:    Level: beginner

2062:    References:
2063: .     MUMPS Users' Guide

2065: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2066: @*/
2067: PetscErrorCode MatMumpsGetIcntl(Mat F,PetscInt icntl,PetscInt *ival)
2068: {

2073:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2076:   PetscUseMethod(F,"MatMumpsGetIcntl_C",(Mat,PetscInt,PetscInt*),(F,icntl,ival));
2077:   return(0);
2078: }

2080: /* -------------------------------------------------------------------------------------------*/
2081: PetscErrorCode MatMumpsSetCntl_MUMPS(Mat F,PetscInt icntl,PetscReal val)
2082: {
2083:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2086:   mumps->id.CNTL(icntl) = val;
2087:   return(0);
2088: }

2090: PetscErrorCode MatMumpsGetCntl_MUMPS(Mat F,PetscInt icntl,PetscReal *val)
2091: {
2092:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

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

2099: /*@
2100:   MatMumpsSetCntl - Set MUMPS parameter CNTL()

2102:    Logically Collective on Mat

2104:    Input Parameters:
2105: +  F - the factored matrix obtained by calling MatGetFactor() from PETSc-MUMPS interface
2106: .  icntl - index of MUMPS parameter array CNTL()
2107: -  val - value of MUMPS CNTL(icntl)

2109:   Options Database:
2110: .   -mat_mumps_cntl_<icntl> <val>

2112:    Level: beginner

2114:    References:
2115: .     MUMPS Users' Guide

2117: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2118: @*/
2119: PetscErrorCode MatMumpsSetCntl(Mat F,PetscInt icntl,PetscReal val)
2120: {

2125:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2128:   PetscTryMethod(F,"MatMumpsSetCntl_C",(Mat,PetscInt,PetscReal),(F,icntl,val));
2129:   return(0);
2130: }

2132: /*@
2133:   MatMumpsGetCntl - Get MUMPS parameter CNTL()

2135:    Logically Collective on Mat

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

2141:   Output Parameter:
2142: .  val - value of MUMPS CNTL(icntl)

2144:    Level: beginner

2146:    References:
2147: .      MUMPS Users' Guide

2149: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2150: @*/
2151: PetscErrorCode MatMumpsGetCntl(Mat F,PetscInt icntl,PetscReal *val)
2152: {

2157:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2160:   PetscUseMethod(F,"MatMumpsGetCntl_C",(Mat,PetscInt,PetscReal*),(F,icntl,val));
2161:   return(0);
2162: }

2164: PetscErrorCode MatMumpsGetInfo_MUMPS(Mat F,PetscInt icntl,PetscInt *info)
2165: {
2166:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2169:   *info = mumps->id.INFO(icntl);
2170:   return(0);
2171: }

2173: PetscErrorCode MatMumpsGetInfog_MUMPS(Mat F,PetscInt icntl,PetscInt *infog)
2174: {
2175:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2178:   *infog = mumps->id.INFOG(icntl);
2179:   return(0);
2180: }

2182: PetscErrorCode MatMumpsGetRinfo_MUMPS(Mat F,PetscInt icntl,PetscReal *rinfo)
2183: {
2184:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2187:   *rinfo = mumps->id.RINFO(icntl);
2188:   return(0);
2189: }

2191: PetscErrorCode MatMumpsGetRinfog_MUMPS(Mat F,PetscInt icntl,PetscReal *rinfog)
2192: {
2193:   Mat_MUMPS *mumps =(Mat_MUMPS*)F->data;

2196:   *rinfog = mumps->id.RINFOG(icntl);
2197:   return(0);
2198: }

2200: /*@
2201:   MatMumpsGetInfo - Get MUMPS parameter INFO()

2203:    Logically Collective on Mat

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

2209:   Output Parameter:
2210: .  ival - value of MUMPS INFO(icntl)

2212:    Level: beginner

2214:    References:
2215: .      MUMPS Users' Guide

2217: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2218: @*/
2219: PetscErrorCode MatMumpsGetInfo(Mat F,PetscInt icntl,PetscInt *ival)
2220: {

2225:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2227:   PetscUseMethod(F,"MatMumpsGetInfo_C",(Mat,PetscInt,PetscInt*),(F,icntl,ival));
2228:   return(0);
2229: }

2231: /*@
2232:   MatMumpsGetInfog - Get MUMPS parameter INFOG()

2234:    Logically Collective on Mat

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

2240:   Output Parameter:
2241: .  ival - value of MUMPS INFOG(icntl)

2243:    Level: beginner

2245:    References:
2246: .      MUMPS Users' Guide

2248: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2249: @*/
2250: PetscErrorCode MatMumpsGetInfog(Mat F,PetscInt icntl,PetscInt *ival)
2251: {

2256:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2258:   PetscUseMethod(F,"MatMumpsGetInfog_C",(Mat,PetscInt,PetscInt*),(F,icntl,ival));
2259:   return(0);
2260: }

2262: /*@
2263:   MatMumpsGetRinfo - Get MUMPS parameter RINFO()

2265:    Logically Collective on Mat

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

2271:   Output Parameter:
2272: .  val - value of MUMPS RINFO(icntl)

2274:    Level: beginner

2276:    References:
2277: .       MUMPS Users' Guide

2279: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2280: @*/
2281: PetscErrorCode MatMumpsGetRinfo(Mat F,PetscInt icntl,PetscReal *val)
2282: {

2287:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2289:   PetscUseMethod(F,"MatMumpsGetRinfo_C",(Mat,PetscInt,PetscReal*),(F,icntl,val));
2290:   return(0);
2291: }

2293: /*@
2294:   MatMumpsGetRinfog - Get MUMPS parameter RINFOG()

2296:    Logically Collective on Mat

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

2302:   Output Parameter:
2303: .  val - value of MUMPS RINFOG(icntl)

2305:    Level: beginner

2307:    References:
2308: .      MUMPS Users' Guide

2310: .seealso: MatGetFactor(), MatMumpsSetICntl(), MatMumpsGetIcntl(), MatMumpsSetCntl(), MatMumpsGetCntl(), MatMumpsGetInfo(), MatMumpsGetInfog(), MatMumpsGetRinfo(), MatMumpsGetRinfog()
2311: @*/
2312: PetscErrorCode MatMumpsGetRinfog(Mat F,PetscInt icntl,PetscReal *val)
2313: {

2318:   if (!F->factortype) SETERRQ(PetscObjectComm((PetscObject)F),PETSC_ERR_ARG_WRONGSTATE,"Only for factored matrix");
2320:   PetscUseMethod(F,"MatMumpsGetRinfog_C",(Mat,PetscInt,PetscReal*),(F,icntl,val));
2321:   return(0);
2322: }

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

2328:   Works with MATAIJ and MATSBAIJ matrices

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

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

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

2364:   Level: beginner

2366:     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 
2367: $          KSPGetPC(ksp,&pc);
2368: $          PCFactorGetMatrix(pc,&mat);
2369: $          MatMumpsGetInfo(mat,....);
2370: $          MatMumpsGetInfog(mat,....); etc.
2371:            Or you can run with -ksp_error_if_not_converged and the program will be stopped and the information printed in the error message.

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

2375: M*/

2377: static PetscErrorCode MatFactorGetSolverPackage_mumps(Mat A,const MatSolverPackage *type)
2378: {
2380:   *type = MATSOLVERMUMPS;
2381:   return(0);
2382: }

2384: /* MatGetFactor for Seq and MPI AIJ matrices */
2385: static PetscErrorCode MatGetFactor_aij_mumps(Mat A,MatFactorType ftype,Mat *F)
2386: {
2387:   Mat            B;
2389:   Mat_MUMPS      *mumps;
2390:   PetscBool      isSeqAIJ;

2393:   /* Create the factorization matrix */
2394:   PetscObjectTypeCompare((PetscObject)A,MATSEQAIJ,&isSeqAIJ);
2395:   MatCreate(PetscObjectComm((PetscObject)A),&B);
2396:   MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);
2397:   PetscStrallocpy("mumps",&((PetscObject)B)->type_name);
2398:   MatSetUp(B);

2400:   PetscNewLog(B,&mumps);

2402:   B->ops->view        = MatView_MUMPS;
2403:   B->ops->getinfo     = MatGetInfo_MUMPS;

2405:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_mumps);
2406:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurIS_C",MatFactorSetSchurIS_MUMPS);
2407:   PetscObjectComposeFunction((PetscObject)B,"MatFactorInvertSchurComplement_C",MatFactorInvertSchurComplement_MUMPS);
2408:   PetscObjectComposeFunction((PetscObject)B,"MatFactorCreateSchurComplement_C",MatFactorCreateSchurComplement_MUMPS);
2409:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSchurComplement_C",MatFactorGetSchurComplement_MUMPS);
2410:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplement_C",MatFactorSolveSchurComplement_MUMPS);
2411:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplementTranspose_C",MatFactorSolveSchurComplementTranspose_MUMPS);
2412:   PetscObjectComposeFunction((PetscObject)B,"MatFactorFactorizeSchurComplement_C",MatFactorFactorizeSchurComplement_MUMPS);
2413:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurComplementSolverType_C",MatFactorSetSchurComplementSolverType_MUMPS);
2414:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetIcntl_C",MatMumpsSetIcntl_MUMPS);
2415:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetIcntl_C",MatMumpsGetIcntl_MUMPS);
2416:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetCntl_C",MatMumpsSetCntl_MUMPS);
2417:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetCntl_C",MatMumpsGetCntl_MUMPS);
2418:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfo_C",MatMumpsGetInfo_MUMPS);
2419:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfog_C",MatMumpsGetInfog_MUMPS);
2420:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfo_C",MatMumpsGetRinfo_MUMPS);
2421:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfog_C",MatMumpsGetRinfog_MUMPS);

2423:   if (ftype == MAT_FACTOR_LU) {
2424:     B->ops->lufactorsymbolic = MatLUFactorSymbolic_AIJMUMPS;
2425:     B->factortype            = MAT_FACTOR_LU;
2426:     if (isSeqAIJ) mumps->ConvertToTriples = MatConvertToTriples_seqaij_seqaij;
2427:     else mumps->ConvertToTriples = MatConvertToTriples_mpiaij_mpiaij;
2428:     mumps->sym = 0;
2429:   } else {
2430:     B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_MUMPS;
2431:     B->factortype                  = MAT_FACTOR_CHOLESKY;
2432:     if (isSeqAIJ) mumps->ConvertToTriples = MatConvertToTriples_seqaij_seqsbaij;
2433:     else mumps->ConvertToTriples = MatConvertToTriples_mpiaij_mpisbaij;
2434: #if defined(PETSC_USE_COMPLEX)
2435:     mumps->sym = 2;
2436: #else
2437:     if (A->spd_set && A->spd) mumps->sym = 1;
2438:     else                      mumps->sym = 2;
2439: #endif
2440:   }

2442:   /* set solvertype */
2443:   PetscFree(B->solvertype);
2444:   PetscStrallocpy(MATSOLVERMUMPS,&B->solvertype);

2446:   mumps->isAIJ    = PETSC_TRUE;
2447:   B->ops->destroy = MatDestroy_MUMPS;
2448:   B->data        = (void*)mumps;

2450:   PetscInitializeMUMPS(A,mumps);

2452:   *F = B;
2453:   return(0);
2454: }

2456: /* MatGetFactor for Seq and MPI SBAIJ matrices */
2457: static PetscErrorCode MatGetFactor_sbaij_mumps(Mat A,MatFactorType ftype,Mat *F)
2458: {
2459:   Mat            B;
2461:   Mat_MUMPS      *mumps;
2462:   PetscBool      isSeqSBAIJ;

2465:   if (ftype != MAT_FACTOR_CHOLESKY) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_SUP,"Cannot use PETSc SBAIJ matrices with MUMPS LU, use AIJ matrix");
2466:   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");
2467:   PetscObjectTypeCompare((PetscObject)A,MATSEQSBAIJ,&isSeqSBAIJ);
2468:   /* Create the factorization matrix */
2469:   MatCreate(PetscObjectComm((PetscObject)A),&B);
2470:   MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);
2471:   PetscStrallocpy("mumps",&((PetscObject)B)->type_name);
2472:   MatSetUp(B);

2474:   PetscNewLog(B,&mumps);
2475:   if (isSeqSBAIJ) {
2476:     mumps->ConvertToTriples = MatConvertToTriples_seqsbaij_seqsbaij;
2477:   } else {
2478:     mumps->ConvertToTriples = MatConvertToTriples_mpisbaij_mpisbaij;
2479:   }

2481:   B->ops->getinfo                = MatGetInfo_External;
2482:   B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_MUMPS;
2483:   B->ops->view                   = MatView_MUMPS;

2485:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_mumps);
2486:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurIS_C",MatFactorSetSchurIS_MUMPS);
2487:   PetscObjectComposeFunction((PetscObject)B,"MatFactorInvertSchurComplement_C",MatFactorInvertSchurComplement_MUMPS);
2488:   PetscObjectComposeFunction((PetscObject)B,"MatFactorCreateSchurComplement_C",MatFactorCreateSchurComplement_MUMPS);
2489:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSchurComplement_C",MatFactorGetSchurComplement_MUMPS);
2490:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplement_C",MatFactorSolveSchurComplement_MUMPS);
2491:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplementTranspose_C",MatFactorSolveSchurComplementTranspose_MUMPS);
2492:   PetscObjectComposeFunction((PetscObject)B,"MatFactorFactorizeSchurComplement_C",MatFactorFactorizeSchurComplement_MUMPS);
2493:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurComplementSolverType_C",MatFactorSetSchurComplementSolverType_MUMPS);
2494:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetIcntl_C",MatMumpsSetIcntl_MUMPS);
2495:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetIcntl_C",MatMumpsGetIcntl_MUMPS);
2496:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetCntl_C",MatMumpsSetCntl_MUMPS);
2497:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetCntl_C",MatMumpsGetCntl_MUMPS);
2498:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfo_C",MatMumpsGetInfo_MUMPS);
2499:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfog_C",MatMumpsGetInfog_MUMPS);
2500:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfo_C",MatMumpsGetRinfo_MUMPS);
2501:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfog_C",MatMumpsGetRinfog_MUMPS);

2503:   B->factortype = MAT_FACTOR_CHOLESKY;
2504: #if defined(PETSC_USE_COMPLEX)
2505:   mumps->sym = 2;
2506: #else
2507:   if (A->spd_set && A->spd) mumps->sym = 1;
2508:   else                      mumps->sym = 2;
2509: #endif

2511:   /* set solvertype */
2512:   PetscFree(B->solvertype);
2513:   PetscStrallocpy(MATSOLVERMUMPS,&B->solvertype);

2515:   mumps->isAIJ    = PETSC_FALSE;
2516:   B->ops->destroy = MatDestroy_MUMPS;
2517:   B->data        = (void*)mumps;

2519:   PetscInitializeMUMPS(A,mumps);

2521:   *F = B;
2522:   return(0);
2523: }

2525: static PetscErrorCode MatGetFactor_baij_mumps(Mat A,MatFactorType ftype,Mat *F)
2526: {
2527:   Mat            B;
2529:   Mat_MUMPS      *mumps;
2530:   PetscBool      isSeqBAIJ;

2533:   /* Create the factorization matrix */
2534:   PetscObjectTypeCompare((PetscObject)A,MATSEQBAIJ,&isSeqBAIJ);
2535:   MatCreate(PetscObjectComm((PetscObject)A),&B);
2536:   MatSetSizes(B,A->rmap->n,A->cmap->n,A->rmap->N,A->cmap->N);
2537:   PetscStrallocpy("mumps",&((PetscObject)B)->type_name);
2538:   MatSetUp(B);

2540:   PetscNewLog(B,&mumps);
2541:   if (ftype == MAT_FACTOR_LU) {
2542:     B->ops->lufactorsymbolic = MatLUFactorSymbolic_BAIJMUMPS;
2543:     B->factortype            = MAT_FACTOR_LU;
2544:     if (isSeqBAIJ) mumps->ConvertToTriples = MatConvertToTriples_seqbaij_seqaij;
2545:     else mumps->ConvertToTriples = MatConvertToTriples_mpibaij_mpiaij;
2546:     mumps->sym = 0;
2547:   } else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot use PETSc BAIJ matrices with MUMPS Cholesky, use SBAIJ or AIJ matrix instead\n");

2549:   B->ops->getinfo     = MatGetInfo_External;
2550:   B->ops->view        = MatView_MUMPS;

2552:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverPackage_C",MatFactorGetSolverPackage_mumps);
2553:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurIS_C",MatFactorSetSchurIS_MUMPS);
2554:   PetscObjectComposeFunction((PetscObject)B,"MatFactorInvertSchurComplement_C",MatFactorInvertSchurComplement_MUMPS);
2555:   PetscObjectComposeFunction((PetscObject)B,"MatFactorCreateSchurComplement_C",MatFactorCreateSchurComplement_MUMPS);
2556:   PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSchurComplement_C",MatFactorGetSchurComplement_MUMPS);
2557:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplement_C",MatFactorSolveSchurComplement_MUMPS);
2558:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSolveSchurComplementTranspose_C",MatFactorSolveSchurComplementTranspose_MUMPS);
2559:   PetscObjectComposeFunction((PetscObject)B,"MatFactorFactorizeSchurComplement_C",MatFactorFactorizeSchurComplement_MUMPS);
2560:   PetscObjectComposeFunction((PetscObject)B,"MatFactorSetSchurComplementSolverType_C",MatFactorSetSchurComplementSolverType_MUMPS);
2561:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetIcntl_C",MatMumpsSetIcntl_MUMPS);
2562:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetIcntl_C",MatMumpsGetIcntl_MUMPS);
2563:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsSetCntl_C",MatMumpsSetCntl_MUMPS);
2564:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetCntl_C",MatMumpsGetCntl_MUMPS);
2565:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfo_C",MatMumpsGetInfo_MUMPS);
2566:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetInfog_C",MatMumpsGetInfog_MUMPS);
2567:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfo_C",MatMumpsGetRinfo_MUMPS);
2568:   PetscObjectComposeFunction((PetscObject)B,"MatMumpsGetRinfog_C",MatMumpsGetRinfog_MUMPS);

2570:   /* set solvertype */
2571:   PetscFree(B->solvertype);
2572:   PetscStrallocpy(MATSOLVERMUMPS,&B->solvertype);

2574:   mumps->isAIJ    = PETSC_TRUE;
2575:   B->ops->destroy = MatDestroy_MUMPS;
2576:   B->data        = (void*)mumps;

2578:   PetscInitializeMUMPS(A,mumps);

2580:   *F = B;
2581:   return(0);
2582: }

2584: PETSC_EXTERN PetscErrorCode MatSolverPackageRegister_MUMPS(void)
2585: {

2589:   MatSolverPackageRegister(MATSOLVERMUMPS,MATMPIAIJ,MAT_FACTOR_LU,MatGetFactor_aij_mumps);
2590:   MatSolverPackageRegister(MATSOLVERMUMPS,MATMPIAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_aij_mumps);
2591:   MatSolverPackageRegister(MATSOLVERMUMPS,MATMPIBAIJ,MAT_FACTOR_LU,MatGetFactor_baij_mumps);
2592:   MatSolverPackageRegister(MATSOLVERMUMPS,MATMPIBAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_baij_mumps);
2593:   MatSolverPackageRegister(MATSOLVERMUMPS,MATMPISBAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_sbaij_mumps);
2594:   MatSolverPackageRegister(MATSOLVERMUMPS,MATSEQAIJ,MAT_FACTOR_LU,MatGetFactor_aij_mumps);
2595:   MatSolverPackageRegister(MATSOLVERMUMPS,MATSEQAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_aij_mumps);
2596:   MatSolverPackageRegister(MATSOLVERMUMPS,MATSEQBAIJ,MAT_FACTOR_LU,MatGetFactor_baij_mumps);
2597:   MatSolverPackageRegister(MATSOLVERMUMPS,MATSEQBAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_baij_mumps);
2598:   MatSolverPackageRegister(MATSOLVERMUMPS,MATSEQSBAIJ,MAT_FACTOR_CHOLESKY,MatGetFactor_sbaij_mumps);
2599:   return(0);
2600: }