C # parallel programming,

Source: Internet
Author: User

C # parallel programming,

Chapter 2 imperative data parallelism

Several parallel types:

Data Parallelism

Parallel Tasks

Assembly Line

 

Under System. threading. tasks. parallel

Parallel.

Parallel. foreach (you can customize parytitioner)

Parallel. invoke

 

1. Parallel. Invoke

No specific execution order

Staggered concurrency: The logic kernel uses the time slice mechanism and quick context switch to achieve parallel illusion.

Concurrency: not explained

 

Hotspot: potential parallel code

Acceleration ratio: serial execution time/parallel execution time

 

2. Parallel.

Each iteration is sent to a thread as a task.

The upper limit of the iteration range is determined to be less than, so we need to add one

 

3. Parallel. ForEach

You can use the partitioner partition machine for partitioning. Each iteration processes a partition, Tuple <int, int>

 

Exit

ParallelLoopState

Break: it does not end immediately. The execution is smaller than the content of the current iteration.

Stop: exit as soon as possible

 

ParallelLoopResult

IsCompleted loop completed

! IsCompleted &&! LowestBreakIteration. HasValue Stop termination

! IsCompleted & LowestBreakIteration. HasValue Break termination

 

Aggresponexception

. InnerExceptions internal exception set

 

ParallelOptions

MaxDegreeoOfParallelism concurrency

CancellationToken cancel token

TaskScheduler Task Scheduler

 

Chapter 3 imperative parallel task Parallelism

System. Threading. Tasks. Task

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

 

Status

TaskStatus. Created initial status

. WaitingForActivation depends on the initial status of tasks of other tasks.

. WaitingToRun the initial status of the task created through TaskFactory. StartNew

. Cancelled

. Faulted

. RunToCompletion

 

Task. Start ()

Task. Wait () waits for a timeout reload.

Task. WaitAll ()

 

The Task. TaskFactory. StartNew method can be used to pass in cancellationToken or TaskCreationOptions.

TaskCreationOption

. AttachedToParent is associated with a parent task

. None default behavior

. LongRunning long-time operations. The scheduler can perform operations with coarse granularity, generally greater than one second.

. PreferFairness tells the scheduler that the scheduled task is executed earlier.

 

Task. ContinueWith

TaskContinuationOptions operation or condition

 

Related Article

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.