Presentation is loading. Please wait.

Presentation is loading. Please wait.

Plinq Presentation Steen L. Knudsen

Similar presentations


Presentation on theme: "Plinq Presentation Steen L. Knudsen"— Presentation transcript:

1 Plinq Presentation 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 Quick Linq Intro Plinq Intro Plinq Pitfalls Task Parallel Library

5 Quick Linq Intro Slides by Paul Litwin

6 PLinq Parrallel Linq Make it easy for the developer to take advantage of multiple cores. Declarative way of expressing parrallel computations

7 Thread Pool A lot of code needed to manage the plumbing invovled in this

8 Plinq thread Pool Split the enumerable list into partitions and let the threads run the tasks

9 AsParrallel.AsParrallel Extension to IEnumerable public static ParallelQuery AsParallel( this IEnumerable source ) The Ienumerable source should represent the tasks that should run in parrallel

10 ParallelQuery.WithDegreeOfParallelism() The number of threads to be used Example:

11 Partitioner The Plinq runtime choose how to partition the source The default for List source is the range partitioner

12 Partitioner Chunk Partitioning Striped Partitioning Hash Partitioning

13 Partitioner You can write a custom Partitioner that inherits from Partitioner This can tune the performance if the partitioning is a bottleneck Example

14 ParallelQuery WithMergeOptions() FullyBuffered each thread process the part, then merge Example

15 ParallelQuery WithCancellation(CancellationToken) Makes it possible to cancel the parrallel query AsOrdered() Wait for all threads to finish and then orders the result as a normal query

16 ParallelQuery ForAll() Do some work for all elements but returns nothing

17 Exceptions AggregateException Collects all the exceptions thrown by the threads InnerExceptions member returns the list of exceptions

18 When to use Plinq N elements - M threads - T time to process Overhead Split the enumerable into parts O(N) Start the threads O(M) Merge the part results into the complete result O(N) Gain O(N/M*T) O(N/M*T) > (2*O(N)+ O(M))

19 Plinq and db sources Beware if the source for the AsParrallel is a database source. Example

20 Task Parallel Library

21 Parallel.Invoke Parallel.Invoke( () => MethodA(), () => MethodB(), () => MethodC()); Parallel.ForEach Parallel.ForEach(list, e => { DoWork(e) }); Parallel.For Parallel.For(start, end, (i) => DoSomeWork(i));

22 Task Parallel Library Task ”Future” a proxy for an object not yet computed. Task task = Task.Factory.StartNew(() => DoAction()); Is the task done : If(task.IsCompleted) Wait to the job to be done task.Wait();


Download ppt "Plinq Presentation Steen L. Knudsen"

Similar presentations


Ads by Google