[petsc-dev] mat nest is done

Barry Smith bsmith at mcs.anl.gov
Thu Nov 25 18:29:48 CST 2010


On Nov 25, 2010, at 4:54 AM, Jed Brown wrote:

> On Thu, Nov 25, 2010 at 11:39, Dave May <dave.mayhem23 at gmail.com> wrote:
> ierr = MatCreate( PETSC_COMM_WORLD, &j22 );CHKERRQ(ierr);
>  ierr = MatSetSizes( j22, PETSC_DECIDE, PETSC_DECIDE, 1, 1 );CHKERRQ(ierr);
>  ierr = MatSetType( j22, MATSEQAIJ );CHKERRQ(ierr);
> 
> produces
> j22->rmap->n = -1
> j22->cmap->n = -1
> 
> I'm not sure why, but PetscLayoutSetUp is called in MatSeqAIJSetPreallocation_SeqAIJ, not MatCreate_SeqAIJ.  There was probably a reason for the present choice.
> 
> Jed

   It used to be that you had to set the sizes BEFORE setting the type. Then we allowed setting the type first, this was implemented by caching the MatCreate_SeqAIJ() function and using it when the sizes are set. Then it was changed to not caching the create function and instead calling it immediately and delaying the computation of sizes etc until the preallocation call. 

   Hence the calling sequence above does not result in sizes be properly set yet. 

   The reason this doesn't cause grief everywhere is that most Mat functions start with a MatPreallocated() that makes sure the setting of sizes is done. 

   The easiest fix would be to put MatPreallocated()  at the beginning of MatGetSizes() and whatever else doesn't have it.  I don't know if there would be any bad side affects to making this change.

   Note that MatPreallocated() is kind of like a XXXSetUp()  for matrices, it may be we want to formalize this a bit more to make the "style" of Mat match PC, KSP, SNES etc more.

   Barry





More information about the petsc-dev mailing list