I'm making a simple eigenvalue solver with SLEPc, using a 5-point stencil and the finite difference method. I want to be able to assemble the matrix in parallel.
My first thought was just to use MatGetOwnershipRange()
to get range_begin
and range_end
, then use tests inside the loop to determine if that row represents a point on the edge. All those conditionals make the loop extremely slow, and elsewhere in the PETSc documentation it recommends building separate loops for the corners and edges.
How can this be done in a parallel program?
Is there a better way that works for parallel code not mentioned in the laplacian example code?