Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-07

Common OpenMP syntax?

50 messages · 15 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Florian Klaempfl

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.

Mattias Gaertner
to Florian Klaempfl
I'am currently thinking about implementing OpenMP support in FPC.

There seems to be something in the air.
I had the same idea two weeks ago. Well, to be honest, I had the idea as I heard of OpenMP 3 years ago, but now I want to finally do it. I want to first write a tutorial for MPICH for FPC and then take a closer look on OpenMP, to get used to it and find out it advantages and disadvantages. We don't need to make the same errors as the C and Fortran compilers.

However, there is currently (to my knowledge) no pascal syntax defined for OpenMp support.

Right. AFAIK OpenMP is only a standard for C/C++ and Fortran. It's not an implementation.

Show quoted text 8 lines
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.

As soon as I done some more OpenMP experiments and made up my mind, I will join. :)

Mattias

Alexandre Leclerc
to Mattias Gaertner

2006/7/17, Mattias Gaertner :

Show quoted text 7 lines
On Mon, 17 Jul 2006 21:12:31 +0200 Florian Klaempfl wrote: > However, there is currently (to my knowledge) no pascal syntax defined > for OpenMp support. Right. AFAIK OpenMP is only a standard for C/C++ and Fortran. It's not an implementation.

If ever it needed an implementation (which I'm glad to hear it is not), maybe a section should be used like with asm (assembler) code. At first glance (2 minutes) I was not able to grasp the big thing about that; are we not yet able to do multi-threaded programming in FPC?

Alexandre Leclerc
Mattias Gaertner
to Alexandre Leclerc
Alexandre Leclerc wrote 14 lines
2006/7/17, Mattias Gaertner : > On Mon, 17 Jul 2006 21:12:31 +0200 > Florian Klaempfl wrote: > > However, there is currently (to my knowledge) no pascal syntax defined > > for OpenMp support. > > Right. AFAIK OpenMP is only a standard for C/C++ and Fortran. It's not an > implementation. If ever it needed an implementation (which I'm glad to hear it is not), maybe a section should be used like with asm (assembler) code. At first glance (2 minutes) I was not able to grasp the big thing about that; are we not yet able to do multi-threaded programming in FPC?

Yes, we are.
But creating and synchronizing threads needs often a lot of overhead, measured in lines of code and in performance.
OpenMP is a specification, how to parallize code blocks easily and give the compiler enough hints to optimize the code.
It is up to compiler developers to support it and provide an implementation. Probably we can not name ours "OpenMP".

Mattias

Marc Weustink
to Mattias Gaertner: On Mon, 17 Jul 2006 21:12:31 +0200 There seems to be something in the air. I had the same…
Florian Klaempfl wrote
I'am currently thinking about implementing OpenMP support in FPC.

Is this similar as polyphinic C# ? (you gave me a link a while ago)

What I'm puzzeled with, usually an API specifies the interface to an external library, where here it seems a spec how a language should "behave" when implementing Multi Processing (and in this case for C++ and Fortran).

Is the idea to implement a similar, based on the ideas of openMP, version for FPC?

Marc

Prof A Olowofoyeku (The African Chief
to Florian Klaempfl: I'am currently thinking about implementing OpenMP support in FPC. However, there is…
Florian Klaempfl wrote 6 lines
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 :)

The only suggestion that I have may be not very useful and may be very obvious - but here goes anyway. Please make the interface as simple (read "high level") as possible, providing high level wrappers for low level routines if necessary. In many cases, writing Pascal interfaces to C libraries often produces something that is no easier to use than the original C interface, and for which one might as well use gcc.

Best regards, The Chief
--------
Prof. Abimbola A. Olowofoyeku (The African Chief)
web: http://www.greatchief.plus.com/

Steve Williams
to Florian Klaempfl: I'am currently thinking about implementing OpenMP support in FPC. However, there is…
Florian Klaempfl wrote 11 lines
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;
Example A.5.1:
uses omp;
begin
  omp_set_dynamic(1);
  {$omp parallel num_threads(10)}
  begin
    (* 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;
Sly This message and its attachments may contain legally privileged or confidential information. This message is intended for the use of the individual or entity to which it is addressed. If you are not the addressee indicated in this message, or the employee or agent responsible for delivering the message to the intended recipient, you may not copy or deliver this message or its attachments to anyone. Rather, you should permanently delete this message and its attachments and kindly notify the sender by reply e-mail. Any content of this message and its attachments, which does not relate to the official business of the sending company must be taken not to have been sent or endorsed by the sending company or any of its related entities. No warranty is made that the e-mail or attachment(s) are free from computer virus or other defect.
Alexandre Leclerc
to Steve Williams

2006/7/20, Steve Williams :

Show quoted text 28 lines
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;

I fear this just looks like a terrible stranger-outsider pach to a superbe language. :) If fpc peoples want to implement new language syntax... may it be pascal-like and good looking. At least in the previous example, a closing block would be required... as for myself:

{$omp parallel for}
...
[$omp end}

The same for the other examples. So if the directive is not understood by the compiler, it becomes standard code without any problems. For me, the best approach would be an unit to be used; not language implementation. (In that unit you could have ugly compiler magic if you want, but at least, when using this technology, it would be much more like using a standard class or set of procedures.)

Any-way; Reagards.

Alexandre Leclerc
Vinzent Höfler
to Marco van de Voort
Marco van de Voort wrote
Isn't there a copascal that already has established concurent pascal syntax?

Yes, there is, but its syntax is very limited AFAICS.

if not, the other wirthian languages look like logical providers?

Ada tasking? Well, too much overkill, I think. ;)

My problem with the OpenMP stuff is that it's more C-centric than concurrency-centric: Basically they give a compiler "hint"s that some sequential statement could be executed concurrently.

A concurrent language goes a different way, there you would simply instantiate the assignment multiple times whether its like "cobegin" in ConcurrentPascal, "PAR" in Occam2, or "task" types in Ada.

So at first the question should be answered if OpenMP in FreePascal should be implemented on language (means: special syntax) level or with compiler directives more similar to the C-version.

Vinzent.

John Coppens
to Florian Klaempfl: I'am currently thinking about implementing OpenMP support in FPC. However, there is…
I'am currently thinking about implementing OpenMP support in FPC.

Florian,

Have you looked at Pascal-FC (a language developped based Pascal/0, I believe, by Alan Burns)? I've used it to teach multiprogramming, and it incorporates many of the items which are available in several other MP languages (such as ADA). It's probably too basic, but there may be some useful ideas.

Is _is_ very clean though. No {$xxx's etc...

John

Vinzent Höfler
to John Coppens
John Coppens wrote 9 lines
On Mon, 17 Jul 2006 21:12:31 +0200 Florian Klaempfl wrote: > I'am currently thinking about implementing OpenMP support in FPC. Florian, Have you looked at Pascal-FC (a language developped based Pascal/0, I believe, by Alan Burns)?

Alan Burns? That's a name which rings a bell. You could have send the URL, though. ;)

http://www-users.cs.york.ac.uk/~burns/pf.html

Hmm, and taking a peek look at the examples, it doesn't really surprise me, that this just looks like the Pascal version of Ada's tasking.

Regards,

Vinzent.

Marc Weustink
to Steve Williams: I would suggest something along the lines of the C/C++ implementation, but using the…
Steve Williams wrote 30 lines
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;
Show quoted text 10 lines
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;
Show quoted text 25 lines
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

Vinzent Höfler
to Marc Weustink
Marc Weustink wrote 15 lines
Steve Williams wrote: > > 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.

"Not native". Well, I would have prefered the term "darn ugly". :)

Show quoted text 9 lines
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;

Yes, this idea looks *much* nicer. And much more Pascalish.

Vinzent.

Steve Williams
to Marc Weustink: Brrr.... using local defines look not native to the language. Why not something like as…
Marc Weustink wrote 26 lines
Steve Williams wrote: > 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;

One of the pretexts behind OpenMP is that the code will still compile if OpenMP is not available or disabled on a particular compiler. That's the reason behind using compiler directives instead of new keywords. Using compiler directives similar to the C/C++ directives also means that the wealth of information already out there is instantly applicable to the Pascal version.

Sly This message and its attachments may contain legally privileged or confidential information. This message is intended for the use of the individual or entity to which it is addressed. If you are not the addressee indicated in this message, or the employee or agent responsible for delivering the message to the intended recipient, you may not copy or deliver this message or its attachments to anyone. Rather, you should permanently delete this message and its attachments and kindly notify the sender by reply e-mail. Any content of this message and its attachments, which does not relate to the official business of the sending company must be taken not to have been sent or endorsed by the sending company or any of its related entities. No warranty is made that the e-mail or attachment(s) are free from computer virus or other defect.
John Coppens
to Vinzent Höfler: Alan Burns? That's a name which rings a bell. You could have send the URL, though. ;)…
Show quoted text 7 lines
Alan Burns? That's a name which rings a bell. You could have send the URL, though. ;) http://www-users.cs.york.ac.uk/~burns/pf.html Hmm, and taking a peek look at the examples, it doesn't really surprise me, that this just looks like the Pascal version of Ada's tasking.

Hi Vinzent.

Yes - quite famous.

But apart from the ADA style resources, it also implement a number of other tools, such as channels/remote invocation, etc. The cobegin/coend pair to specify concurrency is elegant, though maybe somewhat 'flat'.

John

Marc Weustink
to Steve Williams: One of the pretexts behind OpenMP is that the code will still compile if OpenMP is not…
Steve Williams wrote 34 lines
Marc Weustink wrote: > Steve Williams wrote: > > >> 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; > One of the pretexts behind OpenMP is that the code will still compile if OpenMP is not available or disabled on a particular compiler.

Mwah... in that case you can still use the same keywords, only it won't be much parallel, since it's executed in one thread. And beeing executed in one or more threads should not matter in parallel blocks.

Marc

That's the reason behind using compiler directives instead of new keywords. Using compiler directives similar to the C/C++ directives also means

eehh... to repeat what someone else already mentioned in this thread, if I want to use C, I don't use pascal.

Marc.

that the wealth of information already out there is instantly applicable to the Pascal version.
Steve Williams
to Marc Weustink
Marc Weustink wrote 9 lines
> One of the pretexts behind OpenMP is that the code will still compile if > OpenMP is not available or disabled on a particular compiler. > Mwah... in that case you can still use the same keywords, only it won't be much parallel, since it's executed in one thread. And beeing executed in one or more threads should not matter in parallel blocks.

But then your code is locked to that version of FPC that supports those new keywords.

Sly This message and its attachments may contain legally privileged or confidential information. This message is intended for the use of the individual or entity to which it is addressed. If you are not the addressee indicated in this message, or the employee or agent responsible for delivering the message to the intended recipient, you may not copy or deliver this message or its attachments to anyone. Rather, you should permanently delete this message and its attachments and kindly notify the sender by reply e-mail. Any content of this message and its attachments, which does not relate to the official business of the sending company must be taken not to have been sent or endorsed by the sending company or any of its related entities. No warranty is made that the e-mail or attachment(s) are free from computer virus or other defect.
Mattias Gaertner
to Steve Williams
Marc Weustink wrote: >> One of the pretexts behind OpenMP is that the code will still compile

if

Show quoted text 12 lines
>> OpenMP is not available or disabled on a particular compiler. >> > > Mwah... in that case you can still use the same keywords, only it won't > be much parallel, since it's executed in one thread. > And beeing executed in one or more threads should not matter in parallel > blocks. > But then your code is locked to that version of FPC that supports those new keywords.

Other compilers will give you warnings about illegal compiler directives. Therefore if your code should work with multiple compilers, you will probably enclose the omp additions with IFDEFs anyway.

{$IFDEF HasOMP}cobegin{$ENDIF}

OpenMP uses pragmas, because
- They didn't want to break ANSI C. FPC has its own mode and compatibility modes for others.
- It takes time before all the C compilers support the OMP additions. For example default gcc does not yet.
Do we plan a syntax for FPC or for pascal in general?
- C programmers are more used to macros and pragmas, than pascal programmers to compiler directives.
IMO Directives are ugly.
- C programmers are more used to hints and notes, than pascal programmers. Although recent fpc additions changed that (hints about unused/uninitialised variables).
IMO Noisy notes make it harder to find the relevant compiler messages.

Mattias

Marco van de Voort
to Mattias Gaertner
> new keywords. Other compilers will give you warnings about illegal compiler directives.

Bad assumption, the only one that matters, Delphi errors on unknown compiler directives. So you will have to ifdef anyway. (tested D6)

And then I prefer the clean syntax.

Vinzent Höfler
to John Coppens: On Thu, 20 Jul 2006 21:11:49 +0200 Hi Vinzent. Yes - quite famous. But apart from the ADA…
John Coppens wrote 17 lines
On Thu, 20 Jul 2006 21:11:49 +0200 Vinzent Höfler wrote: > Alan Burns? That's a name which rings a bell. You could have send the > URL, though. ;) > > http://www-users.cs.york.ac.uk/~burns/pf.html > > Hmm, and taking a peek look at the examples, it doesn't really surprise > me, that this just looks like the Pascal version of Ada's tasking. Hi Vinzent. Yes - quite famous. But apart from the ADA style resources, it also implement a number of other tools, such as channels/remote invocation, etc.

Yes, he borrowed from quite some concurrent languages (the semaphore could be Modula, and the channels maybe occam, I'm not sure). It still looks very much like Ada to me, especially the remote invocation just looks like Ada's rendezvous. Well, he calls it process, not task - just like in VHDL - but apart from that it looks very similar.

The cobegin/coend pair to specify concurrency is elegant, though maybe somewhat 'flat'.

What do you mean by 'flat'? That it can't be nested? If I read the OpenMP specs correctly, they say there, that they don't expect vendors to implement nested stuff real soon anyway. :)

Yet, I don't see a compelling reason - apart from the question how to implement it - why a nice new syntax couldn't nest "cobegin"s just like we already do with "begin"s:

cobegin
    Do_This;
    Do_That;
    cobegin
      Do_More;
      Do_Much_More;
    coend;
coend;

Not sure of that would work. ;)

Well, I guess, I have to read the specs more thoroughly, perhaps I come up with an idea, how all this stuff can be mapped nicely to this ugly C hack. They even state, that they are so much more special an better compared with all the existing concurrent languages, that I'd like to prove them otherwise. ;)

Vinzent.

Vinzent Höfler
to Marco van de Voort: Bad assumption, the only one that matters, Delphi errors on unknown compiler directives.…
Marco van de Voort wrote 5 lines
>> new keywords. > Other compilers will give you warnings about illegal compiler directives. Bad assumption, the only one that matters, Delphi errors on unknown compiler directives. So you will have to ifdef anyway. (tested D6)
Does Delphi support FPC style macros? In that case, perhaps as sort of
include file to map "cobegin" or whatever to normal ones ...
And then I prefer the clean syntax.

Yes, absolutely.

Vinzent.

Marco van de Voort
to Vinzent Höfler
Show quoted text 9 lines
Marco van de Voort wrote: >>> new keywords. >> Other compilers will give you warnings about illegal compiler directives. > > Bad assumption, the only one that matters, Delphi errors on unknown compiler directives. So > you will have to ifdef anyway. (tested D6) Does Delphi support FPC style macros? In that case, perhaps as sort of include file to map "cobegin" or whatever to normal ones ...

No. There is not much that can be done about this. Except postprocessing FPC source and stripping out paralel syntax. Be it directives or keywords.

Vinzent Höfler
to Marco van de Voort
Marco van de Voort wrote 10 lines
> Marco van de Voort wrote: >>>> new keywords. >>> Other compilers will give you warnings about illegal compiler directives. >> Bad assumption, the only one that matters, Delphi errors on unknown compiler directives. So >> you will have to ifdef anyway. (tested D6) > Does Delphi support FPC style macros? In that case, perhaps as sort of > include file to map "cobegin" or whatever to normal ones ... No. There is not much that can be done about this. Except postprocessing FPC source and stripping out paralel syntax. Be it directives or keywords.

In that case directives don't make any sense like they'd do in a C-version.

So it'll have to be syntax. :)

Vinzent.

Steve Williams
to Vinzent Höfler
Vinzent Höfler wrote 22 lines
Marco van de Voort wrote: >> Marco van de Voort wrote: >> >>>>> new keywords. >>>>> >>>> Other compilers will give you warnings about illegal compiler directives. >>>> >>> Bad assumption, the only one that matters, Delphi errors on unknown compiler directives. So >>> you will have to ifdef anyway. (tested D6) >>> >> Does Delphi support FPC style macros? In that case, perhaps as sort of >> include file to map "cobegin" or whatever to normal ones ... >> > No. There is not much that can be done about this. Except postprocessing FPC > source and stripping out paralel syntax. Be it directives or keywords. > In that case directives don't make any sense like they'd do in a C-version. So it'll have to be syntax. :)

Ok. Beaten. :)

But at least it provoked discussion on it.

Sly This message and its attachments may contain legally privileged or confidential information. This message is intended for the use of the individual or entity to which it is addressed. If you are not the addressee indicated in this message, or the employee or agent responsible for delivering the message to the intended recipient, you may not copy or deliver this message or its attachments to anyone. Rather, you should permanently delete this message and its attachments and kindly notify the sender by reply e-mail. Any content of this message and its attachments, which does not relate to the official business of the sending company must be taken not to have been sent or endorsed by the sending company or any of its related entities. No warranty is made that the e-mail or attachment(s) are free from computer virus or other defect.
Jonas Maebe
to Marco van de Voort: Bad assumption, the only one that matters, Delphi errors on unknown compiler directives.…
Marco van de Voort wrote 6 lines
> Other compilers will give you warnings about illegal compiler > directives. Bad assumption, the only one that matters, Delphi errors on unknown compiler directives. So you will have to ifdef anyway. (tested D6)

I think at least in this case GPC also matters, since Florian is also soliciting feedback on the syntax on the GPC list (and code written for parallel calculations can probably be easily made compatible with multiple Pascal dialects). I don't know what they do with unknown compiler directives though.

Jonas

Marco van de Voort
to Jonas Maebe
Show quoted text 10 lines
On 21 Jul 2006, at 11:42, Marco van de Voort wrote: > > Bad assumption, the only one that matters, Delphi errors on unknown > compiler directives. So > you will have to ifdef anyway. (tested D6) I think at least in this case GPC also matters, since Florian is also soliciting feedback on the syntax on the GPC list (and code written for parallel calculations can probably be easily made compatible with multiple Pascal dialects).

I meant more that GPC also still can implement the new syntax. This will be a bit harder with Delphi :-)

Vinzent Hoefler
to Florian Klaempfl: I'am currently thinking about implementing OpenMP support in FPC. However, there is…
Florian Klaempfl wrote
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.

Well, I just added some stuff there, yesterday. It's far from being complete yet (it just covers a basic "parallel" construct), nor is it really thought through yet, but well, it might be a start; something to begin with.

Any suggestions are welcome, of course.

Due to the fact, that the OpenMP specification is neither the easiest one to read or understand, and it's not particularly tiny, neither, I don't want to put hours and hours of then wasted effort into this, if everyone here thinks that this idea is total crap.

And yes, I admit, I like code being a little bit more verbose. :)

Vinzent.

Micha Nelissen
to Vinzent Hoefler
Vinzent Hoefler wrote 6 lines
Well, I just added some stuff there, yesterday. It's far from being complete yet (it just covers a basic "parallel" construct), nor is it really thought through yet, but well, it might be a start; something to begin with. Any suggestions are welcome, of course.

Does parallel mean all the statements in the block can be executed in parallel, or that multiple copies of the block of statements can be started in parallel ?

Micha

Vinzent Hoefler
to Micha Nelissen
Micha Nelissen wrote 11 lines
Vinzent Hoefler wrote: > Well, I just added some stuff there, yesterday. It's far from being > complete yet (it just covers a basic "parallel" construct), nor is > it really thought through yet, but well, it might be a start; > something to begin with. > > Any suggestions are welcome, of course. Does parallel mean all the statements in the block can be executed in parallel, or that multiple copies of the block of statements can be started in parallel ?

The latter.

Vinzent.

Michael Van Canneyt
to Vinzent Hoefler
Vinzent Hoefler wrote 14 lines
On Wednesday 26 July 2006 08:17, Micha Nelissen wrote: > Vinzent Hoefler wrote: > > Well, I just added some stuff there, yesterday. It's far from being > > complete yet (it just covers a basic "parallel" construct), nor is > > it really thought through yet, but well, it might be a start; > > something to begin with. > > > > Any suggestions are welcome, of course. > > Does parallel mean all the statements in the block can be executed in > parallel, or that multiple copies of the block of statements can be > started in parallel ? The latter.

Which is why I think that it's better to have them as local functions, instead of having to introduce a lot of new functions.

Local functions are very pascal-ish. C doesn't have it, which is why they can't use it. Let's use the language features to their full extent.

Michael.

Micha Nelissen
to Vinzent Hoefler: The latter. Vinzent.
Vinzent Hoefler wrote 6 lines
On Wednesday 26 July 2006 08:17, Micha Nelissen wrote: > Does parallel mean all the statements in the block can be executed in > parallel, or that multiple copies of the block of statements can be > started in parallel ? The latter.

Strange. How many copies ?

Vinzent Hoefler
to Micha Nelissen
Micha Nelissen wrote 9 lines
Vinzent Hoefler wrote: > On Wednesday 26 July 2006 08:17, Micha Nelissen wrote: >> Does parallel mean all the statements in the block can be executed >> in parallel, or that multiple copies of the block of statements >> can be started in parallel ? > > The latter. Strange.

That somehow applies to the whole original specification. :)

How many copies ?

Omp.Get_Num_Threads(), AFAICS.

Vinzent.

Vincent Snijders
to Micha Nelissen: Strange. How many copies ?
Micha Nelissen wrote 8 lines
Vinzent Hoefler wrote: > On Wednesday 26 July 2006 08:17, Micha Nelissen wrote: >> Does parallel mean all the statements in the block can be executed in >> parallel, or that multiple copies of the block of statements can be >> started in parallel ? > The latter. Strange. How many copies ?

Looking at the example, I would say as many copies as there are threads: OMP.Get_Thread_Num

Vincent

Vinzent Hoefler
to Michael Van Canneyt: Which is why I think that it's better to have them as local functions, instead of having…
Michael Van Canneyt wrote 18 lines
On Wed, 26 Jul 2006, Vinzent Hoefler wrote: > On Wednesday 26 July 2006 08:17, Micha Nelissen wrote: > > Vinzent Hoefler wrote: > > > Well, I just added some stuff there, yesterday. It's far from > > > being complete yet (it just covers a basic "parallel" > > > construct), nor is it really thought through yet, but well, it > > > might be a start; something to begin with. > > > > > > Any suggestions are welcome, of course. > > > > Does parallel mean all the statements in the block can be > > executed in parallel, or that multiple copies of the block of > > statements can be started in parallel ? > > The latter. Which is why I think that it's better to have them as local functions, instead of having to introduce a lot of new functions.

Hey, it's only *one* new keyword yet. :)

Admitted, local blocks are more Adaish, but with this approach, I was trying to avoid introducing a lot more keywords. There still probably will be some, because there are more constructs like "barrier", "workshare" (which I didn't fully understand yet) and "section".

And well, such blocks are already known in Object Pascal. Just look at them as in object declarations the public/protected/private modifiers.

Local functions are very pascal-ish. C doesn't have it, which is why they can't use it. Let's use the language features to their full extent.

Yes. I agree with that. The problem is that there are more "variable" types than just shared and private (like "firstprivate"), so it might prove to be quite difficult to do that if you only have local functions. I just didn't come to that part yet.

I'll probably update the WiKi this evening/night (can't do that from work, where freepascal.org still times out).

Vinzent.

Steve Williams
to Michael Van Canneyt: Which is why I think that it's better to have them as local functions, instead of having…
Michael Van Canneyt wrote 6 lines
Which is why I think that it's better to have them as local functions, instead of having to introduce a lot of new functions. Local functions are very pascal-ish. C doesn't have it, which is why they can't use it. Let's use the language features to their full extent.
  *procedure* SubDomain (*var* x       : *array of* Float;
                           istart  : Integer;
                           ipoints : Integer)
  *var*
     i : Integer;
  *begin*
     *for* i := 0 *to* ipoints - 1 *do*
        x[istart + i] := 123.456;
  *end* /{SubDomain}/;
  *procedure* Sub (*var* x : *array of* Float);
  /// Variables declared here should have /|*shared*|/ context./
  /// This would include the function's parameters then.../
    *procedure* SubTask(*var* x : *array of* Float);
    *var*
      /// Variables declared here have /|*private*|/ context./
      iam     : Integer;
      nt      : Integer;
      ipoints : Integer;
    *parallel*
      iam := OMP.Get_Thread_Num;  /// OMP library calls./
      nt  := OMP.Get_Num_Threads;
      ipoints := Length (x) *div* nt; /// size of partition/
      istart  := iam * ipoints;     /// starting array index/
      *if* iam = Pred (nt) *then*
        ipoints := Length (x) - istart; /// last thread may do more/
      SubDomain (x, istart, ipoints);
    *end*;
  *begin*
    SubTask(x);
  *end* /{Sub}/;
  *var*
     arr = *array*[0 .. 9999] *of* Float;
  *begin* / // Main program/
     Sub (arr);
  *end*.
Sly This message and its attachments may contain legally privileged or confidential information. This message is intended for the use of the individual or entity to which it is addressed. If you are not the addressee indicated in this message, or the employee or agent responsible for delivering the message to the intended recipient, you may not copy or deliver this message or its attachments to anyone. Rather, you should permanently delete this message and its attachments and kindly notify the sender by reply e-mail. Any content of this message and its attachments, which does not relate to the official business of the sending company must be taken not to have been sent or endorsed by the sending company or any of its related entities. No warranty is made that the e-mail or attachment(s) are free from computer virus or other defect.
Steve Williams
to Steve Williams
Steve Williams wrote 10 lines
*begin* SubTask(x); *end* /{Sub}/; *var* arr = *array*[0 .. 9999] *of* Float; *begin* / // Main program/ Sub (arr); *end*.

Damn Thunderbird.

Sly This message and its attachments may contain legally privileged or confidential information. This message is intended for the use of the individual or entity to which it is addressed. If you are not the addressee indicated in this message, or the employee or agent responsible for delivering the message to the intended recipient, you may not copy or deliver this message or its attachments to anyone. Rather, you should permanently delete this message and its attachments and kindly notify the sender by reply e-mail. Any content of this message and its attachments, which does not relate to the official business of the sending company must be taken not to have been sent or endorsed by the sending company or any of its related entities. No warranty is made that the e-mail or attachment(s) are free from computer virus or other defect.
Vinzent Hoefler
to Micha Nelissen: Ah the number of threads is determined by the RTL, and any parallel block must be written…
Micha Nelissen wrote 9 lines
Vinzent Hoefler wrote: > On Wednesday 26 July 2006 09:07, Micha Nelissen wrote: >> How many copies ? > > Omp.Get_Num_Threads(), AFAICS. Ah the number of threads is determined by the RTL, and any parallel block must be written flexible, so that it can work for any given number of threads ?

Yes and no. I think, there are constructs to set a specific number of threads. And as I tried to say, the specification is quite large. If not to say even convoluted. I've seen easier to read stuff recently.

Vinzent.

Vincent Snijders
to Michael Van Canneyt: Which is why I think that it's better to have them as local functions, instead of having…
Michael Van Canneyt wrote 23 lines
On Wed, 26 Jul 2006, Vinzent Hoefler wrote: > On Wednesday 26 July 2006 08:17, Micha Nelissen wrote: >> Vinzent Hoefler wrote: >>> Well, I just added some stuff there, yesterday. It's far from being >>> complete yet (it just covers a basic "parallel" construct), nor is >>> it really thought through yet, but well, it might be a start; >>> something to begin with. >>> >>> Any suggestions are welcome, of course. >> Does parallel mean all the statements in the block can be executed in >> parallel, or that multiple copies of the block of statements can be >> started in parallel ? > The latter. Which is why I think that it's better to have them as local functions, instead of having to introduce a lot of new functions. Local functions are very pascal-ish. C doesn't have it, which is why they can't use it. Let's use the language features to their full extent.

I added an example with nested procedures.

Vincent

Vinzent Hoefler
to Steve Williams: Damn Thunderbird. Sly This message and its attachments may contain legally privileged or…
Steve Williams wrote 12 lines
Steve Williams wrote: > *begin* > SubTask(x); > *end* /{Sub}/; > > *var* > arr = *array*[0 .. 9999] *of* Float; > *begin* / // Main program/ > Sub (arr); > *end*. Damn Thunderbird.

Well, it tried to mimic my syntax highlighting. :) Apart from that, your change is quite nice, yes. That's what Michael meant, I guess.

Vinzent.

Michael Van Canneyt
to Micha Nelissen: There is no real reason to restrict 'parallel' to local functions, is there ? Micha
Micha Nelissen wrote 8 lines
Michael Van Canneyt wrote: >> The latter. > > Which is why I think that it's better to have them as local functions, > instead of having to introduce a lot of new functions. There is no real reason to restrict 'parallel' to local functions, is there ?

No, but I used that because in the example you make use of variables defined in the local function, but also in the parent function.

It seems obvious to me that a global function can be called in parallel at any time. The compiler can perfectly detect whether a global function writes to variables outside it's own scope, in which case it's probably a no-no to paralellize the function. The programmer could help there by adding the parallel keyword indicating that the programmer knows it is safe to parallelize it.

For local functions it is less obvious, there the compiler could use some help in most cases...

Michael.

Vinzent Hoefler
to Michael Van Canneyt
Michael Van Canneyt wrote
It seems obvious to me that a global function can be called in parallel at any time. The compiler can perfectly detect whether a global function writes to variables outside it's own scope, in which case it's probably a no-no to paralellize the function.

Hey, you're trying to put more burden on the compiler here as the spec even allows, I'd say.

Don't go on or you'll end up with the requirement for compile time dead-lock detection. :)

Vinzent.

Michael Van Canneyt
to Vinzent Hoefler
Vinzent Hoefler wrote 12 lines
On Wednesday 26 July 2006 09:46, Michael Van Canneyt wrote: > It seems obvious to me that a global function can be called in > parallel at any time. The compiler can perfectly detect whether a > global function writes to variables outside it's own scope, in which > case it's probably a no-no to paralellize the function. Hey, you're trying to put more burden on the compiler here as the spec even allows, I'd say. Don't go on or you'll end up with the requirement for compile time dead-lock detection. :)

Well, my statement is moderate in the sense that the compiler does this anyway already (see the hints/warnings about unused params/vars); let's use this information as much as we can. To avoid more difficult detections such as possible dead-locks, I would let the programmer add some keywords...

Michael.

Andreas Berger
to Steve Williams: *procedure* SubDomain (*var* x : *array of* Float; istart : Integer; ipoints :…
Steve Williams wrote 24 lines
Michael Van Canneyt wrote: > Which is why I think that it's better to have them as local functions, > instead of having to introduce a lot of new functions. > > Local functions are very pascal-ish. C doesn't have it, which is why > they can't use it. > Let's use the language features to their full extent. > *procedure* SubTask(*var* x : *array of* Float); *var* /// Variables declared here have /|*private*|/ context./ iam : Integer; nt : Integer; ipoints : Integer; *parallel* iam := OMP.Get_Thread_Num; /// OMP library calls./ nt := OMP.Get_Num_Threads; ipoints := Length (x) *div* nt; /// size of partition/ istart := iam * ipoints; /// starting array index/ *if* iam = Pred (nt) *then* ipoints := Length (x) - istart; /// last thread may do more/ SubDomain (x, istart, ipoints); *end*;
Wouldn't it be better to write it like this:
    procedure SubTask(var x: array of Float); *parallel*;
    var
       ...
    begin
       ...
    end;
Vinzent Hoefler
to Michael Van Canneyt: Well, my statement is moderate in the sense that the compiler does this anyway already…
Michael Van Canneyt wrote 16 lines
On Wed, 26 Jul 2006, Vinzent Hoefler wrote: > On Wednesday 26 July 2006 09:46, Michael Van Canneyt wrote: > > It seems obvious to me that a global function can be called in > > parallel at any time. The compiler can perfectly detect whether > > a global function writes to variables outside it's own scope, in > > which case it's probably a no-no to paralellize the function. > > Hey, you're trying to put more burden on the compiler here as the > spec even allows, I'd say. > > Don't go on or you'll end up with the requirement for compile time > dead-lock detection. :) Well, my statement is moderate in the sense that the compiler does this anyway already (see the hints/warnings about unused params/vars); let's use this information as much as we can.

True. Using information that's already there, can't be wrong. I second that.

We're not C, where everything is standardized to be the programmer's problem. So yes, if concurrency will ever be implemented in the language, no matter how, some decent warnings/hints/notes about several questionable constructs would be nice.

Vinzent.

Vinzent Hoefler
to Andreas Berger: Wouldn't it be better to write it like this: procedure SubTask(var x: array of Float);…
Andreas Berger wrote 32 lines
Steve Williams wrote: > Michael Van Canneyt wrote: >> Which is why I think that it's better to have them as local >> functions, instead of having to introduce a lot of new functions. >> >> Local functions are very pascal-ish. C doesn't have it, which is >> why they can't use it. >> Let's use the language features to their full extent. > > *procedure* SubTask(*var* x : *array of* Float); > *var* > /// Variables declared here have /|*private*|/ context./ > iam : Integer; > nt : Integer; > ipoints : Integer; > *parallel* > iam := OMP.Get_Thread_Num; /// OMP library calls./ > nt := OMP.Get_Num_Threads; > ipoints := Length (x) *div* nt; /// size of partition/ > istart := iam * ipoints; /// starting array index/ > *if* iam = Pred (nt) *then* > ipoints := Length (x) - istart; /// last thread may do more/ > SubDomain (x, istart, ipoints); > *end*; Wouldn't it be better to write it like this: procedure SubTask(var x: array of Float); *parallel*; var ... begin ... end;

Actually no. I thought about it, but I didn't get through all that stuff yesterday evening or else I would have updated the WiKi already. The problem I see is that the parallel directive has more meanings (basically it is the main directive). For that reason, I wouldn't want to put in on the callee, but rather on the caller.

I think it would also be easier for the compiler then to detect alls those parallel regions.

Let's see. Anyway, there was already more response I would have expected after the days of silence. :)

Vinzent.

Alexandre Leclerc
to Vinzent Hoefler

2006/7/27, Vinzent Hoefler :

Show quoted text 45 lines
On Wednesday 26 July 2006 10:05, Andreas Berger wrote: > Steve Williams wrote: > > Michael Van Canneyt wrote: > >> Which is why I think that it's better to have them as local > >> functions, instead of having to introduce a lot of new functions. > >> > >> Local functions are very pascal-ish. C doesn't have it, which is > >> why they can't use it. > >> Let's use the language features to their full extent. > > > > *procedure* SubTask(*var* x : *array of* Float); > > *var* > > /// Variables declared here have /|*private*|/ context./ > > iam : Integer; > > nt : Integer; > > ipoints : Integer; > > *parallel* > > iam := OMP.Get_Thread_Num; /// OMP library calls./ > > nt := OMP.Get_Num_Threads; > > ipoints := Length (x) *div* nt; /// size of partition/ > > istart := iam * ipoints; /// starting array index/ > > *if* iam = Pred (nt) *then* > > ipoints := Length (x) - istart; /// last thread may do more/ > > SubDomain (x, istart, ipoints); > > *end*; > > Wouldn't it be better to write it like this: > procedure SubTask(var x: array of Float); *parallel*; > var > ... > begin > ... > end; Actually no. I thought about it, but I didn't get through all that stuff yesterday evening or else I would have updated the WiKi already. The problem I see is that the parallel directive has more meanings (basically it is the main directive). For that reason, I wouldn't want to put in on the callee, but rather on the caller. I think it would also be easier for the compiler then to detect alls those parallel regions. Let's see. Anyway, there was already more response I would have expected after the days of silence. :)

What about the same approach as the class procedures?

Actually we have in a class the possibility to:
class procedure MyProc;
class function MyFunc: Integer;
Then we could very simply have:
parallel procedure ParallelBlock;
parallel function ParallelFunction; //if this can happen...

Also, I read that in example 1: "Variables declared here should have shared context." In fact by default they have private context and to me it looks like more normal. Maybe we should have a way to do the contrary: specify that a variable has shared context... What others think?

Alexandre Leclerc
Vinzent Hoefler
to Alexandre Leclerc
Alexandre Leclerc wrote
Then we could very simply have: parallel procedure ParallelBlock; parallel function ParallelFunction; //if this can happen...

Yes. I thought of something like that, because it could quite easily match with a "parallel for" construct. That's why I don't like the idea of a function modifier.

But pleeeaaase, people. This was only one single and little example and it's not nearly close to what the spec says. It just scratched the surface of it. So it's a bit early to hang on this only parallel keyword in that particular example. In the end, *all* constructs should nicely match together.

What about those "parallel section" and "parallel workshare" constructs? The latter bothers me a lot (section might prove to be quite easy) plus all the /parameters/ those stuff can have:

You don't want to write

|parallel (Num_Threads := 3, ...)
|function

or something similar, do you?

Or think of this "reduction" keyword...

Also, I read that in example 1: "Variables declared here should have shared context."

Yes, if they're declared outside of the parallel block, they can be seen by every single one, so "shared" would IMO be a more natural visibility rule here. This could remove the need for another keyword.

In fact by default they have private context and to me it looks like more normal.

What do you mean "by default"? The OpenMP spec? Well, I wasn't trying to copy the idiocies mainly caused by the chosen base language(s). :->

Thread private variables don't make sense outside of the parallel block, especially *after* it, so why should the default be "private" here?

Maybe we should have a way to do the contrary: specify that a variable has shared context... What others think?

The approach allowed both in a (I think, logical way, because of the implied scoping rules). The problems begin with the "firstprivate" and such directives.

Vinzent.