[Haskell-cafe] Parallel Matrix Multiplication

mukesh tiwari mukeshtiwari.iiitm at gmail.com
Sat Dec 10 21:24:46 CET 2011


I changed it bit and use pseq to force the computation but still its
non of the sparks are converting.

import Data.List
import Control.Parallel

parHelp :: ( Num a ) => [ a ] -> [ a ] -> a
parHelp [] [] = 0
parHelp ( x : xs ) ( y : ys ) = ret where
        ret = par a ( pseq b ( a + b ) ) where
            a = x * y
            b = parHelp xs ys

helpMult :: ( Num a ) => [ a ] -> [ [ a ] ] -> [ a ]
helpMult _ [] = []
helpMult x ( y : ys ) = ret where
     ret =  par a ( pseq b  ( a : b ) ) where
       a = parHelp x y
       b = helpMult x ys

mult :: ( Num a ) => [ [ a ] ] -> [ [ a ] ] -> [ [ a ] ]
mult [] _ = []
mult ( x : xs ) ys = ret where
     ret = par a ( pseq b  ( a : b ) ) where
        a = helpMult x ys
        b = mult xs ys

main = print $ mult [[1 .. 4 ] , [ 1 .. 4 ] , [ 1 .. 4 ] , [ 1 .. 4] ]
( transpose [[1 .. 4 ] , [ 1 .. 4 ] , [ 1 .. 4 ] , [ 1 .. 4] ])



More information about the Haskell-Cafe mailing list