Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. missing parallelism (Maurizio Vitale)
2. Strange "Not in scope" error message (Matthew Moppett)
3. Re: Strange "Not in scope" error message (Alex Hammel)
4. Re: Strange "Not in scope" error message (Francesco Ariis)
5. Re: missing parallelism ([email protected])
6. Re: missing parallelism (Maurizio Vitale)
----------------------------------------------------------------------
Message: 1
Date: Fri, 24 Apr 2015 08:21:12 -0400
From: Maurizio Vitale <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] missing parallelism
Message-ID:
<CAAeLbQJ1TU78MK=fqzsoxd5q46roagh57wxhb2ynusnanqt...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
G'day,
I have a test code that I compile with ghc -threaded -eventlog
-rtsopts --make parallel.hs and run with ./parallel 2 +RTS -ls -N4 on
a laptop with 4 physical cores. I would expect activities in two
threads, but threadscope shows only one active thread.
Can somebody explain me the program's behaviour?
Thanks a lot
Maurizio
{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE TupleSections #-}
import Control.Applicative
import Control.Concurrent.Async (async, waitAny, Async)
import Data.List (delete, sortBy)
import Data.Ord (comparing)
import System.CPUTime
import System.Environment
import GHC.Conc (numCapabilities)
concurrentlyLimited :: Int -> [IO a] -> IO [a]
concurrentlyLimited n tasks = concurrentlyLimited' n (zip [0..] tasks) [] []
concurrentlyLimited' ? Int -- ^ number of concurrent evaluations
? [(Int, IO b)] -- ^ still to run (ordered by
first element)
? [Async (Int,b)] -- ^ currently running
? [(Int,b)] -- ^ partial results (ordered
by first element)
? IO [b]
concurrentlyLimited' _ [] [] results = return . map snd $ sortBy
(comparing fst) results
concurrentlyLimited' 0 todo ongoing results = do
(task, newResult) <- waitAny ongoing
concurrentlyLimited' 1 todo (delete task ongoing) (newResult:results)
concurrentlyLimited' _ [] ongoing results = concurrentlyLimited' 0 []
ongoing results
concurrentlyLimited' n ((i, task):otherTasks) ongoing results = do
t <- async $ (i,) <$> task
concurrentlyLimited' (n-1) otherTasks (t:ongoing) results
euler :: Int ? Int
euler n = length (filter (relprime n) [1..n-1])
where
relprime x y = gcd x y == 1
sumEuler :: Int ? Int
sumEuler = sum . (map euler) . mkList
where
mkList n = [1..n-1]
p ? IO Int
p = return $ sumEuler 3000
numThreads ? [String] ? IO Int
numThreads [] = return numCapabilities
numThreads [cores] = return $ read cores
main ? IO()
main = do
threads ? getArgs >>= numThreads
putStrLn $ "Running up to " ++ show threads ++ " threads in parallel
(on " ++ show numCapabilities ++ " cores)"
startTime ? getCPUTime
f ? concurrentlyLimited threads $ replicate 10 p
endTime ? getCPUTime
putStrLn $ foldr ((++) . show ) "" f
putStrLn $ "Evaluation took " ++ show (fromIntegral (endTime -
startTime) / 1000000000000?Double)
------------------------------
Message: 2
Date: Fri, 24 Apr 2015 23:49:15 +0700
From: Matthew Moppett <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Strange "Not in scope" error message
Message-ID:
<camlejzcoeja66f-yctpbn_e5zuq+zw3mm3zzzgwcv7aoenx...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
I have a file with the following relevant lines:
import qualified Control.Concurrent as C
...
isCancelled = C.isEmptyMvar . stopConcurrentProcess
Trying to compile this or run it in ghci yields a puzzling error message:
Not in scope: `C.isEmptyMvar'
Perhaps you meant one of these:
`C.isEmptyMVar' (imported from Control.Concurrent),
`C.isEmptyChan' (imported from Control.Concurrent)
Any idea what could be going wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150424/709f3764/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 24 Apr 2015 16:51:30 +0000
From: Alex Hammel <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Strange "Not in scope" error message
Message-ID:
<ca+_xferkxvfbtschlgksgzv_fpoo41nhg+xmdx2tc-ka_ae...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
You forgot to capitalize the 'V' in 'isEmptyMVar' :)
On Fri, 24 Apr 2015 at 09:49 Matthew Moppett <[email protected]>
wrote:
> I have a file with the following relevant lines:
>
> import qualified Control.Concurrent as C
>
> ...
>
> isCancelled = C.isEmptyMvar . stopConcurrentProcess
>
> Trying to compile this or run it in ghci yields a puzzling error message:
>
> Not in scope: `C.isEmptyMvar'
> Perhaps you meant one of these:
> `C.isEmptyMVar' (imported from Control.Concurrent),
> `C.isEmptyChan' (imported from Control.Concurrent)
>
> Any idea what could be going wrong?
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150424/e1d18a5f/attachment-0001.html>
------------------------------
Message: 4
Date: Fri, 24 Apr 2015 19:14:26 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Strange "Not in scope" error message
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Fri, Apr 24, 2015 at 11:49:15PM +0700, Matthew Moppett wrote:
> Perhaps you meant one of these:
> `C.isEmptyMVar' (imported from Control.Concurrent),
Haskell is case sensitive, isEmptyMVar is different from isEmptyMvar
(lowercase v)
------------------------------
Message: 5
Date: Fri, 24 Apr 2015 19:44:22 +0200
From: [email protected]
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] missing parallelism
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
On 24/04/2015 14:21, Maurizio Vitale wrote:
> G'day,
> I have a test code that I compile with ghc -threaded -eventlog
> -rtsopts --make parallel.hs and run with ./parallel 2 +RTS -ls -N4 on
> a laptop with 4 physical cores. I would expect activities in two
> threads, but threadscope shows only one active thread.
> Can somebody explain me the program's behaviour?
>
> Thanks a lot
>
> Maurizio
>
> {-# LANGUAGE UnicodeSyntax #-}
> {-# LANGUAGE TupleSections #-}
>
> import Control.Applicative
> import Control.Concurrent.Async (async, waitAny, Async)
> import Data.List (delete, sortBy)
> import Data.Ord (comparing)
> import System.CPUTime
> import System.Environment
> import GHC.Conc (numCapabilities)
>
> concurrentlyLimited :: Int -> [IO a] -> IO [a]
> concurrentlyLimited n tasks = concurrentlyLimited' n (zip [0..] tasks) [] []
>
> concurrentlyLimited' ? Int -- ^ number of concurrent evaluations
> ? [(Int, IO b)] -- ^ still to run (ordered by
> first element)
> ? [Async (Int,b)] -- ^ currently running
> ? [(Int,b)] -- ^ partial results (ordered
> by first element)
> ? IO [b]
> concurrentlyLimited' _ [] [] results = return . map snd $ sortBy
> (comparing fst) results
> concurrentlyLimited' 0 todo ongoing results = do
> (task, newResult) <- waitAny ongoing
> concurrentlyLimited' 1 todo (delete task ongoing) (newResult:results)
>
> concurrentlyLimited' _ [] ongoing results = concurrentlyLimited' 0 []
> ongoing results
> concurrentlyLimited' n ((i, task):otherTasks) ongoing results = do
> t <- async $ (i,) <$> task
> concurrentlyLimited' (n-1) otherTasks (t:ongoing) results
>
> euler :: Int ? Int
> euler n = length (filter (relprime n) [1..n-1])
> where
> relprime x y = gcd x y == 1
>
> sumEuler :: Int ? Int
> sumEuler = sum . (map euler) . mkList
> where
> mkList n = [1..n-1]
>
> p ? IO Int
> p = return $ sumEuler 3000
>
> numThreads ? [String] ? IO Int
> numThreads [] = return numCapabilities
> numThreads [cores] = return $ read cores
>
> main ? IO()
> main = do
> threads ? getArgs >>= numThreads
> putStrLn $ "Running up to " ++ show threads ++ " threads in parallel
> (on " ++ show numCapabilities ++ " cores)"
> startTime ? getCPUTime
> f ? concurrentlyLimited threads $ replicate 10 p
> endTime ? getCPUTime
> putStrLn $ foldr ((++) . show ) "" f
> putStrLn $ "Evaluation took " ++ show (fromIntegral (endTime -
> startTime) / 1000000000000?Double)
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Hello,
I don't have an Haskell environnement at hand, but my advice is to
search for when your Async/eulerSum calls are evaluated.
For example try to remove this line -- putStrLn $ foldr ((++) . show
) "" f
Does your program still compute something ? If no that's because your
sum is evaluated due to the show and not due to your async.
t <- async $ (i,) <$> task
Your async will try to compute (i,eulerSum) but you never force the
computation of the eulersum inside the async, so the async take no time
and return quickly.
Instead of this type [Async (Int, b)] you should aim for this one [(Int,
Async b)]
Let me know if that helps you.
Regards,
Romain
------------------------------
Message: 6
Date: Fri, 24 Apr 2015 19:06:08 -0400
From: Maurizio Vitale <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] missing parallelism
Message-ID:
<caaelbq++cdu2-1qgbshw4p26tobjx0fzyv554v7mrtp6w0r...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
You're right, without the show, no work is done.
But I'm puzzled. I thought waitAny would have caused one task to be executed.
If that doesn't wait for the async to compute a value (and not some
thunk) I don't see how to use asyncs, so I'm obviously missing
something.
How can I force deeper evaluation?
[in the end p would be a full parser, so whatever it is needed to
cause the parsing needs to be done outside of it]
On Fri, Apr 24, 2015 at 10:44 AM, <[email protected]> wrote:
> On 24/04/2015 14:21, Maurizio Vitale wrote:
>>
>> G'day,
>> I have a test code that I compile with ghc -threaded -eventlog
>> -rtsopts --make parallel.hs and run with ./parallel 2 +RTS -ls -N4 on
>> a laptop with 4 physical cores. I would expect activities in two
>> threads, but threadscope shows only one active thread.
>> Can somebody explain me the program's behaviour?
>>
>> Thanks a lot
>>
>> Maurizio
>>
>> {-# LANGUAGE UnicodeSyntax #-}
>> {-# LANGUAGE TupleSections #-}
>>
>> import Control.Applicative
>> import Control.Concurrent.Async (async, waitAny, Async)
>> import Data.List (delete, sortBy)
>> import Data.Ord (comparing)
>> import System.CPUTime
>> import System.Environment
>> import GHC.Conc (numCapabilities)
>>
>> concurrentlyLimited :: Int -> [IO a] -> IO [a]
>> concurrentlyLimited n tasks = concurrentlyLimited' n (zip [0..] tasks) []
>> []
>>
>> concurrentlyLimited' ? Int -- ^ number of concurrent
>> evaluations
>> ? [(Int, IO b)] -- ^ still to run (ordered by
>> first element)
>> ? [Async (Int,b)] -- ^ currently running
>> ? [(Int,b)] -- ^ partial results (ordered
>> by first element)
>> ? IO [b]
>> concurrentlyLimited' _ [] [] results = return . map snd $ sortBy
>> (comparing fst) results
>> concurrentlyLimited' 0 todo ongoing results = do
>> (task, newResult) <- waitAny ongoing
>> concurrentlyLimited' 1 todo (delete task ongoing) (newResult:results)
>>
>> concurrentlyLimited' _ [] ongoing results = concurrentlyLimited' 0 []
>> ongoing results
>> concurrentlyLimited' n ((i, task):otherTasks) ongoing results = do
>> t <- async $ (i,) <$> task
>> concurrentlyLimited' (n-1) otherTasks (t:ongoing) results
>>
>> euler :: Int ? Int
>> euler n = length (filter (relprime n) [1..n-1])
>> where
>> relprime x y = gcd x y == 1
>>
>> sumEuler :: Int ? Int
>> sumEuler = sum . (map euler) . mkList
>> where
>> mkList n = [1..n-1]
>>
>> p ? IO Int
>> p = return $ sumEuler 3000
>>
>> numThreads ? [String] ? IO Int
>> numThreads [] = return numCapabilities
>> numThreads [cores] = return $ read cores
>>
>> main ? IO()
>> main = do
>> threads ? getArgs >>= numThreads
>> putStrLn $ "Running up to " ++ show threads ++ " threads in parallel
>> (on " ++ show numCapabilities ++ " cores)"
>> startTime ? getCPUTime
>> f ? concurrentlyLimited threads $ replicate 10 p
>> endTime ? getCPUTime
>> putStrLn $ foldr ((++) . show ) "" f
>> putStrLn $ "Evaluation took " ++ show (fromIntegral (endTime -
>> startTime) / 1000000000000?Double)
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> Hello,
>
> I don't have an Haskell environnement at hand, but my advice is to search
> for when your Async/eulerSum calls are evaluated.
> For example try to remove this line -- putStrLn $ foldr ((++) . show ) ""
> f
> Does your program still compute something ? If no that's because your sum is
> evaluated due to the show and not due to your async.
>
> t <- async $ (i,) <$> task
>
> Your async will try to compute (i,eulerSum) but you never force the
> computation of the eulersum inside the async, so the async take no time and
> return quickly.
> Instead of this type [Async (Int, b)] you should aim for this one [(Int,
> Async b)]
>
> Let me know if that helps you.
>
> Regards,
> Romain
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
On Fri, Apr 24, 2015 at 1:44 PM, <[email protected]> wrote:
> On 24/04/2015 14:21, Maurizio Vitale wrote:
>>
>> G'day,
>> I have a test code that I compile with ghc -threaded -eventlog
>> -rtsopts --make parallel.hs and run with ./parallel 2 +RTS -ls -N4 on
>> a laptop with 4 physical cores. I would expect activities in two
>> threads, but threadscope shows only one active thread.
>> Can somebody explain me the program's behaviour?
>>
>> Thanks a lot
>>
>> Maurizio
>>
>> {-# LANGUAGE UnicodeSyntax #-}
>> {-# LANGUAGE TupleSections #-}
>>
>> import Control.Applicative
>> import Control.Concurrent.Async (async, waitAny, Async)
>> import Data.List (delete, sortBy)
>> import Data.Ord (comparing)
>> import System.CPUTime
>> import System.Environment
>> import GHC.Conc (numCapabilities)
>>
>> concurrentlyLimited :: Int -> [IO a] -> IO [a]
>> concurrentlyLimited n tasks = concurrentlyLimited' n (zip [0..] tasks) []
>> []
>>
>> concurrentlyLimited' ? Int -- ^ number of concurrent
>> evaluations
>> ? [(Int, IO b)] -- ^ still to run (ordered by
>> first element)
>> ? [Async (Int,b)] -- ^ currently running
>> ? [(Int,b)] -- ^ partial results (ordered
>> by first element)
>> ? IO [b]
>> concurrentlyLimited' _ [] [] results = return . map snd $ sortBy
>> (comparing fst) results
>> concurrentlyLimited' 0 todo ongoing results = do
>> (task, newResult) <- waitAny ongoing
>> concurrentlyLimited' 1 todo (delete task ongoing) (newResult:results)
>>
>> concurrentlyLimited' _ [] ongoing results = concurrentlyLimited' 0 []
>> ongoing results
>> concurrentlyLimited' n ((i, task):otherTasks) ongoing results = do
>> t <- async $ (i,) <$> task
>> concurrentlyLimited' (n-1) otherTasks (t:ongoing) results
>>
>> euler :: Int ? Int
>> euler n = length (filter (relprime n) [1..n-1])
>> where
>> relprime x y = gcd x y == 1
>>
>> sumEuler :: Int ? Int
>> sumEuler = sum . (map euler) . mkList
>> where
>> mkList n = [1..n-1]
>>
>> p ? IO Int
>> p = return $ sumEuler 3000
>>
>> numThreads ? [String] ? IO Int
>> numThreads [] = return numCapabilities
>> numThreads [cores] = return $ read cores
>>
>> main ? IO()
>> main = do
>> threads ? getArgs >>= numThreads
>> putStrLn $ "Running up to " ++ show threads ++ " threads in parallel
>> (on " ++ show numCapabilities ++ " cores)"
>> startTime ? getCPUTime
>> f ? concurrentlyLimited threads $ replicate 10 p
>> endTime ? getCPUTime
>> putStrLn $ foldr ((++) . show ) "" f
>> putStrLn $ "Evaluation took " ++ show (fromIntegral (endTime -
>> startTime) / 1000000000000?Double)
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> Hello,
>
> I don't have an Haskell environnement at hand, but my advice is to search
> for when your Async/eulerSum calls are evaluated.
> For example try to remove this line -- putStrLn $ foldr ((++) . show ) ""
> f
> Does your program still compute something ? If no that's because your sum is
> evaluated due to the show and not due to your async.
>
> t <- async $ (i,) <$> task
>
> Your async will try to compute (i,eulerSum) but you never force the
> computation of the eulersum inside the async, so the async take no time and
> return quickly.
> Instead of this type [Async (Int, b)] you should aim for this one [(Int,
> Async b)]
>
> Let me know if that helps you.
>
> Regards,
> Romain
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 82, Issue 34
*****************************************