<div dir="ltr">On Wed, Aug 14, 2013 at 12:28 PM, Danyang Su <span dir="ltr"><<a href="mailto:danyang.su@gmail.com" target="_blank">danyang.su@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  

    
  
  <div text="#000000" bgcolor="#FFFFFF">
    Hi All,<br>
    <br>
    I have many linear equations with the same matrix structure (same
    non-zero entries) that are derived from a flow problem at different
    time steps. I feel puzzled that the results are a little different
    when the solver run repeatedly and one by one. Say, I have three
    equations, I can get the following results if running three
    equations together<br>
    <br>
    Equation 1: Iterations     1 norm  0.9457E-02    Result error PETSc
    vs Solver2, max  0.4362E-02 min -0.2277E-04 norm  0.9458E-02<br>
    <font color="#ff0000">Equation 2: Iterations     2 norm 
      0.2994E-05    Result error PETSc vs Solver2, max  0.1381E-05 min
      -0.7209E-08 norm  0.2994E-05<br>
      Equation 3: Iterations     2 norm  0.3919E-04    Result error
      PETSc vs Solver2, max  0.9435E-07 min -0.1808E-04 norm  0.3919E-04</font><br>
    <br>
    But if I solve only one equation every time, then restart the
    program to run another one, the results are like this:<br>
    <br>
    Equation 1: Iterations     1 norm  0.9457E-02    Result error PETSc
    vs Solver2, max  0.4362E-02 min -0.2277E-04 norm  0.9458E-02<br>
    <font color="#ff0000">Equation 2: Iterations     1 norm 
      0.7949E-05    Result error PETSc vs Solver2, max  0.3501E-05 min
      -0.8377E-06 norm  0.7949E-05<br>
      Equation 3: Iterations     1 norm  0.1980E-04    Result error
      PETSc vs Solver2, max  0.4168E-08 min -0.9085E-05 norm  0.1980E-04</font><br>
    <br>
    <font color="#000099">Note: Solver2 is the original sequential
      solver used in this flow model.</font><br>
    <br>
    Though there are no big difference in the solution for the above
    equations, I want to know why?<br>
    <br>
    For another large linear equations with more than 400,000 unknowns
    and 10,000,000 non-zero entries, if the equations are solved
    repeatedly, they need a lot of iterations or fail, but if the
    equations are solved one by one, it only needs 1 to 2 iterations.<br>
    <br>
    How does this difference come from?<br>
    <br>
    The sample codes are attached bellow.<br>
    <br>
    Thanks and regards,<br>
    <br>
    Danyang<br>
    <br>
!***************************************************************************!<br>
    !Create matrix, rhs and solver<br>
    call MatCreateAIJ(Petsc_Comm_World, Petsc_Decide, Petsc_Decide, nb,
    nb, nd_nzrow, &<br>
                      Petsc_Null_Integer, nd_nzrow, Petsc_Null_Integer,
    a, ierr) <br>
    call MatSetOption(a,Mat_New_Nonzero_Allocation_Err,Petsc_False,ierr)<br>
    call VecCreateMPI(Petsc_Comm_World, Petsc_Decide, nb, b, ierr)  <br>
    call VecDuplicate(b, x, ierr) <br>
    call VecDuplicate(x, u, ierr)<br>
    call KSPCreate(Petsc_Comm_World,ksp,ierr)<br>
    call KSPSetTolerances(ksp,tol,                                 &<br>
                          PETSC_DEFAULT_DOUBLE_PRECISION,          &<br>
                          PETSC_DEFAULT_DOUBLE_PRECISION,          &<br>
                          100,ierr)<br>
    call KSPSetFromOptions(ksp,ierr)<br>
    <br>
    !Do time loop<br>
    do i = 1, nTimeStep<br>
        call MatGetOwnershipRange(a,istart,iend,ierr)<br>
        do i = istart, iend - 1<br>
           ii = ia_in(i+1)<br>
           jj = ia_in(i+2)<br>
           call MatSetValues(a, ione, i, jj-ii, ja_in(ii:jj-1)-1,
    a_in(ii:jj-1), Insert_Values, ierr)<br>
        end do <br>
        call MatAssemblyBegin(a, Mat_Final_Assembly, ierr)    <br>
        call MatAssemblyEnd(a, Mat_Final_Assembly, ierr)<br>
        <br>
        call VecGetOwnershipRange(b,istart,iend,ierr)<br>
        call VecSetValues(b, iend-istart, ix(istart+1:iend),
    b_in(istart+1:iend), Insert_Values, ierr)<br>
        call VecAssemblyBegin(b,ierr)<br>
        call VecAssemblyEnd(b,ierr)<br>
        <br>
        if(i == 1) then<br>
            call MatConvert(a,MATSAME,MAT_INITIAL_MATRIX,a2,ierr)<br></div></blockquote><div><br></div><div>   Why are you doing this?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
        end if<br>
        !call KSPSetOperators(ksp,a,a2,SAME_PRECONDITIONER,ierr) <br></div></blockquote><div><br></div><div>Just use a, a for the matrices</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
        call KSPSetOperators(ksp,a,a2,SAME_NONZERO_PATTERN,ierr)       
        !These three patterns make no difference in current codes<br></div></blockquote><div><br></div><div>This DOES matter here if you are using the default PC which is ILU.</div><div><br></div><div>   Matt</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div text="#000000" bgcolor="#FFFFFF">
        !call KSPSetOperators(ksp,a,a2,DIFFERENT_NONZERO_PATTERN,ierr)<br>
    <br>
        call KSPSolve(ksp,b,x,ierr)<br>
        <br>
        call KSPGetResidualNorm(ksp,norm,ierr)<br>
        call KSPGetIterationNumber(ksp,its,ierr)    <br>
    end do<br>
    <br>
    !Destroy objects<br>
    !...<br>
!***************************************************************************!<br>
  </div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener
</div></div>