[petsc-users] MatMPIAIJSetPreallocation question

Barry Smith bsmith at mcs.anl.gov
Sun Feb 15 20:31:36 CST 2015


> On Feb 15, 2015, at 8:22 PM, Gideon Simpson <gideon.simpson at gmail.com> wrote:
> 
> I’m trying to get a handle on the different ways of constructing matrices.  Currently, I have:
> 
> MatCreate(...)
> MatSetSizes(...)
> MatSetFromOptions(...)
> MatSetUp(…)
> 
> but I gather from reading the manual that, by not preallocating, I’m losing out in performance.  If I assume that my matrix will either by SeqAIJ or MPIAIJ, depending on the number of processors available, how would I go about doing this.  I see some of the example codes with:
> 
> MatSeqAIJSetPreallocation(…)
> MatMPIAIJSetPreallocation(…)
> 
> as successive commands.  Should I interpret this as saying that PETSc will just ignore the one that is not the active one in the current instance? 

  Exactly*.

  You can also use MatXAIJSetPreallocation() which sets the possible preallocation forms for all the matrix types without requiring you to set one each individuallly.

  Barry

* We support this in many places because we hate requiring users to put a bunch of if (type == xxx) kind of code in their applications. For example KSPGMRESSetRestart() is ignored if the KSP type is not GMRES.


> 
> -gideon
> 



More information about the petsc-users mailing list