[petsc-users] Question about preallocation and getOwnership functions

Sun, Hui hus003 at ucsd.edu
Thu Dec 4 01:46:51 CST 2014


After reading some documentation, I figured it out myself. MATAIJ can be MATSEQAIJ or MATMPIAIJ, depending on the number of processors involved. Thus, I need to include the command MatSeqAIJSetPreallocation as well, to cover both cases.

Best,
Hui


________________________________
From: Sun, Hui
Sent: Wednesday, December 03, 2014 11:09 PM
To: petsc-users at mcs.anl.gov
Subject: Question about preallocation and getOwnership functions

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/f88c34f4/attachment-0001.html>


More information about the petsc-users mailing list