<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">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><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">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<br></div><div><br></div><div>Thanks,<br></div><div> Dave<br></div><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></div><br></div></div>