[petsc-users] zeros in sparse aij
Xiangdong Liang
xdliang at gmail.com
Fri Dec 9 18:15:43 CST 2011
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
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
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>
More information about the petsc-users
mailing list