[petsc-users] Efficient reuse of vectors and matrices

Matthew Knepley knepley at gmail.com
Wed Jul 4 08:28:48 CDT 2012


On Wed, Jul 4, 2012 at 5:33 AM, Margreet Nool <margreet.nool at gmail.com>wrote:

> Dear list,
>
> How can I reuse vectors and matrices efficiently?
>
> Our program uses a lot of global matrices and vectors and I want to reduce
> the amount of memory. Are there PETSC functions, which check whether a Mat
> or Vec is already created or destroyed? Our programs have been written in
> Fortran90.
>

In C, you can initialize the pointer to PETSC_NULL, and then check whether
it has been changed (created).
However, I do not yet understand why you can't just create all the Vec and
Mat structures up front. That is
what I usually do.


> The program performs a time stepping process, and I want to know what the
> best way is  to create a global vector only once. As an example, a global
> vector Vec y is created as a result of a matrix-vector product A . x = y,
> by calling the PETSC function MatMult. After the first call the Vec Y has
> already been created.
>

To clarify, MatMult() does not create anything. It takes in 2 Vec and 1 Mat
which have already been created.

    Matt


> 1. Do we have to store the result into a temporary vector temp_vec and
> copy its values into Vec y and destroy temp_vec?
> 2. Do we have to destroy Vec y before a call of MatMult and store the
> result directly in Vec y?
> 3. Does there exist a better solution?
>
> Thanks in advance,
> Margreet Nool
>
> --
> Margreet Nool
> CWI - Centrum Wiskunde & Informatica
> Science Park 123,
> 1098 XG Amsterdam
> P.O. Box 94079
> 1090 GB Amsterdam
> --------------------
> tel: +31 20 592 4120
> Room, M131
>
>


-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120704/86b1cc4d/attachment.html>


More information about the petsc-users mailing list