← Back to team overview

dolfin team mailing list archive

Re: [Question #121973]: Get sparse matrix data

 

On Fri, 2010-08-20 at 11:08 -0700, Johan Hake wrote:
> Hello Dominique!
> 
> The CRS representation of a sparse matrix is LA backend dependent. It only 
> works for uBLAS and MTL4. 

This is because we know the layout used by uBLAS and MTL4, and we use it
in linear solevrs. We deliberately make it harder to get the the PETSc
and Trilinos data, but from C++ it is possible. You can get a pointer to
the underlying PETSc/Trilinos object, and then use any PETSc/Trilinos
functions.

Garth 

> So before you do your assemble, make sure that:
> 
>   parameters.linear_algebra_backend = "uBLAS" or "MTL4"
> 
> then:
> 
>   rows, cols, values = A.data()
> 
> 
> The transposed matrix vector product is not wrapped to a more simpler syntax 
> (if that is what you are asking for?). Not sure what operator in Python we 
> need to overload to make that both pretty and without to much copying of data.
> 
> Cheers!
> 
> Johan
> 
> On Friday August 20 2010 03:22:31 Dominique wrote:
> > New question #121973 on DOLFIN:
> > https://answers.launchpad.net/dolfin/+question/121973
> > 
> > Hello,
> > 
> > The questions below are PETSc-related so please let me know if I really
> > should ask them elsewhere.
> > 
> > I'm generating a sparse coefficient matrix A using
> > 
> > A = assemble(a)
> > 
> > where a is some bilinear form. I'm wondering how I can access the arrays
> > that describe A in compressed sparse row format. I thought A.data would do
> > the job but:
> > 
> > In [61]: A.data?
> > Type:		instancemethod
> > Base Class:	<type 'instancemethod'>
> > String Form:	<bound method Matrix.data of <dolfin.cpp.Matrix; proxy of
> > <Swig Object of type 'dolfin::Matrix *' at 0x916ab18> >>
> > Namespace:	Interactive
> > File:		/home/orban/Work/FEniCS/lib/python2.6/site-
> packages/dolfin/cpp.py
> > Definition:	A.data(self)
> > Docstring:
> >     Return arrays to underlying compresssed row/column storage data
> > 
> > 
> > In [62]: A.data()
> > ---------------------------------------------------------------------------
> > RuntimeError                              Traceback (most recent call last)
> > 
> > /home/orban/Envs/sparse/dev/fenics/<ipython console> in <module>()
> > 
> > /home/orban/Work/FEniCS/lib/python2.6/site-packages/dolfin/cpp.pyc in
> > data(self) 2124         """ Return arrays to underlying compresssed
> > row/column storage data """ 2125
> > -> 2126         return self._data()
> >    2127
> >    2128     def __getitem__(self,indices):
> > 
> > RuntimeError: *** Error: Unable to return pointers to underlying matrix
> > data.
> > 
> > 
> > I'm using FEniCS under Fedora.
> > 
> > Also, I can compute matrix-vector products with A*x, but is there a better
> > way to compute transpose matrix-vector products than with A.transpmult?
> >
> > Thanks!
> > Dominique
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp





Follow ups

References