most efficient way to use local CSR matrix?

Chris Kees christopher.e.kees at
Tue Oct 20 20:04:55 CDT 2009


Our unstructured finite element code does a fairly standard  
overlapping decomposition that allows it to calculate all the non-zero  
column entries for the rows owned by the processor (rows 0...ldim-1 in  
the local numbering).  We assemble them into a local CSR matrix and  
then copy them into a PETSc matrix like this:

for (int i=0;i<ldim;i++)
   irow[0] = i;

where rowptr and colind are the CSR indexing arrays in the local  

I would like to eliminate the duplicate memory (and the copy above).  
Is there a recommended way to let PETSc reference array 'a' directly  
or a way to get rid of 'a' and translate our CSR assembly routines to  
use low level PETSc data structures?

So far I've added MatMPIAIJSetPreallocationCSR to try to speed up the  
first solve, but the documentation is clear that 'a' is not a pointer  
to the AIJ storage so I still need the copy. I tried using  
MatCreateMPIAIJWithSplitArrays with the 'o' arrays set to zero but I  
got indexing errors, and the documentation really seems to imply that  
the local matrix is really not a standard CSR anyway. If that's true  
then it seems like the options I have are to write a shell matrix for  
parallel CSR storage or write some new assembly routines that use  
MatSetValuesLocal. I'm more concerned about the memory than the  
overhead of MatSetValuesLocal, but it would certainly be easier on me  
to use the CSR-based assembly routines we already have.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the petsc-dev mailing list