<div class="gmail_quote">On Mon, Sep 19, 2011 at 14:43, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":ly"> In our case of MatGetSubMatrices() there are two main use cases.<br>
<br>
1) something like 80+ percent of the indices are non-null, maybe even 99 percent. Clearly an array makes sense here and there is no reason to use a hash table<br>
<br>
2) something like at most for large problems a couple percent of the indices are non-null. An array is not scalable for large problems.<br></div></blockquote><div><br></div><div>Can we declare the expected sizes and make an automatic choice, perhaps with manual override?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div id=":ly">
<br>
3) have two different (but almost identical routines), one that is hardwired with the array lookup one hardwired with hash table look up (yuck)<br>
<br>
In order for the (1) case to be efficient (that is many lookups are done and are successful) I don't want to have "two" implementations handled by the usual virtual function business (too much overhead is introduced)</div>
</blockquote><div><br></div><div>It is not necessarily the case that an if statement is less overhead than a virtual function. It depends whether the compiler decides to inline the whole thing and which branch of the if statement is taken. (The if statement implicitly makes a choice about which branch will be preferred by which jumps it inserts in the assembly. The virtual function is more symmetric. Now _PETSc_ virtual functions with string lookup are way expensive, and PetscFunctionBegin is significant when running in debug mode.</div>
<div><br></div></div>