<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jun 3, 2016 at 5:56 AM, Dave May <span dir="ltr"><<a href="mailto:dave.mayhem23@gmail.com" target="_blank">dave.mayhem23@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On 3 June 2016 at 11:37, Michael Becker <span dir="ltr"><<a href="mailto:Michael.Becker@physik.uni-giessen.de" target="_blank">Michael.Becker@physik.uni-giessen.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear all,<br>
<br>
I have a few questions regarding possible performance enhancements for the PETSc solver I included in my project.<br>
<br>
It's a particle-in-cell plasma simulation written in C++, where Poisson's equation needs to be solved repeatedly on every timestep.<br>
The simulation domain is discretized using finite differences, so the solver therefore needs to be able to efficiently solve the linear system A x = b successively with changing b. The solution x of the previous timestep is generally a good initial guess for the solution.<br>
<br>
I wrote a class PETScSolver that holds all PETSc objects and necessary information about domain size and decomposition. To solve the linear system, two arrays, 'phi' and 'charge', are passed to a member function solve(), where they are copied to PETSc vectors, and KSPSolve() is called. After convergence, the solution is then transferred again to the phi array so that other program parts can use it.<br>
<br>
The matrix is created using DMDA. An array 'bound' is used to determine whether a node is either a Dirichlet BC or holds a charge.<br>
<br>
I attached three files, petscsolver.h, petscsolver.cpp and main.cpp, that contain a shortened version of the solver class and a set-up to initialize and run a simple problem.<br>
<br>
Is there anything I can change to generally make the program run faster?<br></blockquote><div><br></div></span><div>Before changing anything, you should profile your code to see where time is being spent.<br><br>To that end, you should compile an optimized build of petsc, link it to you application and run your code with the option -log_summary. The -log_summary flag will generate a performance profile of specific functionality within petsc (KSPSolve, MatMult etc) so you can see where all the time is being spent.<br><br></div><div>As a second round of profiling, you should consider registering specific functionality in your code you think is performance critical. <br>You can do this using the function PetscLogStageRegister()<br><br><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Profiling/PetscLogStageRegister.html" target="_blank">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Profiling/PetscLogStageRegister.html</a> <br></div><div><br></div><div>Check out the examples listed at the bottom of this web page to see how to log stages. Once you've registered stages, these will appear in the report provided by -log_summary</div></div></div></div></blockquote><div><br></div><div>Do everything Dave said. I will also note that since you are using FD, I am guessing you are solving on a square. Then</div><div>you should really be using geometric MG. We support this through the DMDA object.</div><div><br></div><div>  Thanks,</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 dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Thanks,<br></div><div>  Dave<br></div><span class=""><div> <br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
And, since I'm rather unexperienced with KSP methods, how do I efficiently choose PC and KSP? Just by testing every combination?<br>
Would multigrid be a viable option as a pure solver (-ksp_type preonly)?<br>
<br>
Thanks,<br>
Michael<br>
</blockquote></span></div><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">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></div>