<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>
<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>