CSC 543 - Multiprocessing & Concurrent Programming (mostly in Java), Old Main 158, W 6-8:50 PM.

Dr. Dale E. Parson
Fall 2018 Office Hours (Old Main 260): Mon 12:30-2:30, Tu 3-4, Wed 3-5, or by appointment

My office hours for final exams week December 10-14 are:
Monday 12:30 - 2:30 PM (normal hours)
Wednesday 3:30-5:30 PM (half hour later than normal)
Thursday 2:30-3:30 PM (no Tuesday) documents the CLASS LIBRARY.


First day handout (syllabus that is specific to this semester).

I have put a copy of the textbook on reserve in Rohrbach Library for the semester. You can go to the front desk & borrow it overnight.
Students can meet in person in OM 158 OR live on-line via Zoom.
    Please read student instructions here. My instructions for CSC faculty are here.
    USE THIS LINK TO LOG INTO ZOOM AT CLASS TIME. Our Zoom course ID is 198597816.
    I will post links to recorded archives at the bottom of this page within a day after each class.
    Fall 2016's course page is here.

We will be multiprocessing on {mcgonagall|harry|dumbledore|luna}, which are accessible via ssh from bill:
        ssh -l yourloginname harry
        ssh -X -l
yourloginname hermione  # The -X enables X11 GUI I/O.

Handouts from Spring 2011 through present.
Slides for week 2, Chapters 1, 2, 3 and 13 on Introduction, Thread Safety, Sharing Objects and Explicit Locks.
    Week 2 added slides on Race Conditions, Critical Sections & Composing Thread-safe Objects.
    Week 2 Jython code to demonstrate using java.lang.Runnable, java.lang.Thread, and a race condition.
Example code is at /export/home/faculty/parson/multip on (and on harry, hermione and ron via NFS).
Locks and condition variables slides from September 21 class session.
Slides for week 3, Chapters 15, 16 and Appendix A on Atomic Variables, Nonblocking Synchronization, the Java Memory Model and Annotations for Concurrency. (4/1/2015)
A problem from the Spring 2011 midterm that uses atomic variables instead of a lock-based monitor.
Slides for week 4, Chapter 4 on Composing Objects. (4/1/2015)
    Code listings for Chapter 4
Slides for week 5, Chapter 5 on Building Block Classes from java.util.concurrent. (4/1/2015)
    Code listings for Chapter 5
    D. Parson and D. Schwesinger, "Minimum-Blocking Parallel Bidirectional Search,"
            Proceedings of PDPTA'12: 2012 Intl. Conf. on Parallel Processing Techniques and Applications , Las Vegas, NV, July 16 - 20, 2012.
             Here are the slides for the talk.

CyclicBarrier, CountDownLatch, and using these & related mechanisms in parallel bidirectional search.
             See code on a
cad at ~parson/multip/pennydime.
Slides for week 7, Chapter 6 on using Executor to schedule tasks using thread pools from java.util.concurrent.
"Creative Graphical Coding via Pipelined Pixel Manipulation, " Proceedings of the 33rd Annual Spring Conference of the Pennsylvania Computer and Information Science Educators (PACISE) Shippensburg University of PA, Shippensburg, PA, April 6-7, 2018.
Processing (Java) code for sketch PhotoArchMontage and its helper active class ImageLoader demonstrating starting a thread.
    Video and some stills from a digital art exhibit in Munich on September 14, 2018.
    This sketch uses my multithreading package PixelVisitor that we will examine in detail.

    Acad ~parson/JavaLang/PixelVisitor has my Java library for Processing that uses Java thread pools.
Slides for week 10, Chapter 7 on Interruption, Cancellation and Shutdown.
More slides for week 10, Chapter 8 on Applying Thread Pools. (4/8/2015)
Slides for week 11, Chapter 9 on GUI Applications. (4/8/2015)
    Tutorial on multithreading in Java FX (GUI framework that supplants Swing.
    Acad ~parson/multip/multip/csc580spring2011/Projects/csc580gps4/ has the Swing example that uses a single-threaded ExecutorService to run the worker thread discussed on 11/30.
More slides for week 11, Chapter 10 on Avoiding Liveness Hazards. (4/15/2015)
Slides for week 12, Chapter 11 on Performance and Scalability. (4/15/2015)
More slides for week 12, Chapter 12 on Testing Concurrent Programs. (4/15/2015)
~parson/Compiler1/optimize5/stepvm/ helper class HeapData has the 12/7 example code for lazy evaluation. Search for:
        class HeapData, HeapData.flatten(...), HeapData.helpflatten(...)
        In optimize5/ see collect_reduce.txt (look for reduce and collect), programqsort1p.txt (reduce), programqsort1p_O2.debug.out (STEP_FORK & STEP_JOIN) the STack-based Emulated Processor
 Slide on critical sections, race conditions, & related concepts
Slide on deadlock

Spring 2011 CSC 580 Special Topics course page.
Spring 2012 CSC 480 Special Topics course.

Example of my Processing visual -> audio work from Cube Fest 2016.
Material in my UNIX account
~parson/multip has a lot of documentation & code examples on current programming.
~parson/multip/spring2015 is where I will work out some code examples for class.
~parson/JavaLang/net/jcip/examples has all example code from our textbook.

Older material
Here is my Summer 2010 study of these machines with a January 2015 update for Dumbledore. We will go over this study in class.
Goetz et. al. Java Concurrency in Practice textbook web site. Code exacadamples on  are under ~parson/JavaLang/net/jcip/examples. An on-line copy of the textbook should be available for 45 days via a code in your hard-copy textbook.
Herlihy / Shavit The Art of Multiprocessor Programming web site.
A secure copy of C++ Concurrency in Action is posted here.
A secure copy of Scala in Depth is posted here.
Parallelism on the Desktop, IEEE Software, January/February 2015 (vol. 28 no. 1) (password restricted access).


Assignment 1 on profiling thread-safe Queues in a pipeline is due by end of September 29 via make turnitin on acad or mcgonagall.
    Here are the grade distribution & outline of important points missed for assignment 1.

Assignment 2 on using implicit locks and explicit locks is due by end of Friday October 19 via make turnitin on acad or mcgonagall. has the algorithm outline from CSC343 Fall 2016.

Assignment 3 on latches, barriers, atomic arrays, thread pools, etc., due by end of Friday November 16 via make turnitin.
    Parson's commandments (rewording of material in the book) for thread safe classes & avoidance of point losses.
    Recheck these before you turn an assignment in.
    Email from November 3 on generating you own student queue functions via make genstudent.

Assignment 4 on thread pools within a server is due on Saturday December 8 via make turnitin.

      Do not catch CancellationException, ExecutionException, or InterruptedException in your submit() functions.

Why? Take a look at the function signature:
    public String submit(Callable<String> task)
        throws CancellationException, // if the computation was cancelled
            ExecutionException, // if the computation threw an exception
            InterruptedException // if the server thread was interrupted
That throws clause means that any function call within submit that throws one of those exceptions, will just send the exception out to the caller of submit() unless you catch it.
You don’t want to catch it in a library function because the library function won’t know what to do with it. You definitely don’t want your submit() to just “swallow” exceptions silently. The correct place for this to get caught is in the calling application, not in the submit() library function. Note this code in
136             try {
137                 String res = server.submit(submitter);
138             } catch (Exception xxx) {
139                 System.err.println("EXCEPTION BY CLIENT THREAD "
140                     + index + " ON SUBMISSION -1 : "
141                     + xxx.getClass().getName() + ", "
142                     + xxx.getMessage());
143             }
Catching Exception (which is a base class) catches all of those exceptions. That is the correct place for the try catch. So, leave it out of submit().
Assignment 5 is here, materials are due via D2L by end of Tuesday, December 11.

Links to Java DOCUMENTATION and download.
documents the CLASS LIBRARY. has downloads
       for JDK 1.6 docs and tools (compiler, etc. for Windows).
       Download Java SE Development Kit (JDK) 6 -> Download -> Continue -> Continue,
       then click the file, ignoring the "Sun Download Manager."

       After installing JDK 1.6
, go to Windows Control Panel -> System -> Advanced -> Environment Variables and set system variable CLASSPATH to your JavaLang directory. If CLASSPATH is already there, append a semicolon followed by your JavaLang path to the string that is there.
Download site for FileZilla file transfer utility for transferring files between bill and your PC, or you can use whatever you already have.

       We will go over Java Projects, source editing and debugging in class.  has the gmake manual.

Zoom Archives

    August 29, 2018 Intro to the course, first day handout.
        We went over memory-consistency limitations for threads running on contexts in different cores, where each context has its own CPU registers, and cores delimit memory caches. Began the Slides for week 2, will resume at slide 6 "Thread safety" on September 5.
    September 5, 2018 Atomics, locks, and thread safe classes, including demos in Jython. We stopped at the last slide in this first set.
    September 12, 2018 Last slide of week 2 through slides for week 3, Java Memory Model, JCIP @annotations, Assignment 1.
    September 19, 2018 Walked through the handout code of assignment 1 in detail; custom class loaders and some O-O concepts.
    September 26, 2018 We went through code examples on mcgonagall in ~parson/multip/spring2015/spring2015exam/.
        ~parson/multip/spring2015/ is a copy. and simulate serial waiting-room ticket taking using atomics and locks.
        make testticket
            time java spring2015exam.AtomicDeliTicket
            55.24user 0.05system 0:10.14elapsed 545%CPU (0avgtext+0avgdata 52844maxresident)k
            time java spring2015exam.LockDeliTicket
            0.10user 0.05system 0:10.12elapsed 1%CPU (0avgtext+0avgdata 47456maxresident)k
            There is a lot of contention for the shared variables in testticket, so atomic spin locks use much more CPU time fruitlessly.
        make testPC
            # Test Producer -> Consumer implementations
            make testpcs 2>&1 | egrep -i '(java )|elapsed|error'
            time java spring2015exam.ProducerConsumerAtomic 4 5000000 12345
            6.53user 0.49system 0:03.70elapsed 189%CPU (0avgtext+0avgdata 558384maxresident)k
            time java spring2015exam.ProducerConsumerAtomicArray 4 5000000 12345 > /tmp/CSC543_X_parson.tmp
            7.53user 0.45system 0:03.91elapsed 203%CPU (0avgtext+0avgdata 555868maxresident)k
            time java spring2015exam.ProducerConsumerLListCondvar 4 5000000 12345 > /tmp/CSC543_X_parson.tmp
            136.72user 1.53system 0:10.50elapsed 1315%CPU (0avgtext+0avgdata 766852maxresident)k
            time java spring2015exam.ProducerConsumerLListReentrantLock 4 5000000 12345 > /tmp/CSC543_X_parson.tmp
            143.64user 2.06system 0:11.67elapsed 1248%CPU (0avgtext+0avgdata 697512maxresident)k
            In contrast, atomics do better here because of low contention for each channel shared by 2 of the 4 threads.
                ProducerConsumerLListCondvar uses implicit locks & condition variables;
                    ProducerConsumerLListReentrantLock uses explicit ones.
                The locks entail blocking in a thread scheduling queue, lock queues, and condition variable queues.
    October 3, 2018 we went over my Assignment 1, added some thread safe mandates, and started Assignment 2.
         In ~parson/multip/spring2015/spring2015exam on mcgonagall:
   shows using an implicit lock (synchronized keyword)
            ProducerConsumerLListReentrantLock shows a reentrant explicit lock.
    October 10, 2018 took questions on Assignment 2, went over slides for weeks 4 & 5 and paper with Dr.
Schwesinger above.
    October 17, 2018 finished week 5 PPT slides and went over "Creative Graphical Coding" app's use of thread pools classes.
    October 24, 2018 went over Assignment 2 results & handed out Assignment 3  & went over.
    October 31, 2018 went over slides for weeks 7 & 10 above (thread pools), possible final presentation topics.
    November 7, 2018 went over new Assignment 4, work time, answered project questions.
    November 14, 2018 Went over assignment 3 questions and Chapter 10 slides on avoiding liveness hazards.
    November 28, 2018 Went over slides on Chapter 11 on Performance and Scalability and Chapter 12 on Testing Concurrent Programs.
        Also examined my parallel quicksort in Java from this summer 2010 study (graph 2).
    December 5, 2018 Went over some Q&A on Assignment 4 and Assignment 5. Work session.
    December 12, 2018 Individual student project 5 presentations.