C # Parallel programming

Source: Internet
Author: User

Chapter II command-style data parallelism

Several parallel types:

Data parallelism

Task parallelism

Pipeline

Under the System.threading.tasks.parallel

Parallel.For

Parallel.ForEach (can be customized Parytitioner)

Parallel.Invoke

1. Parallel.Invoke

No specific execution order

Interleaved Concurrency: Logical cores implement parallel artifacts through time-slice mechanisms and fast context switches

Concurrency: Not explained

Hot spots: Potentially parallel code

Speedup: Serial execution time/parallel execution time

2. Parallel.For

Each iteration is assigned to a thread as a task

The upper bounds of the iteration range are less than, so it is necessary to add a

3. Parallel.ForEach

Can be partitioned through the partitioner partition, with each iteration processing a partition,tuple<int,int>

Exit

ParallelLoopState

Break: Does not end immediately, execution is less than the current iteration of the content

Stop: Exit as soon as possible

Parallelloopresult

IsCompleted Cycle Complete

! IsCompleted &&! Lowestbreakiteration.hasvalue Stop Termination

! IsCompleted && Lowestbreakiteration.hasvalue Break terminated

AggregateException

. InnerExceptions Internal Exception Collection

ParallelOptions

Maxdegreeoofparallelism degree of parallelism

CancellationToken Cancel Token

TaskScheduler Task Scheduler

Chapter III Command-parallel task parallelism

System.Threading.Tasks.Task

A task represents an asynchronous operation and does not target a thread

State

Taskstatus.created Initial State

. Waitingforactivation the initial state of tasks that depend on other tasks

. Waitingtorun the initial state of a task created by taskfactory.startnew

. Cancelled

. Faulted

. Runtocompletion

Task. Start ()

Task. Wait () Waits also have overloads that are timed out

Task.waitall ()

The Task.TaskFactory.StartNew method can pass arguments to the CancellationToken, or taskcreationoptions

Taskcreationoption

. AttachedToParent associated with a parent task

. None default behavior

. Longrunning long-time operation, the scheduler can be coarse-grained operation, generally more than one second

. Preferfairness tells the scheduler that earlier scheduled tasks are executed earlier

Task. ContinueWith Continuation Tasks

Taskcontinuationoptions operation or condition

C # Parallel programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.