simonmar / parconc-examples Goto Github PK
View Code? Open in Web Editor NEWSample code to accompany the book "Parallel and Concurrent Programming in Haskell"
License: Other
Sample code to accompany the book "Parallel and Concurrent Programming in Haskell"
License: Other
Hi Simon,
I experienced some issues when I tried to build this project with my Haskell versions (cabal 1.22.3.0 and GHC 7.10.1). The build was done on Mac OS X, although I don't think the OS played much of a role in this case.
I was able to fix most of these failures by relaxing the version requirements, see my commit for details:
apauley@771c4e5
The executables that I could not fix with version number bumping are left commented out.
Would you like a pull request for the fixes in the commit above?
For completeness, below are the errors I initially received when attempting to follow the book instructions (in a clean sandbox) listed at http://chimera.labs.oreilly.com/books/1230000000929/ch01.html#sec_into-tools
The same errors are present when trying to compile from the git repository.
Iris:parconc andreas$ cabal unpack parconc-examples
Unpacking to parconc-examples-0.3.4/
Iris:parconc andreas$ cd parconc-examples-0.3.4
Iris:parconc-examples-0.3.4 andreas$ cabal sandbox init
Writing a default package environment file to
/Users/andreas/Code/Haskell/tmp/parconc/parconc-examples-0.3.4/cabal.sandbox.config
Creating a new sandbox at
/Users/andreas/Code/Haskell/tmp/parconc/parconc-examples-0.3.4/.cabal-sandbox
Iris:parconc-examples-0.3.4 andreas$ cabal install --only-dependencies
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: parconc-examples-0.3.4 (user goal)
next goal: base (dependency of parconc-examples-0.3.4)
rejecting: base-4.8.0.0/installed-901... (conflict: parconc-examples =>
base>=4.5 && <4.8)
rejecting: base-4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0, 4.6.0.1, 4.6.0.0, 4.5.1.0,
4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0,
4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global constraint requires installed
instance)
Dependency tree exhaustively searched.
Note: when using a sandbox, all packages are required to have consistent
dependencies. Try reinstalling/unregistering the offending packages or
recreating the sandbox.
ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.4.3
cabal install --only-dependencies
clang: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: parconc-examples-0.4.5 (user goal)
[__1] next goal: base (dependency of parconc-examples)
[__1] rejecting: base-4.11.1.0/installed-4.1... (conflict: parconc-examples =>
base>=4.5 && <4.9)
[__1] rejecting: base-4.11.1.0, base-4.11.0.0, base-4.10.1.0, base-4.10.0.0,
base-4.9.1.0, base-4.9.0.0, base-4.8.2.0, base-4.8.1.0, base-4.8.0.0,
base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1, base-4.6.0.0,
base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0, base-4.3.1.0,
base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0, base-4.1.0.0,
base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from non-upgradeable
package requires installed instance)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base, parconc-examples
It succeeds if I add --allow-new
In the "Parallel Type Inferencer" example in chapter 4, parinfer
is invoked like this
$ ./parinfer <benchmark.in +RTS -s -N2
The recipe for parinfer
in parconc-examples.cabal
doesn't allow this, however, as parinfer
is not built with -threaded
. Running with stack
following a stack build
leads to the following error:
$ stack exec parinfer <parinfer/benchmark.in -- +RTS -s -N2
parinfer: the flag -N2 requires the program to be built with -threaded
The problem is with the following code:
liftPar :: ParIO a -> EParIO a
liftPar p = E $ p >>= return . Right
new :: EParIO (EVar a)
new = liftPar P.new
-- new :: Par (IVar a)
Par.new
returns a Par (IVar a)
not ParIO (IVar a)
, how can I get this compiling? I have the same problem getting the code in the book working.
GHC 7.10.3, cabal 1.22.5.0
I'm currently looking to run the ping.hs program example under the distrib-ping directory and to that end im trying to build the executables with cabal.
on building parconc as directed in the book by the following (as stated on the book)
The sample code is collected together in the package parconc-examples on Hackage.
To download and unpack it, run:
$ cabal unpack parconc-examples
Then, install the dependent packages:
$ cd parconc-examples
$ cabal install --only-dependencies
Next, build all the sample programs:
$ cabal build
The parconc-examples package will be updated as necessary to follow future changes
in the Haskell Platform or other APIs.
I have downloaded stack from the official site
and cable from here
on building I get the following error
sanjitkumar@Sanjits-MacBook-Air parconc-examples-0.4.8 % cabal install --only-dependencies
cabal: Could not resolve dependencies:
[__0] trying: parconc-examples-0.4.8 (user goal)
[__1] next goal: base (dependency of parconc-examples)
[__1] rejecting: base-4.14.1.0/installed-4.14.1.0 (conflict: parconc-examples
=> base>=4.5 && <4.14)
[__1] skipping: base-4.15.0.0, base-4.14.1.0, base-4.14.0.0 (has the same
characteristics that caused the previous version to fail: excluded by
constraint '>=4.5 && <4.14' from 'parconc-examples')
[__1] rejecting: base-4.13.0.0, base-4.12.0.0, base-4.11.1.0, base-4.11.0.0,
base-4.10.1.0, base-4.10.0.0, base-4.9.1.0, base-4.9.0.0, base-4.8.2.0,
base-4.8.1.0, base-4.8.0.0, base-4.7.0.2, base-4.7.0.1, base-4.7.0.0,
base-4.6.0.1, base-4.6.0.0, base-4.5.1.0, base-4.5.0.0, base-4.4.1.0,
base-4.4.0.0, base-4.3.1.0, base-4.3.0.0, base-4.2.0.2, base-4.2.0.1,
base-4.2.0.0, base-4.1.0.0, base-4.0.0.0, base-3.0.3.2, base-3.0.3.1
(constraint from non-upgradeable package requires installed instance)
[__1] fail (backjumping, conflict set: base, parconc-examples)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base, parconc-examples
Cloning this repository on Mac with a case-insensitive filesystem doesn't work because of the files TMVar.hs and tmvar.hs (one of which is a soft-link to the other).
I propose to put these "miscmodules" into a subdirectory with soft links back to the parent directory. This way the filenames are still the same as in the book but the code can be used on a Mac with the default filesystem.
When i run the command below:
ghc -O2 fwaccel-gpu.hs -threaded
it states:
AccelerateCompat.hs:3:27:
error: token is not a valid binary operator in a preprocessor subexpression
#if MIN_VERSION_accelerate(0, 14, 0)
~~~~~~~~~~~~~~~~~~~~~~^
1 error generated.
The Repa code uses repa-devil, and the latest version of that package requires transformers <0.5, which requires base <4.9. But the stack.yaml lists the resolver as lts-8.21, which has base of 4.9.1.
Need to switch to using repa-io, friday-devil, or JuicyPixels-repa.
$ ghc ByteStringCompat.hs
ByteStringCompat.hs:8:0:
error: missing binary operator before token "("
In chat example from Chapter 12, it seems to me that there is no guarantee that when two users kick each other at the same time, only one of the kicks will succeed.
The kick operation is divided to two STM transactions (two atomically
calls): one of them is in server
function in runClient
(at line 214), the second one is in handleMessage
(at line 236). When we divide the transaction into two, we lose the atomicity, right?
Here is an example project (https://github.com/shiraeeshi/hs-parconc-chat-server) that shows how to make two concurrent kicks succeed. I added /pause
, /resume
, /pauseKicks
, /resumeKicks
commands. You can see the scenario in readme.
When I run cabal install --only-dependencies with ghc 7.8.2 / base-4.7.0.0 I get:
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: parconc-examples-0.3.2 (user goal)
next goal: base (dependency of parconc-examples-0.3.2)
rejecting: base-4.7.0.0/installed-018... (conflict: parconc-examples =>
base>=4.5 && <4.7)
rejecting: base-4.7.0.0, 4.6.0.1, 4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0,
4.3.1.0, 4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2,
3.0.3.1 (global constraint requires installed instance)
Dependency tree exhaustively searched.
Wikipedia now seems to use HTTPS for all connections, which breaks the example code for the geturl
files.
I've found that on my computer, not using a proxy or anything to complicate the connection, the following simple changes to geturl1.hs
allow it to work:
import Control.Concurrent
import qualified Data.ByteString.Lazy as B -- Use Data.ByteString.Lazy
import Network.HTTP.Conduit
-- Use Network.HTTP.Conduit instead of the GetURL.hs file
main = do
m1 <- newEmptyMVar
m2 <- newEmptyMVar
forkIO $ do
r <- simpleHttp "https://www.wikipedia.org/wiki/Shovel" -- Change getURL to simpleHttp
putMVar m1 r
forkIO $ do
r <- simpleHttp "https://www.wikipedia.org/wiki/Spade" -- Change getURL to simpleHttp
putMVar m2 r
r1 <- takeMVar m1
r2 <- takeMVar m2
print (B.length r1, B.length r2)
Cloning from master and stack build
produces the error pasted below.
I tried the recommended action to add to extra-deps but it seemed to lead me down an endless path of adding things to extra-deps.
Stack version 2.7.1, Linux 5.9, HEAD at 840a3f5
Cabal file warning in /parconc-examples/parconc-examples.cabal@281:3: The field "build-tools" is deprecated in the Cabal specification version 2.0. Please use 'build-tool-depends' field
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for parconc-examples-0.4.8(+accelerate +distributed):
Cabal-2.0.1.1 from stack configuration does not match >=2.2 (latest matching version is 3.4.0.0)
needed since parconc-examples is a build target.
Some different approaches to resolving this:
* Set 'allow-newer: true'
in /.stack/config.yaml to ignore all version constraints and build anyway.
* Recommended action: try adding the following to your extra-deps
in /parconc-examples/stack.yaml:
- Cabal-3.4.0.0@sha256:74ca2bc93297dc20b291c8dc721055278aa4a7942b0b5aca86766d407e3cbe5f,30533
Plan construction failed.
The book is fantastic. (Apart from the subject matter, I'm learning loads from the elegance of your code.)
Nonetheless, it would be good if the sample code would build. In your spare time, please convert the project to build with stack.
Cheers,
Jason
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.