Steve Williams wrote:
Florian Klaempfl wrote:

I'am currently thinking about implementing OpenMP support in FPC.
However, there is currently (to my knowledge) no pascal syntax defined
for OpenMp support. Do you think we can find a common syntax to simplify
things for users? I've some ideas how it be done, but I want to hear
other ideas first so they are maybe better if they aren't influenced by
my ideas :)

I started also a wiki page about it
http://www.freepascal.org/wiki/index.php/OpenMP_support where ideas can
be written down and shared.



I would suggest something along the lines of the C/C++ implementation, but using the Pascal form of compiler directives.

Using some of the documented examples in the v2.5 spec:

Example A.1.1:
procedure a1(n: Integer; a: PSingleArray; b: PSingleArray);
var
 i: Integer;
begin
 {$omp parallel for}
 for i := 1 to n - 1 do
   b^[i] := (a^[i] + a^[i - 1]) / 2.0;
end;

Brrr.... using local defines look not native to the language.
Why not something like as (refered in another thread) pascal-fc which uses cobegin..coend or known blocks like asm..end; try..end;

for instance:
 omp..end;
 parralel..end;


so:

procedure a1(n: Integer; a: PSingleArray; b: PSingleArray);
var
 i: Integer;
begin
 for i := 1 to n - 1 do
 parallel
   b^[i] := (a^[i] + a^[i - 1]) / 2.0;
 end;
end;



Example A.5.1:
uses omp;

begin
 omp_set_dynamic(1);
 {$omp parallel num_threads(10)}
 begin
   (* Do work here *)
 end;
end;


 uses omp;

 begin
  omp_set_dynamic(1);
//  {$omp parallel num_threads(10)}
// why not:
  omp_set_num_threads(10);
  parallel
    (* Do work here *)
  end;
 end;



Example A.13.1:
interface

function dequeue(var a: Single): Integer;
procedure work(i: Integer; var a: Single);

implementation

procedure a13(var x: Single; var y: Single);
var
 ix_next, iy_next: Integer;
begin
 {$omp parallel shared(x, y) private(ix_next, iy_next)}
 begin
   {$omp critical (xaxis)}
     ix_next := dequeue(x);
   work(ix_next, x);

   {$omp critical (yaxis)}
     iy_next := dequeue(y);
   work(iy_next, y);
 end;
end;



 procedure a13(var ax: Single; var ay: Single);
 begin
  parallel
  shared
    x: Single; absolute ax;
    y: Single; absolute ay;
  private
    ix_next, iy_next: Integer;
  begin
    // where does xaxis come from ?
    // {$omp critical (xaxis)}
    ix_next := dequeue(x);
    work(ix_next, x);

    // where does yaxis come from ?
    // {$omp critical (yaxis)}
    iy_next := dequeue(y);
    work(iy_next, y);
  end;
 end;


or:


 procedure a13(var ax: Single; shared var y: Single);
 shared var
   x: Single; absolute ax;
// y: Single; absolute ay;
 private var
   ix_next, iy_next: Integer;
 begin
  parallel
    // where does xaxis come from ?
    // {$omp critical (xaxis)}
    ix_next := dequeue(x);
    work(ix_next, x);

    // where does yaxis come from ?
    // {$omp critical (yaxis)}
    iy_next := dequeue(y);
    work(iy_next, y);
  end;
 end;


Marc
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to