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: [email protected] 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
