Advertisement
Guest User

Untitled

a guest
May 13th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.05 KB | None | 0 0
  1. module MatrixMult
  2. open System
  3. open System.Threading
  4.  
  5. let calcEl(l, r , max, str1, stol1, long, m1:int[,], m2:int[,], resMatrix:int[,]) =
  6.  if (r<max) then do
  7.   let mutable res = 0
  8.   for x=l to r do
  9.    res <- 0
  10.    let str = x / stol1
  11.    let stol = x%stol1
  12.    for i=0 to long-1 do
  13.     res <- res + (m1.[str,i] * m2.[i,stol])
  14.     resMatrix.[str,stol] <- res
  15.   resMatrix  
  16.    
  17.  
  18. let multiply (m1: int[,] , m2: int[,] , threadNumber:int) =
  19.  let l11 = m1.GetLength 0
  20.  let l12 = m1.GetLength 1
  21.  
  22.  let l21 = m2.GetLength 0
  23.  let l22 = m2.GetLength 1
  24.  let resLength = l11*l22
  25.  let resMatrix = (Array2D.zeroCreate l11 l22)
  26.  let step = resLength / threadNumber
  27.  let threadArray = Array.init (threadNumber) (fun i -> new Thread(ThreadStart(fun _ ->
  28.     calcEl (i*step , (i+1)*step, resLength, l11, l22, l12, m1, m2, resMatrix)
  29.     )))
  30.  calcEl ((threadNumber-1)*step, resLength-1, resLength, l11,l22,l12,m1,m2,resMatrix)
  31.  
  32.  for t in threadArray do
  33.   t.Start()
  34.  for t in threadArray do
  35.   t.Join()
  36.   resMatrix
  37.  
  38.  
  39.  
  40. [<EntryPoint>]
  41. let main argv =
  42.  0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement