24-parallel-for.student - Last Time The"stateful...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Last Time: * The "stateful function problem" * Classes: combine state and functions (methods) * Override the function-call operator: functors Today: * Introduction to concurrency * Things that are easy * Threading Building Blocks * Parallel For (uses recursion, functors)-------------------------------------- Increasingly, gains in performance coming from *more* processors rather than *faster* processors. This trend is accelerating. Two ways to exploit "more processors": * Run more programs at the same time. * Have single programs do more than one thing at once. A program that can do more than one thing at a time is called a "concurrent program." Concurrent programs are interesting, but they are surprisingly difficult to do well. To get a sense for why, think about the List ADT. Each method is allowed to assume that the List invariants are true, as long as it establishes them before exiting---in effect, no other method can "see" the broken invariants. But, if two (or more) List methods can execute *at the same time*, then they could *each* be in "the middle", and the invariants broken by one would be visible in the other. This is clearly Not Good. In the simplest terms, any time two different pieces of a concurrent program could possibly touch the same piece of state, Bad Things (tm) can happen. However, there exists an interesting class of concurrent programs called "embarrasingly parallel". These are programs where there are lots of things that *could* happen at the same time, without any shared state between them. Such programs are very easy to make concurrent, because you don't have to worry about a whole class of problems. For example, consider the following loop: template <typename T> void apply(T a, int size, T (*fn)(T)) // REQUIRES: fn has no side effects, a has size elements // EFFECTS: a[i] = fn(a[i]), for each element in a. { for (int i = 0; i<size; i++) { a[i] = fn(a[i]); } } In this loop, each iteration could be done concurrently: * Each works on a different element....
View Full Document

This note was uploaded on 01/28/2010 for the course EECS 280 taught by Professor Noble during the Winter '08 term at University of Michigan.

Page1 / 6

24-parallel-for.student - Last Time The"stateful...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online