[Haskell-cafe] Control.Parallel seemingly randomly behaviour

11 views
Skip to first unread message

Juan Luis Martty

unread,
Jan 15, 2017, 6:33:08 PM1/15/17
to haskel...@haskell.org

Hello everyone,


I'm having a consistency issue with the following piece of code:

heavyAm = 500
lightAm = 1000

heavyCalc :: Int -> Int
heavyCalc s = sum [1..1000000*s]

parallel = (heavyCalc lightAm, heavyCalc heavyAm) `using` (parTuple2 rseq rseq)

For some reason, during runtime the RTS sometimes parallelizes the evaluation and sometimes it doesn't. I'm running with all the RTS/compile time options correctly afaik. Here is the output from a couple of runs of the program:

jmartty@walrus:~/hs/parallel$ stack build && time stack exec par-exe
Warning: File listed in par.cabal file does not exist: README.md
(500000000500000000,125000000250000000)
Computation time: 1.557007s

real    0m1.732s
user    0m2.528s
sys 0m0.464s
jmartty@walrus:~/hs/parallel$ stack build && time stack exec par-exe
Warning: File listed in par.cabal file does not exist: README.md
(500000000500000000,125000000250000000)
Computation time: 1.544837s

real    0m1.720s
user    0m2.544s
sys 0m0.712s
jmartty@walrus:~/hs/parallel$ stack build && time stack exec par-exe
Warning: File listed in par.cabal file does not exist: README.md
(500000000500000000,125000000250000000)
Computation time: 2.316537s

real    0m2.484s
user    0m2.592s
sys 0m0.680s
jmartty@walrus:~/hs/parallel$ stack build && time stack exec par-exe
Warning: File listed in par.cabal file does not exist: README.md
(500000000500000000,125000000250000000)
Computation time: 2.318514s

real    0m2.489s
user    0m2.612s
sys 0m0.688s
jmartty@walrus:~/hs/parallel$ stack build && time stack exec par-exe
Warning: File listed in par.cabal file does not exist: README.md
(500000000500000000,125000000250000000)
Computation time: 1.544975s

real    0m1.718s
user    0m2.512s
sys 0m0.456s

As you can see, sometimes wall time roughly equals userspace time, sometimes it doesn't (meaning it parallelized at least some amount). I'm running on a dual core machine under Ubuntu using stack with lts-7.14 (GHC 8.0.1) and parallel-3.2.1.0.

Regards,
Juan

David Feuer

unread,
Jan 16, 2017, 7:12:35 PM1/16/17
to Juan Luis Martty, haskel...@haskell.org
Just to remove one variable: what happens if you run the same executable multiple times, rather than rebuilding it each time?

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

David Feuer

unread,
Jan 16, 2017, 7:17:47 PM1/16/17
to Juan Luis Martty, haskel...@haskell.org
Oh, and you should probably be passing your program an explicit +RTS option to tell it how many OS threads to use.

Juan Luis Martty

unread,
Jan 17, 2017, 8:20:03 AM1/17/17
to haskel...@haskell.org


The build isn't really doing anything after the first build cause it doesn't detect any changes. And stack exec is already passing the right RTS options


From: David Feuer <david...@gmail.com>
Sent: Monday, January 16, 2017 9:02 PM
To: Juan Luis Martty
Cc: haskel...@haskell.org
Subject: Re: [Haskell-cafe] Control.Parallel seemingly randomly behaviour
 

Johannes Waldmann

unread,
Jan 17, 2017, 2:06:00 PM1/17/17
to haskel...@haskell.org
Hi Juan, I am interested in this because I use
Control.Parallel in teaching currently. But -

* what is your actual Main program / main function
(it was not included in your message?)
* what is your actual cabal / stack config file?
* on what machine (OS, CPU) are you running this (it seems pretty slow)?
* have you looked at eventlogs with threadscope?

- J.

Juan Luis Martty

unread,
Jan 18, 2017, 5:54:27 PM1/18/17
to haskel...@haskell.org

The program is attached in this mail, along with stack & cabal config. The machine is an old T400 with an Intel dual core.

Followin some advice, I checked the output of `+RTS -s` and apparently sometimes one of the sparks is fizzled which is what causes the unexpected behaviour




From: Haskell-Cafe <haskell-ca...@haskell.org> on behalf of Johannes Waldmann <johannes...@htwk-leipzig.de>
Sent: Tuesday, January 17, 2017 3:56 PM
To: haskel...@haskell.org

Subject: Re: [Haskell-cafe] Control.Parallel seemingly randomly behaviour
Hi Juan, I am interested in this because I use
Control.Parallel in teaching currently. But -

* what is your actual Main program / main function
  (it was not included in your message?)
* what is your actual cabal / stack config file?
* on what machine (OS, CPU) are you running this (it seems pretty slow)?
* have you looked at eventlogs with threadscope?

- J.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
This mailing list is for the discussion of topics related to Haskell. The volume may at times be high, as the scope is broader than the main Haskell mailing list.
par.cabal
stack.yaml
Main.hs
Reply all
Reply to author
Forward
0 new messages