{"id":55912,"date":"2010-04-28T07:00:00","date_gmt":"2010-04-28T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/pfxteam\/2010\/04\/28\/parallelextensionsextras-tour-14-singleitempartitioner\/"},"modified":"2010-04-28T07:00:00","modified_gmt":"2010-04-28T07:00:00","slug":"parallelextensionsextras-tour-14-singleitempartitioner","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/parallelextensionsextras-tour-14-singleitempartitioner\/","title":{"rendered":"ParallelExtensionsExtras Tour &#8211; #14 &#8211; SingleItemPartitioner"},"content":{"rendered":"<p class=\"MsoNormal\"><em>(The full set of ParallelExtensionsExtras Tour posts is available <\/em><a href=\"https:\/\/blogs.msdn.com\/pfxteam\/archive\/2010\/04\/04\/9990342.aspx\"><em>here<\/em><\/a><em>.)<\/em>&nbsp;<\/p>\n<p class=\"MsoNormal\">In a <a href=\"https:\/\/blogs.msdn.com\/pfxteam\/archive\/2010\/04\/06\/9990420.aspx\">previous<\/a> ParallelExtensionsExtras Tour blog post, we talked about implementing a custom partitioner for BlockingCollection&lt;T&gt;.&nbsp; Custom partitioning is an advanced but important feature supported by both Parallel.ForEach and PLINQ, as it allows the developer full control over how data is distributed during parallel processing.&nbsp; .NET 4 includes several high-quality partitioning algorithms that are built-in and used by default, but sometimes you do want to tweak the employed behaviors, and that&#8217;s where the Partitioner&lt;T&gt; and OrderablePartitioner&lt;T&gt; types come in.<\/p>\n<p>For example, the built-in partitioning algorithms do chunking in order to amortize the cost of synchronization across multiple data elements.&nbsp; For some scenarios, however, that chunking could lead to less-than-ideal behavior, and thus you might want to write a custom partitioner that doesn&#8217;t do any chunking, that instead always hands out a single data element at a time to whichever thread is ready next to process more data.&nbsp; ParallelExtensionsExtras includes just such a partitioner, SingleItemPartitioner, in the SingleItemPartitioner.cs file.&nbsp; Rather than explain this type in detail here, I&#8217;ll instead point you to a new article in Dr. Dobbs &#8220;<a href=\"http:\/\/www.drdobbs.com\/visualstudio\/224600406\">Custom Parallel Partitioning in .NET 4<\/a>&#8221;&nbsp;that walks through the principles of custom partitioning and SingleItemPartitioner&#8217;s implementation in detail.<\/p>\n<p>Enjoy!<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>(The full set of ParallelExtensionsExtras Tour posts is available here.)&nbsp; In a previous ParallelExtensionsExtras Tour blog post, we talked about implementing a custom partitioner for BlockingCollection&lt;T&gt;.&nbsp; Custom partitioning is an advanced but important feature supported by both Parallel.ForEach and PLINQ, as it allows the developer full control over how data is distributed during parallel processing.&nbsp; [&hellip;]<\/p>\n","protected":false},"author":360,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[7908],"tags":[7907,7911,7916,7909,7924,7910,7912],"class_list":["post-55912","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pfxteam","tag-net-4","tag-code-samples","tag-coordination-data-structures","tag-parallel-extensions","tag-parallelextensionsextras","tag-plinq","tag-task-parallel-library"],"acf":[],"blog_post_summary":"<p>(The full set of ParallelExtensionsExtras Tour posts is available here.)&nbsp; In a previous ParallelExtensionsExtras Tour blog post, we talked about implementing a custom partitioner for BlockingCollection&lt;T&gt;.&nbsp; Custom partitioning is an advanced but important feature supported by both Parallel.ForEach and PLINQ, as it allows the developer full control over how data is distributed during parallel processing.&nbsp; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/55912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/360"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=55912"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/55912\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=55912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=55912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=55912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}