Hi all,
I'm quite new to fpc, but having already a lot of fun
Currently I am working on a data processing tool. The required algos are really simple to spread to several threads as nothing depends on each other, but each calculation portion is time consuming.
I got the MTProcs package (
http://wiki.freepascal.org/Parallel_procedures) running, which does a perfect job.
Especially the "experimental" feature to parallelize nested procedures is really helpfull
Currently I am using "DoParallelLocalProc" in the following form:
procedure main();
procedure DoSomethingParallel(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem);
var
i: Integer;
begin
writeln(Index);
for i:=1 to Index*1000000000 do ; // do some work
writeln('done')
end;
begin
ProcThreadPool.DoParallelLocalProc(@DoSomethingParallel,1,5,nil); // address, startindex, endindex, optional data
end;
begin
main();
readln;
end.}
However the wiki page warns: "Beware that calling nested procedures is not yet supported by the compiler and therefore one has to use unsafe type casts."
I am wondering: This info is not up to date anymore: nested proc vars are available and will help to overcome this unsafe call!
To test this proposal i set this type def in MTProcs.pas as is nested:
TMTProcedure = procedure(Index: PtrInt; Data: Pointer;
Item: TMultiThreadProcItem) is nested;
Now the user can use "DoParallel" for both local procedures and normal procedures, without unsafe calls!
program partest;
{$mode objfpc}{$H+}
{$modeswitch nestedprocvars}
uses
{$IFDEF UNIX}
cthreads, cmem,
{$ENDIF}
MTProcs;
// a simple parallel procedure
procedure main();
procedure DoSomethingParallel(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem);
var
i: Integer;
begin
writeln(Index);
for i:=1 to Index*1000000000 do ; // do some work
writeln('done')
end;
begin
ProcThreadPool.DoParallel(@DoSomethingParallel,1,5,nil); // address, startindex, endindex, optional data
end;
begin
main();
readln;
end.
The original wiki testprog is working as well without change.
What do you (more experienced users) say, can this be integrated to the official MTProcs package?
Thanks for reading