Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem appears to be that <code>parVector</code> doesn't force evaluation of the elements of the vector. Each element remains a thunk and nothing is sparked until the vector is consumed (by being printed), which is too late for the sparks to do work. You can force evaluation of each element by composing the <code>parVector</code> strategy with <code>rdeepseq</code>.</p> <pre><code>import qualified Data.Vector as V import qualified Data.Vector.Unboxed as U import Data.Vector.Strategies import Control.DeepSeq import Control.Parallel.Strategies main = do let res = genVVec 200 `using` (rdeepseq `dot` parVector 20) print res genUVec :: Int -&gt; U.Vector Int genUVec n = U.map (ack 2) $ U.enumFromN n 75 genVVec :: Int -&gt; V.Vector (U.Vector Int) genVVec n = V.map genUVec $ V.enumFromN 0 n ack :: Int -&gt; Int -&gt; Int ack 0 n = n+1 ack m 0 = ack (m-1) 1 ack m n = ack (m-1) (ack m (n-1)) instance (NFData a, U.Unbox a) =&gt; NFData (U.Vector a) where rnf vec = seq vec () instance (NFData a) =&gt; NFData (V.Vector a) where rnf = rnf . V.toList </code></pre> <p>I also changed your <code>NFData (U.Vector a)</code> instance. Since a <code>U.Vector</code> is unboxed, evaluation to WHNF is sufficient, and forcing each element via the list conversion is wasteful. In fact the default definition for <code>rnf</code> works fine if you like.</p> <p>With these two changes, I get the following</p> <pre><code>SPARKS: 200 (200 converted, 0 pruned) </code></pre> <p>and the runtime has been reduced by nearly 50%. I also adjusted the vector chunk size to 20, but the result is very similar to a chunk size of 2.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload