[petsc-users] Reading matrices into PETSc

Umut Tabak u.tabak at tudelft.nl
Wed Dec 22 03:32:57 CST 2010


On 12/22/2010 08:56 AM, Gaurish Telang wrote:
> but I am not yet clear on how to do this. I read ex32.c and ex72.c but 
> I am still confused. What is ASCII 'slap' format? How should  matrix 
> be supplied to PETSc?
>
> My matrix is a 2000x1900 matrix given in the format MATLAB stores 
> sparse matrices. i.e
What exactly do you want to do, here is a simple example for Compressed 
Row Storage (CSR) format which is the default format in PETSc as far as 
I know. You can use the MatSetValues function to set the nonzeros, Have 
you tried to read the documentation about the matrices in the user manual?

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);
// assemble after

HTH,
Umut

-- 
  - Hope is a good thing, maybe the best of things
    and no good thing ever dies...
  The Shawshank Redemption, replique of Tim Robbins



More information about the petsc-users mailing list