The code you have there will create a matrix for every loop iteration,<br>
and will only destroy one at the end. The new MatMatMult() interface<br>
has an argument which allows the user to pass in a matrix.<br>
<br>
&nbsp;&nbsp; Matt<br><br><div><span class="gmail_quote">On 5/10/06, <b class="gmail_sendername">Jordi Marcé Nogué</b> &lt;<a href="mailto:jordi.marce@upc.edu">jordi.marce@upc.edu</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Yes, of course I destroy the matrix.... The scheme of my code when I<br>create a diagonal Mass-lumping matrix is the code below.<br><br>In MatSeqAIJSetPreallocation(M_aux1,6,PETSC_NULL); the number is 6<br>because in a general coordinates it's possible this matrix changes in a
<br>6x6 full matrix.<br><br>&quot;element3D *p_element = lfiber[i].getElement(e)&quot;&nbsp;&nbsp;is a internal<br>procedure to obtain information about the element<br><br>------------------------------------------------------------------
<br><br>Mat M_aux1, M_aux2;<br><br>MatCreateSeqAIJ(PETSC_COMM_SELF, 6, 6, 6, PETSC_NULL, &amp;M_aux1);<br>MatCreateSeqAIJ(PETSC_COMM_SELF, 6, 6, 6, PETSC_NULL, &amp;M_aux2);<br><br>MatSeqAIJSetPreallocation(M_aux1,6,PETSC_NULL);
<br>MatSeqAIJSetPreallocation(M_aux2,6,PETSC_NULL);<br><br>MatSetFromOptions(M_aux1);<br>MatSetOption(M_aux1, MAT_SYMMETRIC);<br>MatSetOption(M_aux1, MAT_IGNORE_ZERO_ENTRIES);<br><br>MatSetFromOptions(M_aux2);<br>MatSetOption(M_aux2, MAT_SYMMETRIC);
<br>MatSetOption(M_aux2, MAT_IGNORE_ZERO_ENTRIES);<br><br><br>for(uint32_t i=0; i&lt;nfiber;i++)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; for(uint32_t e=0; e&lt;lfiber[i].nelements;e++)<br>&nbsp;&nbsp;&nbsp;&nbsp; {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatZeroentries(M_aux1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatZeroentries(M_aux2);
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;element3D *p_element = lfiber[i].getElement(e);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p_element-&gt;updateTs();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatSetValue(M_aux1, 0, 0, p_element-&gt;L0 * value.pho / 6.,<br>INSERT_VALUES);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatSetValue(M_aux1, 1, 1, p_element-&gt;L0 * 
value.pho / 6.,<br>INSERT_VALUES);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatSetValue(M_aux1, 2, 2, p_element-&gt;L0 * value.pho / 6.,<br>INSERT_VALUES);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatSetValue(M_aux1, 3, 3, p_element-&gt;L0 * value.pho / 6.,<br>INSERT_VALUES);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatSetValue(M_aux1, 4, 4, p_element-&gt;L0 * 
value.pho / 6.,<br>INSERT_VALUES);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatSetValue(M_aux1, 5, 5, p_element-&gt;L0 * value.pho / 6.,<br>INSERT_VALUES);<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatAssemblyBegin(M_aux1,MAT_FINAL_ASSEMBLY);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatAssemblyEnd(M_aux1,MAT_FINAL_ASSEMBLY);
<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatMatMult(M_aux1,p_element-&gt;T,&amp;M_aux2);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatMatMult(p_element-&gt;TT,M_aux2,&amp;M_aux1);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// here I work with the matrix M_aux2, but in this point the memory
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// is constant. The code doesn't waste memory<br>}<br><br>MatDestroy(M_aux1);<br>MatDestroy(M_aux2);<br><br>------------------------<br><br><br>Thanks,<br><br>best regards<br><br><br>--<br>Jordi Marcé-Nogué<br>Dept. Resistència de Materials i Estructures a l'Enginyeria
<br>Universitat Politècnica de Catalunya (UPC)<br><br>Edifici T45 - despatx 137<br>ETSEIAT (Terrassa)<br><br>phone: +34 937 398 728<br>mail: <a href="mailto:jordi.marce@upc.edu">jordi.marce@upc.edu</a><br><br></blockquote>
</div><br><br clear="all"><br>-- <br>&quot;Failure has a thousand explanations. Success doesn't need one&quot; -- Sir Alec Guiness