Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

C/C++

Going Superlinear


A Word About Sequential Efficiency versus Complexity

At this point, it's important to consider and understand a potential objection. "But wait," someone could complain, "your example so far is unfair because you've stacked the deck. The truth is that, when you find a superlinear speedup, what you've really found is an inefficiency in the sequential algorithm." Taking a deep breath, the dissenter might correctly point out: "For any P-way parallel algorithm, we can find a sequential algorithm that is only P times slower (that is, the parallel advantage is linear, not superlinear) as follows: Just visit the nodes in the same order as the parallel algorithm, only one at a time instead of P at a time. Visit the set of nodes visited first by each worker, then the set of nodes visited second by each worker, and so on. Obviously, that will be slower than the parallel version by only a factor of P." Give yourself bonus points if you noticed that, and more bonus points if you noticed that even Amdahl's Law (covered last month [3]) implies that the maximum speedup though the use of P processors cannot be more than P.

It is indeed important and useful to know we can turn any parallel algorithm into a sequential one by just doing the steps of the work one at a time instead of P at a time. This is a simple and cool technique that often helps us reason clearly about the performance of our parallel algorithms; we definitely need this one in our algorithm design toolchests.

But we cannot therefore conclude that superlinear speedups are simply due to inefficiency in the sequential algorithm ("you should have written the sequential one better"). Let's consider a few pitfalls in the proposed resequentialized algorithm.

First, it has worse memory behavior, especially if (a) the algorithm makes multiple passes over the same region of data and/or (b) the collection is an array. The proposed algorithm has worse memory and cache locality because it deliberately keeps jumping around through the search space. Further, its traversal order is hostile to prefetching: Hardware prefetchers try to hide the cost of accessing memory by noticing that if your program is asking for memory location X now, it's likely to want memory locations like X+1 or X-1 next, so it can choose to speculatively request those at the same time without actually waiting for the program to ask for them. This typically gives a big performance boost to code that traverses memory in order, either forward or backward, instead of jumping around. (This applies less if the collection is a node-based data structure like a tree or graph, because node-based structures typically make their traversals jump around in memory anyway.)

Note that the parallel algorithm avoids this problem because each worker naturally maintains both linear traversal order and locality within its contiguous subrange. You might expect that if the workers all share the same cache anyway, the analysis could come out the same, but the problem doesn't bite us for reasons we'll consider in more detail next month when we cover hardware considerations. (Hint: The workers typically do not share the same cache...)

Second, it's more complex. It has to do more bookkeeping than a simple linear traversal. This additional work can be a small additional source of performance overhead, but the more important effect is that algorithms that are more complex require more work to write, test, and maintain.

Third, it will sometimes be a pessimization. Even when the values are nonuniform (which is what the complexified algorithm is designed to exploit), sometimes there will be high-probability areas near the front of the collection, and the original sequential search would have searched them thoroughly first whereas the modified version will keep jumping away from them. After all, there's no way to tell what visitation order is best without knowing in advance where the high-probability regions are.

Finally, and perhaps most importantly, when we're comparing the proposed algorithm with simple parallel search, we're not really comparing apples with apples. We are comparing:

  • A complex sequential algorithm that has been designed to optimize for certain expected data distributions, and
  • A simple parallel algorithm that doesn't make assumptions about distributions, works well for a wide range of distributions, and naturally takes advantage of the special ones the optimized one is trying to exploit...and still gets linear speedup over its optimized sequential competition on the latter's home turf.

On Deck

There are two main ways into the superlinear stratosphere:

  • Do disproportionately less work.
  • Harness disproportionately more resources.

This month, I focused on the first point. Next month, I conclude that with a few more examples, then consider how to set superlinear speedups by harnessing more resources—quite literally, running on a bigger machine without any change in the hardware.

Acknowledgments

Thanks to Tim Harris, Stephan Lavavej, and Joe Duffy for their input on drafts of this article.

Notes

[1] V.N. Rao and V. Kumar. "Superlinear speedup in parallel state-space search," Foundations of Software Technology and Theoretical Computer Science (Springer, 1988).

[2] Si. Pi Ravikumar. Parallel Methods for VLSI Layout Design, 4.3.2 (Ablex/Greenwood, 1996).

[3] H. Sutter. "Break Amdahl's Law!" (DDJ, February 2008).


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.