[petsc-users] zeros in sparse aij
Matthew Knepley
knepley at gmail.com
Fri Dec 9 18:23:52 CST 2011
On Fri, Dec 9, 2011 at 6:15 PM, Xiangdong Liang <xdliang at gmail.com> wrote:
> If I use MAT_IGNORE_ZERO_ENTRIES option, is it possible that I still
> see some zeros in the sparse matrix? In my problem, when I use this
>
Not if they are truly zero.
> ignore_zero options, the number of nonzeros is significantly reduced
> (from mat_view_info) but still larger than the number of nonzeros
> counting from matlab. When I use mat_view_draw, I see some light green
> lines (corresponding to zeros). I am wondering where these zeros come
> from? Thanks
>
Print it and see where they are.
Matt
> Xiangdong
>
> On Wed, Dec 7, 2011 at 12:15 PM, Satish Balay <balay at mcs.anl.gov> wrote:
> > On Wed, 7 Dec 2011, Satish Balay wrote:
> >
> >> As indicated call "MatSetOption(A,MAT_IGNORE_ZERO_ENTRIES,PETSC_TRUE)
> >> - before any calls to MatSetValue/s()
> >>
> >> And verify with MatView()
> >
> > Ok - here is what you can see with a slightly modified
> mat/examples/tests/ex38.c
> >
> > Notice "C[0,1] = 0.0" and thats not visible anymore with
> > MatSetOption(MAT_IGNORE_ZERO_ENTRIES)
> >
> > Satish
> >
> > --------
> > asterix:/home/balay/spetsc/src/mat/examples/tests>cat ex38.c
> > static char help[] = "Tests MatSetValues().\n\n";
> > #include <petscmat.h>
> > #undef __FUNCT__
> > #define __FUNCT__ "main"
> > int main(int argc,char **args)
> > {
> > Mat C;
> > PetscInt i,n = 5,midx[3],nidx[2];
> > PetscErrorCode ierr;
> > PetscBool flg;
> > PetscScalar v[6];
> >
> > PetscInitialize(&argc,&args,(char *)0,help);
> > ierr = MatCreate(PETSC_COMM_WORLD,&C);CHKERRQ(ierr);
> > ierr = MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,n,n);CHKERRQ(ierr);
> > ierr = MatSetFromOptions(C);CHKERRQ(ierr);
> >
> > ierr =
> PetscOptionsHasName(PETSC_NULL,"-ignore_zero_entries",&flg);CHKERRQ(ierr);
> > if (flg) { ierr =
> MatSetOption(C,MAT_IGNORE_ZERO_ENTRIES,PETSC_TRUE);CHKERRQ(ierr);}
> >
> > for (i=0; i<6; i++) v[i] = (PetscReal)i;
> > midx[0] = 0; midx[1] = 2; midx[2] = 3;
> > nidx[0] = 1; nidx[1] = 3;
> > ierr = MatSetValues(C,3,midx,2,nidx,v,ADD_VALUES);CHKERRQ(ierr);
> > ierr = MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
> > ierr = MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
> > ierr = MatView(C,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
> > ierr = MatDestroy(&C);CHKERRQ(ierr);
> > ierr = PetscFinalize();
> > return 0;
> > }
> >
> > asterix:/home/balay/spetsc/src/mat/examples/tests>./ex38 -mat_view_info
> > Matrix Object: 1 MPI processes
> > type: seqaij
> > rows=5, cols=5
> > total: nonzeros=6, allocated nonzeros=25
> > total number of mallocs used during MatSetValues calls =0
> > using I-node routines: found 4 nodes, limit used is 5
> > Matrix Object: 1 MPI processes
> > type: seqaij
> > row 0: (1, 0) (3, 1)
> > row 1:
> > row 2: (1, 2) (3, 3)
> > row 3: (1, 4) (3, 5)
> > row 4:
> > asterix:/home/balay/spetsc/src/mat/examples/tests>./ex38 -mat_view_info
> -ignore_zero_entries
> > Matrix Object: 1 MPI processes
> > type: seqaij
> > rows=5, cols=5
> > total: nonzeros=5, allocated nonzeros=25
> > total number of mallocs used during MatSetValues calls =0
> > using I-node routines: found 4 nodes, limit used is 5
> > Matrix Object: 1 MPI processes
> > type: seqaij
> > row 0: (3, 1)
> > row 1:
> > row 2: (1, 2) (3, 3)
> > row 3: (1, 4) (3, 5)
> > row 4:
> > asterix:/home/balay/spetsc/src/mat/examples/tests>
>
--
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/20111209/b53ee4f5/attachment.htm>
More information about the petsc-users
mailing list