[petsc-users] Question about preallocation and getOwnership functions

Sun, Hui hus003 at ucsd.edu
Thu Dec 4 01:09:44 CST 2014


Hello,

The following lines of code give me trouble because PETSc gives me an error message saying the object A is in a wrong state, and Must call MatXXXSetPreallocation() or MatSetUp() on argument 1 "mat" before MatGetOwnershipRange().

Here is part of the code:


    ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);

    ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,2*nx*ny,2*nx*ny);CHKERRQ(ierr);

    ierr = MatSetType(A,MATAIJ);CHKERRQ(ierr);

    ierr = MatMPIAIJSetPreallocation(A,9,NULL,9,NULL);CHKERRQ(ierr);

    ierr = MatGetOwnershipRange(A, &start, &end);CHKERRQ(ierr);


I think I have called MatMPIAIJSetPreallocation, so what might be causing the problem here?


Best,

Hui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20141204/bb3ec3d0/attachment.html>


More information about the petsc-users mailing list