On Fri, Dec 9, 2011 at 6:15 PM, Xiangdong Liang <span dir="ltr"><<a href="mailto:xdliang@gmail.com">xdliang@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
If I use MAT_IGNORE_ZERO_ENTRIES option, is it possible that I still<br>
see some zeros in the sparse matrix? In my problem, when I use this<br></blockquote><div><br></div><div>Not if they are truly zero.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
ignore_zero options, the number of nonzeros is significantly reduced<br>
(from mat_view_info) but still larger than the number of nonzeros<br>
counting from matlab. When I use mat_view_draw, I see some light green<br>
lines (corresponding to zeros). I am wondering where these zeros come<br>
from? Thanks<br></blockquote><div><br></div><div>Print it and see where they are.</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Xiangdong<br>
<br>
On Wed, Dec 7, 2011 at 12:15 PM, Satish Balay <<a href="mailto:balay@mcs.anl.gov">balay@mcs.anl.gov</a>> wrote:<br>
> On Wed, 7 Dec 2011, Satish Balay wrote:<br>
><br>
>> As indicated call "MatSetOption(A,MAT_IGNORE_ZERO_ENTRIES,PETSC_TRUE)<br>
>> - before any calls to MatSetValue/s()<br>
>><br>
>> And verify with MatView()<br>
><br>
> Ok - here is what you can see with a slightly modified mat/examples/tests/ex38.c<br>
><br>
> Notice "C[0,1] = 0.0" and thats not visible anymore with<br>
> MatSetOption(MAT_IGNORE_ZERO_ENTRIES)<br>
><br>
> Satish<br>
><br>
> --------<br>
> asterix:/home/balay/spetsc/src/mat/examples/tests>cat ex38.c<br>
> static char help[] = "Tests MatSetValues().\n\n";<br>
> #include <petscmat.h><br>
> #undef __FUNCT__<br>
> #define __FUNCT__ "main"<br>
> int main(int argc,char **args)<br>
> {<br>
> Mat C;<br>
> PetscInt i,n = 5,midx[3],nidx[2];<br>
> PetscErrorCode ierr;<br>
> PetscBool flg;<br>
> PetscScalar v[6];<br>
><br>
> PetscInitialize(&argc,&args,(char *)0,help);<br>
> ierr = MatCreate(PETSC_COMM_WORLD,&C);CHKERRQ(ierr);<br>
> ierr = MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,n,n);CHKERRQ(ierr);<br>
> ierr = MatSetFromOptions(C);CHKERRQ(ierr);<br>
><br>
> ierr = PetscOptionsHasName(PETSC_NULL,"-ignore_zero_entries",&flg);CHKERRQ(ierr);<br>
> if (flg) { ierr = MatSetOption(C,MAT_IGNORE_ZERO_ENTRIES,PETSC_TRUE);CHKERRQ(ierr);}<br>
><br>
> for (i=0; i<6; i++) v[i] = (PetscReal)i;<br>
> midx[0] = 0; midx[1] = 2; midx[2] = 3;<br>
> nidx[0] = 1; nidx[1] = 3;<br>
> ierr = MatSetValues(C,3,midx,2,nidx,v,ADD_VALUES);CHKERRQ(ierr);<br>
> ierr = MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br>
> ierr = MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br>
> ierr = MatView(C,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);<br>
> ierr = MatDestroy(&C);CHKERRQ(ierr);<br>
> ierr = PetscFinalize();<br>
> return 0;<br>
> }<br>
><br>
> asterix:/home/balay/spetsc/src/mat/examples/tests>./ex38 -mat_view_info<br>
> Matrix Object: 1 MPI processes<br>
> type: seqaij<br>
> rows=5, cols=5<br>
> total: nonzeros=6, allocated nonzeros=25<br>
> total number of mallocs used during MatSetValues calls =0<br>
> using I-node routines: found 4 nodes, limit used is 5<br>
> Matrix Object: 1 MPI processes<br>
> type: seqaij<br>
> row 0: (1, 0) (3, 1)<br>
> row 1:<br>
> row 2: (1, 2) (3, 3)<br>
> row 3: (1, 4) (3, 5)<br>
> row 4:<br>
> asterix:/home/balay/spetsc/src/mat/examples/tests>./ex38 -mat_view_info -ignore_zero_entries<br>
> Matrix Object: 1 MPI processes<br>
> type: seqaij<br>
> rows=5, cols=5<br>
> total: nonzeros=5, allocated nonzeros=25<br>
> total number of mallocs used during MatSetValues calls =0<br>
> using I-node routines: found 4 nodes, limit used is 5<br>
> Matrix Object: 1 MPI processes<br>
> type: seqaij<br>
> row 0: (3, 1)<br>
> row 1:<br>
> row 2: (1, 2) (3, 3)<br>
> row 3: (1, 4) (3, 5)<br>
> row 4:<br>
> asterix:/home/balay/spetsc/src/mat/examples/tests><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>