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