Re: [Lazarus] Is there any alternative to PPL (Parallel Programming Library) on FPC?

2016-02-26 Thread silvioprog
On Thu, Feb 25, 2016 at 9:55 PM, Kostas Michalopoulos <
badsectorac...@gmail.com> wrote:

> 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
>

Awesome!

I didn't know that this package existed. I'll test it tonight.

Thanks a lot for share this link! :-)

-- 
Silvio Clécio
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Is there any alternative to PPL (Parallel Programming Library) on FPC?

2016-02-25 Thread Kostas Michalopoulos
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  wrote:

> Hello,
>
> Just a quote from Embarcadero doc
> 
> :
>
> 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
> )
> 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@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Is there any alternative to PPL (Parallel Programming Library) on FPC?

2016-02-25 Thread silvioprog
Hello,

Just a quote from Embarcadero doc

:

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
)
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@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus