[petsc-users] Reading matrices into PETSc
Tomasz Jankowski
tomjan at jay.au.poznan.pl
Tue Mar 8 04:38:58 CST 2011
> Matlab pseudo code
> A = diag([1 1 1])
>
> So table is sth like this
> i j val
> 0 0 1
> 1 1 1
> 2 2 1
>
> see this
>
> Mat A; // of course, A should be created first and assembled after the set
> operation
> int m =3;
> int n = 3;
> PetscInt indxm [] ={0, 1, 2};
> PetscInt indxn [] = {0, 1, 2};
> PetscScalar vals[] = {1.,1.,1.}
> MatSetValues(A, m, idxm, n, idxn, vals, INSERT_VALUES);
you example doen't work
the result matrix is:
row 0: (0, 1.1) (1, 1.2) (2, 1.3)
row 1: (0, 2.07356e-317) (1, 2.122e-314) (2, 9.88131e-324)
row 2: (0, 2.122e-314) (1, 9.88131e-324) (2, 1.40122e-316)
tom
here is the code for this example
Mat xx;
PetscInitialize(&argc,&argv,(char *)0,help);
MatCreateSeqAIJ(PETSC_COMM_SELF,3,3,1,PETSC_NULL,&xx);
int m =3;
int n = 3;
PetscInt indxm [] ={0, 1, 2};
PetscInt indxn [] = {0, 1, 2};
PetscScalar vals[] = {1.1,1.2,1.3};
MatSetValues(xx,m,indxm,n,indxn,vals,INSERT_VALUES);
MatAssemblyBegin(xx,MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(xx,MAT_FINAL_ASSEMBLY);
MatView(xx,PETSC_VIEWER_STDOUT_WORLD);
PetscFinalize();
return EXIT_SUCCESS;
More information about the petsc-users
mailing list