Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Threadpool with priority version 1.1 is here ...

aminer10
Novice
664 Views

Hello all,



Description:

Lock-free threadpool with priority.

The following have been added:

- You can give the following priorities to jobs:

LOW_PRIORITY
NORMAL_PRIORITY
HIGH_PRIORITY

-- Lockfree ParallelQueue for less contention and more efficiency or
it can use lockfree_mpmc - flqueue that i have modified, enhanced and
improved... -

- Work-stealing - for more efficiency -

- Enters in a wait state when there no job in the queue, hence, it's
very efficient

Look into define.inc there is many options:

CPU32: for 32 bits architecture
MUTIPLE_PRODUCER: mutiple producer (threads)
SINGLE_PRODUCER: for a single producer (thread)

Required switches: -Sd (Delphi mode) for FPC

Please look at the examples test.pas and testpool.pas inside the
zip...

Note: testpool.pas does require Delphi 5+, test.pas works with both
FreePascal and Delphi

You can download Threadpool with priority version 1.1 from:

http://pages.videotron.com/aminer/

Language: FPC Pascal v2.2.0+ / Delphi 5+: http://www.freepascal.org/

Operating Systems: Win , Linux and Mac (x86).

Threadpool is *VERY* easy to use, here is an example:

-----------------------------------------------------------------------------------

program test;

uses
{$IFDEF Delphi}
cmem,
{$ENDIF}
PThreadPool,sysutils,syncobjs;

{$I defines.inc}

type
TMyThread = class (TPThreadPoolThread)
//procedure ProcessRequest(obj: Pointer); override;

procedure MyProc1(obj: Pointer);
procedure MyProc2(obj: Pointer);

end;

var
myobj:TMyThread;
TP: TPThreadPool;
obj:pointer;
cs:TCriticalSection;

procedure TMyThread.MyProc1(obj: Pointer);
begin

cs.enter;
writeln('This is MyProc1 with parameter: ',integer(obj));
cs.leave;

end;

procedure TMyThread.MyProc2(obj: Pointer);
begin

cs.enter;
writeln('This is MyProc2 with parameter: ',integer(obj));
cs.leave;

end;

begin

myobj:=TMyThread.create;

cs:=TCriticalSection.create;

TP := TPThreadPool.Create(4, 20, TMyThread); // 4 workers threads and
2^20 items for each queue.

obj:=pointer(1);
TP.execute(myobj.myproc1,pointer(obj),NORMAL_PRIORITY);

obj:=pointer(2);
TP.execute(myobj.myproc2,pointer(obj),NORMAL_PRIORITY);

readln;

TP.Terminate;
TP.Free;

end.

----------------------------------------------------------------------------


Sincerely,
Amine Moulay Ramdane.


0 Kudos
1 Reply
aminer10
Novice
664 Views


Hello,


II have forgot to tell you that i have added also the
following:

You can now call any method with the execute() method, like this


execute(your method, parameter , priority);


In Object Pascal it looks like this:

TP.execute(myobj.myproc1,pointer(obj),NORMAL_PRIORITY);

(look inside the zipfile i have included two demos:
test.pas, and ptestpool.pas - a Parallel program of Matrix
multiply by a vector that use SSE+ -

Also, as i have promised, the workers threads now
enters in a wait state when there is no jobs in the queues ,
- now it doesn't consume the CPU when there is no jobs in the queues -
hence, it's very efficient


And, as i have promised and as you have noticed, my threadpool
now use my lockfree ParallelQueue:
at http://pages.videotron.com/aminer/parallelqueue/parallelqueue.htm

for less contention and more efficiency...

etc.

Sincerely
Amine Moulay Ramdane.

0 Kudos
Reply