I wrote simple parallel matrix multiplication using par and pseq .
After starting this program, none of the converted sparks (SPARKS: 20 (0 converted, 0 trimmed)).
I would like to hear your comment on improving this program.
Also on approaches to learning concurrent programming in Haskell.
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 * yb = 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 = sum . zipWith ( *) x $ yb = 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] ])
source share