Presented by David Bunde.
Tutorial at
CCSC-CP 2014.
Resources related to this tutorial:
Abstract:
One of the current big challenges in CS education is how to incorporate parallel programming to prepare our graduates for a world in which essentially all computers have multiple cores. This tutorial presents a parallel programming language and some ways that it can be used to teach parallel concepts in a variety of courses without a wholesale redesign of those courses. Attendees will be given access to an account on a test machine so they can experiment with the language during and after the tutorial.
The language is Chapel, a parallel programming language designed for high-performance computing (HPC). One of Chapel's original design goals was programmer productivity. Both students and faculty at previous workshops have found that this translates into ease of use, finding themselves able to quickly pick it up after minimal instruction. Chapel is a language that supports short script-style programs (e.g. Hello World in a single line) as well as full OO applications. Because it was designed with parallelism in mind, Chapel easily supports common features of parallel programs. Examples include the following:
cobegin { something1(); something2(); something3(); }runs each of the somethingX functions as a separate task, letting it take advantage of available parallel hardware. The construct also provides synchronization at the brace that closes the cobegin statement. This kind of structure is called fork-join parallelism.
forall i in {1..10} do something(i);runs the function something on each integer 1 to 10 (inclusive). Multiple tasks are created automatically, allowing iterations to run in parallel. Because this is a common pattern, it even has a shortcut; the code
[i in {1..10}] something(i);is equivalent to the longer version above.
x = + reduce A;sets x to the sum of the values in the array A. The array can be replaced with other data structures and even a forall construct, such as in the following program to find pi by approximating the integral from -1 to 1 of sqrt(1-x2): (i.e. the area of the unit circle):
const numRect = 10000000; const w = 2.0 / numRect; //rectangle width const baseX = -1 - w/2; const halfPI = + reduce [i in {1..numRect}] (w * sqrt(1.0 - (baseX + i*w)**2)); writeln(2.0*halfPI);Essentially all the work is done in the 2nd to last statement; the lines before that are setting up constants. In addition to +, Chapel provides other common reduction operators such as max, logical or, and *. It also provides facilities for programmers to define their own.
In the tutorial, I will present basic syntax, the parallel features of Chapel, and talk about how it can be used in courses such as Algorithms, Programming Languages, and Parallel Computing. I will particularly demonstrate Chapel's parallel features and concise syntax by working a series of example problems. The unit for Algorithms focuses on the use of reduction as a standard parallel algorithmic technique and the relationship between defining parallel reductions and dynamic programming. The unit for Programming Languages focuses on the design choices made in Chapel. The Parallel Computing unit focuses on some features relatively unique to Chapel for managing locality and controlling the amount of communication in parallel programs.