简体   繁体   English

显式多核C#应用程序

[英]Explicit multi-core C# applications

Is there any easy way to explicitly make an already threaded application utilise a multicore environment? 是否有任何简单的方法可以明确地使已经线程化的应用程序使用多核环境? (if avaliable). (如果可用的话)。

The first problem would be how do I determine if my runtime environment supports multi-core applications? 第一个问题是如何确定我的运行时环境是否支持多核应用程序?

If I then determine that I can use multi core functionality, can I explicitly assign threads to run on different cores? 如果我确定我可以使用多核功能,我可以显式分配线程以在不同的内核上运行吗? If so Is the thread communication handled by the OS/Hardware or do I have to get my hands dirty? 如果是这样,线程通信是由OS /硬件处理还是我必须弄脏手?

If your application is already threaded properly, you dont have to do anything. 如果您的应用程序已经正确穿线,则无需执行任何操作。 Thread context execution and handling is done for you. 线程上下文执行和处理已完成。

Now when it comes to threading, is your app threaded in a way to utilize the cores? 现在谈到线程,您的应用程序是否以某种方式利用核心? do you have processor intensive tasks split into seperate threads. 您是否将处理器密集型任务拆分为单独的线程。 If not, then you will need to make changes to split up your processing tasks into more threads. 如果没有,那么您将需要进行更改以将处理任务拆分为更多线程。 You can use Environment.ProcessorCount to get the core count and make as many threads as appropriate at runtime for your tasks. 您可以使用Environment.ProcessorCount来获取核心数,并在运行时为您的任务生成尽可能多的线程。

As of now, there is not really any way to make an improperly threaded app(single thread) into a threaded app taking advantage of all the processors/cores, unless you look to future technologies, such as plinq and Parallel FX 截至目前,除非您关注未来的技术,例如plinqParallel FX ,否则没有任何方法可以将不正确的线程应用程序(单线程)制作成利用所有处理器/核心的线程应用程序。

Hi there are 2 extentions that I know about 嗨,我知道有两个延伸

Parallel C# Homepage 并行C#主页

Check out Somasegars MSDN blog on MS June CTP for parallel 3.5 extenstions 在MS June CTP上查看Somasegars MSDN博客,了解并行3.5扩展

MSDN MSDN

The library is made up of the following components: 该库由以下组件组成:

  • The Task Parallel Library (TPL), which provides support for imperative data and task parallelism. 任务并行库(TPL),它为命令式数据和任务并行性提供支持。
  • Parallel LINQ (PLINQ), which provides support for declarative data parallelism. 并行LINQ(PLINQ),它提供对声明性数据并行性的支持。
  • Coordination Data Structures (CDS), which provide support for work coordination and managing shared state. 协调数据结构(CDS),为工作协调和管理共享状态提供支持。

Currently, you can set the available processors for a given process using Process.ProcessorAffinity , but assigning specific threads to specific processors is handled under the hood implicitly. 目前,您可以使用Process.ProcessorAffinity为给定进程设置可用的处理器,但是隐式地处理将特定线程分配给特定处理器。 This is actually a good thing most of the time, as an intelligent runtime using real-time performance and load balance information can usually do a better job than you can statically, at least for the few-core context mainstream multicore operates in. 这在大多数情况下确实是一件好事,因为使用实时性能和负载平衡信息的智能运行时通常可以比静态更好地工作,至少对于少数核心上下文主流多核运行而言。

That's the problem. 那就是问题所在。 How to make a threaded application, how to convert your existing code. 如何制作线程应用程序,如何转换现有代码。 I want to exploit multi-core in C#. 我想在C#中利用多核。 However, ParallelFX is still beta. 但是,ParallelFX仍然是测试版。 I won't develop using a beta. 我不会使用测试版开发。 And, I don't want to change all the code again (I translated my apps from VB 6). 并且,我不想再次更改所有代码(我从VB 6翻译了我的应用程序)。 Today, I received a newsletter from Packt Publishing announcing a new book about parallel programming with C#. 今天,我收到了Packt Publishing的新闻通讯,宣布了一本关于使用C#进行并行编程的新书。 C# 2008 and 2005 Threaded Programming. C#2008和2005线程编程。 I think it focuses in the things we are blogging about everywhere. 我认为它关注的是我们在任何地方写博客的事情。 How to think and develop a threaded application without waiting for a new miracle language. 如何在不等待新的奇迹语言的情况下思考和开发线程化应用程序。 It's cool to see books entirely dedicated about the topic, because we have full of blogs about that. 很高兴看到完全专注于这个主题的书籍,因为我们有很多关于这个的博客。 The link is http://www.packtpub.com/beginners-guide-for-C-sharp-2008-and-2005-threaded-programming/book I think it deserves an apportunity. 链接是http://www.packtpub.com/beginners-guide-for-C-sharp-2008-and-2005-threaded-programming/book我认为值得一个机会。 I'll let you know my feedback when I buy it. 我买的时候会通知你我的反馈意见。

Without getting into specifics (I'm not sure how much information is public yet), the next version of the .NET framework will be more helpful with doing this. 没有详细说明(我不确定有多少信息是公开的),下一版本的.NET框架将更有帮助。 You will likely not want or need to be thinking about managing threads by hand. 您可能不想或不需要考虑手动管理线程。 I'm sure more information will be public about this after PDC (end of October). 我相信在PDC(10月底)之后会有更多的信息公开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM