CS250 Project 5: Parallel Processing
Due Wednesday, May 11, at 12:00 PM (noon)
Parallel processing is required to fully utilize most modern CPUs. This assignment is intended to give you some practical experience in parallel programming. A program is supplied which calculates the sum of a large list, using only one thread, and displays the amount of time required. Your task is to modify this program so that it can take advantage of multiple cores. Isoptera is available for testing, with 24 real cores (48 apparent cores, due to hyperthreading). However, you can do this assignment on any multi-core computer, including any of the lab computers in MLH.
The program is called p5start.c, and comes with a Makefile. You can download it here. You don't have to use the Makefile, but if you decide to use it, here's how:
Test to see how much improvement is gained by parallel processing. In addition to the source code of your completed program, include a brief report showing the amount of time required for different numbers of processors, and the answers to the following questions:
- Place the Makefile in the same directory as p5start.c
- At the command line, type "make".
- If make is installed, and so are all the libraries required, the project will build. If not, you will have to install make, required libraries, or both. isoptera and the lab computers are already set up correctly.
- Does parallel processing speed up processing of short lists? Try a length of 1000 items.
- Why do you think a single processor is more than half as fast as two processors?
The pthreads library is not covered at all in the book. The manpages cover the individual functions, and "man pthreads" will provide a summary, but this may not be the most accessible documentation. Here are a couple suggestions:
- The void* parameter passed to the function started by pthread_create can point to a structure. You can cast a structure pointer to a void* like this: (void*)my_structure_pointer.
- Besides passing with a void*, global variables can be used to share data with threads.
- The result can be calculated by assigning each worker thread a secton of the array, and then adding up the results from each worker thread.
- Assuming you use the method above, the worker threads may not finish at the same time, but they will be pretty close. Remember not to summarize the results until all worker threads have finished.
Complete, but maybe more details than you need: https://computing.llnl.gov/tutorials/pthreads/
Fairly detailed, again more details than you need: http://randu.org/tutorials/threads/
C tutorial, which might answer language questions: http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basics/c_tutorial.html