xref: /petsc/src/mat/interface/matrix.c (revision 8b1af7b3d7ce1298a43af33cb6c2e0c485b769e8)
1 #ifndef lint
2 static char vcid[] = "$Id: matrix.c,v 1.133 1996/01/26 04:33:32 bsmith Exp curfman $";
3 #endif
4 
5 /*
6    This is where the abstract matrix operations are defined
7 */
8 
9 #include "petsc.h"
10 #include "matimpl.h"        /*I "mat.h" I*/
11 #include "vec/vecimpl.h"
12 #include "pinclude/pviewer.h"
13 #include "draw.h"
14 
15 /*@C
16    MatGetReordering - Gets a reordering for a matrix to reduce fill or to
17    improve numerical stability of LU factorization.
18 
19    Input Parameters:
20 .  mat - the matrix
21 .  type - type of reordering, one of the following:
22 $      ORDER_NATURAL - Natural
23 $      ORDER_ND - Nested Dissection
24 $      ORDER_1WD - One-way Dissection
25 $      ORDER_RCM - Reverse Cuthill-McGee
26 $      ORDER_QMD - Quotient Minimum Degree
27 
28    Output Parameters:
29 .  rperm - row permutation indices
30 .  cperm - column permutation indices
31 
32    Options Database Keys:
33    To specify the ordering through the options database, use one of
34    the following
35 $    -mat_order natural, -mat_order nd, -mat_order 1wd,
36 $    -mat_order rcm, -mat_order qmd
37 
38    Notes:
39    If the column permutations and row permutations are the same,
40    then MatGetReordering() returns 0 in cperm.
41 
42    The user can define additional orderings; see MatReorderingRegister().
43 
44 .keywords: matrix, set, ordering, factorization, direct, ILU, LU,
45            fill, reordering, natural, Nested Dissection,
46            One-way Dissection, Cholesky, Reverse Cuthill-McGee,
47            Quotient Minimum Degree
48 
49 .seealso:  MatGetReorderingTypeFromOptions(), MatReorderingRegister()
50 @*/
51 int MatGetReordering(Mat mat,MatOrdering type,IS *rperm,IS *cperm)
52 {
53   int         ierr;
54   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
55   if (!mat->assembled) SETERRQ(1,"MatGetReordering:Not for unassembled matrix");
56 
57   if (!mat->ops.getreordering) {*rperm = 0; *cperm = 0; return 0;}
58   PLogEventBegin(MAT_GetReordering,mat,0,0,0);
59   ierr = MatGetReorderingTypeFromOptions(0,&type); CHKERRQ(ierr);
60   ierr = (*mat->ops.getreordering)(mat,type,rperm,cperm); CHKERRQ(ierr);
61   PLogEventEnd(MAT_GetReordering,mat,0,0,0);
62   return 0;
63 }
64 
65 /*@C
66    MatGetRow - Gets a row of a matrix.  You MUST call MatRestoreRow()
67    for each row that you get to ensure that your application does
68    not bleed memory.
69 
70    Input Parameters:
71 .  mat - the matrix
72 .  row - the row to get
73 
74    Output Parameters:
75 .  ncols -  the number of nonzeros in the row
76 .  cols - if nonzero, the column numbers
77 .  vals - if nonzero, the values
78 
79    Notes:
80    This routine is provided for people who need to have direct access
81    to the structure of a matrix.  We hope that we provide enough
82    high-level matrix routines that few users will need it.
83 
84    For better efficiency, set cols and/or vals to zero if you do not
85    wish to extract these quantities.
86 
87 .keywords: matrix, row, get, extract
88 
89 .seealso: MatRestoreRow()
90 @*/
91 int MatGetRow(Mat mat,int row,int *ncols,int **cols,Scalar **vals)
92 {
93   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
94   if (!mat->assembled) SETERRQ(1,"MatGetRow:Not for unassembled matrix");
95   return (*mat->ops.getrow)(mat,row,ncols,cols,vals);
96 }
97 
98 /*@C
99    MatRestoreRow - Frees any temporary space allocated by MatGetRow().
100 
101    Input Parameters:
102 .  mat - the matrix
103 .  row - the row to get
104 .  ncols, cols - the number of nonzeros and their columns
105 .  vals - if nonzero the column values
106 
107 .keywords: matrix, row, restore
108 
109 .seealso:  MatGetRow()
110 @*/
111 int MatRestoreRow(Mat mat,int row,int *ncols,int **cols,Scalar **vals)
112 {
113   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
114   if (!mat->assembled) SETERRQ(1,"MatRestoreRow:Not for unassembled matrix");
115   if (!mat->ops.restorerow) return 0;
116   return (*mat->ops.restorerow)(mat,row,ncols,cols,vals);
117 }
118 /*@
119    MatView - Visualizes a matrix object.
120 
121    Input Parameters:
122 .  mat - the matrix
123 .  ptr - visualization context
124 
125    Notes:
126    The available visualization contexts include
127 $     STDOUT_VIEWER_SELF - standard output (default)
128 $     STDOUT_VIEWER_WORLD - synchronized standard
129 $       output where only the first processor opens
130 $       the file.  All other processors send their
131 $       data to the first processor to print.
132 
133    The user can open alternative vistualization contexts with
134 $    ViewerFileOpenASCII() - output to a specified file
135 $    ViewerFileOpenBinary() - output in binary to a
136 $         specified file; corresponding input uses MatLoad()
137 $    DrawOpenX() - output nonzero matrix structure to
138 $         an X window display
139 $    ViewerMatlabOpen() - output matrix to Matlab viewer.
140 $         Currently only the sequential dense and AIJ
141 $         matrix types support the Matlab viewer.
142 
143    The user can call ViewerFileSetFormat() to specify the output
144    format of ASCII printed objects (when using STDOUT_VIEWER_SELF,
145    STDOUT_VIEWER_WORLD and ViewerFileOpenASCII).  Available formats include
146 $    FILE_FORMAT_DEFAULT - default, prints matrix contents
147 $    FILE_FORMAT_IMPL - implementation-specific format
148 $      (which is in many cases the same as the default)
149 $    FILE_FORMAT_INFO - basic information about the matrix
150 $      size and structure (not the matrix entries)
151 $    FILE_FORMAT_INFO_DETAILED - more detailed information about the
152 $      matrix structure
153 
154 .keywords: matrix, view, visualize, output, print, write, draw
155 
156 .seealso: ViewerFileSetFormat(), ViewerFileOpenASCII(), DrawOpenX(),
157           ViewerMatlabOpen(), ViewerFileOpenBinary(), MatLoad()
158 @*/
159 int MatView(Mat mat,Viewer ptr)
160 {
161   int          format, ierr, rows, cols,nz, nzalloc, mem;
162   FILE         *fd;
163   char         *cstring;
164   PetscObject  vobj = (PetscObject) ptr;
165 
166   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
167   if (!mat->assembled) SETERRQ(1,"MatView:Not for unassembled matrix");
168 
169   if (!ptr) { /* so that viewers may be used from debuggers */
170     ptr = STDOUT_VIEWER_SELF; vobj = (PetscObject) ptr;
171   }
172   ierr = ViewerFileGetFormat_Private(ptr,&format); CHKERRQ(ierr);
173   ierr = ViewerFileGetPointer(ptr,&fd); CHKERRQ(ierr);
174   if (vobj->cookie == VIEWER_COOKIE &&
175       (format == FILE_FORMAT_INFO || format == FILE_FORMAT_INFO_DETAILED) &&
176       (vobj->type == ASCII_FILE_VIEWER || vobj->type == ASCII_FILES_VIEWER)) {
177     MPIU_fprintf(mat->comm,fd,"Matrix Object:\n");
178     ierr = MatGetType(mat,PETSC_NULL,&cstring); CHKERRQ(ierr);
179     ierr = MatGetSize(mat,&rows,&cols); CHKERRQ(ierr);
180     MPIU_fprintf(mat->comm,fd,"  type=%s, rows=%d, cols=%d\n",cstring,rows,cols);
181     if (mat->ops.getinfo) {
182       ierr = MatGetInfo(mat,MAT_GLOBAL_SUM,&nz,&nzalloc,&mem); CHKERRQ(ierr);
183       MPIU_fprintf(mat->comm,fd,"  total: nonzeros=%d, allocated nonzeros=%d\n",nz,nzalloc);
184     }
185   }
186   if (mat->view) {ierr = (*mat->view)((PetscObject)mat,ptr); CHKERRQ(ierr);}
187   return 0;
188 }
189 /*@C
190    MatDestroy - Frees space taken by a matrix.
191 
192    Input Parameter:
193 .  mat - the matrix
194 
195 .keywords: matrix, destroy
196 @*/
197 int MatDestroy(Mat mat)
198 {
199   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
200   return (*mat->destroy)((PetscObject)mat);
201 }
202 /*@
203    MatValidMatrix - Returns 1 if a valid matrix else 0.
204 
205    Input Parameter:
206 .  m - the matrix to check
207 
208 .keywords: matrix, valid
209 @*/
210 int MatValidMatrix(Mat m)
211 {
212   if (!m) return 0;
213   if (m->cookie != MAT_COOKIE) return 0;
214   return 1;
215 }
216 
217 /*@
218    MatSetValues - Inserts or adds a block of values into a matrix.
219    These values may be cached, so MatAssemblyBegin() and MatAssemblyEnd()
220    MUST be called after all calls to MatSetValues() have been completed.
221 
222    Input Parameters:
223 .  mat - the matrix
224 .  v - a logically two-dimensional array of values
225 .  m, indexm - the number of rows and their global indices
226 .  n, indexn - the number of columns and their global indices
227 .  addv - either ADD_VALUES or INSERT_VALUES, where
228 $     ADD_VALUES - adds values to any existing entries
229 $     INSERT_VALUES - replaces existing entries with new values
230 
231    Notes:
232    By default the values, v, are row-oriented and unsorted.
233    See MatSetOptions() for other options.
234 
235    Calls to MatSetValues() with the INSERT_VALUES and ADD_VALUES
236    options cannot be mixed without intervening calls to the assembly
237    routines.
238 
239 .keywords: matrix, insert, add, set, values
240 
241 .seealso: MatSetOptions(), MatAssemblyBegin(), MatAssemblyEnd()
242 @*/
243 int MatSetValues(Mat mat,int m,int *idxm,int n,int *idxn,Scalar *v,
244                                                         InsertMode addv)
245 {
246   int ierr;
247   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
248 
249   if (mat->assembled) {
250     mat->was_assembled = PETSC_TRUE;
251     mat->assembled     = PETSC_FALSE;
252     mat->same_nonzero  = PETSC_TRUE;
253   }
254 
255   PLogEventBegin(MAT_SetValues,mat,0,0,0);
256   ierr = (*mat->ops.setvalues)(mat,m,idxm,n,idxn,v,addv);CHKERRQ(ierr);
257   PLogEventEnd(MAT_SetValues,mat,0,0,0);
258   return 0;
259 }
260 
261 /*@
262    MatGetValues - Gets a block of values from a matrix.
263 
264    Input Parameters:
265 .  mat - the matrix
266 .  v - a logically two-dimensional array for storing the values
267 .  m, indexm - the number of rows and their global indices
268 .  n, indexn - the number of columns and their global indices
269 
270    Notes:
271    The user must allocate space (m*n Scalars) for the values, v.
272    The values, v, are then returned in a row-oriented format,
273    analogous to that used by default in MatSetValues().
274 
275 .keywords: matrix, get, values
276 
277 .seealso: MatGetRow(), MatGetSubmatrix(), MatGetSubmatrices(), MatSetValues()
278 @*/
279 int MatGetValues(Mat mat,int m,int *idxm,int n,int *idxn,Scalar *v)
280 {
281   int ierr;
282 
283   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
284   if (!mat->assembled) SETERRQ(1,"MatGetValues:Not for unassembled matrix");
285 
286   PLogEventBegin(MAT_GetValues,mat,0,0,0);
287   ierr = (*mat->ops.getvalues)(mat,m,idxm,n,idxn,v); CHKERRQ(ierr);
288   PLogEventEnd(MAT_GetValues,mat,0,0,0);
289   return 0;
290 }
291 
292 /* --------------------------------------------------------*/
293 /*@
294    MatMult - Computes matrix-vector product.
295 
296    Input Parameters:
297 .  mat - the matrix
298 .  x   - the vector to be multilplied
299 
300    Output Parameters:
301 .  y - the result
302 
303 .keywords: matrix, multiply, matrix-vector product
304 
305 .seealso: MatMultTrans(), MatMultAdd(), MatMultTransAdd()
306 @*/
307 int MatMult(Mat mat,Vec x,Vec y)
308 {
309   int ierr;
310   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
311   PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE);PETSCVALIDHEADERSPECIFIC(y,VEC_COOKIE);
312   if (!mat->assembled) SETERRQ(1,"MatMult:Not for unassembled matrix");
313   if (x == y) SETERRQ(1,"MatMult:x and y must be different vectors");
314 
315   PLogEventBegin(MAT_Mult,mat,x,y,0);
316   ierr = (*mat->ops.mult)(mat,x,y); CHKERRQ(ierr);
317   PLogEventEnd(MAT_Mult,mat,x,y,0);
318   return 0;
319 }
320 /*@
321    MatMultTrans - Computes matrix transpose times a vector.
322 
323    Input Parameters:
324 .  mat - the matrix
325 .  x   - the vector to be multilplied
326 
327    Output Parameters:
328 .  y - the result
329 
330 .keywords: matrix, multiply, matrix-vector product, transpose
331 
332 .seealso: MatMult(), MatMultAdd(), MatMultTransAdd()
333 @*/
334 int MatMultTrans(Mat mat,Vec x,Vec y)
335 {
336   int ierr;
337   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
338   PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(y,VEC_COOKIE);
339   if (!mat->assembled) SETERRQ(1,"MatMultTrans:Not for unassembled matrix");
340   if (x == y) SETERRQ(1,"MatMultTrans:x and y must be different vectors");
341 
342   PLogEventBegin(MAT_MultTrans,mat,x,y,0);
343   ierr = (*mat->ops.multtrans)(mat,x,y); CHKERRQ(ierr);
344   PLogEventEnd(MAT_MultTrans,mat,x,y,0);
345   return 0;
346 }
347 /*@
348     MatMultAdd -  Computes v3 = v2 + A * v1.
349 
350   Input Parameters:
351 .    mat - the matrix
352 .    v1, v2 - the vectors
353 
354   Output Parameters:
355 .    v3 - the result
356 
357 .keywords: matrix, multiply, matrix-vector product, add
358 
359 .seealso: MatMultTrans(), MatMult(), MatMultTransAdd()
360 @*/
361 int MatMultAdd(Mat mat,Vec v1,Vec v2,Vec v3)
362 {
363   int ierr;
364   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);PETSCVALIDHEADERSPECIFIC(v1,VEC_COOKIE);
365   PETSCVALIDHEADERSPECIFIC(v2,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(v3,VEC_COOKIE);
366   if (!mat->assembled) SETERRQ(1,"MatMultAdd:Not for unassembled matrix");
367 
368   PLogEventBegin(MAT_MultAdd,mat,v1,v2,v3);
369   if (v1 == v3) SETERRQ(1,"MatMultAdd:v1 and v3 must be different vectors");
370   ierr = (*mat->ops.multadd)(mat,v1,v2,v3); CHKERRQ(ierr);
371   PLogEventEnd(MAT_MultAdd,mat,v1,v2,v3);
372   return 0;
373 }
374 /*@
375     MatMultTransAdd - Computes v3 = v2 + A' * v1.
376 
377   Input Parameters:
378 .    mat - the matrix
379 .    v1, v2 - the vectors
380 
381   Output Parameters:
382 .    v3 - the result
383 
384 .keywords: matrix, multiply, matrix-vector product, transpose, add
385 
386 .seealso: MatMultTrans(), MatMultAdd(), MatMult()
387 @*/
388 int MatMultTransAdd(Mat mat,Vec v1,Vec v2,Vec v3)
389 {
390   int ierr;
391   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); PETSCVALIDHEADERSPECIFIC(v1,VEC_COOKIE);
392   PETSCVALIDHEADERSPECIFIC(v2,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(v3,VEC_COOKIE);
393   if (!mat->assembled) SETERRQ(1,"MatMultTransAdd:Not for unassembled matrix");
394   if (!mat->ops.multtransadd) SETERRQ(PETSC_ERR_SUP,"MatMultTransAdd");
395   if (v1 == v3) SETERRQ(1,"MatMultTransAdd:v1 and v2 must be different vectors");
396 
397   PLogEventBegin(MAT_MultTransAdd,mat,v1,v2,v3);
398   ierr = (*mat->ops.multtransadd)(mat,v1,v2,v3); CHKERRQ(ierr);
399   PLogEventEnd(MAT_MultTransAdd,mat,v1,v2,v3);
400   return 0;
401 }
402 /* ------------------------------------------------------------*/
403 /*@
404    MatGetInfo - Returns information about matrix storage (number of
405    nonzeros, memory).
406 
407    Input Parameters:
408 .  mat - the matrix
409 
410    Output Parameters:
411 .  flag - flag indicating the type of parameters to be returned
412 $    flag = MAT_LOCAL: local matrix
413 $    flag = MAT_GLOBAL_MAX: maximum over all processors
414 $    flag = MAT_GLOBAL_SUM: sum over all processors
415 .   nz - the number of nonzeros
416 .   nzalloc - the number of allocated nonzeros
417 .   mem - the memory used (in bytes)
418 
419 .keywords: matrix, get, info, storage, nonzeros, memory
420 @*/
421 int MatGetInfo(Mat mat,MatInfoType flag,int *nz,int *nzalloc,int *mem)
422 {
423   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
424   if (!mat->ops.getinfo) SETERRQ(PETSC_ERR_SUP,"MatGetInfo");
425   return  (*mat->ops.getinfo)(mat,flag,nz,nzalloc,mem);
426 }
427 /* ----------------------------------------------------------*/
428 /*@
429    MatLUFactor - Performs in-place LU factorization of matrix.
430 
431    Input Parameters:
432 .  mat - the matrix
433 .  row - row permutation
434 .  col - column permutation
435 .  f - expected fill as ratio of original fill.
436 
437 .keywords: matrix, factor, LU, in-place
438 
439 .seealso: MatLUFactorSymbolic(), MatLUFactorNumeric(), MatCholeskyFactor()
440 @*/
441 int MatLUFactor(Mat mat,IS row,IS col,double f)
442 {
443   int ierr;
444   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
445   if (!mat->ops.lufactor) SETERRQ(PETSC_ERR_SUP,"MatLUFactor");
446   if (!mat->assembled) SETERRQ(1,"MatLUFactor:Not for unassembled matrix");
447 
448   PLogEventBegin(MAT_LUFactor,mat,row,col,0);
449   ierr = (*mat->ops.lufactor)(mat,row,col,f); CHKERRQ(ierr);
450   PLogEventEnd(MAT_LUFactor,mat,row,col,0);
451   return 0;
452 }
453 /*@
454    MatILUFactor - Performs in-place ILU factorization of matrix.
455 
456    Input Parameters:
457 .  mat - the matrix
458 .  row - row permutation
459 .  col - column permutation
460 .  f - expected fill as ratio of original fill.
461 .  level - number of levels of fill.
462 
463    Note: probably really only in-place when level is zero.
464 .keywords: matrix, factor, ILU, in-place
465 
466 .seealso: MatILUFactorSymbolic(), MatLUFactorNumeric(), MatCholeskyFactor()
467 @*/
468 int MatILUFactor(Mat mat,IS row,IS col,double f,int level)
469 {
470   int ierr;
471   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
472   if (!mat->ops.ilufactor) SETERRQ(PETSC_ERR_SUP,"MatILUFactor");
473   if (!mat->assembled) SETERRQ(1,"MatILUFactor:Not for unassembled matrix");
474 
475   PLogEventBegin(MAT_ILUFactor,mat,row,col,0);
476   ierr = (*mat->ops.ilufactor)(mat,row,col,f,level); CHKERRQ(ierr);
477   PLogEventEnd(MAT_ILUFactor,mat,row,col,0);
478   return 0;
479 }
480 
481 /*@
482    MatLUFactorSymbolic - Performs symbolic LU factorization of matrix.
483    Call this routine before calling MatLUFactorNumeric().
484 
485    Input Parameters:
486 .  mat - the matrix
487 .  row, col - row and column permutations
488 .  f - expected fill as ratio of the original number of nonzeros,
489        for example 3.0; choosing this parameter well can result in
490        more efficient use of time and space.
491 
492    Output Parameters:
493 .  fact - new matrix that has been symbolically factored
494 
495 .keywords: matrix, factor, LU, symbol CHKERRQ(ierr);ic
496 
497 .seealso: MatLUFactor(), MatLUFactorNumeric(), MatCholeskyFactor()
498 @*/
499 int MatLUFactorSymbolic(Mat mat,IS row,IS col,double f,Mat *fact)
500 {
501   int ierr,flg;
502   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
503   if (!fact) SETERRQ(1,"MatLUFactorSymbolic:Missing factor matrix argument");
504   if (!mat->ops.lufactorsymbolic) SETERRQ(PETSC_ERR_SUP,"MatLUFactorSymbolic");
505   if (!mat->assembled) SETERRQ(1,"MatLUFactorSymbolic:Not for unassembled matrix");
506 
507   ierr = OptionsGetDouble(PETSC_NULL,"-mat_lu_fill",&f,&flg); CHKERRQ(ierr);
508   PLogEventBegin(MAT_LUFactorSymbolic,mat,row,col,0);
509   ierr = (*mat->ops.lufactorsymbolic)(mat,row,col,f,fact); CHKERRQ(ierr);
510   PLogEventEnd(MAT_LUFactorSymbolic,mat,row,col,0);
511   return 0;
512 }
513 /*@
514    MatLUFactorNumeric - Performs numeric LU factorization of a matrix.
515    Call this routine after first calling MatLUFactorSymbolic().
516 
517    Input Parameters:
518 .  mat - the matrix
519 .  row, col - row and  column permutations
520 
521    Output Parameters:
522 .  fact - symbolically factored matrix that must have been generated
523           by MatLUFactorSymbolic()
524 
525    Notes:
526    See MatLUFactor() for in-place factorization.  See
527    MatCholeskyFactorNumeric() for the symmetric, positive definite case.
528 
529 .keywords: matrix, factor, LU, numeric
530 
531 .seealso: MatLUFactorSymbolic(), MatLUFactor(), MatCholeskyFactor()
532 @*/
533 int MatLUFactorNumeric(Mat mat,Mat *fact)
534 {
535   int ierr,flg;
536 
537   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
538   if (!fact) SETERRQ(1,"MatLUFactorNumeric:Missing factor matrix argument");
539   if (!mat->ops.lufactornumeric) SETERRQ(PETSC_ERR_SUP,"MatLUFactorNumeric");
540   if (!mat->assembled) SETERRQ(1,"MatLUFactorNumeric:Not for unassembled matrix");
541 
542   PLogEventBegin(MAT_LUFactorNumeric,mat,*fact,0,0);
543   ierr = (*mat->ops.lufactornumeric)(mat,fact); CHKERRQ(ierr);
544   PLogEventEnd(MAT_LUFactorNumeric,mat,*fact,0,0);
545   ierr = OptionsHasName(PETSC_NULL,"-mat_view_draw",&flg); CHKERRQ(ierr);
546   if (flg) {
547     Draw    win;
548     ierr = DrawOpenX((*fact)->comm,0,0,0,0,300,300,&win); CHKERRQ(ierr);
549     ierr = MatView(*fact,(Viewer)win); CHKERRQ(ierr);
550     ierr = DrawSyncFlush(win); CHKERRQ(ierr);
551     ierr = DrawDestroy(win); CHKERRQ(ierr);
552   }
553   return 0;
554 }
555 /*@
556    MatCholeskyFactor - Performs in-place Cholesky factorization of a
557    symmetric matrix.
558 
559    Input Parameters:
560 .  mat - the matrix
561 .  perm - row and column permutations
562 .  f - expected fill as ratio of original fill
563 
564    Notes:
565    See MatLUFactor() for the nonsymmetric case.  See also
566    MatCholeskyFactorSymbolic(), and MatCholeskyFactorNumeric().
567 
568 .keywords: matrix, factor, in-place, Cholesky
569 
570 .seealso: MatLUFactor(), MatCholeskyFactorSymbolic(), MatCholeskyFactorNumeric()
571 @*/
572 int MatCholeskyFactor(Mat mat,IS perm,double f)
573 {
574   int ierr;
575   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
576   if (!mat->ops.choleskyfactor) SETERRQ(PETSC_ERR_SUP,"MatCholeskyFactor");
577   if (!mat->assembled) SETERRQ(1,"MatCholeskyFactor:Not for unassembled matrix");
578 
579   PLogEventBegin(MAT_CholeskyFactor,mat,perm,0,0);
580   ierr = (*mat->ops.choleskyfactor)(mat,perm,f); CHKERRQ(ierr);
581   PLogEventEnd(MAT_CholeskyFactor,mat,perm,0,0);
582   return 0;
583 }
584 /*@
585    MatCholeskyFactorSymbolic - Performs symbolic Cholesky factorization
586    of a symmetric matrix.
587 
588    Input Parameters:
589 .  mat - the matrix
590 .  perm - row and column permutations
591 .  f - expected fill as ratio of original
592 
593    Output Parameter:
594 .  fact - the factored matrix
595 
596    Notes:
597    See MatLUFactorSymbolic() for the nonsymmetric case.  See also
598    MatCholeskyFactor() and MatCholeskyFactorNumeric().
599 
600 .keywords: matrix, factor, factorization, symbolic, Cholesky
601 
602 .seealso: MatLUFactorSymbolic(), MatCholeskyFactor(), MatCholeskyFactorNumeric()
603 @*/
604 int MatCholeskyFactorSymbolic(Mat mat,IS perm,double f,Mat *fact)
605 {
606   int ierr;
607   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
608   if (!fact) SETERRQ(1,"MatCholeskyFactorSymbolic:Missing factor matrix argument");
609   if (!mat->ops.choleskyfactorsymbolic)SETERRQ(PETSC_ERR_SUP,"MatCholeskyFactorSymbolic");
610   if (!mat->assembled) SETERRQ(1,"MatCholeskyFactorSymbolic:Not for unassembled matrix");
611 
612   PLogEventBegin(MAT_CholeskyFactorSymbolic,mat,perm,0,0);
613   ierr = (*mat->ops.choleskyfactorsymbolic)(mat,perm,f,fact); CHKERRQ(ierr);
614   PLogEventEnd(MAT_CholeskyFactorSymbolic,mat,perm,0,0);
615   return 0;
616 }
617 /*@
618    MatCholeskyFactorNumeric - Performs numeric Cholesky factorization
619    of a symmetric matrix. Call this routine after first calling
620    MatCholeskyFactorSymbolic().
621 
622    Input Parameter:
623 .  mat - the initial matrix
624 
625    Output Parameter:
626 .  fact - the factored matrix
627 
628 .keywords: matrix, factor, numeric, Cholesky
629 
630 .seealso: MatCholeskyFactorSymbolic(), MatCholeskyFactor(), MatLUFactorNumeric()
631 @*/
632 int MatCholeskyFactorNumeric(Mat mat,Mat *fact)
633 {
634   int ierr;
635   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
636   if (!fact) SETERRQ(1,"MatCholeskyFactorNumeric:Missing factor matrix argument");
637   if (!mat->ops.choleskyfactornumeric) SETERRQ(PETSC_ERR_SUP,"MatCholeskyFactorNumeric");
638   if (!mat->assembled) SETERRQ(1,"MatCholeskyFactorNumeric:Not for unassembled matrix");
639 
640   PLogEventBegin(MAT_CholeskyFactorNumeric,mat,*fact,0,0);
641   ierr = (*mat->ops.choleskyfactornumeric)(mat,fact); CHKERRQ(ierr);
642   PLogEventEnd(MAT_CholeskyFactorNumeric,mat,*fact,0,0);
643   return 0;
644 }
645 /* ----------------------------------------------------------------*/
646 /*@
647    MatSolve - Solves A x = b, given a factored matrix.
648 
649    Input Parameters:
650 .  mat - the factored matrix
651 .  b - the right-hand-side vector
652 
653    Output Parameter:
654 .  x - the result vector
655 
656 .keywords: matrix, linear system, solve, LU, Cholesky, triangular solve
657 
658 .seealso: MatSolveAdd(), MatSolveTrans(), MatSolveTransAdd()
659 @*/
660 int MatSolve(Mat mat,Vec b,Vec x)
661 {
662   int ierr;
663   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
664   PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE);  PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE);
665   if (x == b) SETERRQ(1,"MatSolve:x and y must be different vectors");
666   if (!mat->factor) SETERRQ(1,"MatSolve:Unfactored matrix");
667 
668   if (!mat->ops.solve) SETERRQ(PETSC_ERR_SUP,"MatSolve");
669   PLogEventBegin(MAT_Solve,mat,b,x,0);
670   ierr = (*mat->ops.solve)(mat,b,x); CHKERRQ(ierr);
671   PLogEventEnd(MAT_Solve,mat,b,x,0);
672   return 0;
673 }
674 
675 /* @
676    MatForwardSolve - Solves L x = b, given a factored matrix, A = LU.
677 
678    Input Parameters:
679 .  mat - the factored matrix
680 .  b - the right-hand-side vector
681 
682    Output Parameter:
683 .  x - the result vector
684 
685    Notes:
686    MatSolve() should be used for most applications, as it performs
687    a forward solve followed by a backward solve.
688 
689 .keywords: matrix, forward, LU, Cholesky, triangular solve
690 
691 .seealso: MatSolve(), MatBackwardSolve()
692 @ */
693 int MatForwardSolve(Mat mat,Vec b,Vec x)
694 {
695   int ierr;
696   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
697   PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE);  PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE);
698   if (x == b) SETERRQ(1,"MatForwardSolve:x and y must be different vectors");
699   if (!mat->factor) SETERRQ(1,"MatForwardSolve:Unfactored matrix");
700   if (!mat->ops.forwardsolve) SETERRQ(PETSC_ERR_SUP,"MatForwardSolve");
701 
702   PLogEventBegin(MAT_ForwardSolve,mat,b,x,0);
703   ierr = (*mat->ops.forwardsolve)(mat,b,x); CHKERRQ(ierr);
704   PLogEventEnd(MAT_ForwardSolve,mat,b,x,0);
705   return 0;
706 }
707 
708 /* @
709    MatBackwardSolve - Solves U x = b, given a factored matrix, A = LU.
710 
711    Input Parameters:
712 .  mat - the factored matrix
713 .  b - the right-hand-side vector
714 
715    Output Parameter:
716 .  x - the result vector
717 
718    Notes:
719    MatSolve() should be used for most applications, as it performs
720    a forward solve followed by a backward solve.
721 
722 .keywords: matrix, backward, LU, Cholesky, triangular solve
723 
724 .seealso: MatSolve(), MatForwardSolve()
725 @ */
726 int MatBackwardSolve(Mat mat,Vec b,Vec x)
727 {
728   int ierr;
729   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
730   PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE);  PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE);
731   if (x == b) SETERRQ(1,"MatBackwardSolve:x and b must be different vectors");
732   if (!mat->factor) SETERRQ(1,"MatBackwardSolve:Unfactored matrix");
733   if (!mat->ops.backwardsolve) SETERRQ(PETSC_ERR_SUP,"MatBackwardSolve");
734 
735   PLogEventBegin(MAT_BackwardSolve,mat,b,x,0);
736   ierr = (*mat->ops.backwardsolve)(mat,b,x); CHKERRQ(ierr);
737   PLogEventEnd(MAT_BackwardSolve,mat,b,x,0);
738   return 0;
739 }
740 
741 /*@
742    MatSolveAdd - Computes x = y + inv(A)*b, given a factored matrix.
743 
744    Input Parameters:
745 .  mat - the factored matrix
746 .  b - the right-hand-side vector
747 .  y - the vector to be added to
748 
749    Output Parameter:
750 .  x - the result vector
751 
752 .keywords: matrix, linear system, solve, LU, Cholesky, add
753 
754 .seealso: MatSolve(), MatSolveTrans(), MatSolveTransAdd()
755 @*/
756 int MatSolveAdd(Mat mat,Vec b,Vec y,Vec x)
757 {
758   Scalar one = 1.0;
759   Vec    tmp;
760   int    ierr;
761   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);PETSCVALIDHEADERSPECIFIC(y,VEC_COOKIE);
762   PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE);  PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE);
763   if (x == b) SETERRQ(1,"MatSolveAdd:x and b must be different vectors");
764   if (!mat->factor) SETERRQ(1,"MatSolveAdd:Unfactored matrix");
765 
766   PLogEventBegin(MAT_SolveAdd,mat,b,x,y);
767   if (mat->ops.solveadd)  {
768     ierr = (*mat->ops.solveadd)(mat,b,y,x); CHKERRQ(ierr);
769   }
770   else {
771     /* do the solve then the add manually */
772     if (x != y) {
773       ierr = MatSolve(mat,b,x); CHKERRQ(ierr);
774       ierr = VecAXPY(&one,y,x); CHKERRQ(ierr);
775     }
776     else {
777       ierr = VecDuplicate(x,&tmp); CHKERRQ(ierr);
778       PLogObjectParent(mat,tmp);
779       ierr = VecCopy(x,tmp); CHKERRQ(ierr);
780       ierr = MatSolve(mat,b,x); CHKERRQ(ierr);
781       ierr = VecAXPY(&one,tmp,x); CHKERRQ(ierr);
782       ierr = VecDestroy(tmp); CHKERRQ(ierr);
783     }
784   }
785   PLogEventEnd(MAT_SolveAdd,mat,b,x,y);
786   return 0;
787 }
788 /*@
789    MatSolveTrans - Solves A' x = b, given a factored matrix.
790 
791    Input Parameters:
792 .  mat - the factored matrix
793 .  b - the right-hand-side vector
794 
795    Output Parameter:
796 .  x - the result vector
797 
798 .keywords: matrix, linear system, solve, LU, Cholesky, transpose
799 
800 .seealso: MatSolve(), MatSolveAdd(), MatSolveTransAdd()
801 @*/
802 int MatSolveTrans(Mat mat,Vec b,Vec x)
803 {
804   int ierr;
805   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
806   PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE);  PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE);
807   if (!mat->factor) SETERRQ(1,"MatSolveTrans:Unfactored matrix");
808   if (x == b) SETERRQ(1,"MatSolveTrans:x and b must be different vectors");
809   if (!mat->ops.solvetrans) SETERRQ(PETSC_ERR_SUP,"MatSolveTrans");
810 
811   PLogEventBegin(MAT_SolveTrans,mat,b,x,0);
812   ierr = (*mat->ops.solvetrans)(mat,b,x); CHKERRQ(ierr);
813   PLogEventEnd(MAT_SolveTrans,mat,b,x,0);
814   return 0;
815 }
816 /*@
817    MatSolveTransAdd - Computes x = y + inv(trans(A)) b, given a
818                       factored matrix.
819 
820    Input Parameters:
821 .  mat - the factored matrix
822 .  b - the right-hand-side vector
823 .  y - the vector to be added to
824 
825    Output Parameter:
826 .  x - the result vector
827 
828 .keywords: matrix, linear system, solve, LU, Cholesky, transpose, add
829 
830 .seealso: MatSolve(), MatSolveAdd(), MatSolveTrans()
831 @*/
832 int MatSolveTransAdd(Mat mat,Vec b,Vec y,Vec x)
833 {
834   Scalar one = 1.0;
835   int    ierr;
836   Vec    tmp;
837   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);PETSCVALIDHEADERSPECIFIC(y,VEC_COOKIE);
838   PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE);  PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE);
839   if (x == b) SETERRQ(1,"MatSolveTransAdd:x and b must be different vectors");
840   if (!mat->factor) SETERRQ(1,"MatSolveTransAdd:Unfactored matrix");
841 
842   PLogEventBegin(MAT_SolveTransAdd,mat,b,x,y);
843   if (mat->ops.solvetransadd) {
844     ierr = (*mat->ops.solvetransadd)(mat,b,y,x); CHKERRQ(ierr);
845   }
846   else {
847     /* do the solve then the add manually */
848     if (x != y) {
849       ierr = MatSolveTrans(mat,b,x); CHKERRQ(ierr);
850       ierr = VecAXPY(&one,y,x); CHKERRQ(ierr);
851     }
852     else {
853       ierr = VecDuplicate(x,&tmp); CHKERRQ(ierr);
854       PLogObjectParent(mat,tmp);
855       ierr = VecCopy(x,tmp); CHKERRQ(ierr);
856       ierr = MatSolveTrans(mat,b,x); CHKERRQ(ierr);
857       ierr = VecAXPY(&one,tmp,x); CHKERRQ(ierr);
858       ierr = VecDestroy(tmp); CHKERRQ(ierr);
859     }
860   }
861   PLogEventEnd(MAT_SolveTransAdd,mat,b,x,y);
862   return 0;
863 }
864 /* ----------------------------------------------------------------*/
865 
866 /*@
867    MatRelax - Computes one relaxation sweep.
868 
869    Input Parameters:
870 .  mat - the matrix
871 .  b - the right hand side
872 .  omega - the relaxation factor
873 .  flag - flag indicating the type of SOR, one of
874 $     SOR_FORWARD_SWEEP
875 $     SOR_BACKWARD_SWEEP
876 $     SOR_SYMMETRIC_SWEEP (SSOR method)
877 $     SOR_LOCAL_FORWARD_SWEEP
878 $     SOR_LOCAL_BACKWARD_SWEEP
879 $     SOR_LOCAL_SYMMETRIC_SWEEP (local SSOR)
880 $     SOR_APPLY_UPPER, SOR_APPLY_LOWER - applies
881 $       upper/lower triangular part of matrix to
882 $       vector (with omega)
883 $     SOR_ZERO_INITIAL_GUESS - zero initial guess
884 .  shift -  diagonal shift
885 .  its - the number of iterations
886 
887    Output Parameters:
888 .  x - the solution (can contain an initial guess)
889 
890    Notes:
891    SOR_LOCAL_FORWARD_SWEEP, SOR_LOCAL_BACKWARD_SWEEP, and
892    SOR_LOCAL_SYMMETRIC_SWEEP perform seperate independent smoothings
893    on each processor.
894 
895    Application programmers will not generally use MatRelax() directly,
896    but instead will employ the SLES/PC interface.
897 
898    Notes for Advanced Users:
899    The flags are implemented as bitwise inclusive or operations.
900    For example, use (SOR_ZERO_INITIAL_GUESS | SOR_SYMMETRIC_SWEEP)
901    to specify a zero initial guess for SSOR.
902 
903 .keywords: matrix, relax, relaxation, sweep
904 @*/
905 int MatRelax(Mat mat,Vec b,double omega,MatSORType flag,double shift,
906              int its,Vec x)
907 {
908   int ierr;
909   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
910   PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE);  PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE);
911   if (!mat->ops.relax) SETERRQ(PETSC_ERR_SUP,"MatRelax");
912   if (!mat->assembled) SETERRQ(1,"MatRelax:Not for unassembled matrix");
913 
914   PLogEventBegin(MAT_Relax,mat,b,x,0);
915   ierr =(*mat->ops.relax)(mat,b,omega,flag,shift,its,x); CHKERRQ(ierr);
916   PLogEventEnd(MAT_Relax,mat,b,x,0);
917   return 0;
918 }
919 
920 /*
921       Default matrix copy routine.
922 */
923 int MatCopy_Basic(Mat A,Mat B)
924 {
925   int    ierr,i,rstart,rend,nz,*cwork;
926   Scalar *vwork;
927 
928   ierr = MatZeroEntries(B); CHKERRQ(ierr);
929   ierr = MatGetOwnershipRange(A,&rstart,&rend); CHKERRQ(ierr);
930   for (i=rstart; i<rend; i++) {
931     ierr = MatGetRow(A,i,&nz,&cwork,&vwork); CHKERRQ(ierr);
932     ierr = MatSetValues(B,1,&i,nz,cwork,vwork,INSERT_VALUES); CHKERRQ(ierr);
933     ierr = MatRestoreRow(A,i,&nz,&cwork,&vwork); CHKERRQ(ierr);
934   }
935   ierr = MatAssemblyBegin(B,FINAL_ASSEMBLY); CHKERRQ(ierr);
936   ierr = MatAssemblyEnd(B,FINAL_ASSEMBLY); CHKERRQ(ierr);
937   return 0;
938 }
939 
940 /*@C
941    MatCopy - Copys a matrix to another matrix.
942 
943    Input Parameters:
944 .  A - the matrix
945 
946    Output Parameter:
947 .  B - where the copy is put
948 
949    Notes:
950    MatCopy() copies the matrix entries of a matrix to another existing
951    matrix (after first zeroing the second matrix).  A related routine is
952    MatConvert(), which first creates a new matrix and then copies the data.
953 
954 .keywords: matrix, copy, convert
955 
956 .seealso: MatConvert()
957 @*/
958 int MatCopy(Mat A,Mat B)
959 {
960   int ierr;
961   PETSCVALIDHEADERSPECIFIC(A,MAT_COOKIE);PETSCVALIDHEADERSPECIFIC(B,MAT_COOKIE);
962   if (!A->assembled) SETERRQ(1,"MatCopy:Not for unassembled matrix");
963 
964   PLogEventBegin(MAT_Copy,A,B,0,0);
965   if (A->ops.copy) {
966     ierr = (*A->ops.copy)(A,B); CHKERRQ(ierr);
967   }
968   else { /* generic conversion */
969     ierr = MatCopy_Basic(A,B); CHKERRQ(ierr);
970   }
971   PLogEventEnd(MAT_Copy,A,B,0,0);
972   return 0;
973 }
974 
975 /*@C
976    MatConvert - Converts a matrix to another matrix, either of the same
977    or different type.
978 
979    Input Parameters:
980 .  mat - the matrix
981 .  newtype - new matrix type.  Use MATSAME to create a new matrix of the
982    same type as the original matrix.
983 
984    Output Parameter:
985 .  M - pointer to place new matrix
986 
987    Notes:
988    MatConvert() first creates a new matrix and then copies the data from
989    the first matrix.  A related routine is MatCopy(), which copies the matrix
990    entries of one matrix to another already existing matrix context.
991 
992 .keywords: matrix, copy, convert
993 
994 .seealso: MatCopy()
995 @*/
996 int MatConvert(Mat mat,MatType newtype,Mat *M)
997 {
998   int ierr;
999   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1000   if (!M) SETERRQ(1,"MatConvert:Bad new matrix address");
1001   if (!mat->assembled) SETERRQ(1,"MatConvert:Not for unassembled matrix");
1002 
1003   PLogEventBegin(MAT_Convert,mat,0,0,0);
1004   if (newtype == mat->type || newtype == MATSAME) {
1005     if (mat->ops.convertsametype) { /* customized copy */
1006       ierr = (*mat->ops.convertsametype)(mat,M,COPY_VALUES); CHKERRQ(ierr);
1007     }
1008   }
1009   else if (mat->ops.convert) { /* customized conversion */
1010     ierr = (*mat->ops.convert)(mat,newtype,M); CHKERRQ(ierr);
1011   }
1012   else { /* generic conversion */
1013     ierr = MatConvert_Basic(mat,newtype,M); CHKERRQ(ierr);
1014   }
1015   PLogEventEnd(MAT_Convert,mat,0,0,0);
1016   return 0;
1017 }
1018 
1019 /*@
1020    MatGetDiagonal - Gets the diagonal of a matrix.
1021 
1022    Input Parameters:
1023 .  mat - the matrix
1024 
1025    Output Parameters:
1026 .  v - the vector for storing the diagonal
1027 
1028 .keywords: matrix, get, diagonal
1029 @*/
1030 int MatGetDiagonal(Mat mat,Vec v)
1031 {
1032   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);PETSCVALIDHEADERSPECIFIC(v,VEC_COOKIE);
1033   if (!mat->assembled) SETERRQ(1,"MatGetDiagonal:Not for unassembled matrix");
1034   if (mat->ops.getdiagonal) return (*mat->ops.getdiagonal)(mat,v);
1035   SETERRQ(PETSC_ERR_SUP,"MatGetDiagonal");
1036 }
1037 
1038 /*@C
1039    MatTranspose - Computes an in-place or out-of-place transpose of a matrix.
1040 
1041    Input Parameters:
1042 .  mat - the matrix to transpose
1043 
1044    Output Parameters:
1045 .   B - the transpose -  pass in zero for an in-place transpose
1046 
1047 .keywords: matrix, transpose
1048 @*/
1049 int MatTranspose(Mat mat,Mat *B)
1050 {
1051   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1052   if (!mat->assembled) SETERRQ(1,"MatTranspose:Not for unassembled matrix");
1053   if (mat->ops.transpose) return (*mat->ops.transpose)(mat,B);
1054   SETERRQ(PETSC_ERR_SUP,"MatTranspose");
1055 }
1056 
1057 /*@
1058    MatEqual - Compares two matrices.  Returns 1 if two matrices are equal.
1059 
1060    Input Parameters:
1061 .  mat1 - the first matrix
1062 .  mat2 - the second matrix
1063 
1064    Returns:
1065    Returns 1 if the matrices are equal; returns 0 otherwise.
1066 
1067 .keywords: matrix, equal, equivalent
1068 @*/
1069 int MatEqual(Mat mat1,Mat mat2)
1070 {
1071   PETSCVALIDHEADERSPECIFIC(mat1,MAT_COOKIE); PETSCVALIDHEADERSPECIFIC(mat2,MAT_COOKIE);
1072   if (!mat1->assembled) SETERRQ(1,"MatEqual:Not for unassembled matrix");
1073   if (!mat2->assembled) SETERRQ(1,"MatEqual:Not for unassembled matrix");
1074   if (mat1->ops.equal) return (*mat1->ops.equal)(mat1,mat2);
1075   SETERRQ(PETSC_ERR_SUP,"MatEqual");
1076 }
1077 
1078 /*@
1079    MatDiagonalScale - Scales a matrix on the left and right by diagonal
1080    matrices that are stored as vectors.  Either of the two scaling
1081    matrices can be null.
1082 
1083    Input Parameters:
1084 .  mat - the matrix to be scaled
1085 .  l - the left scaling vector
1086 .  r - the right scaling vector
1087 
1088 .keywords: matrix, scale
1089 @*/
1090 int MatDiagonalScale(Mat mat,Vec l,Vec r)
1091 {
1092   int ierr;
1093   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1094   if (!mat->ops.scale) SETERRQ(PETSC_ERR_SUP,"MatDiagonalScale");
1095   if (l) PETSCVALIDHEADERSPECIFIC(l,VEC_COOKIE);
1096   if (r) PETSCVALIDHEADERSPECIFIC(r,VEC_COOKIE);
1097   if (!mat->assembled) SETERRQ(1,"MatDiagonalScale:Not for unassembled matrix");
1098 
1099   PLogEventBegin(MAT_Scale,mat,0,0,0);
1100   ierr = (*mat->ops.diagonalscale)(mat,l,r); CHKERRQ(ierr);
1101   PLogEventEnd(MAT_Scale,mat,0,0,0);
1102   return 0;
1103 }
1104 
1105 /*@
1106    MatScale - Scales a matrix by a number.
1107 
1108    Input Parameters:
1109 .  mat - the matrix to be scaled
1110 .   a  - the number
1111 
1112    Note: the name of this routine MUST change.
1113 .keywords: matrix, scale
1114 @*/
1115 int MatScale(Scalar *a,Mat mat)
1116 {
1117   int ierr;
1118   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1119   if (!mat->ops.scale) SETERRQ(PETSC_ERR_SUP,"MatScale");
1120   if (!mat->assembled) SETERRQ(1,"MatScale:Not for unassembled matrix");
1121 
1122   PLogEventBegin(MAT_Scale,mat,0,0,0);
1123   ierr = (*mat->ops.scale)(a,mat); CHKERRQ(ierr);
1124   PLogEventEnd(MAT_Scale,mat,0,0,0);
1125   return 0;
1126 }
1127 
1128 /*@
1129    MatNorm - Calculates various norms of a matrix.
1130 
1131    Input Parameters:
1132 .  mat - the matrix
1133 .  type - the type of norm, NORM_1, NORM_2, NORM_FROBENIUS, NORM_INFINITY
1134 
1135    Output Parameters:
1136 .  norm - the resulting norm
1137 
1138 .keywords: matrix, norm, Frobenius
1139 @*/
1140 int MatNorm(Mat mat,NormType type,double *norm)
1141 {
1142   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1143   if (!norm) SETERRQ(1,"MatNorm:bad addess for value");
1144   if (!mat->assembled) SETERRQ(1,"MatNorm:Not for unassembled matrix");
1145   if (mat->ops.norm) return (*mat->ops.norm)(mat,type,norm);
1146   SETERRQ(PETSC_ERR_SUP,"MatNorm:Not for this matrix type");
1147 }
1148 
1149 /*@
1150    MatAssemblyBegin - Begins assembling the matrix.  This routine should
1151    be called after completing all calls to MatSetValues().
1152 
1153    Input Parameters:
1154 .  mat - the matrix
1155 .  type - type of assembly, either FLUSH_ASSEMBLY or FINAL_ASSEMBLY
1156 
1157    Notes:
1158    MatSetValues() generally caches the values.  The matrix is ready to
1159    use only after MatAssemblyBegin() and MatAssemblyEnd() have been called.
1160    Use FLUSH_ASSEMBLY when switching between ADD_VALUES and SetValues; use
1161    FINAL_ASSEMBLY for the final assembly before the matrix is used.
1162 
1163 .keywords: matrix, assembly, assemble, begin
1164 
1165 .seealso: MatAssemblyEnd(), MatSetValues()
1166 @*/
1167 int MatAssemblyBegin(Mat mat,MatAssemblyType type)
1168 {
1169   int ierr;
1170   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1171   PLogEventBegin(MAT_AssemblyBegin,mat,0,0,0);
1172   if (mat->ops.assemblybegin) {ierr = (*mat->ops.assemblybegin)(mat,type); CHKERRQ(ierr);}
1173   PLogEventEnd(MAT_AssemblyBegin,mat,0,0,0);
1174   return 0;
1175 }
1176 
1177 /*@
1178    MatAssemblyEnd - Completes assembling the matrix.  This routine should
1179    be called after all calls to MatSetValues() and after MatAssemblyBegin().
1180 
1181    Input Parameters:
1182 .  mat - the matrix
1183 .  type - type of assembly, either FLUSH_ASSEMBLY or FINAL_ASSEMBLY
1184 
1185    Options Database Keys:
1186 $  -mat_view_draw : Draw nonzero structure of matrix at conclusion of MatEndAssembly(),
1187                using MatView() and DrawOpenX().
1188 $  -mat_view_info : Prints info on matrix.
1189 $  -mat_view_info_detailed: More detailed information.
1190 $  -mat_view_ascii : Prints matrix out in ascii.
1191 $  -display <name> : Set display name (default is host)
1192 $  -draw_pause <sec> : Set number of seconds to pause after display
1193 
1194    Note:
1195    MatSetValues() generally caches the values.  The matrix is ready to
1196    use only after MatAssemblyBegin() and MatAssemblyEnd() have been called.
1197    Use FLUSH_ASSEMBLY when switching between ADD_VALUES and SetValues; use
1198    FINAL_ASSEMBLY for the final assembly before the matrix is used.
1199 
1200 .keywords: matrix, assembly, assemble, end
1201 
1202 .seealso: MatAssemblyBegin(), MatSetValues()
1203 @*/
1204 int MatAssemblyEnd(Mat mat,MatAssemblyType type)
1205 {
1206   int        ierr,flg;
1207   static int inassm = 0;
1208 
1209   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1210   inassm++;
1211   PLogEventBegin(MAT_AssemblyEnd,mat,0,0,0);
1212   if (mat->ops.assemblyend) {ierr = (*mat->ops.assemblyend)(mat,type); CHKERRQ(ierr);}
1213   mat->assembled = PETSC_TRUE; mat->num_ass++;
1214   PLogEventEnd(MAT_AssemblyEnd,mat,0,0,0);
1215 
1216   if (inassm == 1) {
1217     ierr = OptionsHasName(PETSC_NULL,"-mat_view_info",&flg); CHKERRQ(ierr);
1218     if (flg) {
1219       Viewer viewer;
1220       ierr = ViewerFileOpenASCII(mat->comm,"stdout",&viewer);CHKERRQ(ierr);
1221       ierr = ViewerFileSetFormat(viewer,FILE_FORMAT_INFO,0);CHKERRQ(ierr);
1222       ierr = MatView(mat,viewer); CHKERRQ(ierr);
1223       ierr = ViewerDestroy(viewer); CHKERRQ(ierr);
1224     }
1225     ierr = OptionsHasName(PETSC_NULL,"-mat_view_info_detailed",&flg); CHKERRQ(ierr);
1226     if (flg) {
1227       Viewer viewer;
1228       ierr = ViewerFileOpenASCII(mat->comm,"stdout",&viewer);CHKERRQ(ierr);
1229       ierr = ViewerFileSetFormat(viewer,FILE_FORMAT_INFO_DETAILED,0);CHKERRQ(ierr);
1230       ierr = MatView(mat,viewer); CHKERRQ(ierr);
1231       ierr = ViewerDestroy(viewer); CHKERRQ(ierr);
1232     }
1233     ierr = OptionsHasName(PETSC_NULL,"-mat_view_draw",&flg); CHKERRQ(ierr);
1234     if (flg) {
1235       Draw    win;
1236       ierr = DrawOpenX(mat->comm,0,0,0,0,300,300,&win); CHKERRQ(ierr);
1237       ierr = MatView(mat,(Viewer)win); CHKERRQ(ierr);
1238       ierr = DrawSyncFlush(win); CHKERRQ(ierr);
1239       ierr = DrawDestroy(win); CHKERRQ(ierr);
1240     }
1241   }
1242   inassm--;
1243   return 0;
1244 }
1245 
1246 /*@
1247    MatCompress - Tries to store the matrix in as little space as
1248    possible.  May fail if memory is already fully used, since it
1249    tries to allocate new space.
1250 
1251    Input Parameters:
1252 .  mat - the matrix
1253 
1254 .keywords: matrix, compress
1255 @*/
1256 int MatCompress(Mat mat)
1257 {
1258   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1259   if (mat->ops.compress) return (*mat->ops.compress)(mat);
1260   return 0;
1261 }
1262 /*@
1263    MatSetOption - Sets a parameter option for a matrix. Some options
1264    may be specific to certain storage formats.  Some options
1265    determine how values will be inserted (or added). Sorted,
1266    row-oriented input will generally assemble the fastest. The default
1267    is row-oriented, nonsorted input.
1268 
1269    Input Parameters:
1270 .  mat - the matrix
1271 .  option - the option, one of the following:
1272 $    ROW_ORIENTED
1273 $    COLUMN_ORIENTED,
1274 $    ROWS_SORTED,
1275 $    COLUMNS_SORTED,
1276 $    NO_NEW_NONZERO_LOCATIONS,
1277 $    YES_NEW_NONZERO_LOCATIONS,
1278 $    SYMMETRIC_MATRIX,
1279 $    STRUCTURALLY_SYMMETRIC_MATRIX,
1280 $    NO_NEW_DIAGONALS,
1281 $    YES_NEW_DIAGONALS,
1282 $    and possibly others.
1283 
1284    Notes:
1285    Some options are relevant only for particular matrix types and
1286    are thus ignored by others.  Other options are not supported by
1287    certain matrix types and will generate an error message if set.
1288 
1289    If using a Fortran 77 module to compute a matrix, one may need to
1290    use the column-oriented option (or convert to the row-oriented
1291    format).
1292 
1293    NO_NEW_NONZERO_LOCATIONS indicates that any add or insertion
1294    that will generate a new entry in the nonzero structure is ignored.
1295    What this means is if memory is not allocated for this particular
1296    lot, then the insertion is ignored. For dense matrices, where
1297    the entire array is allocated, no entries are ever ignored.
1298 
1299 .keywords: matrix, option, row-oriented, column-oriented, sorted, nonzero
1300 @*/
1301 int MatSetOption(Mat mat,MatOption op)
1302 {
1303   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1304   if (mat->ops.setoption) return (*mat->ops.setoption)(mat,op);
1305   return 0;
1306 }
1307 
1308 /*@
1309    MatZeroEntries - Zeros all entries of a matrix.  For sparse matrices
1310    this routine retains the old nonzero structure.
1311 
1312    Input Parameters:
1313 .  mat - the matrix
1314 
1315 .keywords: matrix, zero, entries
1316 
1317 .seealso: MatZeroRows()
1318 @*/
1319 int MatZeroEntries(Mat mat)
1320 {
1321   int ierr;
1322   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1323   if (!mat->ops.zeroentries) SETERRQ(PETSC_ERR_SUP,"MatZeroEntries");
1324 
1325   PLogEventBegin(MAT_ZeroEntries,mat,0,0,0);
1326   ierr = (*mat->ops.zeroentries)(mat); CHKERRQ(ierr);
1327   PLogEventEnd(MAT_ZeroEntries,mat,0,0,0);
1328   return 0;
1329 }
1330 
1331 /*@
1332    MatZeroRows - Zeros all entries (except possibly the main diagonal)
1333    of a set of rows of a matrix.
1334 
1335    Input Parameters:
1336 .  mat - the matrix
1337 .  is - index set of rows to remove
1338 .  diag - pointer to value put in all diagonals of eliminated rows.
1339           Note that diag is not a pointer to an array, but merely a
1340           pointer to a single value.
1341 
1342    Notes:
1343    For the AIJ matrix formats this removes the old nonzero structure,
1344    but does not release memory.  For the dense and block diagonal
1345    formats this does not alter the nonzero structure.
1346 
1347    The user can set a value in the diagonal entry (or for the AIJ and
1348    row formats can optionally remove the main diagonal entry from the
1349    nonzero structure as well, by passing a null pointer as the final
1350    argument).
1351 
1352 .keywords: matrix, zero, rows, boundary conditions
1353 
1354 .seealso: MatZeroEntries(), MatGetSubMatrix(), MatGetSubMatrixInPlace()
1355 @*/
1356 int MatZeroRows(Mat mat,IS is, Scalar *diag)
1357 {
1358   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1359   if (!mat->assembled) SETERRQ(1,"MatZeroRows:Not for unassembled matrix");
1360   if (mat->ops.zerorows) return (*mat->ops.zerorows)(mat,is,diag);
1361   SETERRQ(PETSC_ERR_SUP,"MatZeroRows");
1362 }
1363 
1364 /*@
1365    MatGetSize - Returns the numbers of rows and columns in a matrix.
1366 
1367    Input Parameter:
1368 .  mat - the matrix
1369 
1370    Output Parameters:
1371 .  m - the number of global rows
1372 .  n - the number of global columns
1373 
1374 .keywords: matrix, dimension, size, rows, columns, global, get
1375 
1376 .seealso: MatGetLocalSize()
1377 @*/
1378 int MatGetSize(Mat mat,int *m,int* n)
1379 {
1380   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1381   if (!m || !n) SETERRQ(1,"MatGetSize:Bad address for result");
1382   return (*mat->ops.getsize)(mat,m,n);
1383 }
1384 
1385 /*@
1386    MatGetLocalSize - Returns the number of rows and columns in a matrix
1387    stored locally.  This information may be implementation dependent, so
1388    use with care.
1389 
1390    Input Parameters:
1391 .  mat - the matrix
1392 
1393    Output Parameters:
1394 .  m - the number of local rows
1395 .  n - the number of local columns
1396 
1397 .keywords: matrix, dimension, size, local, rows, columns, get
1398 
1399 .seealso: MatGetSize()
1400 @*/
1401 int MatGetLocalSize(Mat mat,int *m,int* n)
1402 {
1403   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1404   if (!m || !n) SETERRQ(1,"MatGetLocalSize:Bad address for result");
1405   return (*mat->ops.getlocalsize)(mat,m,n);
1406 }
1407 
1408 /*@
1409    MatGetOwnershipRange - Returns the range of matrix rows owned by
1410    this processor, assuming that the matrix is laid out with the first
1411    n1 rows on the first processor, the next n2 rows on the second, etc.
1412    For certain parallel layouts this range may not be well-defined.
1413 
1414    Input Parameters:
1415 .  mat - the matrix
1416 
1417    Output Parameters:
1418 .  m - the first local row
1419 .  n - one more then the last local row
1420 
1421 .keywords: matrix, get, range, ownership
1422 @*/
1423 int MatGetOwnershipRange(Mat mat,int *m,int* n)
1424 {
1425   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1426   if (!m || !n) SETERRQ(1,"MatGetOwnershipRange:Bad address for result");
1427   if (mat->ops.getownershiprange) return (*mat->ops.getownershiprange)(mat,m,n);
1428   SETERRQ(PETSC_ERR_SUP,"MatGetOwnershipRange");
1429 }
1430 
1431 /*@
1432    MatILUFactorSymbolic - Performs symbolic ILU factorization of a matrix.
1433    Uses levels of fill only, not drop tolerance. Use MatLUFactorNumeric()
1434    to complete the factorization.
1435 
1436    Input Parameters:
1437 .  mat - the matrix
1438 .  row - row permutation
1439 .  column - column permutation
1440 .  fill - number of levels of fill
1441 .  f - expected fill as ratio of original fill
1442 
1443    Output Parameters:
1444 .  fact - puts factor
1445 
1446 .keywords: matrix, factor, incomplete, ILU, symbolic, fill
1447 
1448 .seealso: MatLUFactorSymbolic(), MatLUFactorNumeric()
1449 @*/
1450 int MatILUFactorSymbolic(Mat mat,IS row,IS col,double f,int fill,Mat *fact)
1451 {
1452   int ierr,flg;
1453 
1454   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1455   if (fill < 0) SETERRQ(1,"MatILUFactorSymbolic:Levels of fill negative");
1456   if (!fact) SETERRQ(1,"MatILUFactorSymbolic:Fact argument is missing");
1457   if (!mat->ops.ilufactorsymbolic) SETERRQ(PETSC_ERR_SUP,"MatILUFactorSymbolic");
1458   if (!mat->assembled) SETERRQ(1,"MatILUFactorSymbolic:Not for unassembled matrix");
1459 
1460   ierr = OptionsGetDouble(PETSC_NULL,"-mat_ilu_fill",&f,&flg); CHKERRQ(ierr);
1461   PLogEventBegin(MAT_ILUFactorSymbolic,mat,row,col,0);
1462   ierr = (*mat->ops.ilufactorsymbolic)(mat,row,col,f,fill,fact); CHKERRQ(ierr);
1463   PLogEventEnd(MAT_ILUFactorSymbolic,mat,row,col,0);
1464   return 0;
1465 }
1466 
1467 /*@
1468    MatIncompleteCholeskyFactorSymbolic - Performs symbolic incomplete
1469    Cholesky factorization for a symmetric matrix.  Use
1470    MatCholeskyFactorNumeric() to complete the factorization.
1471 
1472    Input Parameters:
1473 .  mat - the matrix
1474 .  perm - row and column permutation
1475 .  fill - levels of fill
1476 .  f - expected fill as ratio of original fill
1477 
1478    Output Parameter:
1479 .  fact - the factored matrix
1480 
1481    Note:  Currently only no-fill factorization is supported.
1482 
1483 .keywords: matrix, factor, incomplete, ICC, Cholesky, symbolic, fill
1484 
1485 .seealso: MatCholeskyFactorNumeric(), MatCholeskyFactor()
1486 @*/
1487 int MatIncompleteCholeskyFactorSymbolic(Mat mat,IS perm,double f,int fill,
1488                                         Mat *fact)
1489 {
1490   int ierr;
1491   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1492   if (fill < 0) SETERRQ(1,"MatIncompleteCholeskyFactorSymbolic:Fill negative");
1493   if (!fact) SETERRQ(1,"MatIncompleteCholeskyFactorSymbolic:Missing fact argument");
1494   if (!mat->ops.incompletecholeskyfactorsymbolic)
1495      SETERRQ(PETSC_ERR_SUP,"MatIncompleteCholeskyFactorSymbolic");
1496   if (!mat->assembled)
1497      SETERRQ(1,"MatIncompleteCholeskyFactorSymbolic:Not for unassembled matrix");
1498 
1499   PLogEventBegin(MAT_IncompleteCholeskyFactorSymbolic,mat,perm,0,0);
1500   ierr = (*mat->ops.incompletecholeskyfactorsymbolic)(mat,perm,f,fill,fact);CHKERRQ(ierr);
1501   PLogEventEnd(MAT_IncompleteCholeskyFactorSymbolic,mat,perm,0,0);
1502   return 0;
1503 }
1504 
1505 /*@C
1506    MatGetArray - Returns a pointer to the element values in the matrix.
1507    This routine  is implementation dependent, and may not even work for
1508    certain matrix types.
1509 
1510    Input Parameter:
1511 .  mat - the matrix
1512 
1513    Output Parameter:
1514 .  v - the location of the values
1515 
1516    Fortran Note:
1517    The Fortran interface is slightly different from that given below.
1518    See the users manual and petsc/src/mat/examples for details.
1519 
1520 .keywords: matrix, array, elements, values
1521 @*/
1522 int MatGetArray(Mat mat,Scalar **v)
1523 {
1524   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1525   if (!v) SETERRQ(1,"MatGetArray:Bad input, array pointer location");
1526   if (!mat->ops.getarray) SETERRQ(PETSC_ERR_SUP,"MatGetArraye");
1527   return (*mat->ops.getarray)(mat,v);
1528 }
1529 
1530 /*@C
1531    MatGetSubMatrix - Extracts a submatrix from a matrix. If submat points
1532                      to a valid matrix, it may be reused.
1533 
1534    Input Parameters:
1535 .  mat - the matrix
1536 .  irow, icol - index sets of rows and columns to extract
1537 .  scall - either MAT_INITIAL_MATRIX or MAT_REUSE_MATRIX
1538 
1539    Output Parameter:
1540 .  submat - the submatrix
1541 
1542    Notes:
1543    MatGetSubMatrix() can be useful in setting boundary conditions.
1544 
1545    Use MatGetSubMatrices() to extract multiple submatrices.
1546 
1547 .keywords: matrix, get, submatrix, boundary conditions
1548 
1549 .seealso: MatZeroRows(), MatGetSubMatrixInPlace(), MatGetSubMatrices()
1550 @*/
1551 int MatGetSubMatrix(Mat mat,IS irow,IS icol,MatGetSubMatrixCall scall,Mat *submat)
1552 {
1553   int ierr;
1554   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1555   if (scall == MAT_REUSE_MATRIX) {
1556     PETSCVALIDHEADERSPECIFIC(*submat,MAT_COOKIE);
1557   }
1558   if (!mat->ops.getsubmatrix) SETERRQ(PETSC_ERR_SUP,"MatGetSubMatrix");
1559   if (!mat->assembled) SETERRQ(1,"MatGetSubMatrix:Not for unassembled matrix");
1560 
1561   PLogEventBegin(MAT_GetSubMatrix,mat,irow,icol,0);
1562   ierr = (*mat->ops.getsubmatrix)(mat,irow,icol,scall,submat); CHKERRQ(ierr);
1563   PLogEventEnd(MAT_GetSubMatrix,mat,irow,icol,0);
1564   return 0;
1565 }
1566 
1567 /*@C
1568    MatGetSubMatrices - Extracts several submatrices from a matrix. If submat
1569    points to an array of valid matrices, it may be reused.
1570 
1571    Input Parameters:
1572 .  mat - the matrix
1573 .  irow, icol - index sets of rows and columns to extract
1574 
1575    Output Parameter:
1576 .  submat - the submatrices
1577 
1578    Note:
1579    Use MatGetSubMatrix() for extracting a sinble submatrix.
1580 
1581 .keywords: matrix, get, submatrix, submatrices
1582 
1583 .seealso: MatGetSubMatrix()
1584 @*/
1585 int MatGetSubMatrices(Mat mat,int n, IS *irow,IS *icol,MatGetSubMatrixCall scall,
1586                       Mat **submat)
1587 {
1588   int ierr;
1589   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1590   if (!mat->ops.getsubmatrices) SETERRQ(PETSC_ERR_SUP,"MatGetSubMatrices");
1591   if (!mat->assembled) SETERRQ(1,"MatGetSubMatrices:Not for unassembled matrix");
1592 
1593   PLogEventBegin(MAT_GetSubMatrices,mat,0,0,0);
1594   ierr = (*mat->ops.getsubmatrices)(mat,n,irow,icol,scall,submat); CHKERRQ(ierr);
1595   PLogEventEnd(MAT_GetSubMatrices,mat,0,0,0);
1596   return 0;
1597 }
1598 
1599 /*@
1600    MatGetSubMatrixInPlace - Extracts a submatrix from a matrix, returning
1601    the submatrix in place of the original matrix.
1602 
1603    Input Parameters:
1604 .  mat - the matrix
1605 .  irow, icol - index sets of rows and columns to extract
1606 
1607 .keywords: matrix, get, submatrix, boundary conditions, in-place
1608 
1609 .seealso: MatZeroRows(), MatGetSubMatrix()
1610 @*/
1611 int MatGetSubMatrixInPlace(Mat mat,IS irow,IS icol)
1612 {
1613   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1614   if (!mat->assembled) SETERRQ(1,"MatGetSubMatrixInPlace:Not for unassembled matrix");
1615 
1616   if (!mat->ops.getsubmatrixinplace) SETERRQ(PETSC_ERR_SUP,"MatGetSubmatrixInPlace");
1617   return (*mat->ops.getsubmatrixinplace)(mat,irow,icol);
1618 }
1619 
1620 /*@
1621    MatIncreaseOverlap - Given a set of submatrices indicated by index sets,
1622    replaces the index by larger ones that represent submatrices with more
1623    overlap.
1624 
1625    Input Parameters:
1626 .  mat - the matrix
1627 .  n   - the number of index sets
1628 .  is  - the array of pointers to index sets
1629 .  ov  - the additional overlap requested
1630 
1631 .keywords: matrix, overlap, Schwarz
1632 
1633 .seealso: MatGetSubMatrices()
1634 @*/
1635 int MatIncreaseOverlap(Mat mat,int n, IS *is, int ov)
1636 {
1637   int ierr;
1638   PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);
1639   if (!mat->assembled) SETERRQ(1,"MatIncreaseOverlap:Not for unassembled matrix");
1640 
1641   if (ov == 0) return 0;
1642   if (!mat->ops.increaseoverlap) SETERRQ(PETSC_ERR_SUP,"MatIncreaseOverlap");
1643   ierr = (*mat->ops.increaseoverlap)(mat,n,is,ov); CHKERRQ(ierr);
1644   return 0;
1645 }
1646 
1647 /*@
1648    MatPrintHelp - Prints all the options for the matrix.
1649 
1650    Input Parameter:
1651 .  mat - the matrix
1652 
1653    Options Database Keys:
1654 $  -help, -h
1655 
1656 .keywords: mat, help
1657 
1658 .seealso: MatCreate(), MatCreateXXX()
1659 @*/
1660 int MatPrintHelp(Mat mat)
1661 {
1662   static int called = 0;
1663   MPI_Comm   comm = mat->comm;
1664 
1665   if (!called) {
1666     MPIU_printf(comm,"General matrix options:\n");
1667     MPIU_printf(comm,"  -mat_view_info : view basic matrix info during MatAssemblyEnd()\n");
1668     MPIU_printf(comm,"  -mat_view_info_detailed : view detailed matrix info during MatAssemblyEnd()\n");
1669     MPIU_printf(comm,"  -mat_view_draw : draw nonzero matrix structure during MatAssemblyEnd()\n");
1670     MPIU_printf(comm,"      -draw_pause <sec> : set seconds of display pause\n");
1671     MPIU_printf(comm,"      -display <name> : set alternate display\n");
1672     called = 1;
1673   }
1674   if (mat->ops.printhelp) (*mat->ops.printhelp)(mat);
1675   return 0;
1676 }
1677 
1678