[petsc-users] MatEqual and explicit zero behaviour

Matthew Knepley knepley at gmail.com
Wed Jan 21 06:38:24 CST 2015


On Wed, Jan 21, 2015 at 6:25 AM, Jørgen Kvalsvik <jorgekva at stud.ntnu.no>
wrote:

> Hi,
>
> I was unable to find this in the PETSc docs nor any relevant example
> through search engines.
>
> I have two matrices, A and B.
>

Equality here also incorporates the sparsity pattern, so that two matrices
with a different
sparsity pattern are not identical.

  Thanks,

    Matt


> A:
> PetscScalar values[] = {
> 10.0, 0, 0, 0, 0, 5.72,
> 0.2, 0, 0, 0, 0, 0,
> 0, 0, 4.2, 0, 0, 0,
> 0, 0, 0, 3.4, 0, 0,
> 0, 0, 3.14, 0, 0, 0,
> 0, 0, 0, 0, 0, 0 };
>
> And an array [0..6] passed to both row and columns in my MatSetValues call.
> err = MatSetValues( A,
>       6, indices,
>       6, indices,
>       values, INSERT_VALUES );
>
> B is constructed from CSR:
> PetscInt csr_rows[] = { 0, 2, 3, 4, 5, 6, 6 };
> PetscInt csr_cols[] = { 0, 5, 0, 2, 3, 2 };
> PetscScalar csr_vals[] = { 10.0, 5.72, 0.2, 4.2, 3.4, 3.14 };
>
> for( int i = 0; i < rows - 1; ++i ) {
>     PetscInt row_entries = csr_rows[ i + 1 ] - csr_rows[ i ];
>
>     PetscInt row_index[] = { i };
>     PetscInt offset = csr_rows[ i ];
>
>     err = MatSetValues( A,
>           1, row_index,
>           row_entries, csr_cols + offset,
>           csr_vals + offset, INSERT_VALUES );
> }
>
> Printing them with PetscView gives:
>
> A:
> Matrix Object: 1 MPI processes
>   type: seqaij
> row 0: (0, 10)  (1, 0)  (2, 0)  (3, 0)  (4, 0)  (5, 5.72)
> row 1: (0, 0.2)  (1, 0)  (2, 0)  (3, 0)  (4, 0)  (5, 0)
> row 2: (0, 0)  (1, 0)  (2, 4.2)  (3, 0)  (4, 0)  (5, 0)
> row 3: (0, 0)  (1, 0)  (2, 0)  (3, 3.4)  (4, 0)  (5, 0)
> row 4: (0, 0)  (1, 0)  (2, 3.14)  (3, 0)  (4, 0)  (5, 0)
> row 5: (0, 0)  (1, 0)  (2, 0)  (3, 0)  (4, 0)  (5, 0)
>
> B:
> Matrix Object: 1 MPI processes
>   type: seqaij
> row 0: (0, 10)  (5, 5.72)
> row 1: (0, 0.2)
> row 2: (2, 4.2)
> row 3: (3, 3.4)
> row 4: (2, 3.14)
> row 5:
>
> Which, as far as I can tell, are identical matrices.
>
> But here's the problem. When I compare them with MatEqual it gives me
> false, which I did not expect. Is there some undocumented behaviour
> regarding explicit and implicit zeroes, and is this intentional? Is it not
> possible to compare matrices with different structures?
>
> Thanks
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150121/749ac55f/attachment-0001.html>


More information about the petsc-users mailing list