开发者

Microsoft Accelerator V2 - toArray2D question

开发者 https://www.devze.com 2022-12-16 01:22 出处:网络
I am new to Microsoft.Accelerator. Take a look at the following code (it is F# but it is similar to C#):

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 c开发者_JAVA百科reate 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


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消