<?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 11, Divide and Conquer via Parallel.Invoke</title>
	<atom:link href="http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/feed/" rel="self" type="application/rss+xml" />
	<link>http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/</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: Reed</title>
		<link>http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-1102</link>
		<dc:creator>Reed</dc:creator>
		<pubDate>Wed, 28 Apr 2010 22:55:20 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-1102</guid>
		<description>John,

It actually does 2^cpus, as you saw.  I&#039;d have two comments for this, however.  First, this was really just written as an example - I&#039;m sure to get this completely optimal, you&#039;d have to find the right balance here.  I suspect that this does run faster with extra work (I picked those numbers after profiling) for reasons such as non-optimal pivots, uneven workloads in comparisons, and other similar issues.

That being said, it is often better to have more work items than processors.  Depending on the work involved, even CPU intensive work often runs faster if given a few extra threads.  It&#039;s all about profiling your algorithm, and finding the right balance.</description>
		<content:encoded><![CDATA[<p>John,</p>
<p>It actually does 2^cpus, as you saw.  I&#8217;d have two comments for this, however.  First, this was really just written as an example &#8211; I&#8217;m sure to get this completely optimal, you&#8217;d have to find the right balance here.  I suspect that this does run faster with extra work (I picked those numbers after profiling) for reasons such as non-optimal pivots, uneven workloads in comparisons, and other similar issues.</p>
<p>That being said, it is often better to have more work items than processors.  Depending on the work involved, even CPU intensive work often runs faster if given a few extra threads.  It&#8217;s all about profiling your algorithm, and finding the right balance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Lilley</title>
		<link>http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-1101</link>
		<dc:creator>John Lilley</dc:creator>
		<pubDate>Wed, 28 Apr 2010 21:35:41 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-1101</guid>
		<description>I&#039;m trying to understand the maxDepth setting, but it looks like setting maxDepth=Cpus will result in 2^Cpus threads, as opposed to CPUs threads?  Is this true?  

Given the potential lopsided-pivot problem of qsort(), is it sometimes better to choose more parallelism than CPUs &quot;just in case&quot; some of the problem sub-parts are much faster than the others?</description>
		<content:encoded><![CDATA[<p>I&#8217;m trying to understand the maxDepth setting, but it looks like setting maxDepth=Cpus will result in 2^Cpus threads, as opposed to CPUs threads?  Is this true?  </p>
<p>Given the potential lopsided-pivot problem of qsort(), is it sometimes better to choose more parallelism than CPUs &#8220;just in case&#8221; some of the problem sub-parts are much faster than the others?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reed</title>
		<link>http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-876</link>
		<dc:creator>Reed</dc:creator>
		<pubDate>Tue, 09 Mar 2010 20:06:20 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-876</guid>
		<description>Jesse:

The operating system will not change the affinity masks, ever.  These exist so that you can explicitly tell the OS (which is now free to ignore this anyways) which processors to use.  The only place where this would happen without your knowledge would be if a library set this, or if the user, as an administrator, overrides the affinity masks via the task manager or a similar tool (neither of which is likely).  Personally, I think this is overkill unless you are explicitly messing with the affinity masks (which I don&#039;t recommend doing...)</description>
		<content:encoded><![CDATA[<p>Jesse:</p>
<p>The operating system will not change the affinity masks, ever.  These exist so that you can explicitly tell the OS (which is now free to ignore this anyways) which processors to use.  The only place where this would happen without your knowledge would be if a library set this, or if the user, as an administrator, overrides the affinity masks via the task manager or a similar tool (neither of which is likely).  Personally, I think this is overkill unless you are explicitly messing with the affinity masks (which I don&#8217;t recommend doing&#8230;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse C. Slicer</title>
		<link>http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-875</link>
		<dc:creator>Jesse C. Slicer</dc:creator>
		<pubDate>Tue, 09 Mar 2010 19:21:23 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-875</guid>
		<description>To be sure *I* wouldn&#039;t be changing my program&#039;s affinity masks, but there&#039;s no guarantees that the .NET runtime (or even operating system) won&#039;t do that to the running program if it feels the need to.</description>
		<content:encoded><![CDATA[<p>To be sure *I* wouldn&#8217;t be changing my program&#8217;s affinity masks, but there&#8217;s no guarantees that the .NET runtime (or even operating system) won&#8217;t do that to the running program if it feels the need to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reed</title>
		<link>http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-865</link>
		<dc:creator>Reed</dc:creator>
		<pubDate>Mon, 08 Mar 2010 19:24:40 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-865</guid>
		<description>Jesse:

This will be the same as Environment.ProcessorCount, provided you didn&#039;t explicitly change your processor affinity masks for your application.  That being said, in general, I usually recommend leaving processor affinity alone, especially on modern operating systems (Vista &amp; esp. W7).  

The Windows process scheduler does a very good job of handling this...</description>
		<content:encoded><![CDATA[<p>Jesse:</p>
<p>This will be the same as Environment.ProcessorCount, provided you didn&#8217;t explicitly change your processor affinity masks for your application.  That being said, in general, I usually recommend leaving processor affinity alone, especially on modern operating systems (Vista &#038; esp. W7).  </p>
<p>The Windows process scheduler does a very good job of handling this&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse C. Slicer</title>
		<link>http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-863</link>
		<dc:creator>Jesse C. Slicer</dc:creator>
		<pubDate>Mon, 08 Mar 2010 17:45:52 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-863</guid>
		<description>Reed,

While Environment.ProcessorCount does a good job at giving you the # of processors in the system, it will *not* give you the number of processors allocated to your process (which may change while the process is running!).  I use this little chunk of code to give me the true number of cores my process can use:

// 
// Copyright (c) 2008 All Rights Reserved
// 
// Jesse C. Slicer
// jslicer@spamcop.net
// 2008-08-05
// Part of the Aesop.Diagnostics.dll assembly.

namespace Aesop.Diagnostics
{
    #region Using Directives

    // System namespaces
    using System;
    using System.Diagnostics;

    #endregion

    #region Class Definition : ProcessInfo

    /// 
    /// Privides a single property which gets the number of processor threads
    /// available to the currently executing process.
    /// 
    internal static class ProcessInfo
    {
        #region Internal Static Properties

        /// 
        /// Gets the number of processors.
        /// 
        /// The number of processors.
        internal static uint NumberOfProcessorThreads
        {
            get
            {
                using (Process currentProcess = Process.GetCurrentProcess())
                {
                    uint result;

                    if (currentProcess == null)
                    {
                        result = (uint)Environment.ProcessorCount;
                    }
                    else
                    {
                        const uint BitsPerByte = 8;
                        uint loop = BitsPerByte * sizeof(uint);
                        uint processAffinityMask =
                           (uint)currentProcess.ProcessorAffinity;

                        result = 0;
                        while (loop != 0)
                        {
                            --loop;
                            result += processAffinityMask &amp; 1;
                            processAffinityMask &gt;&gt;= 1;
                        }
                    }

                    return (result == 0) ? 1 : result;
                }
            }
        }

        #endregion
    }

    #endregion
}</description>
		<content:encoded><![CDATA[<p>Reed,</p>
<p>While Environment.ProcessorCount does a good job at giving you the # of processors in the system, it will *not* give you the number of processors allocated to your process (which may change while the process is running!).  I use this little chunk of code to give me the true number of cores my process can use:</p>
<p>//<br />
// Copyright (c) 2008 All Rights Reserved<br />
//<br />
// Jesse C. Slicer<br />
// <a href="mailto:jslicer@spamcop.net">jslicer@spamcop.net</a><br />
// 2008-08-05<br />
// Part of the Aesop.Diagnostics.dll assembly.</p>
<p>namespace Aesop.Diagnostics<br />
{<br />
    #region Using Directives</p>
<p>    // System namespaces<br />
    using System;<br />
    using System.Diagnostics;</p>
<p>    #endregion</p>
<p>    #region Class Definition : ProcessInfo</p>
<p>    ///<br />
    /// Privides a single property which gets the number of processor threads<br />
    /// available to the currently executing process.<br />
    ///<br />
    internal static class ProcessInfo<br />
    {<br />
        #region Internal Static Properties</p>
<p>        ///<br />
        /// Gets the number of processors.<br />
        ///<br />
        /// The number of processors.<br />
        internal static uint NumberOfProcessorThreads<br />
        {<br />
            get<br />
            {<br />
                using (Process currentProcess = Process.GetCurrentProcess())<br />
                {<br />
                    uint result;</p>
<p>                    if (currentProcess == null)<br />
                    {<br />
                        result = (uint)Environment.ProcessorCount;<br />
                    }<br />
                    else<br />
                    {<br />
                        const uint BitsPerByte = 8;<br />
                        uint loop = BitsPerByte * sizeof(uint);<br />
                        uint processAffinityMask =<br />
                           (uint)currentProcess.ProcessorAffinity;</p>
<p>                        result = 0;<br />
                        while (loop != 0)<br />
                        {<br />
                            &#8211;loop;<br />
                            result += processAffinityMask &amp; 1;<br />
                            processAffinityMask &gt;&gt;= 1;<br />
                        }<br />
                    }</p>
<p>                    return (result == 0) ? 1 : result;<br />
                }<br />
            }<br />
        }</p>
<p>        #endregion<br />
    }</p>
<p>    #endregion<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Alexander</title>
		<link>http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-824</link>
		<dc:creator>James Alexander</dc:creator>
		<pubDate>Thu, 04 Mar 2010 15:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-824</guid>
		<description>Great article, very clear and to the point.</description>
		<content:encoded><![CDATA[<p>Great article, very clear and to the point.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Parallelism in .NET – Part 11, Divide and Conquer via Parallel … Get Pivot</title>
		<link>http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-773</link>
		<dc:creator>Parallelism in .NET – Part 11, Divide and Conquer via Parallel … Get Pivot</dc:creator>
		<pubDate>Sat, 27 Feb 2010 02:01:13 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/2010/02/26/parallelism-in-net-part-11-divide-and-conquer-via-parallel-invoke/#comment-773</guid>
		<description>[...] here: Parallelism in .NET – Part 11, Divide and Conquer via Parallel &#8230;          By pivot &#124; category: pivot, pivot point &#124; tags: around-the-pivot, each-side, elements, [...]
</description>
		<content:encoded><![CDATA[<p>[...] here: Parallelism in .NET – Part 11, Divide and Conquer via Parallel &#8230;          By pivot | category: pivot, pivot point | tags: around-the-pivot, each-side, elements, [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
 
