Sample Chapel Exercises (SC 13 Ed Program)
Feel free to follow your interests in exploring Chapel, but here are
some suggestions:
Suggestions for hands-on session one:
- Write a procedure to compute the dot product of two vectors.
One possible signature for the method is
proc getDotProduct(v : [] real, w : [] real) {
For testing, you may find it helpful to create random vectors.
You can do this by adding use Random; at the top of file and
then using the fillRandom function:
fillRandom(numbers);
where numbers has already been declared as an array.
This also works on 2D (or higher) arrays.
-
Define a function for matrix-vector products.
A possible signature:
proc matrixVectorProduct(matrix : [] real, vector : [] real) {
If you want to use your dot product routine, you can get the range of
row values using matrix.domain.dim(1) and you can extract a
single row of the matrix by accessing it with only one coordinate:
matrix[index].
- Define a node class and use it to make a linked list.
(nil is the name of a null reference in Chapel.)
Write functions for inserting, removing, printing the list, etc.
- Implement binary search.
- Use a reduction to sum a Taylor series (e.g. to estimate ex)
- Write a custom reduction to identify the 2nd smallest value.
What about the kth smallest?
Suggestions for hands-on session two:
(You can also continue with the session one problems...)
- Write a function to split a one-dimensional range into two equal
pieces.
For a range R, you can get the lowest value, the highest
value, and the stride (distance between consecutive elements) using
R.low, R.high, and R.stride respectively.
- Write a function to perform bubble sort.
Next, try to do a parallel version: Repeatedly compare each even-indexed
element with its successor and then each odd-indexed element with
its successor.
After n repetitions of this, the array should be sorted.
- Implement binary search by changing the domain.
- See if you can implement the Game of Life by following the
algorithm descriptions.