On Mon, 2008-08-04 at 10:38 -0500, Matthew Knepley wrote: > On Mon, Aug 4, 2008 at 9:58 AM, Ahmed El Zein <ahmed at azein.com> wrote: > > On Mon, 2008-08-04 at 04:17 -0500, Matthew Knepley wrote: > >> On Mon, Aug 4, 2008 at 3:14 AM, Ahmed El Zein <ahmed at azein.com> wrote: > >> > I am working on a project where I would like to copy a sparse matrix in > >> > CSR format. > >> > > >> > I have tried MatGetRow() which works OK but I would really like to get > >> > pointers to the 3 arrays directly. > >> > > >> > I also tried MatGetRowIJ() which allows me to get the i and j arrays but > >> > I can't see how to access the nonzero elements. > >> > >> You can use MatGetArray(). > > Thanks. The man page states that: > > The result of this routine is dependent on the underlying matrix data > > structure, and may not even work for certain matrix types. > > > > How do I find out which matrix types support it? and is there a method > > that works across all matrix types? > > 1) There is nothing that works for all matrix types > > 2) There should NEVER be something that works for all matrix type. That is > the point of using an interface, so we can use arbitrary implementation > structures underneath. Shouldn't that be the opposite? Isn't the whole idea of an interface, to have a set of functions that will work on all matrix types, regardless of implementation.
Thanks for the info though. If I can't get direct access I will used MatGetRowIJ() + MatGetArray() and hope that the matrices I come across will support them. Ahmed > > Matt > > > Thanks, > > Ahmed > >> > >> Matt > >> > >> > and finally I attempted to access the arrays directly like this: > >> > Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; > >> > MatScalar *val = a->a; > >> > PetscInt *ptr = a->i; > >> > PetscInt *ind = a->j; > >> > > >> > However when accessing directly I get different values for ptr and > >> > SIGSEGV when accessing val or ind. > >> > > >> > also I get a bogus number for a->nz (134630032 instead of 21) > > What is the correct way to get the number of nonzeros? > > > >> > > >> > Can someone please explain when I am doing wrong? > >> > > >> > Ahmed > >> > > >> > > >> > >> > >> > > > > > > >
