[Lazarus] Is there any alternative to PPL (Parallel Programming Library) on FPC?
Kostas Michalopoulos
badsectoracula at gmail.com
Fri Feb 26 01:55:13 CET 2016
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:
http://wiki.freepascal.org/Parallel_procedures
On Thu, Feb 25, 2016 at 5:38 PM, silvioprog <silvioprog at gmail.com> wrote:
> Hello,
>
> Just a quote from Embarcadero doc
> <http://docwiki.embarcadero.com/RADStudio/XE8/en/Using_the_Parallel_Programming_Library>
> :
>
> 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.
>
>
> To check it, we can take a small example (full source here
> <http://docwiki.embarcadero.com/RADStudio/XE8/en/Tutorial:_Using_the_For_Loop_from_the_Parallel_Programming_Library>)
> that looks for prime numbers using a classic for loop:
>
> var
> I, Tot: Integer;
> SW: TStopwatch;
> begin
> Tot := 0;
> SW := TStopwatch.Create;
> SW.Start;
> for I := 1 to Max do
> if IsPrime(I) then
> Inc(Tot);
> SW.Stop;
> WriteLn
> (Format('Sequential For loop. Time (in milliseconds): %d - Primes
> found: %d',
> [SW.ElapsedMilliseconds, Tot]));
> end;
>
> The result:
>
> Sequential For loop. Time (in milliseconds): 764 - Primes found: 348513
>
> Now, a similar example however using PPL:
>
> var
> Tot: Integer;
> SW: TStopwatch;
> begin
> try
> Tot := 0;
> SW := TStopwatch.Create;
> SW.Start;
> TParallel.For(2, 1, Max,
> procedure(I: Int64)
> begin
> if IsPrime(I) then
> TInterlocked.Increment(Tot);
> end);
> SW.Stop;
> WriteLn
> (Format('Parallel For loop. Time (in milliseconds): %d - Primes
> found: %d',
> [SW.ElapsedMilliseconds, Tot]));
> except
> on E: EAggregateException do
> ShowMessage(E.ToString);
> end;
> end;
>
> Result:
>
> Parallel For loop. Time (in milliseconds): 315 - Primes found: 348513
>
> Awesome, I got a nice performance using PPL and it seems a nice feature,
> but where can I get anything like this for FPC?
>
> Thank you!
>
> --
> Silvio Clécio
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160226/bf40a327/attachment-0003.html>
More information about the Lazarus
mailing list