[petsc-users] MatShift and unassembled matrices

Barry Smith bsmith at mcs.anl.gov
Thu Oct 7 21:16:07 CDT 2010


  Just call MatAssemblyBegin/End() before making the call to MatShift().

   Yes for dense matrices this is sort of silly (since dense matrices are essentially always assembled) but since it is needed for sparse matrices we use the same paradigm for all matrix types.

   Barry

On Oct 7, 2010, at 5:14 PM, Harsh Sharma wrote:

> Hi,
>  
> I am creating a square matrix using MatCreateMPIDense, then
> zero-ing its entries using MatZeroEntries and finally using the
> MatShift operation to make it the identity matrix. Here's the code
> snippet that I'm using for doing this:
>  
>  Mat OP1;   /* n1xn1 matrix */
>  
>  MatCreateMPIDense(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE,n1,n1,PETSC_NULL,&OP1);
>  MatZeroEntries(OP1);
>  MatShift(OP1,1.0);
>  
> The error I get is:
>  
> [0]PETSC ERROR: --------------------- Error Message ------------------------------------
> [0]PETSC ERROR: Object is in wrong state!
> [0]PETSC ERROR: Not for unassembled matrix!
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: MatShift() line 110 in src/mat/utils/axpy.c
> [0]PETSC ERROR: --------------------- Error Message ------------------------------------
>  
> Apparently, the matrix OP1 is in unassembled state. All the
> examples that I have seen for MatShift() do not call any
> assembly routines before or after calling the MatShift() function.
>  
> What am I doing wrong here?
>  
> Thanks very much,
> Harsh



More information about the petsc-users mailing list