1 / 23

Plinq Presentation

Plinq Presentation. Steen L. Knudsen slk@neas.dk steen.l.knudsen@gmail.com. ?. Datalog fra Århus Speciale: Neural Networks DDE / Ehuset KMD Bluetags Statsbilioteket Saxotech Gatehouse Nordjysk Elhandel. NEAS.DK. Nordjysk Elhandel Pris aftaler el forbrug

chick
Download Presentation

Plinq Presentation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PlinqPresentation Steen L. Knudsen slk@neas.dk steen.l.knudsen@gmail.com

  2. ? • Datalog fra Århus • Speciale: Neural Networks • DDE / Ehuset • KMD • Bluetags • Statsbilioteket • Saxotech • Gatehouse • Nordjysk Elhandel

  3. NEAS.DK • Nordjysk Elhandel • Pris aftaler el forbrug • Pris aftaler el produktion • Klima • Trading

  4. Agenda • QuickLinq Intro • Plinq Intro • PlinqPitfalls • Task Parallel Library

  5. QuickLinq Intro • Slides by Paul Litwin

  6. PLinq • ParrallelLinq • Make it easy for the developer to takeadvantage of multiple cores. • Declarativeway of expressing parrallel computations

  7. Thread Pool • A lot of codeneeded to manage the plumbinginvovled in this

  8. Plinqthread Pool • Split the enumerable list intopartitions and let the threads run the tasks

  9. AsParrallel • .AsParrallel • Extension to IEnumerable • publicstaticParallelQueryAsParallel( thisIEnumerable source ) • The Ienumerablesourceshouldrepresent the tasksthatshould run in parrallel

  10. ParallelQuery • .WithDegreeOfParallelism() • The number of threads to beused • Example:

  11. Partitioner • The Plinqruntimechoosehow to partition the source • The default for List<T> source is the range partitioner

  12. Partitioner • ChunkPartitioning • StripedPartitioning • Hash Partitioning

  13. Partitioner • Youcanwrite a customPartitionerthatinherits from Partitioner<T> • Thiscan tune the performance if the partitioning is a bottleneck • Example

  14. ParallelQuery • WithMergeOptions() • FullyBufferedeachthreadprocess the part, thenmerge • Example

  15. ParallelQuery • WithCancellation(CancellationToken) • Makes it possible to cancel the parrallelquery • AsOrdered() • Wait for all threads to finish and thenorders the result as a normal query

  16. ParallelQuery • ForAll() • Do somework for all elements but returnsnothing

  17. Exceptions • AggregateException • Collects all the exceptionsthrown by the threads • InnerExceptionsmemberreturns the list of exceptions

  18. 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))

  19. Plinq and dbsources • Bewareif the source for the AsParrallel is a database source. • Example

  20. Task Parallel Library

  21. Task Parallel Library • Parallel.Invoke Parallel.Invoke( () => MethodA(), () => MethodB(), () => MethodC()); • Parallel.For Parallel.For(start, end, (i) => DoSomeWork(i));

  22. Task Parallel Library • Parallel.ForEach

  23. Task<T> • ”Future” a proxy for an object not yetcomputed. • Taskt = Task.Factory.StartNew(() => DoAction());

More Related