Microsoft Accelerator V2 - toArray2D 问题
我是 Microsoft.Accelerator 的新手。看一下下面的代码(它是 F#,但与 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))
基本上,我创建一个 FPA 列表,并以生成的 newfi 列表中的每个元素都依赖于 fi 列表中的所有元素的方式处理它。最后我想得到最终的 fi 列表。我的问题是:我应该为生成的 FPA 列表中的每个元素 (FPA) 调用 toArray2D 吗?在我看来,每次调用 toArray2D 时都会运行整个计算,这非常耗时。
感谢您的帮助。 奥尔德里奇
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
FPA 表示要执行的计算。您有两个此类计算列表,
fi
和newfi
。由于您定义事物的方式,newfi
的每个元素都是一个计算,需要独立运行才能获取其值;尽管它是根据fi
的常见底层元素定义的,但无法利用这一事实仅计算一次底层fi
值并重用他们。如果您希望这些fi
计算仅执行一次,则需要执行以下操作之一:fi
计算的结果(例如,通过使用toArray2D
),并根据这些计算值构建newfi
列表。fi
值。An FPA represents a computation to be performed. You have two lists of such computations,
fi
andnewfi
. Because of how you're defining things, each element ofnewfi
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 offi
, there is no way to take advantage of that fact to only compute the underlyingfi
values a single time and reuse them. If you want thosefi
computations to be performed only a single time, you'll need to do one of the following:fi
computations (e.g. by usingtoArray2D
), and build thenewfi
list based on these computed values.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 thefi
values.