Exercise 1

Description

This exercise is designed to get you started with looking at the course materials and with playing with parallelism in Haskell. It does not need to be submitted. Feel free to discuss it with your class mates and help each other out. If you run into problems, mail Nick, the course assistant (frolov at chalmers.se). If you have a eureka moment while reading papers or doing the exercise, let us know.

1. First, you need to get as far as running and profiling a parallel Haskell program. The stuDAT (Linux) computers have a recent Haskell Platform installed.
2. The GHC user guide contains a chapter about Using GHC (command-line arguments and the like).
4. Next, write, compile and run a sequential merge sort program in Haskell.
```

msort :: Ord a => [a] -> [a]
```
If your Haskell is very rusty, you might want to look back at Dave Sands' course on Functional Programming. The course pages point to plenty of useful information about Haskell.
5. Next, study the section on using multiple cores with GHC in Chapter 24 of Real World Haskell. We are going to concentrate on the examples involving quicksort. See also the slides from Lecture 1. The actual code (for the whole book) is available. Download this and pick out the Sorting.hs and SortMain.hs files from Chapter 24. Play with them and then use them for inspiration in your own coding.
6. For benchmarking, we advise using the Criterion package from Hackage. Type
```

cabal update
cabal install criterion
```
(and be prepared to wait a while). A nice intro. to the package (by its author Bryan O'Sullivan) is well worth reading, even though it is about an older version of the package. (See also Lecture 1).
7. Think about the questions raised at the end of Lecture 1. What exactly has been parallelised in quicksort?
8. Parallelise your merge sort in much the same way as quicksort is parallelised in the RWH code or in Lecture 1. Be prepared to play with the code. Develop a habit of documenting what you have tried. Does it help to introduce a threshold below which the code reverts to a sequential algorithm? Does changing heap size for garbage collection have a noticeable effect? We don't expect spectacular results -- just some speedup. The aim of the exercise is to get used to the tools, and to get you thinking.
9. More questions to think about: Does it help to use a tree data structure to represent lists during the sorting (so as to avoid repeated list splitting or appending)? What about Strategies? Will they help here?