An overview of… Luis Guerrero Plain Concepts
Finding exploitable parallelism Organizing by Tasks Organizing by Data Organizing by Ordering
Linear or recursive? Task parallel Divide and conquer Enough task? Too many – thrashing Too few – under utilization Dependencies between tasks Scheduling work to tasks {}
Work per task? Small workloads Variable workloads Dependencies between tasks? Removable Separable Read only or read/write {}
Linear or recursive? Geometric decomposition Recursive data Data “chunk” size? Too big – under utilization Too small – trashing Chunk layout? Cache and cache line size False cache sharing {}
Implementation Patterns Fork / Join Loop Parallel Divide and Conquer Producer / Consumer Pipeline Asynchronous Agents
Task Parallel Library Parallel LINQ (PLINQ) Data Structures for Parallel Programming Parallel Diagnostic Tools
Data parallelism: The Parallel Class Parallel For For<> Foreach Invoke
Parallel class
Task is the minimum unit of work in TPL Can be scheduled by request 2 Scheduled inside.NET box, ThreadPool y UI Can have a result Is observable Can be continue with another task Can be securely cancelled Someone can wait for a completion
Creating Tasks
Task continuation
Exceptions and cancellation support
A Barrier is a synchronization primitive that enforces the stopping of execution between a number of threads or processes at a given point and prevents further execution until all threads or processors have reached the given point. A CountdownEvent is a synchronization primitive that enables ongoing tracking of a given workload in order to determine if processing of that workload is finished or not.
Barrier y CountdownEvent
PLINQ
An introduction to….
The Managed Extensibility Framework (MEF) is a new library in.NET 4 for building applications that can be incrementally extended. For customers For you and your team Always there, always ready
The Managed Extensibility Framework (MEF) is a new library in the.NET Framework that enables greater reuse of applications and components. Using MEF,.NET applications can make the shift from being statically compiled to dynamically composed
In software engineering, extensibility is a systemic measure of the ability to extend a system and the level of effort required to implement the extension.
Software entities should be open for extension, but closed for modification.
KnownUnknown VS.
An Application is built of parts.
Export it. Import it. Compose it.
Widget1 [Export(typeof(UserControl))] public class Widget1 : UserControl { public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } Export
Widget1 [Export(typeof(UserControl))] public class Widget1 : UserControl { [Import] public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } Import
Widget1 [Export(typeof(UserControl))] public class Widget1 : UserControl { [Import(“HelloMEF.Message”)] public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } Import
Main Page [Export(typeof(UserControl))] public class MainPage: UserControl { [ImportMany(typeof(UserControl))] public IEnumerable { get;set; } ImportMany
PartIntializer: “Compose yourself” Main Page Compose public MainPage() { InitializeComponent(); PartInitializer.SatisfyImports(this); }
Widget1 [ExportMetadata(“Location”,Location.Top)] [Export(typeof(UserControl))] public class Widget1 : UserControl { public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } Export
Main Page [Export(typeof(UserControl))] public class MainPage: UserControl { [ImportMany(typeof(UserControl))] public IEnumerable { get;set; } ImportMany
Widget1 [ExportMetadata(“Location”,Location.Top)] [Export(typeof(UserControl))] public class Widget1 : UserControl { public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } Export
Widget1 [Widget(Location=Location.Top)] public class Widget1 : UserControl { public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } Export
Container
Catalog
Container Catalog TypeCatalog AssemblyCatalog DirectoryCatalog AggregatingCatalog
Part B Export Export [Import(typeof(ILogger))] public ILogger Export Logger { get; set; }
Container Part A Part B [CompositionOptions(CreationPolicy=CreationPolicy.NonShared)] [CompositionOptions(CreationPolicy=CreationPolicy.Shared)] Shared Non-Shared On Export [Import(RequiredCreationPolicy=CreationPolicy.NonShared)] [Import(RequiredCreationPolicy=CreationPolicy.Shared)] On Import