# Sample Chapel Exercises (CCSC-CP 2014 Tutorial)

Feel free to follow your interests in exploring Chapel, but here are
some suggestions.
For examples of Chapel syntax, refer to the cheat sheet and
to examples.chpl
(html version).
You can also refer to our tutorials:

and the slides on the workshop main page.
Remember that to compile and run, you can do the following:

chpl -o hello hello.chpl
./hello

#### Suggestions for hands-on session:

- Write some of the simple example programs from the slides
("Hello World", summing numbers 1 to 100, etc)
- Write a parallel version of bubble sort: 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.
examples.chpl
(html version) gives a serial implementation.
- Implement binary search.
- Use scan to compute an array of factorials (0!, 1!, 2!, 3!, ...)
- Use scan to compute an array of powers of 3 (1, 3, 9, 27, 81, ...)
- Use the previous two parts to compute the (partial) sum of a Taylor series such as
e^{x}=1+x+x^{2}/2! + x^{3}/3! + ... + x^{i}/i! + ...

- 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.
- Write a custom reduction to identify the 2nd smallest value.
(The sample custom reduction is in
sampleReduction.chpl
(html version).)
What about the k
^{th} smallest?
- Write a custom reduction to compute a histogram from an array of
0s, 1s, and 2s.
- Use a reduction to compute the index where the pivot of quicksort
will be placed, i.e. the number of values smaller than the pivot value.