<div dir="ltr">Check the MTProcs unit in the multithreadprocs package (part of Lazarus, but you need to manually install it from the Install/Uninstall Packages box). This wiki page describes how to use it:<br><br><a href="http://wiki.freepascal.org/Parallel_procedures">http://wiki.freepascal.org/Parallel_procedures</a><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 25, 2016 at 5:38 PM, silvioprog <span dir="ltr"><<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>Just a quote from <a href="http://docwiki.embarcadero.com/RADStudio/XE8/en/Using_the_Parallel_Programming_Library" target="_blank">Embarcadero doc</a>:<br clear="all"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">The RTL provides the Parallel Programming Library (PPL), giving your applications the ability to have tasks running in parallel taking advantage of working across multiple CPU devices and computers. The PPL includes a number of advanced features for running tasks, joining tasks, waiting on groups of tasks, etc. to process. For all this, there is a thread pool that self tunes itself automatically (based on the load on the CPU’s) so you do not have to care about creating or managing threads for this purpose.</blockquote><div><br></div><div>To check it, we can take a small example (<a href="http://docwiki.embarcadero.com/RADStudio/XE8/en/Tutorial:_Using_the_For_Loop_from_the_Parallel_Programming_Library" target="_blank">full source here</a>) that looks for prime numbers using a classic for loop:</div><div><br></div><div><div><font face="monospace, monospace">var<br></font></div><div><font face="monospace, monospace"> I, Tot: Integer;</font></div><div><font face="monospace, monospace"> SW: TStopwatch;</font></div><div><font face="monospace, monospace">begin</font></div><div><font face="monospace, monospace"> Tot := 0;</font></div><div><font face="monospace, monospace"> SW := TStopwatch.Create;</font></div><div><font face="monospace, monospace"> SW.Start;</font></div><div><font face="monospace, monospace"> for I := 1 to Max do</font></div><div><font face="monospace, monospace"> if IsPrime(I) then</font></div><div><font face="monospace, monospace"> Inc(Tot);</font></div><div><font face="monospace, monospace"> SW.Stop;</font></div><div><font face="monospace, monospace"> WriteLn</font></div><div><font face="monospace, monospace"> (Format('Sequential For loop. Time (in milliseconds): %d - Primes found: %d',</font></div><div><font face="monospace, monospace"> [SW.ElapsedMilliseconds, Tot]));</font></div><div><font face="monospace, monospace">end;</font></div></div><div><br></div><div>The result:</div><div><br></div><div><font face="monospace, monospace">Sequential For loop. Time (in milliseconds): 764 - Primes found: 348513</font><br></div><div><br></div><div>Now, a similar example however using PPL:</div><div><br></div><div><div><font face="monospace, monospace">var</font></div><div><font face="monospace, monospace"> Tot: Integer;</font></div><div><font face="monospace, monospace"> SW: TStopwatch;</font></div><div><font face="monospace, monospace">begin</font></div><div><font face="monospace, monospace"> try</font></div><div><font face="monospace, monospace"> Tot := 0;</font></div><div><font face="monospace, monospace"> SW := TStopwatch.Create;</font></div><div><font face="monospace, monospace"> SW.Start;</font></div><div><font face="monospace, monospace"> TParallel.For(2, 1, Max,</font></div><div><font face="monospace, monospace"> procedure(I: Int64)</font></div><div><font face="monospace, monospace"> begin</font></div><div><font face="monospace, monospace"> if IsPrime(I) then</font></div><div><font face="monospace, monospace"> TInterlocked.Increment(Tot);</font></div><div><font face="monospace, monospace"> end);</font></div><div><font face="monospace, monospace"> SW.Stop;</font></div><div><font face="monospace, monospace"> </font><span style="font-family:monospace,monospace">WriteLn</span></div><div><font face="monospace, monospace"> (Format('Parallel For loop. Time (in milliseconds): %d - Primes found: %d',</font></div><div><font face="monospace, monospace"> [SW.ElapsedMilliseconds, Tot]));</font></div><div><font face="monospace, monospace"> except</font></div><div><font face="monospace, monospace"> on E: EAggregateException do</font></div><div><font face="monospace, monospace"> ShowMessage(E.ToString);</font></div><div><font face="monospace, monospace"> end;</font></div><div><font face="monospace, monospace">end;</font></div></div><div><br></div><div>Result:</div><div><br></div><div><font face="monospace, monospace">Parallel For loop. Time (in milliseconds): 315 - Primes found: 348513</font><br></div><div><br></div><div>Awesome, I got a nice performance using PPL and it seems a nice feature, but where can I get anything like this for FPC?</div><div><br></div><div>Thank you!</div><div><br></div>--<br><div><div dir="ltr"><div>Silvio Clécio</div></div></div>
</div></div>
<br>--<br>
_______________________________________________<br>
Lazarus mailing list<br>
<a href="mailto:Lazarus@lists.lazarus.freepascal.org">Lazarus@lists.lazarus.freepascal.org</a><br>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus" rel="noreferrer" target="_blank">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a><br>
<br></blockquote></div><br></div>