Skip to content

Commit c4c942d

Browse files
committed
Parallel matrices initialization
1 parent 3914f15 commit c4c942d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/MatrixMultiplication/Matrices.fs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ type Kernels = K0 = 0 | K1 = 1 | K2 = 2 | K3 = 3 | K4 = 4
66
let rand = new System.Random()
77

88
let getRandomMatrix (n: uint) init =
9-
10-
[|
11-
for i in 0 .. int n - 1 -> Array.init (int n) init
12-
|]
9+
Array.Parallel.init (int n) (fun i -> Array.init (int n) init)
1310

1411
let cpuMxM opAdd opMult zero (m1 : array<array<_>>) (m2: array<array<_>>) =
1512
let res = Array.init (m1.Length * m1.Length) (fun _ -> zero)
@@ -280,13 +277,14 @@ let applyMultiplyGPU<'a,'b,'e,'f> (kernel:Kernels) (clContext: ClContext) (numTo
280277
| Kernels.K3 -> multiplyKernel3 clContext localWorkSize workPerThread opAdd opMult zero
281278
| Kernels.K4 -> multiplyKernel4 clContext localWorkSize workPerThread opAdd opMult zero
282279
| x -> failwithf $"Unexpected kernel {x}."
280+
283281
let queue = clContext.QueueProvider.CreateQueue()
284-
//queue.Error.Add(fun x -> printfn "%A" x)
282+
285283
let numToRun = int numToRun
286284

287285
fun (m1: 'e[][]) (m2: 'f[][]) ->
288-
let start = System.DateTime.Now
289286
let result : 'a[] = Array.zeroCreate(m1.Length * m1.Length)
287+
let start = System.DateTime.Now
290288
for i in 0 .. numToRun - 1 do
291289
let m1_gpu =
292290
clContext.CreateClArray<_>(Array.concat m1, HostAccessMode.NotAccessible)

0 commit comments

Comments
 (0)