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>
Matt<br><br><div><span class="gmail_quote">On 5/10/06, <b class="gmail_sendername">Jordi Marcé Nogué</b> <<a href="mailto:jordi.marce@upc.edu">jordi.marce@upc.edu</a>> 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>"element3D *p_element = lfiber[i].getElement(e)" 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, &M_aux1);<br>MatCreateSeqAIJ(PETSC_COMM_SELF, 6, 6, 6, PETSC_NULL, &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<nfiber;i++)<br>{<br> for(uint32_t e=0; e<lfiber[i].nelements;e++)<br> {<br><br> MatZeroentries(M_aux1);<br> MatZeroentries(M_aux2);
<br><br> element3D *p_element = lfiber[i].getElement(e);<br><br> p_element->updateTs();<br><br> MatSetValue(M_aux1, 0, 0, p_element->L0 * value.pho / 6.,<br>INSERT_VALUES);<br> MatSetValue(M_aux1, 1, 1, p_element->L0 *
value.pho / 6.,<br>INSERT_VALUES);<br> MatSetValue(M_aux1, 2, 2, p_element->L0 * value.pho / 6.,<br>INSERT_VALUES);<br> MatSetValue(M_aux1, 3, 3, p_element->L0 * value.pho / 6.,<br>INSERT_VALUES);<br> MatSetValue(M_aux1, 4, 4, p_element->L0 *
value.pho / 6.,<br>INSERT_VALUES);<br> MatSetValue(M_aux1, 5, 5, p_element->L0 * value.pho / 6.,<br>INSERT_VALUES);<br><br><br> MatAssemblyBegin(M_aux1,MAT_FINAL_ASSEMBLY);<br> MatAssemblyEnd(M_aux1,MAT_FINAL_ASSEMBLY);
<br><br><br> MatMatMult(M_aux1,p_element->T,&M_aux2);<br> MatMatMult(p_element->TT,M_aux2,&M_aux1);<br><br> }<br><br> // here I work with the matrix M_aux2, but in this point the memory
<br> // 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>"Failure has a thousand explanations. Success doesn't need one" -- Sir Alec Guiness