<div dir="ltr"><div dir="ltr">On Thu, Oct 14, 2021 at 11:48 PM 王一甲 via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p style="font-family:Arial">
        <span style="font-size:16px">Hi!Everyone:</span>
</p>
<p style="font-family:Arial">
        <span style="font-size:16px">    Glad to join the mailing list.Recently I 've been working on a program using block jacobi preconditioner for a sequence solve of two linear system A_1x_1=b_1,A_2x_2=b_2.</span>
</p>
<p style="font-family:Arial">
        <span style="font-size:16px">   </span><span style="font-size:16px"> Since A1 and A2 have same nonzero pattern and their element values are quite close, we hope to reuse the preconditoners constructed </span><span style="font-size:16px">when solving A_1x_1=b_1 ,</span>
</p>
<p style="font-family:Arial">
        <span style="font-size:18px"><span style="font-size:16px">    however after calling KSPSetReusePreconditioner, though the iteration number of second ksp solve is very small but the time used did not decrease much, these are my code:</span></span></p></blockquote><div>We can use some diagnostic output to help see what is going on. Can you run with</div><div><br></div><div>  -ksp_view -ksp_monitor_true_residual</div><div>  -info :pc -log_view</div><div><br></div><div>and send all the output?</div><div><br></div><div>  Thanks,</div><div><br></div><div>    Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p style="font-family:Arial">
</p>
<p style="font-family:Arial">
        <span style="font-size:18px"><span style="font-size:16px">   <span style="font-family:Arial">          ierr = KSPSetUp(ksp);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">             ierr = PCBJacobiGetSubKSP(pc, &num_local, &idx_first_local, &subksp);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial"><br>
</span><br>
<span style="font-family:Arial">                for (i=0; i<num_local; i++)</span><br>
<span style="font-family:Arial">                {</span><br>
<span style="font-family:Arial">                        ierr = KSPGetPC(subksp[i], &subpc);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                        if (i==0)</span><br>
<span style="font-family:Arial">                        {</span><br>
<span style="font-family:Arial">                                ierr = KSPSetType(subksp[i],"gmres");CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                                ierr = PCSetType(subpc, PCLU);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                                ierr = PCFactorSetMatSolverType(subpc, "mkl_pardiso");CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                                ierr = KSPSetOptionsPrefix(subksp[i], "Blk0_");CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                                ierr = KSPSetReusePreconditioner(subksp[i],PETSC_TRUE);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                                ierr = KSPSetFromOptions(subksp[i]);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                        }</span><br>
<span style="font-family:Arial">                        if (i==1)</span><br>
<span style="font-family:Arial">                        {</span><br>
<span style="font-family:Arial">                                ierr = KSPSetType(subksp[i],"gmres");CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                                ierr = PCSetType(subpc, PCHYPRE);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                                ierr = PCHYPRESetType(pc, "boomeramg");CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                                ierr = KSPSetReusePreconditioner(subksp[i],PETSC_TRUE);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                                ierr = KSPSetOptionsPrefix(subksp[i], "Blk1_");CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">                        }</span><br>
<span style="font-family:Arial">                }//nlocal</span><br>
<span style="font-family:Arial">        }//isbjacobi</span><br>
<span style="font-family:Arial"><br>
</span><br>
<span style="font-family:Arial">        //Solve the Linear System</span><br>
<span style="font-family:Arial">        ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">        //Solve the Linear System</span><br>
<span style="font-family:Arial">t0 = MPI_Wtime();</span><br>
<span style="font-family:Arial">        ierr = KSPSolve(ksp, b1, x1);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">t0 = MPI_Wtime()-t0;</span><br>
<span style="font-family:Arial">        ierr = PetscPrintf(PETSC_COMM_SELF,"First KSP Solve time: %g s\n",t0);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">        //Preconditioner Reuse</span><br>
<span style="font-family:Arial">        ierr = KSPSetReusePreconditioner(ksp, PETSC_TRUE);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">        ierr = KSPSetOperators(ksp,A2,A1);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">t0 = MPI_Wtime();</span><br>
<span style="font-family:Arial">        ierr = KSPSolve(ksp,b2,x2);CHKERRQ(ierr);</span><br>
<span style="font-family:Arial">t0 = MPI_Wtime()-t0;</span><br>
<span style="font-family:Arial">        ierr = PetscPrintf(PETSC_COMM_SELF,"Second KSP Solve time: %g s\n",t0);CHKERRQ(ierr);</span></span></span>
</p>
<p style="font-family:Arial">
        <span style="font-size:18px"><span style="font-size:16px"><br>
</span></span>
</p>
<p style="font-family:Arial">
        <span style="font-size:18px"><span style="font-size:16px">The total block number is 2, and the first block is solved using direct method and the second block is solved using hypre's boomeramg, so I hope to reuse the factor of the first block and the set up phase of boomeramg as preconditioner of the next solve, is there anything wrong with the reuse code?</span></span>
</p>
<p style="font-family:Arial">
        <span style="font-size:18px"><span style="font-size:16px">                                                                                                                                                                                                                                                                                                                                                                                                                        Best Wishes</span></span>
</p>
<p style="font-family:Arial">
        <span style="font-size:18px"><span style="font-size:16px">                                                                                                                                                                                                                                                                                                                                                                                                                        WANG Yijia<br>
</span></span>
</p>
<p style="font-family:Arial">
        <span style="font-size:18px"><span style="font-size:16px">                                                                                                                                                                                                                                                                                                                                                                                                                         2021/10/15 <br>
</span></span>
</p>
<p style="font-family:Arial">
        <span style="font-size:18px"><span style="font-size:16px">                                                                                                                                                                                                                                                                                                                                                                        <br>
</span></span>
</p></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>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><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>