haskell / criterion

A powerful but simple library for measuring the performance of Haskell code.
http://www.serpentine.com/criterion
BSD 2-Clause "Simplified" License
501 stars 86 forks source link

thread blocked indefinitely in an MVar operation (HP 2013 ghc 7.6.3 on mac) #28

Closed cartazio closed 11 years ago

cartazio commented 11 years ago

I get the following error in my criterion code

Exception inside child thread "(worker 0 of originator ThreadId 3)", ThreadId 7: thread blocked indefinitely in an MVar operation
benchmarks: thread blocked indefinitely in an MVar operation

heres a simplified piece of code that replicates this error

{-# LANGUAGE BangPatterns #-}

module Main where

import Criterion.Main

import Criterion.Config
import Data.Word 

import Data.Foldable 

whnfIter:: Int ->(a->a)-> a -> Pure 
whnfIter cnt f  arg = whnf (\v -> foldl' (\ a b -> f a ) v [0 .. cnt]  ) arg

main =  defaultMainWith defaultConfig{cfgSamples=ljust 10} (return ()) [
    bgroup "Morton Z" [
        bcompare [ 

        bench "addingNumbersIter1000" $! whnfIter 1000 ( (7 + ):: Word->Word)  9 -- ,

        ]]  ]

heres the ghc options i'd used, most of these probably are irrelevant, but i'm putting them here for completeness

   ghc-options: -O2 -optlo "-O3"  -fllvm   -optlc "-O3" -optlo "-std-compile-opts"      -optlo "-bb-vectorize"   -fllvm-tbaa -optlo  "-regalloc=pbqp"     -rtsopts -threaded -with-rtsopts=-N2 
cartazio commented 11 years ago

huh, i seem to have given you a wrong repro. I'll post a corrected one that does trigger it later

cartazio commented 11 years ago

heres the REPRO that works

this is for current haskell platform, and using the current version of monad-par, statistics, and criterion

call this code test.hs


{-# LANGUAGE BangPatterns #-}

module Main where

import Criterion.Main

import Criterion.Config
import Data.Word 

import Data.Foldable 

whnfIter:: Int ->(a->a)-> a -> Pure 
whnfIter cnt f  arg = whnf (\v -> foldl' (\ a b -> f a ) v [0 .. cnt]  ) arg

main =  defaultMainWith defaultConfig{cfgSamples=ljust 10} (return ()) [
    bgroup "Morton Z" [
        bcompare [ 

        bench "addingNumbersIter1000" $! whnfIter 1000 ( (7 + ):: Word->Word)  9, -- ,
        bench "other thing "$!  whnfIter 1000 ( (7 + ):: Word->Word)  9
        ]]  ]  

build this using

ghc -threaded test.hs -fllvm -O2  -rtsopts -threaded -with-rtsopts=-N2

then run

./test

then you'll get

./test
warming up
estimating clock resolution...
mean is 2.060888 us (320001 iterations)
found 85631 outliers among 319999 samples (26.8%)
  71168 (22.2%) low severe
  14463 (4.5%) high severe
estimating cost of a clock call...
mean is 76.44681 ns (17 iterations)
found 1 outliers among 17 samples (5.9%)
  1 (5.9%) high mild

benchmarking Morton Z/addingNumbersIter1000
mean: 2.516616 us, lb 2.463436 us, ub 2.603236 us, ci 0.950
std dev: 113.6857 ns, lb 66.06086 ns, ub 165.7635 ns, ci 0.950
found 1 outliers among 10 samples (10.0%)
  1 (10.0%) high mild
variance introduced by outliers: 9.234%
variance is slightly inflated by outliers

benchmarking Morton Z/other thing 

Exception inside child thread "(worker 1 of originator ThreadId 3)", ThreadId 8: thread blocked indefinitely in an MVar operation
test: thread blocked indefinitely in an MVar operation
alpmestan commented 11 years ago

I can reproduce this with HP 2013 ghc 7.6.3 and with 7.6.1 on mac too. No problem with -N1, one "thread blocked indefinitely in an MVar operation" with -N2, two with -N3 and three with -N4. I'm using Carter's code a few hours ago, from the last comment.

criterion-0.8, monad-par 0.3.4.2, statistics 0.10.4.1, for what it's worth.

cartazio commented 11 years ago

@alpmestan thanks for adding the version numbers to the mix (was a bit tired yesterday)

We should probably figure out how to repro this directly in in terms of monad-par so we can give them a useful test case.
the only place that monad par is used is in statistics in the boostrapBCA function https://github.com/bos/statistics/blob/master/Statistics/Resampling/Bootstrap.hs#L86-L89

cartazio commented 11 years ago

i've simplified the test case a teeny bit more


{-# LANGUAGE BangPatterns #-}

module Main where

import Criterion.Main

import Criterion.Config
import Data.Word 

import Data.Foldable 

whnfIter:: Int ->(a->a)-> a -> Pure 
whnfIter cnt f  arg = whnf (\v -> foldl' (\ a b -> f a ) v [0 .. cnt]  ) arg

main =  defaultMainWith defaultConfig{cfgSamples=ljust 10} (return ()) [

        bench "addingNumbersIter1000" $! whnfIter 1000 ( (7 + ):: Word->Word)  9, -- ,
        bench "other thing "$!  whnfIter 1000 ( (7 + ):: Word->Word)  9
        ]

should be doable to figure out a direct repro in monad-par using this

bos commented 11 years ago

This is due to the upstream monad-par bug => closing.