|
Projects
Exams
Lecture Material
- September 4 - Introduction
- September 9 - Concurrency, java threading
- September 9,11 - Thread-safe classes. Example programs:
- September 16 - Synchronization
- September 18 - Synchronization and testing.
- September 23 - Visiblity
- September 25 - Sharing objects
- Understanding volatile:
- Protecting internal state:
- BadLine.java -
broken because internal fields are public, and because the those
fields point to mutable objects
- BadLineTwo.java - better
than the above because fields no longer modifiable, but point objects
themselves are still accessible, and mutable
- Line.java - fixes
problems in the above two examples by making point objects immutable
(i.e., Point.java
objects) and fields pointing to them private
- BadLineThree.java - broken
because the internal array is returned, and can thus be modified
- Not "leaking" the this pointer during initialization
- September 30 - Concurrent
collections
- Synchronizing standard collections classes using the
java.util.Collections.synchronizedXXX factory method:
how it works
- Client-side locking for compound operations: ListGetLast.java
- ConcurrentHashMap vs. other maps performance test: ConcSyncHashMapPerfTest.java
- October 2 - Synchronizers
- October 7 - State dependent
actions
- October 9 - Midterm review (see above)
- October 14 - Midterm
- October 16 - Task Execution
(JCIP chapter 6)
We started with
WordCount.java
(note that this file more intelligently uses a StringBuffer, in
contrast to the one we started with in class). We referred to these
slides to identify
the kinds of parallelism. We went over this design recipe. We
developed versions of word counting as follows:
- WordCountTransition.java
"chunks" the units of work but executes them sequentially.
- WordCountParallelBad.java
performs the units of work in parallel using a thread pool, and
synchronizing on the map when updating it. The overhead from
synchronization becomes prohibitive.
- WordCountParallel.java
uses a ConcurrentHashMap to avoid the synchronization overhead, and
it performs much better, but it must be clever about updating the
counts to avoid read-modify-write atomicity violations.
- WordCountParallelAtomicInt.java
uses an AtomicInteger in the range of the map to avoid these
problems. We use same AtomicInteger once it is added to the table,
and modify it in place.
Here is a transcript of runs on my
machine that shows the performance of each approach. This comes
from my 8-core, 16 GB-of-RAM Mac Pro.
- October 21 - Thread
pools
- October 23 - Parallelization
- We went over the puzzle solving framework from the text (see
code examples 8.13 - 8.18 here)
- We also discussed Fork/Join parallelism, using these slides. The example from the slides, fully
implemented, is in the files
If you are running Java 6 you will need to download the jsr166y.jar
library from Doug Lea's
concurrency interest page (which contains API
documentation) and include it in your classpath; e.g., add it to
your Eclipse project as an external library. You will also have to
change java.util.concurrent.ForkJoinPool and other
imports in the code to be
jsr166y.ForkJoinPool instead.
- October 28 - Performance and Scalability
- Three examples of a map using striped locking:
- We also looked at JCIP examples from chapter 10 (demonstrating
deadlock) and chapter 11 (identifying serial work)
- October 30 - Nonblocking
synchronization and atomic variables
- November 4 - Introduction to Erlang. Code:
- Erlang
distribution with source, Windows binaries. Distribution can
be also gotten from MacPorts (port install erlang), and
Linux package mangers (e.g., apt-get install erlang on
Debian, and yum install erlang on Fedora). We are using
major revision 16. Will be installed on Linuxlab.
- Erlide, an Erlang Eclipse plugin
On-line tutorial:
Documentation:
- November 6 - Introduction to Concurrent Programming in
Erlang. We went over the content of Jim Larson's article on
Erlang, and covered the following code examples:
- November 11 - More Concurrent Programming in
Erlang. Programs considered:
- November 13 - Erlang Parallelization and other odds and
ends.
- name_server.erl uses the
server1.erl
behavior to illustrate Erlang dictionaries
- receivedmod.erl
illustrates the after pattern for receive
- try_test.erl
illustrates error handling
- fun.erl is an
example use of the lists:map function
- parmap.erl is
the version of a parallelized map that we developed
in class.
- parmap-erlang.zip
contains files for testing parallel map, including the
runtests script. You can copy these files to
Linuxlab, compile them, and then execute ./runtests
to see the benefits of parallelization.
- November 18 - midterm review
- November 20 - midterm
- November 25 - Remote Method Invocation (guest lecturer, Rance Cleaveland). Main example used in class:
- December 2 - MapReduce,
- December 4 - Parallel and
concurrent garbage collection
- See also this lecture on memory
management, particularly the slides on automatic memory
management, for the serial algorithms
- and this white
paper on the Java HotSpot collector
- December 9 - Actors in
Scala. In addition to going over the above-linked tutorial, we
briefly went over Scala generally, using this tutorial
for Java programmers. We went over several actor examples, some
of which had Erlang analogues:
|