<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Lucida Console";
        panose-1:2 11 6 9 4 5 4 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hello PETSc team,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am currently using PETSc to improve the performance of a CFD solver by using it’s parallel linear solver. While doing so I ran across some scaling issues where performance increase ( measured as KSPSolve time using MPI_Wtime() function
 )  in the linear algebra operation was only 2 times while using 4 processes. So I tried to check the scaling of the example problem ex2f.F90 provided as a part of the PETSc package and ran across a similar issue there. Here is the issue, If I run the problem
 on 1000 x 1000 2-D, five-point stencil with the exact solution set to 1.0, the scaling is perfect. But as soon as I change the exact solution to random values by using the flag -random_exact_sol (generally between 0 and 1), the scaling takes a  major hit.
 I have not changed the example code apart from increasing problem size and adding the time stamps before and after KSPSolve. Could you please let me know what I am missing (or) doing wrong here ? And I was also wondering if PETSc had an option to print out
 the pre-conditioned matrix as changing the exact solution changes the RHS and hence might change the pre-conditioned matrix. I have provided below the exact code and the results from the 4 runs including the compilation part.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><u>Source Code: </u></b>(ex2f.F90 with time stamps and increased problem size)<o:p></o:p></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Description: Solves a linear system in parallel with KSP (Fortran code).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!               Also shows how to set a user-defined monitoring routine.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! -----------------------------------------------------------------------<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      program main<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">#include <petsc/finclude/petscksp.h><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      use petscksp<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      implicit none<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!                   Variable declarations<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Variables:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     ksp     - linear solver context<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     ksp      - Krylov subspace method context<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     pc       - preconditioner context<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     x, b, u  - approx solution, right-hand-side, exact solution vectors<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     A        - matrix that defines linear system<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     its      - iterations for convergence<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     norm     - norm of error in solution<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     rctx     - random number generator context<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Note that vectors are declared as PETSc "Vec" objects.  These vectors<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  are mathematical objects that contain more than just an array of<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  double precision numbers. I.e., vectors in PETSc are not just<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!        double precision x(*).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  However, local vector data can be easily accessed via VecGetArray().<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  See the Fortran section of the PETSc users manual for details.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscReal  norm,t1,t2<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscInt  i,j,II,JJ,m,n,its<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscInt  Istart,Iend,ione<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscErrorCode ierr<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscMPIInt     rank,size<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscBool   flg<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscScalar v,one,neg_one<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      Vec         x,b,u<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      Mat         A<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      KSP         ksp<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscRandom rctx<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscViewerAndFormat vf,vzero<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  These variables are not currently used.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      PC          pc<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      PCType      ptype<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      PetscReal tol<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Note: Any user-defined Fortran routines (such as MyKSPMonitor)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  MUST be declared as external.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      external MyKSPMonitor,MyKSPConverged<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!                 Beginning of program<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call PetscInitialize(PETSC_NULL_CHARACTER,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      if (ierr .ne. 0) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        print*,'Unable to initialize PETSc'<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        stop<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      m = 1000      
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      n = 1000<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      one  = 1.0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      neg_one = -1.0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      ione    = 1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-m',m,flg,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-n',n,flg,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MPI_Comm_size(PETSC_COMM_WORLD,size,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      Compute the matrix and right-hand-side vector that define<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      the linear system, Ax = b.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Create parallel matrix, specifying only its global dimensions.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  When using MatCreate(), the matrix format can be specified at<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  runtime. Also, the parallel partitioning of the matrix is<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  determined by PETSc at runtime.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MatCreate(PETSC_COMM_WORLD,A,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MatSetFromOptions(A,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MatSetUp(A,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Currently, all PETSc parallel matrix formats are partitioned by<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  contiguous chunks of rows across the processors.  Determine which<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  rows of the matrix are locally owned.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MatGetOwnershipRange(A,Istart,Iend,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Set matrix elements for the 2-D, five-point stencil in parallel.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!   - Each processor needs to insert only elements that it owns<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     locally (but any non-local elements will be sent to the<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     appropriate processor during matrix assembly).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!   - Always specify global row and columns of matrix entries.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!   - Note that MatSetValues() uses 0-based row and column numbers<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     in Fortran as well as in C.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     Note: this uses the less common natural ordering that orders first<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     all the unknowns for x = h then for x = 2h etc; Hence you see JH = II +- n<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     instead of JJ = II +- m as you might expect. The more standard ordering<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     would first do all variables for y = h, then y = 2h etc.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      do 10, II=Istart,Iend-1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        v = -1.0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        i = II/n<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        j = II - i*n<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        if (i.gt.0) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">          JJ = II - n<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">          call MatSetValues(A,ione,II,ione,JJ,v,INSERT_VALUES,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        if (i.lt.m-1) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">          JJ = II + n<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">          call MatSetValues(A,ione,II,ione,JJ,v,INSERT_VALUES,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        if (j.gt.0) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">          JJ = II - 1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">          call MatSetValues(A,ione,II,ione,JJ,v,INSERT_VALUES,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        if (j.lt.n-1) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">          JJ = II + 1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">          call MatSetValues(A,ione,II,ione,JJ,v,INSERT_VALUES,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        v = 4.0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        call  MatSetValues(A,ione,II,ione,II,v,INSERT_VALUES,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">10   continue<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Assemble matrix, using the 2-step process:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!       MatAssemblyBegin(), MatAssemblyEnd()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Computations can be done while messages are in transition,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  by placing code between these two statements.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Create parallel vectors.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!   - Here, the parallel partitioning of the vector is determined by<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     PETSc at runtime.  We could also specify the local dimensions<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     if desired -- or use the more general routine VecCreate().<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!   - When solving a linear system, the vectors and matrices MUST<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     be partitioned accordingly.  PETSc automatically generates<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     appropriately partitioned matrices and vectors when MatCreate()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     and VecCreate() are used with the same communicator.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!   - Note: We form 1 vector from scratch and then duplicate as needed.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call VecCreateMPI(PETSC_COMM_WORLD,PETSC_DECIDE,m*n,u,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call VecSetFromOptions(u,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call VecDuplicate(u,b,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call VecDuplicate(b,x,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Set exact solution; then compute right-hand-side vector.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  By default we use an exact solution of a vector with all<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  elements of 1.0;  Alternatively, using the runtime option<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  -random_sol forms a solution vector with random components.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call PetscOptionsHasName(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-random_exact_sol',flg,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      if (flg) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">         call PetscRandomCreate(PETSC_COMM_WORLD,rctx,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">         call PetscRandomSetFromOptions(rctx,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">         call VecSetRandom(u,rctx,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">         call PetscRandomDestroy(rctx,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      else<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">         call VecSet(u,one,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MatMult(A,u,b,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">                
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  View the exact solution vector if desired<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call PetscOptionsHasName(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-view_exact_sol',flg,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      if (flg) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">         call VecView(u,PETSC_VIEWER_STDOUT_WORLD,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!         Create the linear solver and set various options<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Create linear solver context<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call KSPCreate(PETSC_COMM_WORLD,ksp,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Set operators. Here the matrix that defines the linear system<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  also serves as the preconditioning matrix.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call KSPSetOperators(ksp,A,A,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Set linear solver defaults for this problem (optional).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!   - By extracting the KSP and PC contexts from the KSP context,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     we can then directly directly call any KSP and PC routines<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     to set various options.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!   - The following four statements are optional; all of these<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     parameters could alternatively be specified at runtime via<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     KSPSetFromOptions(). All of these defaults can be<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     overridden at runtime, as indicated below.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     We comment out this section of code since the Jacobi<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     preconditioner is not a good general default.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      call KSPGetPC(ksp,pc,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      ptype = PCJACOBI<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      call PCSetType(pc,ptype,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      tol = 1.e-7<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      call KSPSetTolerances(ksp,tol,PETSC_DEFAULT_REAL,PETSC_DEFAULT_REAL,PETSC_DEFAULT_INTEGER,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Set user-defined monitoring routine if desired<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call PetscOptionsHasName(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-my_ksp_monitor',flg,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      if (flg) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        vzero = 0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        call KSPMonitorSet(ksp,MyKSPMonitor,vzero,PETSC_NULL_FUNCTION,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     Also use the default KSP monitor routine showing how it may be used from Fortran<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        call PetscViewerAndFormatCreate(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_DEFAULT,vf,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        call KSPMonitorSet(ksp,KSPMonitorResidual,vf,PetscViewerAndFormatDestroy,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Set runtime options, e.g.,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      -ksp_type <type> -pc_type <type> -ksp_monitor -ksp_rtol <rtol><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  These options will override those specified above as long as<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  KSPSetFromOptions() is called _after_ any other customization<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  routines.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call KSPSetFromOptions(ksp,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Set convergence test routine if desired<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call PetscOptionsHasName(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-my_ksp_convergence',flg,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      if (flg) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        call KSPSetConvergenceTest(ksp,MyKSPConverged,0,PETSC_NULL_FUNCTION,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!                      Solve the linear system<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">                 t1 = MPI_Wtime()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call KSPSolve(ksp,b,x,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">                 t2 = MPI_Wtime()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">                 !x =A-1b<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!                     Check solution and clean up<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Check the error<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call VecAXPY(x,neg_one,u,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call VecNorm(x,NORM_2,norm,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call KSPGetIterationNumber(ksp,its,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      if (rank .eq. 0) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        if (norm .gt. 1.e-12) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">           write(6,100) norm,its<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        else<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">           write(6,110) its<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">                              write(6,111) t2 - t1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">  100 format('Norm of error ',e11.4,' iterations ',i5)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">  110 format('Norm of error < 1.e-12 iterations ',i5)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">  111 format('KSPSolve time: ',f10.3)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Free work space.  All PETSc objects should be destroyed when they<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  are no longer needed.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call KSPDestroy(ksp,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call VecDestroy(u,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call VecDestroy(x,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call VecDestroy(b,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MatDestroy(A,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Always call PetscFinalize() before exiting a program.  This routine<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!    - finalizes the PETSc libraries as well as MPI<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!    - provides summary and diagnostic information if certain runtime<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      options are chosen (e.g., -log_view).  See PetscFinalize()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      manpage for more information.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call PetscFinalize(ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      end<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! --------------------------------------------------------------<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  MyKSPMonitor - This is a user-defined routine for monitoring<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  the KSP iterative solvers.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Input Parameters:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!    ksp   - iterative context<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!    n     - iteration number<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!    rnorm - 2-norm (preconditioned) residual value (may be estimated)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!    dummy - optional user-defined monitor context (unused here)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      subroutine MyKSPMonitor(ksp,n,rnorm,dummy,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      use petscksp<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      implicit none<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      KSP              ksp<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      Vec              x<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscErrorCode ierr<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscInt n,dummy<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscMPIInt rank<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscReal rnorm<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Build the solution vector<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call KSPBuildSolution(ksp,PETSC_NULL_VEC,x,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Write the solution vector and residual norm to stdout<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!   - Note that the parallel viewer PETSC_VIEWER_STDOUT_WORLD<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     handles data from multiple processors so that the<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!     output is not jumbled.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      if (rank .eq. 0) write(6,100) n<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      call VecView(x,PETSC_VIEWER_STDOUT_WORLD,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      if (rank .eq. 0) write(6,200) n,rnorm<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">100  format('iteration ',i5,' solution vector:')<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">200  format('iteration ',i5,' residual norm ',e11.4)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      ierr = 0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      end<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">! --------------------------------------------------------------<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  MyKSPConverged - This is a user-defined routine for testing<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  convergence of the KSP iterative solvers.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!  Input Parameters:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!    ksp   - iterative context<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!    n     - iteration number<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!    rnorm - 2-norm (preconditioned) residual value (may be estimated)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!    dummy - optional user-defined monitor context (unused here)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      subroutine MyKSPConverged(ksp,n,rnorm,flag,dummy,ierr)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      use petscksp<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      implicit none<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      KSP              ksp<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscErrorCode ierr<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscInt n,dummy<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      KSPConvergedReason flag<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      PetscReal rnorm<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      if (rnorm .le. .05) then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        flag = 1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      else<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">        flag = 0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      ierr = 0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">      end<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!/*TEST<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!   test:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      nsize: 2<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      args: -pc_type jacobi -ksp_monitor_short -ksp_gmres_cgs_refinement_type refine_always<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!   test:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      suffix: 2<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      nsize: 2<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!      args: -pc_type jacobi -my_ksp_monitor -ksp_gmres_cgs_refinement_type refine_always<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%">!TEST*/<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#2F5597;mso-style-textfill-fill-color:#2F5597;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><u>Output:<o:p></o:p></u></b></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console";color:#1CA800">snarayanan1@USLN38
</span><span style="font-size:9.0pt;font-family:"Lucida Console";color:#C0A000">/cygdrive/c/sidarth/petsc-test/scaling_test<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">$ make ex2f<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">/home/snarayanan1/petsc-release/lib/petsc/bin/win32fe/win32fe ifort -MT -O3 -fpp  -MT -O3 -fpp   -I/home/snarayanan1/petsc-release/include -I/home/snarayanan1/petsc-release/arch-ci-mswin-opt-impi/include
 -I/cygdrive/c/PROGRA~2/Intel/oneAPI/mpi/2021.5.0/include     ex2f.F90  -L/cygdrive/c/cygwin64/home/snarayanan1/petsc-release/arch-ci-mswin-opt-impi/lib -L/cygdrive/c/PROGRA~2/Intel/oneAPI/mkl/2022.0.0/lib/intel64 -lpetsc mkl_intel_lp64_dll.lib mkl_sequential_dll.lib
 mkl_core_dll.lib /cygdrive/c/PROGRA~2/Intel/oneAPI/mpi/2021.5.0/lib/release/impi.lib Gdi32.lib User32.lib Advapi32.lib Kernel32.lib Ws2_32.lib -o ex2f<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console""><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console";color:#1CA800">snarayanan1@USLN38
</span><span style="font-size:9.0pt;font-family:"Lucida Console";color:#C0A000">/cygdrive/c/sidarth/petsc-test/scaling_test<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">$ $PETSC_DIR/lib/petsc/bin/petscmpiexec -n 1 ex2f.exe<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">Norm of error  0.1214E+02 iterations  2571<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">KSPSolve time:    104.949<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console""><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console";color:#1CA800">snarayanan1@USLN38
</span><span style="font-size:9.0pt;font-family:"Lucida Console";color:#C0A000">/cygdrive/c/sidarth/petsc-test/scaling_test<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">$ $PETSC_DIR/lib/petsc/bin/petscmpiexec -n 2 ex2f.exe<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">Norm of error  0.1221E+02 iterations  1821<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">KSPSolve time:     47.139<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console""><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console";color:#1CA800">snarayanan1@USLN38
</span><span style="font-size:9.0pt;font-family:"Lucida Console";color:#C0A000">/cygdrive/c/sidarth/petsc-test/scaling_test<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">$ $PETSC_DIR/lib/petsc/bin/petscmpiexec -n 1 ex2f.exe -random_exact_sol<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">Norm of error  0.8541E+02 iterations  1003<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">KSPSolve time:     40.853<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console""><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console";color:#1CA800">snarayanan1@USLN38
</span><span style="font-size:9.0pt;font-family:"Lucida Console";color:#C0A000">/cygdrive/c/sidarth/petsc-test/scaling_test<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">$ $PETSC_DIR/lib/petsc/bin/petscmpiexec -n 2 ex2f.exe -random_exact_sol<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">Norm of error  0.8562E+02 iterations  1191<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.0pt;font-family:"Lucida Console"">KSPSolve time:     31.745<o:p></o:p></span></p>
<p class="MsoNormal"><b><u><o:p><span style="text-decoration:none"> </span></o:p></u></b></p>
<p class="MsoNormal"><b><u><o:p><span style="text-decoration:none"> </span></o:p></u></b></p>
<p class="MsoNormal">Thank You,<br>
Sidarth Narayanan<o:p></o:p></p>
<p class="MsoNormal"><i><span style="font-size:9.0pt">Electronics Thermal Management Intern<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:9.0pt">Altair Engineering Inc.<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:9.0pt">Troy, MI<o:p></o:p></span></i></p>
</div>
</body>
</html>