我怎样才能最有效地利用多核短计算在

我怎样才能最有效地利用多核短计算在

本文介绍了我怎样才能最有效地利用多核短计算在.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 下面是背景:我正在写一个跨preTER在C#中的一个小编程语言,称为鹭,而且它具有能并行执行的一些原始列表操作。Here is the context: I am writing an interpreter in C# for a small programming language called Heron, and it has some primitive list operations which can be executed in parallel.一个我面临的最大挑战之一是由分布在不同的内核有效每当并行操作中遇到的评估所做的工作。这可以是短期或长期的操作,也很难提前确定。One of the biggest challenges I am facing is to distribute the work done by the evaluator across the different cores effectively whenever a parallelizable operation is encountered. This can be a short or long operation, it is hard to determine in advance.这我不担心正在同步数据一件事:并行操作被明确不允许修改数据。One thing that I don't have to worry about is synchronizing data: the parallel operations are explicitly not allowed to modify data.因此​​,主要的问题我已经是:So the primary questions I have is:什么是分发跨线程的工作,这样我可以保证电脑会在两个内核分配工作的最有效的方法是什么?我也有兴趣在一个相关的问题:I am also interested in a related question:在大约应的操作需要多长时间才可以开始克服工作中分离到另一个线程的开销?推荐答案如果你想要做了很多与并行操作,你将要开始的.Net 4.0。这里的并行编程.NET文档。你要从这里开始,虽然。 .NET 4.0中添加了多核利用方面很多。这里有一个简单的例子:If you want to do a lot with parallel operations, you're going to want to start with .Net 4.0. Here's the Parallel Programming for .Net documentation. You'll want to start here though. .Net 4.0 adds a LOT in terms of multi-core utilization. Here's a quick example:目前的3.5串行方式:Current 3.5 Serial method:for(int i = 0; i < 30000; i++){ doSomething(i);}新的.NET 4.0并行方式:New .Net 4.0 Parallel method:Parallel.For(0, 30000, (i) => doSomething(i));借助并行。对于方法在可用的内核数量自动缩放,你可以看到有多快,你可以​​开始利用这一点。有几十个新图书馆的框架,支持全线程/任务管理就像你的例子还有(包括所有管道进行同步,注销等)。The Parallel.For method automatically scales across the number of cores available, you can see how fast you could start taking advantage of this. There are dozens of new libraries in the framework, supporting full thread/task management like your example as well (Including all the piping for syncing, cancellation, etc).有用于并行LINQ(PLINQ)库 任务工厂,任务调度和其他几个人。总之,对于特定的任务,你奠定了.NET 4.0中对你有巨大的好处,而且我的继续前进,抢免费测试2 ( RC即将的),并开始使用。 (不,我不为微软工作......但很少会看到即将到来的版本满足需要如此完美,所以我强烈建议.NET 4.0中为你)的There are libraries for Parallel LINQ (PLINQ), Task Factories, Task Schedulers and a few others. In short, for the specific task you laid out .Net 4.0 has huge benefits for you, and I'd go ahead and grab the free beta 2 (RC coming soon) and get started. (No, I don't work for Microsoft...but rarely do I see an upcoming release fulfill a need so perfectly, so I highly recommend .Net 4.0 for you) 这篇关于我怎样才能最有效地利用多核短计算在.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 19:42