0

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.

ll_jack
  • 1
  • 4

1 Answers1

0

Try moving the Array.Parallel.map up one level so that you are creating the data in parallel, and then creating the chart lines on the same thread.

Something like this:

let prepData (stats:string) =
    [|for i in (dataSort stats) -> i|]
    |> Array.Parallel.map (fun i -> liveChartData.SampleData i 200)
    |> Array.map (fun data ->  LiveChart.FastLineIncremental(data |> snd, data |> fst))
John Atwood
  • 1,505
  • 10
  • 19
  • I have already done this and this does not parallelize the binding of the data to the chart. When I run it as you suggested, I am still not using all my cores. The problem seems to be with parallelizing the data binding to the chart. – ll_jack Oct 31 '14 at 18:57