Sample code to accompany the book "Parallel and Concurrent Programming in Haskell"
Haskell Makefile Other
Pull request Compare This branch is 14 commits ahead, 23 commits behind simonmar:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
crc32
distrib-chat
distrib-db
distrib-ping
fwsparse
index
kmeans
mandel
other
parinfer
.gitignore
.travis-setup.sh
.travis.yml
AccelerateCompat.hs
Async.hs
ByteStringCompat.hs
CasIORef.hs
ConcurrentUtils.hs
DistribUtils.hs
GetURL.hs
LICENSE
Makefile
README.md
Setup.hs
Stream.hs
Sudoku.hs
TBQueue.hs
TBQueue2.hs
TChan.hs
TList.hs
TQueue.hs
ThreadPool.hs
TimeIt.hs
appveyor.yml
catch-mask.hs
catch-mask2.hs
chan.hs
chan2.hs
chan3.hs
chanbench.hs
chat.hs
deadlock1.hs
deadlock2.hs
findpar.hs
findpar2.hs
findpar3.hs
findpar4.hs
findpar5.hs
findseq.hs
fork.hs
fwaccel-gpu.hs
fwaccel.hs
fwdense.hs
fwdense1.hs
geturls.hs
geturls1.hs
geturls2.hs
geturls3.hs
geturls4.hs
geturls5.hs
geturls6.hs
geturls7.hs
geturls8.hs
geturls9.hs
geturlscancel.hs
geturlscancel2.hs
geturlsfirst.hs
geturlsstm.hs
logger.hs
modifytwo.hs
mvar1.hs
mvar2.hs
mvar3.hs
mvar4.hs
parconc-examples.cabal
parlist.hs
parmonad.hs
phonebook.hs
reminders.hs
reminders2.hs
rotateimage.hs
rpar.hs
rsa-pipeline.hs
rsa.hs
rsa1.hs
rsa2.hs
server.hs
server2.hs
stack.yaml
strat.hs
strat2.hs
strat3.hs
sudoku-par1.hs
sudoku-par2.hs
sudoku-par3.hs
sudoku-par4.hs
sudoku1.hs
sudoku17.1000.txt
sudoku17.16000.txt
sudoku17.49151.txt
sudoku2.hs
sudoku3.hs
sudoku4.hs
sudoku5.hs
threadperf1.hs
threadperf2.hs
timeout.hs
timeout2.hs
timetable.hs
timetable1.hs
timetable2.hs
timetable3.hs
tmvar.hs
windowman.hs

README.md

Linux/OS X build status Windows build status

SeaHUG "Parallel and concurrent programming in Haskell" materials

About the book

To get more information about the source text "Parallel and Concurrent Programming in Haskell" by Simon Marlow, please visit the book's web site. You can purchase the book or read it online there for free.

Installing stack

Stack is a tool for downloading, installing, and building haskell projects. It takes care of handling multiple compiler versions, and supports sandboxing sharing build results between projects.

Windows 64bit

Download and run the installer from here.

Also, take a look at the instructions here. While not strictly necessary, it is a good idea to use set STACK_ROOT=c:\stack_root with stack, due to windows MAX_PATH restrictions.

Mac OS

brew install haskell-stack

Linux 64bit

There are also distribution specific versions (see the "Other" section below), but I find this to be the most straightforward way to get a recent version:

wget https://github.com/commercialhaskell/stack/releases/download/v1.0.4/stack-1.0.4-linux-x86_64.tar.gz
mkdir -p ~/.local/bin
tar -xvf stack-1.0.4-linux-x86_64.tar.gz
mv stack-1.0.4-linux-x86_64/stack ~/.local/bin/stack

# Optionally, remove the archive and its unpacked dir
rm -r stack-1.0.4-linux-x86_64
rm stack-1.0.4-linux-x86_64.tar.gz

Then, try which stack. If the response is not the .local/bin/stack folder within your home directory, then you will need to add .local/bin/stack to your PATH. To do this, add the following to your ~/.profile, and then start a new terminal:

if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

Other

See the installation instructions here.

Cloning this repo and setting up your environment

Clone this repo as follows:

git clone https://github.com/seahug/parconc-examples.git

We then ask stack to set up an appropriate version of GHC:

cd parconc-examples/
stack setup

Loading examples into ghci

Usually we'll only want to load up a single example at a time. stack ghci is a good way to do this:

mgsloan@computer:~/oss/seahug/pcph$ stack ghci --no-build :parmonad
There were multiple candidates for the Cabal entry "Lex" (/home/mgsloan/oss/seahug/pcph/examples/parinfer/Lex.x), picking /home/mgsloan/oss/seahug/pcph/examples/parinfer/Lex.hs
There were multiple candidates for the Cabal entry "Parse" (/home/mgsloan/oss/seahug/pcph/examples/parinfer/Parse.y), picking /home/mgsloan/oss/seahug/pcph/examples/parinfer/Parse.hs
There were multiple candidates for the Cabal entry "Lex" (/home/mgsloan/oss/seahug/pcph/examples/parinfer/Lex.x), picking /home/mgsloan/oss/seahug/pcph/examples/parinfer/Lex.hs
There were multiple candidates for the Cabal entry "Parse" (/home/mgsloan/oss/seahug/pcph/examples/parinfer/Parse.y), picking /home/mgsloan/oss/seahug/pcph/examples/parinfer/Parse.hs
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Using main module: 1. Package `parconc-examples' component exe:parmonad with main-is file: /home/mgsloan/oss/seahug/pcph/examples/parmonad.hs
Configuring GHCi with the following packages: parconc-examples
GHCi, version 7.8.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package containers-0.5.5.1 ... linking ... done.
Loading package old-locale-1.0.0.6 ... linking ... done.
Loading package time-1.4.2 ... linking ... done.
Loading package random-1.0.1.1 ... linking ... done.
Loading package abstract-deque-0.3 ... linking ... done.
Loading package abstract-par-0.3.3 ... linking ... done.
Loading package bytestring-0.10.4.0 ... linking ... done.
Loading package cereal-0.4.1.1 ... linking ... done.
Loading package transformers-0.3.0.0 ... linking ... done.
Loading package mtl-2.1.3.1 ... linking ... done.
Loading package monad-par-extras-0.3.3 ... linking ... done.
Loading package primitive-0.6.1.0 ... linking ... done.
Loading package vector-0.10.12.3 ... linking ... done.
Loading package mwc-random-0.13.4.0 ... linking ... done.
Loading package parallel-3.2.0.6 ... linking ... done.
Loading package monad-par-0.3.4.7 ... linking ... done.
unknown option: 'c'
[1 of 1] Compiling Main             ( /home/mgsloan/oss/seahug/pcph/examples/parmonad.hs, interpreted )
Ok, modules loaded: Main.
*Main> :set args 4 5
*Main> main
13
*Main> :t fib
fib :: Integer -> Integer
*Main> :bro
fib :: Integer -> Integer
main :: IO ()

Building all examples

To build optimized versions of the examples, run stack build. Then, you can run the example by name by using stack exec. For example, stack exec -- parmonad 4 5.

License

  • Released under BSD3 License
  • Code samples, copyright © Simon Marlow 2011-2013
  • Other material, copyright © Richard Cook and Michael Sloan 2016