150 likes | 362 Views
Plinq Presentation. Steen L. Knudsen slk@neas.dk steen.l.knudsen@gmail.com. NEAS. Nordjysk Elhandel. PLinq. Parrallel Linq Make it easy for the developer to take advantage of multiple cores . Declarative way of expressing parrallel computations. Thread Pool.
E N D
PlinqPresentation Steen L. Knudsen slk@neas.dk steen.l.knudsen@gmail.com
NEAS • Nordjysk Elhandel
PLinq • ParrallelLinq • Make it easy for the developer to takeadvantage of multiple cores. • Declarativeway of expressing parrallel computations
Thread Pool • A lot of codeneeded to manage the plumbinginvovled in this
Plinqthread Pool • Split the enumerable list intopartitions and let the threads run the tasks
When to usePlinq • N elements - M threads - T time to process • Overhead • Split the enumerableinto parts O(N) • Start the threads O(M) • Merge the part resultsinto the completeresult O(N) • Gain O(N/M*T) • O(N/M*T) > (2*O(N)+ O(M))
AsParrallel • .AsParrallel • Extension to IEnumerable • publicstaticParallelQueryAsParallel( thisIEnumerable source ) • The IEnumerableshouldrepresent the tasksthatshould run in parrallel
ParallelQuery • .WithDegreeOfParallelism() • The number of threadsused
Partitioner • The default partitioner split the list intochunks • Youcanwrite a customPartitionerthatinherits from Partitioner<T> • Example
ParallelQuery • ForAll() • WithMergeOptions() • FullyBufferedeachthreadprocess the part, thenmerge • Example • WithCancellation() • CancellationToken • AsOrdered()
Exceptions • AggregateException
Plinq and dbsources • Becareful the source for the AsParrallel is a database source. • Example
Task Parallel Library • Task<T> • Future • Parallel.ForEach