Matrix reuse

Lisandro Dalcin dalcinl at gmail.com
Fri Nov 23 09:01:06 CST 2007


On 11/23/07, Berend van Wachem <berend at chalmers.se> wrote:
> Hi,
> I use MatZeroEntries on the matrix, and then re-use it. I'm not sure
> what the gain in time is, though.

MatZeroEntries just  zero-out in the scalar entries, but it retains
the nonzero structure of the matrix. Thus, the next time you make a
loop calling MatSetValues(), PETSc will fastly put the new values in
the right location, avoiding any memory allocation or data movement
inside the sparse structure. Spase matrix assembly is not actually a
trivial task, and in the parallel case, it is even far harder. But
PETSc make it really easy and it is optimized for data reuse. Then, to
get good performace, you have to create and preallocate your matrix,
and next reuse it as much as you can. You can gain a lot, unless your
matrices are really small.


> Zhifeng Sheng wrote:
> > Dear all
> >
> > In my application, I have small matrices that are created and destroied,
> > those matrices are of the same nozero pattern.
> >
> > I wonder if there is a way to reuse that matrices instead of destroy
> > them every time.
> >
> > Thank you
> >
> > Best regards
> > Zhifeng Sheng
> >
>
>


-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594




More information about the petsc-users mailing list