<div>So dynamic array is suitable for acting as a plus to the preallocation. <br>Only a few extra matrix entries not considered in the preallocation are needed to be processed. <br></div><div>For example, an integral boundary condition with dynamic integration range may have different nonzero entry in a row,<br>which can be hold by the dynamic array.<br><br><br>&nbsp; <br> </div><blockquote style="padding-left: 5px; margin-left: 5px; border-left: 2px solid rgb(160, 198, 229); margin-right: 0px;"><br><p>Values in each location are often set many times. Once per element in FEM, so about 20 times for P1 tets. That uses a lot more memory and you need to sort that beast to count correctly. Using a separate dynamic data structure for each row would be a lot more mallocs, but you could keep the rows sorted and avoid storing 20 copies, however insertion is still expensive. A heap is nice for insertion, but not for searching.</p>

<p>So dynamic data structures could help, but they still cost quite a bit. The preallocation problem is trivial for finite difference methods so any useful solution needs to handle many insertions to the same location.</p>

<p></p><blockquote type="cite">On Feb 19, 2011 9:35 AM, "Gong Ding" &lt;<a href="mailto:gdiso@ustc.edu">gdiso@ustc.edu</a>&gt; wrote:<br><br>Hi,<br>
After reading the source code of aij.c, I think the MatSetValues function can be more flexible when preallocation is not correct.<br>
<br>
Why not use a dynamic array such as c++ vector of triple(a, i, j) to buffer the operation?<br>
And flush the buffer to real a,i,j array when MatAssemblyEnd is called?<br>
<font color="#888888"><br>
Gong Ding<br>
</font></blockquote>
</blockquote><span ></span>