views:

153

answers:

1

Hi,

I am new to Microsoft.Accelerator. Take a look at the following code (it is F# but it is similar to C#):

type FPA = Microsoft.ParallelArrays.FloatParallelArray

let fi = List.init 9 (fun i -> new FPA(i, [|10;10|])) 
let process (fi: FPA list) : FPA list = fi // complicated function
let newfi = process fi
let target = new DX9Target()
for newf in newfi do printfn "%A" (target.toArray2D(newf))

Basicaly I create a list of FPAs and process it in a way that every element in the resulting newfi list is dependend on all elements in the fi list. Finaly I would like to get the resulting fi list. And my question is: Should I call toArray2D for every single element (FPA) in the resulting FPA list? It seems to me that the whole computation is run everytime I call toArray2D, which is very time consuming.

Thank you for your help. Oldrich

+1  A: 

An FPA represents a computation to be performed. You have two lists of such computations, fi and newfi. Because of how you're defining things, each element of newfi is a computation which will need to be run independently to get its value; even though it is defined in terms of common underlying elements of fi, there is no way to take advantage of that fact to only compute the underlying fi values a single time and reuse them. If you want those fi computations to be performed only a single time, you'll need to do one of the following:

  1. Get the results of the fi computations (e.g. by using toArray2D), and build the newfi list based on these computed values.
  2. Create a single computation which represents all newfi values in a single array - you may need to be a bit clever to compose such a computation, but this could allow you to calculate all values at once without needing to recompute the fi values.
kvb
Thank you for your answer. I was afraid of that...What did you mean by?:Create a single computation which represents all newfi values in a single array. How can I put "2D array of 1D array" into single 2D array? I can use FPA4, but there is a limit to 4 values. I need 9 values.PS: What I would like to implement is a Lattice Boltzmann Modeling
Oldrich Svec