Difference between revisions of "Talk:OpenMP support"

From Lazarus wiki
Jump to navigationJump to search
(New page: IMHO the discussion about the value of threadvar count does not make much sense. Each thread has it's own threadvar instance. Thus before and after the "parallel" section there is one....)
 
(Propose sequential modifier)
Line 8: Line 8:
  
 
[[User:Mschnell|Mschnell]] 15:54, 4 December 2007 (CET)
 
[[User:Mschnell|Mschnell]] 15:54, 4 December 2007 (CET)
 +
 +
 +
----
 +
 +
 +
I like proposal 2 using 'parallel' as a modifier rather than a keyword since that would tie in well with it being an optional facility enabled by e.g. -dUseOpenMP rather than a mandatory part of the language. It would be desirable if a program ran properly even if not told to use parallelisation, but I think it should compile even if it failed to link e.g. because the OpenMP library was missing.
 +
 +
An interesting question is what would happen if somebody mixed both conventional thread handling and procedures marked as parallel. An easy hack would be to enforce that only the root thread of the program could call a parallel procedure, I think that would be safe but would be a bit brutal.
 +
 +
A more elegant way to solve the problem would be by introducing a 'sequential' modifier, and defining that the outer procedure should be marked as such- this could be possibly be enforced by the compiler or at least recognised as good practice. I'm somewhat rusty but I believe that this would make the outer procedure equivalent to a Brinch Hansen monitor.
 +
 +
Hence:
 +
 +
 +
  procedure Sub (var x : array of Float); sequential;
 +
 
 +
    procedure ParallelBlock; parallel;
 +
 
 +
    begin
 +
 
 +
    end {ParallelBlock};
 +
 
 +
  begin
 +
    ParallelBlock;
 +
  end {Sub};
 +
 +
-- [[User:MarkMLl|MarkMLl]] 12:40, 9 December 2007 (CET)

Revision as of 12:40, 9 December 2007

IMHO the discussion about the value of threadvar count does not make much sense.

Each thread has it's own threadvar instance.

Thus before and after the "parallel" section there is one. Within the parallel section this "mainthread" instance still exists and each of the some_value new threads gets it's own. So there are some_value+1 of them. Those used in the "loop" don't have an initial value so they are undefined (thus the "loop" does not do any sensible work).

After the parallel section the only remaining variable still has it's initial value of 0.

Mschnell 15:54, 4 December 2007 (CET)




I like proposal 2 using 'parallel' as a modifier rather than a keyword since that would tie in well with it being an optional facility enabled by e.g. -dUseOpenMP rather than a mandatory part of the language. It would be desirable if a program ran properly even if not told to use parallelisation, but I think it should compile even if it failed to link e.g. because the OpenMP library was missing.

An interesting question is what would happen if somebody mixed both conventional thread handling and procedures marked as parallel. An easy hack would be to enforce that only the root thread of the program could call a parallel procedure, I think that would be safe but would be a bit brutal.

A more elegant way to solve the problem would be by introducing a 'sequential' modifier, and defining that the outer procedure should be marked as such- this could be possibly be enforced by the compiler or at least recognised as good practice. I'm somewhat rusty but I believe that this would make the outer procedure equivalent to a Brinch Hansen monitor.

Hence:


 procedure Sub (var x : array of Float); sequential;
 
   procedure ParallelBlock; parallel;
 
   begin
 
   end {ParallelBlock};
 
 begin
   ParallelBlock;
 end {Sub};

-- MarkMLl 12:40, 9 December 2007 (CET)