将工作负载分配到多个线程上
我想知道是否有人知道一篇描述将工作负载分配到多个线程的好文章? 最好它是为 C# 编写的,但这确实是我所追求的概念,所以如果它是为不同的、相似的语言编写的,这不是问题。
我遇到一个问题,我必须将大量计算划分为多个线程,然后在一次迭代完成后对生成的数据求和(因此我需要知道所有线程都已完成),然后开始新的迭代,提供所有具有上次迭代中生成的数据的线程(数据将在每次迭代结束之前修改)。
我希望这是有道理的,并且是可能的。 无论哪种方式,我都希望得到一些关于如何解决计算划分到多个线程的大量数据的问题的建议(这样我就可以使用多个处理器的核心)。
谢谢您的回答!
I was wondering if anyone knows about a good article which describes dividing workload on to several Threads? Preferebly it would be written for C# but it's really the concept I'm after, so it's not an issue if it's written for a different, similar, language.
I have a problem where I would have to divide a large amount of computing into several threads and then Sum the generated data after one iteration completes (so I would need to know that all threads have finished) and then start a new iteration, supplying all the threads with the data generated in the last iteration (the data would be modified before the end of each iteration).
I hope this makes sense, and is possible. Either way I would appreciate some advice on how to tackle the problem of computing large amounts of data divided on to several threads (so I can use more than one processor's core).
Thank you for your answers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该查看 Parallel FX (PFX),您可以在此处找到博客和下载链接< a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=348F73FD-593D-4B3C-B055-694C50D2B0F3" rel="nofollow noreferrer">此处(感谢马克)。
不幸的是,我不知道它是否会针对 .NET 2.0/3.5 发布,因为它目前计划针对 .NET 4.0 发布。
如果您想自己实现,请查看工作窃取算法。
还有一个名为 Power Threading 的库,由来自 Wintellect 其中有一些相当不错的课程可供您使用。
You should look at Parallel FX (PFX), you can find the blog here and the download link here (Thanks Marc).
Unfortunately I don't know if this will be released for .NET 2.0/3.5 as it is currently slated for .NET 4.0.
If you're looking at implementing it yourself, look into Work Stealing Algorithms.
There is also a library named Power Threading, by Jeffrey Richter from Wintellect which has some rather good classes available for you.
Lasse 和 Marc 已经谈到了并行扩展。 我有几篇关于使用和基准测试的博客文章(带有代码):
这些可能有助于展示分解工作的各种不同方式。
Lasse and Marc have already spoken about Parallel Extensions. I have a couple of blog articles (with code) about using and benchmarking it:
These might be helpful to show various different ways that work can be broken up.
“并行扩展”就是为此而设计的,特别是
Parallel
类(它允许您非常轻松地在线程之间分割工作)。 结果的汇总比较棘手; 一些快速搜索显示一些 混合结果 - 但我不知道最终版本会是什么(即它可能会更容易)。CTP 可在此处获取< /a>,或等待.NET 4.0。
"Parallel Extensions" is designed for this, in particular the
Parallel
class (which allows you to split work up between the threads very easily). The aggregation of results is trickier; some quick searching shows some mixed results - but I don't know what will be in the final release (i.e. it could be easier).The CTP is available here, or wait for .NET 4.0.
Paint.NET 做得很好(用于图像处理),旧版本的源代码可能仍然是可以在某处免费获得。
有关更多信息,请转到我关于 作者的一篇白皮书我曾经看到过关于这个主题的内容。 最近,当我想向同事展示那篇文章时,我(即:谷歌)无法再找到这篇文章,因此出现了这个问题。
Paint.NET does this quite well (for image processing) and the source code to older versions of might still be freely available somewhere.
For more information, please move over to my question regarding a white paper by the author I once saw about this subject. When I wanted to show that article it to a co-worker recently I (that is: Google) was not able to find this any more, hence the question.