[petsc-users] Matrix reuse with changing structure

Barry Smith bsmith at mcs.anl.gov
Tue Mar 15 12:47:53 CDT 2016


> On Mar 15, 2016, at 12:28 PM, Matthew Knepley <knepley at gmail.com> wrote:
> 
> On Tue, Mar 15, 2016 at 12:24 PM, Smith, Kevin R. <Kevin.R.Smith at jhuapl.edu> wrote:
> Hello,
> 
>  
> 
> Is it possible to reuse a sparse matrix and not reuse its non-zero structure?   I have a matrix whose sparse structure changes each time. I’m hoping to avoid destroying and allocating new matrices each time the structure changes.

   Sure you can just add new nonzero locations at a later time. But it won't take out any current entries even if they are zero. So effectively the nonzero structure grows over time.

   Barry

> 
> 
> Hmm, I can't find a toplevel API that does this (it would be something like MatReset()). You can get this effect using
> 
>   MatSetType(A, MATSHELL)
>   MatSetType(A, <type you had before>)
> 
> A little messy but it will work.
> 
>   Thanks,
> 
>      Matt
>  
>  
> 
> Thanks,
> 
>   Kevin
> 
> 
> 
> 
> -- 
> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
> -- Norbert Wiener



More information about the petsc-users mailing list