[petsc-users] Tuning performance for simple solver

Michael Becker Michael.Becker at physik.uni-giessen.de
Fri Jun 3 05:37:38 CDT 2016

Dear all,

I have a few questions regarding possible performance enhancements for 
the PETSc solver I included in my project.

It's a particle-in-cell plasma simulation written in C++, where 
Poisson's equation needs to be solved repeatedly on every timestep.
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.

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.

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.

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.

Is there anything I can change to generally make the program run faster?
And, since I'm rather unexperienced with KSP methods, how do I 
efficiently choose PC and KSP? Just by testing every combination?
Would multigrid be a viable option as a pure solver (-ksp_type preonly)?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 5029 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160603/a2c0f1fb/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: petscsolver.h
Type: text/x-chdr
Size: 615 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160603/a2c0f1fb/attachment.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: petscsolver.cpp
Type: text/x-c++src
Size: 4104 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160603/a2c0f1fb/attachment-0001.cpp>

More information about the petsc-users mailing list