[petsc-users] How much memory does TS use (in terms of # of matrices)
Matthew Knepley
knepley at gmail.com
Wed May 16 09:28:40 CDT 2012
On Wed, May 16, 2012 at 10:17 AM, Andrew Spott <andrew.spott at gmail.com>wrote:
> Ok, so now I'm leaking memory without even creating the extra matrix:
>
> PetscErrorCode HamiltonianJ(TS timeStepContext, PetscReal t, Vec u, Mat
> *A, Mat *B, MatStructure *flag, void* context)
> {
> PetscErrorCode err;
> Context *cntx = (Context*)context;
> PetscScalar ef = eField(t, cntx->params);
> //if (cntx->rank == 0) std::cout << "ef: " << ef;
>
> err = MatDuplicate(cntx->energy_eigenstates,MAT_COPY_VALUES,A);
>
I think you do not understand what this call does. It allocates a new
matrix. That is what Duplicate means.
Matt
> err = MatAXPY(*A, ef, cntx->dipole_matrix, DIFFERENT_NONZERO_PATTERN);
>
> err = MatAssemblyBegin(*A, MAT_FINAL_ASSEMBLY);
> err = MatAssemblyEnd(*A, MAT_FINAL_ASSEMBLY);
>
> *flag = DIFFERENT_NONZERO_PATTERN;
>
> // absorb!
>
> return err;
> }
>
> I'm honestly stumped now…
>
> -Andrew
>
>
> On May 16, 2012, at 7:17 AM, Jed Brown wrote:
>
> On Wed, May 16, 2012 at 7:08 AM, Andrew Spott <andrew.spott at gmail.com>wrote:
>
>> Not until you pointed it out… :). Though it probably should have been.
>> It was late.
>>
>> Though I'm not sure how to fix that… should I do a MatDestroy(A) at the
>> beginning of that function every time?.
>>
>> Is *A a pointer to the last used matrix, should I just do the mat
>> duplicate into A?
>>
>
> Do you really mean to only change A (the operator), but not B (the
> preconditioning matrix)?
>
> Why do you want to create a new matrix instead of reusing those?
>
>
>
--
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/20120516/abc8d65f/attachment-0001.htm>
More information about the petsc-users
mailing list