<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Parallelism in .NET &#8211; Part 4, Imperative Data Parallelism: Aggregation</title>
	<atom:link href="http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/feed/" rel="self" type="application/rss+xml" />
	<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/</link>
	<description>Thoughts on C#, WPF, .NET, and programming for Scientific Visualization</description>
	<lastBuildDate>Wed, 01 Feb 2012 16:38:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Overview of Simple Parallel Programming with .NET 4.0</title>
		<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-2014</link>
		<dc:creator>Overview of Simple Parallel Programming with .NET 4.0</dc:creator>
		<pubDate>Fri, 06 Jan 2012 22:33:25 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-2014</guid>
		<description>[...] information on synchronized parallel programming, take a look at http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/. The author goes over how you can synchronize dependent data using the .NET 4.0 multithreading [...]</description>
		<content:encoded><![CDATA[<p>[...] information on synchronized parallel programming, take a look at <a href="http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/" rel="nofollow">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/</a>. The author goes over how you can synchronize dependent data using the .NET 4.0 multithreading [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Parallel Programming with .NET</title>
		<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-1114</link>
		<dc:creator>Parallel Programming with .NET</dc:creator>
		<pubDate>Sun, 23 May 2010 17:51:28 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-1114</guid>
		<description>&lt;strong&gt;&quot;Parallelism in .NET&quot; Series by Reed Copsey, Jr....&lt;/strong&gt;

Reed Copsey, Jr. has been writing a great series of articles on parallelism with the .NET Framework 4...</description>
		<content:encoded><![CDATA[<p><strong>&#8220;Parallelism in .NET&#8221; Series by Reed Copsey, Jr&#8230;.</strong></p>
<p>Reed Copsey, Jr. has been writing a great series of articles on parallelism with the .NET Framework 4&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todd</title>
		<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-1066</link>
		<dc:creator>Todd</dc:creator>
		<pubDate>Wed, 14 Apr 2010 03:14:35 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-1066</guid>
		<description>For a minute I thought you were gonna drop the &quot;MapReduce&quot; scheme here but instead you went with the LocalState.

I am still having a hard time grasping this LocalState example and how it is different than original locking issue. In my mind I have the following:

a) There is some kind of WorkItemQueue filled with the doubles in the collection.
b) There is a pool of Threads where the # of threads is &quot;generally&quot; based on the # of processing elements (i.e. cores)
c) The TPL will unleash all the threads in the pool at once
d) Rathe than issuing a single WorkItem per thread, the TPL &quot;partitions&quot; the WorkItemQueue such that each thread gets a chunk of WorkItems. 

I am to understand that the Action(TLocal) is the delegate that is called at the conclusion of the thread/task processing each WorkItem in its chunk...head scratching.

Also, in early comment you mentioned the overhead if a Dictionary was used. However, this may minimized with the use of the the ConcurrentDictionary....rendering a MapReduce-like solution. Regardless, a lock is necessary somewhere I suppose.  Ah.... never-mind....I cheated and looked ahead....I see the nice PLINQ example in Part 6 :-). Nice!</description>
		<content:encoded><![CDATA[<p>For a minute I thought you were gonna drop the &#8220;MapReduce&#8221; scheme here but instead you went with the LocalState.</p>
<p>I am still having a hard time grasping this LocalState example and how it is different than original locking issue. In my mind I have the following:</p>
<p>a) There is some kind of WorkItemQueue filled with the doubles in the collection.<br />
b) There is a pool of Threads where the # of threads is &#8220;generally&#8221; based on the # of processing elements (i.e. cores)<br />
c) The TPL will unleash all the threads in the pool at once<br />
d) Rathe than issuing a single WorkItem per thread, the TPL &#8220;partitions&#8221; the WorkItemQueue such that each thread gets a chunk of WorkItems. </p>
<p>I am to understand that the Action(TLocal) is the delegate that is called at the conclusion of the thread/task processing each WorkItem in its chunk&#8230;head scratching.</p>
<p>Also, in early comment you mentioned the overhead if a Dictionary was used. However, this may minimized with the use of the the ConcurrentDictionary&#8230;.rendering a MapReduce-like solution. Regardless, a lock is necessary somewhere I suppose.  Ah&#8230;. never-mind&#8230;.I cheated and looked ahead&#8230;.I see the nice PLINQ example in Part 6 <img src='http://reedcopsey.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . Nice!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reed</title>
		<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-732</link>
		<dc:creator>Reed</dc:creator>
		<pubDate>Mon, 15 Feb 2010 23:04:41 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-732</guid>
		<description>I agree, Naim.  The TPL is very nicely designed, once you understand how it works.</description>
		<content:encoded><![CDATA[<p>I agree, Naim.  The TPL is very nicely designed, once you understand how it works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naim</title>
		<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-731</link>
		<dc:creator>Naim</dc:creator>
		<pubDate>Mon, 15 Feb 2010 17:26:02 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-731</guid>
		<description>Great article! I like the way it&#039;s been done, even the final action has been made part of the Parallel.ForEach call :)</description>
		<content:encoded><![CDATA[<p>Great article! I like the way it&#8217;s been done, even the final action has been made part of the Parallel.ForEach call <img src='http://reedcopsey.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reed</title>
		<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-693</link>
		<dc:creator>Reed</dc:creator>
		<pubDate>Fri, 05 Feb 2010 17:22:08 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-693</guid>
		<description>Basically, yes, I believe this is (generally) what&#039;s happening underneath.  Your &quot;local state&quot; variable is actually being stored in a ThreadLocal&lt;TLocal&gt;, which is then used in each iteration (value passed into state, returned, and reset to the local thread state).  When you do the final delegate, you are passed the accumulated results of the ThreadLocal variable, which you can then use to do your aggregation.  Finally, the ThreadLocal&lt;T&gt; is disposed of, cleaning it up.

Without doing this, you&#039;d need to either add locking, or put in some form of Dictionary&lt;Thread, TLocal&gt; object that could be used to store the local state - either of which would add quite a bit of contention, and slow things down.</description>
		<content:encoded><![CDATA[<p>Basically, yes, I believe this is (generally) what&#8217;s happening underneath.  Your &#8220;local state&#8221; variable is actually being stored in a ThreadLocal<tlocal>, which is then used in each iteration (value passed into state, returned, and reset to the local thread state).  When you do the final delegate, you are passed the accumulated results of the ThreadLocal variable, which you can then use to do your aggregation.  Finally, the ThreadLocal<t> is disposed of, cleaning it up.</p>
<p>Without doing this, you&#8217;d need to either add locking, or put in some form of Dictionary
<thread , TLocal> object that could be used to store the local state &#8211; either of which would add quite a bit of contention, and slow things down.</thread></t></tlocal></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Sternal</title>
		<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-692</link>
		<dc:creator>Jeff Sternal</dc:creator>
		<pubDate>Fri, 05 Feb 2010 17:21:48 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-692</guid>
		<description>&quot;In a world without ThreadLocal, .NET would need a factory method to create an object instance to host the aggregation delegate, which would be significantly more cumbersome.&quot;

I should have written &quot;to host the aggregation delegate *and maintain a per-thread accumulator variable*, which would be significantly more cumbersome.&quot;</description>
		<content:encoded><![CDATA[<p>&#8220;In a world without ThreadLocal, .NET would need a factory method to create an object instance to host the aggregation delegate, which would be significantly more cumbersome.&#8221;</p>
<p>I should have written &#8220;to host the aggregation delegate *and maintain a per-thread accumulator variable*, which would be significantly more cumbersome.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Sternal</title>
		<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-691</link>
		<dc:creator>Jeff Sternal</dc:creator>
		<pubDate>Fri, 05 Feb 2010 15:46:20 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-691</guid>
		<description>Thanks for the excellent series!

Do I have this right?

Behind the scenes, Parallel.ForEach is creating a ThreadLocal to store the local state, using the ThreadLocal(Func) constructor.  So the TPL decides how many threads it will use and executes your local state initialization delegate once for each thread (on the first iteration handled by that thread).

In a  world without ThreadLocal, .NET would need a factory method to create an object instance to host the aggregation delegate, which would be significantly more cumbersome.</description>
		<content:encoded><![CDATA[<p>Thanks for the excellent series!</p>
<p>Do I have this right?</p>
<p>Behind the scenes, Parallel.ForEach is creating a ThreadLocal to store the local state, using the ThreadLocal(Func) constructor.  So the TPL decides how many threads it will use and executes your local state initialization delegate once for each thread (on the first iteration handled by that thread).</p>
<p>In a  world without ThreadLocal, .NET would need a factory method to create an object instance to host the aggregation delegate, which would be significantly more cumbersome.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Parallelism in .NET &#8211; Part 6, Declarative Data Parallelism : Reed Copsey, Jr.</title>
		<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-609</link>
		<dc:creator>Parallelism in .NET &#8211; Part 6, Declarative Data Parallelism : Reed Copsey, Jr.</dc:creator>
		<pubDate>Wed, 27 Jan 2010 01:26:30 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-609</guid>
		<description>[...] When working with a problem that can be decomposed by data, we have a collection, and some operation being performed upon the collection.&#160; I’ve demonstrated how this can be parallelized using the Task Parallel Library and imperative programming using imperative data parallelism via the Parallel class.&#160; While this provides a huge step forward in terms of power and capabilities, in many cases, special care must still be given for relative common scenarios. [...]</description>
		<content:encoded><![CDATA[<p>[...] When working with a problem that can be decomposed by data, we have a collection, and some operation being performed upon the collection.&#160; I’ve demonstrated how this can be parallelized using the Task Parallel Library and imperative programming using imperative data parallelism via the Parallel class.&#160; While this provides a huge step forward in terms of power and capabilities, in many cases, special care must still be given for relative common scenarios. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reed</title>
		<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-581</link>
		<dc:creator>Reed</dc:creator>
		<pubDate>Sat, 23 Jan 2010 20:49:51 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-581</guid>
		<description>Thanks for the feedback!  I&#039;m going to keep them coming...</description>
		<content:encoded><![CDATA[<p>Thanks for the feedback!  I&#8217;m going to keep them coming&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ed Ball</title>
		<link>http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-575</link>
		<dc:creator>Ed Ball</dc:creator>
		<pubDate>Sat, 23 Jan 2010 06:50:28 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/#comment-575</guid>
		<description>Great articles! I really appreciate this relaxed introduction to the new APIs.</description>
		<content:encoded><![CDATA[<p>Great articles! I really appreciate this relaxed introduction to the new APIs.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
 
