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