Available parallel technologies in .Net

前端 未结 6 1320
星月不相逢
星月不相逢 2021-02-04 10:58

I am new to .Net platform. I did a search and found that there are several ways to do parallel computing in .Net:

  1. Parallel task in Task Parallel Library, which

相关标签:
6条回答
  • 2021-02-04 11:30

    One more is the new Task Parallel library in .NET 4.0, which is similar and along the lines of what you've already discovered, but this may be an interesting read:

    Task Parallel Library

    0 讨论(0)
  • 2021-02-04 11:41

    You do need to do a fair amount of research in order to determine how to effectively multithread. There are some good technical articles, part of the Microsoft Parallel Computing team's site.

    Off the top of my head, there are several ways to go about multithreading:

    1. Thread class.
    2. ThreadPool, which also has support for I/O-bound operations and an I/O completion port.
    3. Begin*/End* asynchronous operations.
    4. Event-based asynchronous programming (or "EBAP") components, which use SynchronizationContext.
    5. BackgroundWorker, which is an EBAP that defines an asynchronous operation.
    6. Task class (Task Parallel Library) in .NET 4.
    7. Parallel LINQ. There is a good article on Parallel.ForEach (Task Parallel Library) vs. PLINQ.
    8. Rx or "LINQ to Events", which does not yet have a non-Beta version but is nearing completion and looks promising.
    9. (F# only) Asynchronous workflows.

    Update: There is an article Understanding and Applying Parallel Patterns with the .NET Framework 4 available for download that gives some direction on which solutions to use for which kinds of parallel scenarios (though it assumes .NET 4 and doesn't cover Rx).

    0 讨论(0)
  • 2021-02-04 11:42

    two major ways to do parallel are threads and the new task based library TPL.

    Asynchronous Programming you mention is nothing more then one new thread in the threadpool.

    PLINQ, Rx and others mentioned are actually extensions sitting on the top of the new task scheduler.

    the best article explaining exactly the new architecture for new task scheduler and all libraries on the top of it, Visual Studio 2010 and new TPL .NET 4.0 Task-based Parallelism is here (by Steve Teixeira, Product Unit Manager for Parallel Developer Tools at Microsoft):

    http://www.drdobbs.com/visualstudio/224400670

    otherwise Dr Dobbs has dedicated parallel programming section here: http://www.drdobbs.com/go-parallel/index.jhtml

    The main difference between say threads and new task based parallel programming is you do not need to think anymore in terms of threads, how do you manage pools and underlying OS and hardware anymore. TPL takes care for that you just use tasks. That is a huge change in the way you do parallel on any level including abstraction.

    So in .NET actually you do not have many choices:

    1. Thread
    2. New task based, task scheduler.

    Obviously the task based is the way to go.

    cheers Valko

    0 讨论(0)
  • 2021-02-04 11:43

    Strictly speaking, the distinction between parallel, asynchronous and concurrent should be made here.

    Parallel means that a "task" is split among several smaller sub-"tasks" that can be run at the same time. This requires a multi-core CPU or a multi-CPU computer, where each task has its dedicated core or CPU. Or multiple computers. PLINQ (data parallelism) and TPL (task parallelism) fall into this category.

    Asynchronous means that tasks run without blocking each other. F#'s async expression, Rx, Begin/End pattern are all APIs for async programming.

    Concurrency is a concept more broad than parallelization and asynchrony. Concurrency means that several "tasks" run at the same time, interacting with each other. But these "tasks" don't have to run on separate physical computing units, as is meant in parallelization. For example, multitasking operating systems can execute multiple processes concurrently even on single-core single-CPU computers, using time slices. Concurrency can be achieved for example with the Actor model and message passing (e.g. F#'s mailbox, Erlang processes (Retlang in .Net))

    Threads are a relatively low-level concept compared to the concepts above. Threads are tasks running within a process, running concurrently and managed directly by the operating system's scheduler. You can implement parallelization when the operating system maps each thread to a separate core, or an Actor model by implementing message queuing, routing, etc on each thread.

    0 讨论(0)
  • 2021-02-04 11:46

    There is also the Reactive Extensions for .NET (Rx)

    Rx is basically linq queries for events. It allows you to process and combine asynchronous data streams in the same way linq allows you to work with collections. So you would probably use it in conjunction with other parallel technologies as a way of bringing the results of your parallel operations together without having to worry about locks and other low level threading primitives.

    Expert to Expert: Brian Beckman and Erik Meijer - Inside the .NET Reactive Framework (Rx) gives a good overview of what Rx is all about.

    EDIT: Another library worth mention is the Concurrency and Coordination Runtime (CCR), it's been around for a long time (earlier than '06) and is shipped as part of the Microsoft Robotics Studio.

    Rx has a lot of the same cool ideas that the CCR has inside it, but with a much nicer API in my opinion. There's still some interesting stuff in the CCR though so it might be worth checking out. There's also a distributed services framework that works with the CCR that might make it useful depending on what you're doing.

    Expert to Expert: Meijer and Chrysanthakopoulos - Concurrency, Coordination and the CCR

    0 讨论(0)
  • 2021-02-04 11:48

    There are also some .NET libraries for data parallel programming which target the Graphics Processing Unit (GPU) including:

    Microsoft Accelerator is for data parallel programming and can target either the GPU or multi-core processors.

    Brama is for LINQ style data transformations that run on the GPU.

    CUDA.NET provides a wrapper to allow to CUDA to be used from .NET programs.

    0 讨论(0)
提交回复
热议问题