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
Show quoted text 6 lines
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!
