Hello all <div>I am trying to learn parallel Haskell and  I have gone through couple of resources ( Real world Haskell and <a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/AFP08-notes.pdf">http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/AFP08-notes.pdf</a> ). I understood par and pseq and I wrote matrix multiplication using these two function but it does not look.  Although I did not get all these details but none of the sparks converted which is really important for parallel programming. Could some one please tell me how to improve this. Also kindly recommend me some  literature for parallel programming in Haskell.</div>
<div><br></div><div>Regards </div><div>Mukesh Tiwari</div><div><br></div><div><div>import Data.List</div><div>import Control.Parallel</div><div><br></div><div>parHelp :: ( Num a ) =&gt; [ a ] -&gt; [ a ] -&gt; a</div><div>
parHelp [] [] = 0</div><div>parHelp ( x : xs ) ( y : ys ) = ret where</div><div>        ret = par a ( pseq a ( a + parHelp xs ys ) ) where</div><div>            a = x * y</div><div><br></div><div><br></div><div>helpMult :: ( Num a ) =&gt; [ a ] -&gt; [ [ a ] ] -&gt; [ a ]</div>
<div>helpMult _ [] = []</div><div>helpMult x ( y : ys ) = ret where</div><div>     ret =  par a ( pseq a  ( a : helpMult x ys ) ) where</div><div>       a = parHelp x y</div><div><br></div><div><br></div><div>mult :: ( Num a ) =&gt; [ [ a ] ] -&gt; [ [ a ] ] -&gt; [ [ a ] ]</div>
<div>mult [] _ = []</div><div>mult ( x : xs ) ys = ret where</div><div>     ret = par a ( pseq a  ( a : mult xs ys ) ) where</div><div>        a = helpMult x ys</div><div><br></div><div>main = print $ mult [[1 .. 4 ] , [ 1 .. 4 ] , [ 1 .. 4 ] , [ 1 .. 4] ] ( transpose [[1 .. 4 ] , [ 1 .. 4 ] , [ 1 .. 4 ] , [ 1 .. 4] ])  </div>
<div>        </div></div><div><div>[user@haskell Programming]$ ghc -O2 -threaded -rtsopts Matpar.hs </div><div>[1 of 1] Compiling Main             ( Matpar.hs, Matpar.o )</div><div>Linking Matpar ...</div><div>[user@haskell Programming]$ ./Matpar +RTS -N2 -s</div>
<div>./Matpar +RTS -N2 -s </div><div>[[10,20,30,40],[10,20,30,40],[10,20,30,40],[10,20,30,40]]</div><div>          85,480 bytes allocated in the heap</div><div>           5,216 bytes copied during GC</div><div>          47,328 bytes maximum residency (1 sample(s))</div>
<div>          22,304 bytes maximum slop</div><div>               2 MB total memory in use (0 MB lost due to fragmentation)</div><div><br></div><div>  Generation 0:     0 collections,     0 parallel,  0.00s,  0.00s elapsed</div>
<div>  Generation 1:     1 collections,     0 parallel,  0.00s,  0.00s elapsed</div><div><br></div><div>  Parallel GC work balance: -nan (0 / 0, ideal 2)</div><div><br></div><div>                        MUT time (elapsed)       GC time  (elapsed)</div>
<div>  Task  0 (worker) :    0.00s    (  0.00s)       0.00s    (  0.00s)</div><div>  Task  1 (worker) :    0.00s    (  0.00s)       0.00s    (  0.00s)</div><div>  Task  2 (bound)  :    0.00s    (  0.00s)       0.00s    (  0.00s)</div>
<div>  Task  3 (worker) :    0.00s    (  0.00s)       0.00s    (  0.00s)</div><div><br></div><div><b>  SPARKS: 84 (0 converted, 0 pruned)</b></div><div><br></div><div>  INIT  time    0.00s  (  0.00s elapsed)</div><div>  MUT   time    0.00s  (  0.00s elapsed)</div>
<div>  GC    time    0.00s  (  0.00s elapsed)</div><div>  EXIT  time    0.00s  (  0.00s elapsed)</div><div>  Total time    0.00s  (  0.00s elapsed)</div><div><br></div><div>  %GC time      33.3%  (13.5% elapsed)</div><div>
<br></div><div>  Alloc rate    42,761,380 bytes per MUT second</div><div><br></div><div>  Productivity  33.3% of total user, 45.0% of total elapsed</div><div><br></div><div>gc_alloc_block_sync: 0</div><div>whitehole_spin: 0</div>
<div>gen[0].sync_large_objects: 0</div><div>gen[1].sync_large_objects: 0</div><div>[user@haskell Programming]$ </div></div>