I am learning to use F# Live Charting and having difficulty making the code go parallel.
I have this code which I wrote with help from some examples from some google searches.
module liveChartData =
let SampledData (tuple) (t:int) =
let name = tuple |> fst
let stat = tuple |> snd
let x = [for i in all.GetColumn<float>((name,stat)).Keys -> i.ToShortDateString()]
let y = all.GetColumn<float>((name,stat)) |> Series.fillMissingWith 0. |> Series.values
let obs =
seq { for i in (Seq.zip x y) do
do Thread.Sleep t
yield (i) } |> Seq.cache |> Seq.observe
"" + name + "-" + stat + "",obs
let dataSort (id:string) =
let name = all.ColumnKeys |> Seq.map fst |> Seq.distinct |> Seq.toList
let stat = all.ColumnKeys |> Seq.map snd |> Seq.distinct |> Seq.toList
[|for i in name do for j in stat -> (i,j)|]
|> Array.filter (fun i -> (i |> snd) = id)
let prepData (stats:string) =
[|for i in (dataSort stats) -> i|]
|> Array.map (fun i -> let data = liveChartData.SampledData i 200
LiveChart.FastLineIncremental(data |> snd,data |> fst))
|> Chart.Combine
let charting_s=
[|for i in ["col1"; "col2";"col3";"col4"; "col5"] -> i|]
|> Array.map (fun i -> prepData i)
|> Chart.Rows
when I change the Array.map to Array.Parallel.map i get the following error.
System.InvalidOperationException: Chart Area Axes - The minimum and maximum axis values have not been specified.
also got
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
Trying to make other parts parallel I get other errors too. It seems that the problem arises when feeding data to the LiveChart.FastLineIncremental in parallel. I also think that the code could benefit from some sort of async process but I dont know how to incorporate this.
Any help would be most appreciated.
This code works fine as it is, but i just want to use all my cores.