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