How can i run these two independent loops simultaneously in parallel.
let a1=Seq.map2 (fun a b->(1.0-a)/(a-b)) a2 a3
let b1=Seq.map2 (fun a b->a*b) b2 b3
You can use standard .NET tasks for this - there are no special F# functions or special syntax for spawning a computation in the background:
let a1Work = Task.Factory.StartNew(fun () ->
Array.map2 (fun a b->(1.0-a)/(a-b)) a2 a3)
let b1 = Array.map2 (fun a b->a*b) b2 b3
let a1 = a1Work.Value
I also changed your Seq.map2
to Array.map2
- computations on sequences are lazy and so running them inside a task would not actually do anything. With arrays, the whole calculation is completed immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With