title: Nested Parallel performance question
body: <p>I have question.</p>
  
  <p>Are there any benefits of using Parallel.Invoke inside of another Parallel.ForEach?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    Parallel.ForEach(yearMonths,
                       () =&gt; new List&lt;DJVSStatsCo&gt;(),
                       (yearMonth, loopState, localDjvsStatsCo) =&gt;
                           {
                               var coVintageCounter = 0;
                               var coExitsCounter = 0;
                               var coExtant = 0;
  
                               Parallel.Invoke(() =&gt;
                                               coVintageCounter = globalData.ValuationEventsPit.
                                                                      Where(x =&gt; x.FirstRoundYearMonth &lt;= yearMonth).
                                                                      Select(x =&gt; x.CompanyId).Distinct().Count(),
                                               () =&gt;
                                               coExitsCounter = globalData.ValuationEventsPit.
                                                                    Where(x =&gt; x.ExitDate != null &amp;&amp; x.ExitDateYearMonth == yearMonth).
                                                                    Select(x =&gt; x.CompanyId).Distinct().Count(),
                                               () =&gt;
                                               coExtant = globalData.ValuationEventsPit.
                                                              Where(x =&gt; x.FirstRoundYearMonth &lt;= yearMonth &amp;&amp; (x.ExitDate == null || x.ExitDateYearMonth &gt; yearMonth)).
                                                              Select(x =&gt; x.CompanyId).Distinct().Count()
                                   );
  
                               localDjvsStatsCo.Add(new DJVSStatsCo(yearMonth, coVintageCounter, coExtant, coExitsCounter));
  
                               return localDjvsStatsCo;
                           },
                       x =&gt;
                           {
                               lock (locker)
                               {
                                   djvsStatsCos.AddRange(x);
                               }
                           });
  </code></pre>
  
  <p>I have about 50K records and my machine has 2 core processors and calculating calc time I am getting almost the same result.  So my question is are there any benefits of using Parallel inside of Parallel?  What is the best practice for this?</p>
  
  <p>Thanks a lot.</p>
  
  <p>Sincerely,
  Vlad.</p>