<div dir="ltr">You do realize that MatDuplicate is making a copy, right?<div><br></div><div>A<br><br><div class="gmail_quote">On Wed, May 16, 2012 at 5:17 PM, Andrew Spott <span dir="ltr"><<a href="mailto:andrew.spott@gmail.com" target="_blank">andrew.spott@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Ok, so now I'm leaking memory without even creating the extra matrix:</div><div>
<br></div><div><div class="im"><div>PetscErrorCode HamiltonianJ(TS timeStepContext, PetscReal t, Vec u, Mat *A, Mat *B, MatStructure *flag, void* context)</div><div>{</div></div><div class="im"><div> PetscErrorCode err;</div>
<div> Context *cntx = (Context*)context;</div><div> PetscScalar ef = eField(t, cntx->params);</div><div> //if (cntx->rank == 0) std::cout << "ef: " << ef;</div><div> </div>
</div><div> err = MatDuplicate(cntx->energy_eigenstates,MAT_COPY_VALUES,A);</div><div> err = MatAXPY(*A, ef, cntx->dipole_matrix, DIFFERENT_NONZERO_PATTERN);</div><div><br></div><div><span style="white-space:pre-wrap">        </span>err = MatAssemblyBegin(*A, MAT_FINAL_ASSEMBLY);</div>
<div><span style="white-space:pre-wrap">        </span>err = MatAssemblyEnd(*A, MAT_FINAL_ASSEMBLY);</div><div> </div><div> *flag = DIFFERENT_NONZERO_PATTERN;</div><div><br></div><div> // absorb!</div><div><br></div><div>
return err;</div><div>}</div></div><div><br></div><div>I'm honestly stumped now…</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Andrew</div><div><br></div><br></font></span><div><div class="im">
<div>On May 16, 2012, at 7:17 AM, Jed Brown wrote:</div><br></div><div><div class="h5"><blockquote type="cite"><div class="gmail_quote">On Wed, May 16, 2012 at 7:08 AM, Andrew Spott <span dir="ltr"><<a href="mailto:andrew.spott@gmail.com" target="_blank">andrew.spott@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Not until you pointed it out… :). Though it probably should have been. It was late.<div><br></div><div>Though I'm not sure how to fix that… should I do a MatDestroy(A) at the beginning of that function every time?.</div>
<div><br></div><div>Is *A a pointer to the last used matrix, should I just do the mat duplicate into A?</div></div></blockquote><div><br></div><div>Do you really mean to only change A (the operator), but not B (the preconditioning matrix)?</div>
<div><br></div><div>Why do you want to create a new matrix instead of reusing those?</div></div>
</blockquote></div></div></div><br></div></blockquote></div><br></div></div>