微软的CCR与任务并行库

时间:2021-11-25 02:23:06

Microsoft has at least two different approches to improved support for concurrent operations.

Microsoft至少有两种不同的方法可以改进对并发操作的支持。

1) Is the Concurrency Coordination Runtime (CCR) which is part of Microsoft Robotics Studio and CCR & DSS Toolkit

1)并发协调运行时(CCR)是Microsoft Robotics Studio和CCR&DSS Toolkit的一部分

2) Task Paralell Library (TPL) (Part of .NET 4.0 and now in Beta 1 release)

2)任务Paralell库(TPL)(.NET 4.0的一部分,现在在Beta 1版本中)

I would like to know if anyone has experience with these two different pieces of software and would compare and contrast them?

我想知道是否有人对这两种不同的软件有经验并会对它们进行比较和对比?

2 个解决方案

#1


By and large, both frameworks have complementary but different goals.

总的来说,两个框架都有互补但不同的目标。

The CCR offers primitives for coordination of concurrent processes. Coordination is the glue that makes a bunch of processes work as a whole - so the CCR offers primitives for exchanging messages through so called channels. Processes can wait for a message to arrive on a channel, or a number of channels, or any one of a number of channels and so forth. This is a particular paradigm for coordination of concurrent processes that works well. Note also that is it not free - you have to buy if from Microsoft separately.

CCR提供了协调并发进程的原语。协调是使一堆进程作为一个整体工作的粘合剂 - 因此CCR提供了通过所谓的通道交换消息的原语。进程可以等待消息到达频道,或多个频道,或多个频道中的任何一个等等。这是协调并发流程的特殊范例。另请注意,它不是免费的 - 您必须单独从Microsoft购买。

The TPL offers primitives and infrastructure to parallellize computations or algorithms semi-automatically. One of the most obvious primitives there is the parallel for loop - looks sort of like a for loop but tries to execute the loop in parallel.

TPL提供原语和基础设施,以半自动平行计算或算法。其中一个最明显的原语是并行for循环 - 看起来有点像for循环但是尝试并行执行循环。

So, if you have a bunch of process that you'd like to coordinate on a higher level than using shared state and locks, use the CCR. If you have a computation-intensive process that you'd like to run efficiently on a multi-core machine, use the TPL.

因此,如果您有一堆进程要在比使用共享状态和锁更高的级别上进行协调,请使用CCR。如果您有一个计算密集型过程,您希望在多核计算机上高效运行,请使用TPL。

#2


It's not an either/or scenario. The CCR is a library that supports certain programming patterns. You can intermix CCR and TPL code like this, here is a Parallel.For inside of a Receive delegate:

这不是一个/或两个场景。 CCR是一个支持某些编程模式的库。你可以像这样混合使用CCR和TPL代码,这里是一个Parallel.For在一个Receive委托中:

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Ccr.Core;

namespace Demo
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Dispatcher dispatcher = new Dispatcher();
            DispatcherQueue taskQueue = new DispatcherQueue("Demo", dispatcher);
            Port<int> portInt = new Port<int>();
            portInt.Post(Int32.Parse(args[0]));

            Arbiter.Activate(
                taskQueue,
                portInt.Receive(delegate(int count)
                {
                    Parallel.For(0, count, i =>
                    {
                        Console.Write(i.ToString() + " ");
                    });
                }
            ));
        }
    }
}

#1


By and large, both frameworks have complementary but different goals.

总的来说,两个框架都有互补但不同的目标。

The CCR offers primitives for coordination of concurrent processes. Coordination is the glue that makes a bunch of processes work as a whole - so the CCR offers primitives for exchanging messages through so called channels. Processes can wait for a message to arrive on a channel, or a number of channels, or any one of a number of channels and so forth. This is a particular paradigm for coordination of concurrent processes that works well. Note also that is it not free - you have to buy if from Microsoft separately.

CCR提供了协调并发进程的原语。协调是使一堆进程作为一个整体工作的粘合剂 - 因此CCR提供了通过所谓的通道交换消息的原语。进程可以等待消息到达频道,或多个频道,或多个频道中的任何一个等等。这是协调并发流程的特殊范例。另请注意,它不是免费的 - 您必须单独从Microsoft购买。

The TPL offers primitives and infrastructure to parallellize computations or algorithms semi-automatically. One of the most obvious primitives there is the parallel for loop - looks sort of like a for loop but tries to execute the loop in parallel.

TPL提供原语和基础设施,以半自动平行计算或算法。其中一个最明显的原语是并行for循环 - 看起来有点像for循环但是尝试并行执行循环。

So, if you have a bunch of process that you'd like to coordinate on a higher level than using shared state and locks, use the CCR. If you have a computation-intensive process that you'd like to run efficiently on a multi-core machine, use the TPL.

因此,如果您有一堆进程要在比使用共享状态和锁更高的级别上进行协调,请使用CCR。如果您有一个计算密集型过程,您希望在多核计算机上高效运行,请使用TPL。

#2


It's not an either/or scenario. The CCR is a library that supports certain programming patterns. You can intermix CCR and TPL code like this, here is a Parallel.For inside of a Receive delegate:

这不是一个/或两个场景。 CCR是一个支持某些编程模式的库。你可以像这样混合使用CCR和TPL代码,这里是一个Parallel.For在一个Receive委托中:

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Ccr.Core;

namespace Demo
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Dispatcher dispatcher = new Dispatcher();
            DispatcherQueue taskQueue = new DispatcherQueue("Demo", dispatcher);
            Port<int> portInt = new Port<int>();
            portInt.Post(Int32.Parse(args[0]));

            Arbiter.Activate(
                taskQueue,
                portInt.Receive(delegate(int count)
                {
                    Parallel.For(0, count, i =>
                    {
                        Console.Write(i.ToString() + " ");
                    });
                }
            ));
        }
    }
}