Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/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. Re:  parMap on multicore computers (Thomas Friedrich)
   2. Re:  parMap on multicore computers (Miguel Pignatelli)
   3. Re:  Catching Network Connection Error (Brent Yorgey)
   4.  QuickCheck (Thomas Friedrich)
   5. Re:  QuickCheck (Lee Duhem)
   6. Re:  QuickCheck (Thomas Friedrich)
   7. Re:  QuickCheck (Thomas Friedrich)
   8. Re:  QuickCheck (Lee Duhem)


----------------------------------------------------------------------

Message: 1
Date: Fri, 22 May 2009 18:02:14 -0400
From: Thomas Friedrich <[email protected]>
Subject: Re: [Haskell-beginners] parMap on multicore computers
To: Miguel Pignatelli <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi Miguel,

I don't think that you can expect a program to process each line of a 
text file in parallel to very efficient.  Opening a new thread is 
usually fairly cheap, however, there is some bookkeeping involved that 
shouldn't be underestimated.  You only have 2 or 4 cores, so opening 100 
threads or more, depending on the size of your file, will do you no 
good.  You should rather split up your file in 4 chunks and and then 
process these *4* threads in parallel.

That should make it more efficient!  Parallel /= faster.  At least not 
automatically.

Happy Hacking,
Thomas



Miguel Pignatelli wrote:
> Hi all,
>
> I'm experimenting a bit with the parallelization capabilities of Haskell.
> What I am trying to do is to process in parallel all the lines of a 
> text file, calculating the edit distance of each of these lines with a 
> given string.
> This is my testing code:
>
>
> import System.IO
> import Control.Monad
> import Control.Parallel
> import Control.Parallel.Strategies
>
> edist :: String -> String -> Int
> -- edist calculates the edit distance of 2 strings
> -- see for 
> example http://www.csse.monash.edu.au/~lloyd/tildeFP/Haskell/1998/Edit01/ 
> <http://www.csse.monash.edu.au/%7Elloyd/tildeFP/Haskell/1998/Edit01/>
>
> getLines :: FilePath -> IO [Int]
> getLines = liftM ((parMap rnf (edist longString)) . lines) . readFile
>
> main :: IO ()
> main = do
> list <- getLines "input.txt"
> mapM_ ( putStrLn . show ) list
>
> I am testing this code in a 2xQuadCore linux (Ubuntu 8.10) machine (8 
> cores in total).
> The code has been compiled with
>
> ghc --make -threaded mytest.hs
>
> I've been trying input files of different lengths, but the more cores 
> I try to use, the worst performance I am getting.
> Here are some examples:
>
> # input.txt -> 10 lines (strings) of ~1200 letters each
> $ time ./mytest +RTS -N1 > /dev/null 
>
> real 0m4.775s
> user 0m4.700s
> sys 0m0.080s
>
> $ time ./mytest +RTS -N4 > /dev/null
>
> real 0m6.272s
> user 0m8.220s
> sys 0m0.290s
>
> $ time ./mytest +RTS -N8 > /dev/null
>
> real 0m7.090s
> user 0m10.960s
> sys 0m0.400s
>
> # input.txt -> 100 lines (strings) of ~1200 letters each
> $ time ./mytest +RTS -N1 > /dev/null
>
> real 0m49.854s
> user 0m49.730s
> sys 0m0.120s
>
> $ time ./mytest +RTS -N4 > /dev/null
>
> real 1m11.303s
> user 1m36.210s
> sys 0m1.070s
>
> $ time ./mytest +RTS -N8 > /dev/null
>
> real 1m19.488s
> user 2m6.250s
> sys 0m1.270s
>
>
> What is going wrong in this code? Is this a problem of the "grain 
> size" of the parallelization?
> Any help / advice would be very welcome,
>
> M;
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>   



------------------------------

Message: 2
Date: Sat, 23 May 2009 12:33:42 +0200
From: Miguel Pignatelli <[email protected]>
Subject: Re: [Haskell-beginners] parMap on multicore computers
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes

Hi Thomas,

Thanks for your answer.
I know that there is needed some tweak in the process of  
parallelization to get a performance gain. I agree with your reasoning  
regarding the 100 string input, but in the other example I gave, I use  
the 8-core machine to process a 10 strings (and each one takes half a  
second to be processed) why is this case failing too?

M;


El 23/05/2009, a las 0:02, Thomas Friedrich escribió:

> Hi Miguel,
>
> I don't think that you can expect a program to process each line of  
> a text file in parallel to very efficient.  Opening a new thread is  
> usually fairly cheap, however, there is some bookkeeping involved  
> that shouldn't be underestimated.  You only have 2 or 4 cores, so  
> opening 100 threads or more, depending on the size of your file,  
> will do you no good.  You should rather split up your file in 4  
> chunks and and then process these *4* threads in parallel.
>
> That should make it more efficient!  Parallel /= faster.  At least  
> not automatically.
>
> Happy Hacking,
> Thomas
>
>
>
> Miguel Pignatelli wrote:
>> Hi all,
>>
>> I'm experimenting a bit with the parallelization capabilities of  
>> Haskell.
>> What I am trying to do is to process in parallel all the lines of a  
>> text file, calculating the edit distance of each of these lines  
>> with a given string.
>> This is my testing code:
>>
>>
>> import System.IO
>> import Control.Monad
>> import Control.Parallel
>> import Control.Parallel.Strategies
>>
>> edist :: String -> String -> Int
>> -- edist calculates the edit distance of 2 strings
>> -- see for example 
>> http://www.csse.monash.edu.au/~lloyd/tildeFP/Haskell/1998/Edit01/ 
>>  <http://www.csse.monash.edu.au/%7Elloyd/tildeFP/Haskell/1998/ 
>> Edit01/>
>>
>> getLines :: FilePath -> IO [Int]
>> getLines = liftM ((parMap rnf (edist longString)) . lines) . readFile
>>
>> main :: IO ()
>> main = do
>> list <- getLines "input.txt"
>> mapM_ ( putStrLn . show ) list
>>
>> I am testing this code in a 2xQuadCore linux (Ubuntu 8.10) machine  
>> (8 cores in total).
>> The code has been compiled with
>>
>> ghc --make -threaded mytest.hs
>>
>> I've been trying input files of different lengths, but the more  
>> cores I try to use, the worst performance I am getting.
>> Here are some examples:
>>
>> # input.txt -> 10 lines (strings) of ~1200 letters each
>> $ time ./mytest +RTS -N1 > /dev/null
>> real 0m4.775s
>> user 0m4.700s
>> sys 0m0.080s
>>
>> $ time ./mytest +RTS -N4 > /dev/null
>>
>> real 0m6.272s
>> user 0m8.220s
>> sys 0m0.290s
>>
>> $ time ./mytest +RTS -N8 > /dev/null
>>
>> real 0m7.090s
>> user 0m10.960s
>> sys 0m0.400s
>>
>> # input.txt -> 100 lines (strings) of ~1200 letters each
>> $ time ./mytest +RTS -N1 > /dev/null
>>
>> real 0m49.854s
>> user 0m49.730s
>> sys 0m0.120s
>>
>> $ time ./mytest +RTS -N4 > /dev/null
>>
>> real 1m11.303s
>> user 1m36.210s
>> sys 0m1.070s
>>
>> $ time ./mytest +RTS -N8 > /dev/null
>>
>> real 1m19.488s
>> user 2m6.250s
>> sys 0m1.270s
>>
>>
>> What is going wrong in this code? Is this a problem of the "grain  
>> size" of the parallelization?
>> Any help / advice would be very welcome,
>>
>> M;
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>



------------------------------

Message: 3
Date: Sat, 23 May 2009 09:56:32 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Catching Network Connection Error
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Fri, May 22, 2009 at 01:20:39AM -0500, aditya siram wrote:
> Hi all,
> I am trying to Network.HTTP to connect to a website and catch the error if
> the network is down. Here's what I have so far:
> 
> data Errors = DocumentParseError
>             | WebsiteUnreachableError
>             | ISBNNotFoundError
> 
> respHTML' :: ISBN -> IO (Either Errors (IO String))
> respHTML' isbn =
>     do
>       rsp <- simpleHTTP (getRequest $ "
> http://isbndb.com/api/books.xml?results=details&access_key=";
>                                         ++ key
>                                         ++ "&index1=isbn&value1="
>                                         ++ isbn :: Request_String)
>       return $ Right $ getResponseBody rsp
>                   `E.catch` (\(e :: E.SomeException ) ->
>                                  return $ Left $ WebsiteUnreachableError)
> 
> I get the following error when I load it into GHCI:
>     Couldn't match expected type `[Char]'
>            against inferred type `Either Errors b'
>       Expected type: IO String
>       Inferred type: IO (Either Errors b)
>     In the expression: return $ Left $ WebsiteUnreachableError
>     In the second argument of `E.catch', namely
>         `(\ (e :: E.SomeException)
>               -> return $ Left $ WebsiteUnreachableError)'
> Failed, modules loaded: none.
> 
> Control.Exception.catch has the following signature :
> catch :: forall a. IO a -> (IOError -> IO a) -> IO a
> 
> I would expect that the handler function needs to return an IO (Either
> Errors (IO String)). Why is it trying to return an IO String?

Because the call to 'catch' only applies to 'getResponseBody rsp',
which is already inside the 'return $ Right $'.  Perhaps you want to
put parentheses around (return $ Right $ getResponseBody rsp) ?

-Brent


------------------------------

Message: 4
Date: Sat, 23 May 2009 23:08:47 -0400
From: Thomas Friedrich <[email protected]>
Subject: [Haskell-beginners] QuickCheck
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hallo everyone,

I am currently playing around with the QuickCheck library.  I came 
across the

Test.QuickCheck.Batch

module a couple of times.  I don't seem to have this module installed?  
Where can I get it and how do I install it?

I also would like to invoke the following in ghci.

generate 10 (System.Random.mkStdGen 1) arbitrary :: [Int]

However, the function `generate` doesn't get imported when importing 
QuickCheck, and I just cannot find out which module this one would be in.

I came to the conclusion that `generate` is just not the best word for a 
google search :(

Cheers,
Thomas



------------------------------

Message: 5
Date: Sun, 24 May 2009 11:21:57 +0800
From: Lee Duhem <[email protected]>
Subject: Re: [Haskell-beginners] QuickCheck
To: Thomas Friedrich <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Sun, May 24, 2009 at 11:08 AM, Thomas Friedrich <[email protected]> wrote:
> Hallo everyone,
>
> I am currently playing around with the QuickCheck library.  I came across
> the
>
> Test.QuickCheck.Batch
>
> module a couple of times.  I don't seem to have this module installed?
>  Where can I get it and how do I install it?

If you use GHC, you already have it, try
    ghc-pkg list | grep -i quickcheck

>
> I also would like to invoke the following in ghci.
>
> generate 10 (System.Random.mkStdGen 1) arbitrary :: [Int]
>
> However, the function `generate` doesn't get imported when importing
> QuickCheck, and I just cannot find out which module this one would be in.

In GHCi, you need import Test.QuickCheck or Debug.QuickCheck before
you use generate.

>
> I came to the conclusion that `generate` is just not the best word for a
> google search :(

Just check the document of GHC libraries:
http://www.haskell.org/ghc/docs/latest/html/libraries/index.html
http://www.haskell.org/ghc/docs/latest/html/libraries/QuickCheck/Test-QuickCheck.html

lee


------------------------------

Message: 6
Date: Sat, 23 May 2009 23:25:23 -0400
From: Thomas Friedrich <[email protected]>
Subject: Re: [Haskell-beginners] QuickCheck
To: Lee Duhem <[email protected]>,    beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi Lee,

I do have GHC and no, I seem to not have it.

$ ghc-pkg list | grep -i quickcheck
    Cabal-1.6.0.3, Chart-0.10.3, HUnit-1.2.0.3, QuickCheck-1.2.0.0,
    Diff-0.1.2, QuickCheck-2.1.0.1, binary-0.5.0.1,


When I am in ghci, I have the following options:

Prelude> :m +Test.QuickCheck
Test.QuickCheck            Test.QuickCheck.Function   
Test.QuickCheck.Monadic    Test.QuickCheck.Property   Test.QuickCheck.Test
Test.QuickCheck.Arbitrary  Test.QuickCheck.Gen        
Test.QuickCheck.Poly       Test.QuickCheck.State      Test.QuickCheck.Text
Prelude> :m +Test.QuickCheck

But no Test.QuickCheck.Batch

:(

Cheers,
Thomas


Lee Duhem wrote:
> On Sun, May 24, 2009 at 11:08 AM, Thomas Friedrich <[email protected]> wrote:
>   
>> Hallo everyone,
>>
>> I am currently playing around with the QuickCheck library.  I came across
>> the
>>
>> Test.QuickCheck.Batch
>>
>> module a couple of times.  I don't seem to have this module installed?
>>  Where can I get it and how do I install it?
>>     
>
> If you use GHC, you already have it, try
>     ghc-pkg list | grep -i quickcheck
>
>   
>> I also would like to invoke the following in ghci.
>>
>> generate 10 (System.Random.mkStdGen 1) arbitrary :: [Int]
>>
>> However, the function `generate` doesn't get imported when importing
>> QuickCheck, and I just cannot find out which module this one would be in.
>>     
>
> In GHCi, you need import Test.QuickCheck or Debug.QuickCheck before
> you use generate.
>
>   
>> I came to the conclusion that `generate` is just not the best word for a
>> google search :(
>>     
>
> Just check the document of GHC libraries:
> http://www.haskell.org/ghc/docs/latest/html/libraries/index.html
> http://www.haskell.org/ghc/docs/latest/html/libraries/QuickCheck/Test-QuickCheck.html
>
> lee
>   



------------------------------

Message: 7
Date: Sat, 23 May 2009 23:47:06 -0400
From: Thomas Friedrich <[email protected]>
Subject: Re: [Haskell-beginners] QuickCheck
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi folks,

I did the following and now it works.  I had a closer look at my ghc-pkg 
list (thanks for the tip), which looked like the following:

$ ghc-pkg list
/usr/lib/ghc-6.10.3/./package.conf:
    Cabal-1.6.0.3, Chart-0.10.3, HUnit-1.2.0.3, QuickCheck-1.2.0.0,
    X11-1.4.5, array-0.2.0.0, base-3.0.3.1, base-4.1.0.0,
    bytestring-0.9.1.4, cairo-0.10.1, containers-0.2.0.1,
    data-accessor-0.2.0.2, data-accessor-template-0.2.1.1,
    directory-1.0.0.3, (dph-base-0.3), (dph-par-0.3),
    (dph-prim-interface-0.3), (dph-prim-par-0.3), (dph-prim-seq-0.3),
    (dph-seq-0.3), extensible-exceptions-0.1.1.0, filepath-1.1.0.2,
    gconf-0.10.1, (ghc-6.10.3), ghc-prim-0.1.0.0, glade-0.10.1,
    glib-0.10.1, gtk-0.10.1, gtkglext-0.10.1, gtksourceview2-0.10.1,
    haddock-2.4.2, haskell-src-1.0.1.3, haskell98-1.0.1.0, hpc-0.5.0.3,
    html-1.0.1.2, integer-0.1.0.1, mtl-1.1.0.2, network-2.2.1,
    old-locale-1.0.0.1, old-time-1.0.0.2, packedstring-0.1.0.1,
    parallel-1.1.0.1, parsec-2.1.0.1, pretty-1.0.1.0, process-1.0.1.1,
    random-1.0.0.1, regex-base-0.72.0.2, regex-compat-0.71.0.1,
    regex-posix-0.72.0.3, rts-1.0, soegtk-0.10.1, stm-2.1.1.2,
    svgcairo-0.10.1, syb-0.1.0.1, template-haskell-2.3.0.1, time-1.1.3,
    transformers-0.1.4.0, unix-2.3.2.0, utf8-string-0.3.4,
    utility-ht-0.0.5.1, xhtml-3000.2.0.1, xmonad-0.8.1,
    xmonad-contrib-0.8.1
/home/thomas/.ghc/i386-linux-6.10.3/package.conf:
    Diff-0.1.2, QuickCheck-2.1.0.1, binary-0.5.0.1,
    data-accessor-monads-fd-0.2, derive-0.1.4, dotgen-0.2,
    fingertree-0.0, ghc-paths-0.1.0.5, haskell-lexer-1.0,
    monads-fd-0.0.0.1, pointedlist-0.3.3, pureMD5-0.2.4,
    regex-base-0.93.1, regex-tdfa-1.0.0, rosezipper-0.1, split-0.1.1,
    terminfo-0.3.0.2, uniplate-1.2.0.3, unix-compat-0.1.2.1,
    vty-3.1.8.4, yi-0.6.0

I think because I installed yi, I must have also ended up with the 
QuickCheck-2.1.0.1 package.  In this package there is NO `generate`, no 
`verboseCheck` and other functions available.  (Why?? Does anyone 
know?)  Also there is no QuickCheck.Batch.

Simply hiding the package solved the problem, by

ghc-pkg hide QuickCheck-2.1.0.1

Now, I can also use the Batch module.

Does anyone know why the now version of QuickCheck is not compatible 
with the old one?

Best,
Thomas



Thomas Friedrich wrote:
> Hi Lee,
>
> I do have GHC and no, I seem to not have it.
>
> $ ghc-pkg list | grep -i quickcheck
>    Cabal-1.6.0.3, Chart-0.10.3, HUnit-1.2.0.3, QuickCheck-1.2.0.0,
>    Diff-0.1.2, QuickCheck-2.1.0.1, binary-0.5.0.1,
>
>
> When I am in ghci, I have the following options:
>
> Prelude> :m +Test.QuickCheck
> Test.QuickCheck            Test.QuickCheck.Function   
> Test.QuickCheck.Monadic    Test.QuickCheck.Property   
> Test.QuickCheck.Test
> Test.QuickCheck.Arbitrary  Test.QuickCheck.Gen        
> Test.QuickCheck.Poly       Test.QuickCheck.State      
> Test.QuickCheck.Text
> Prelude> :m +Test.QuickCheck
>
> But no Test.QuickCheck.Batch
>
> :(
>
> Cheers,
> Thomas
>
>
> Lee Duhem wrote:
>> On Sun, May 24, 2009 at 11:08 AM, Thomas Friedrich <[email protected]> wrote:
>>  
>>> Hallo everyone,
>>>
>>> I am currently playing around with the QuickCheck library.  I came 
>>> across
>>> the
>>>
>>> Test.QuickCheck.Batch
>>>
>>> module a couple of times.  I don't seem to have this module installed?
>>>  Where can I get it and how do I install it?
>>>     
>>
>> If you use GHC, you already have it, try
>>     ghc-pkg list | grep -i quickcheck
>>
>>  
>>> I also would like to invoke the following in ghci.
>>>
>>> generate 10 (System.Random.mkStdGen 1) arbitrary :: [Int]
>>>
>>> However, the function `generate` doesn't get imported when importing
>>> QuickCheck, and I just cannot find out which module this one would 
>>> be in.
>>>     
>>
>> In GHCi, you need import Test.QuickCheck or Debug.QuickCheck before
>> you use generate.
>>
>>  
>>> I came to the conclusion that `generate` is just not the best word 
>>> for a
>>> google search :(
>>>     
>>
>> Just check the document of GHC libraries:
>> http://www.haskell.org/ghc/docs/latest/html/libraries/index.html
>> http://www.haskell.org/ghc/docs/latest/html/libraries/QuickCheck/Test-QuickCheck.html
>>  
>>
>>
>> lee
>>   
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners



------------------------------

Message: 8
Date: Sun, 24 May 2009 11:49:17 +0800
From: Lee Duhem <[email protected]>
Subject: Re: [Haskell-beginners] QuickCheck
To: Thomas Friedrich <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Sun, May 24, 2009 at 11:25 AM, Thomas Friedrich <[email protected]> wrote:
> Hi Lee,
>
> I do have GHC and no, I seem to not have it.
>
> $ ghc-pkg list | grep -i quickcheck
>   Cabal-1.6.0.3, Chart-0.10.3, HUnit-1.2.0.3, QuickCheck-1.2.0.0,
>   Diff-0.1.2, QuickCheck-2.1.0.1, binary-0.5.0.1,

Did you notice that you have two QuickCheck installed?

>
>
> When I am in ghci, I have the following options:
>
> Prelude> :m +Test.QuickCheck
> Test.QuickCheck            Test.QuickCheck.Function
> Test.QuickCheck.Monadic    Test.QuickCheck.Property   Test.QuickCheck.Test
> Test.QuickCheck.Arbitrary  Test.QuickCheck.Gen       
>  Test.QuickCheck.Poly
>     Test.QuickCheck.State      Test.QuickCheck.Text
> Prelude> :m +Test.QuickCheck
>
> But no Test.QuickCheck.Batch
>

I guess you use QuickCheck-2.1 instead of 1.2, and Test.QuickCheck.Batch
in QuickCheck-1.2, not in 2.1

lee


------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 11, Issue 16
*****************************************

Reply via email to