Talk:OpenMP support

From Lazarus wiki
Jump to navigationJump to search

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)


move to it's own page

As the purpose and implementation details are completely different, it has been suggested to separate the "TEventThread / Thread Event" proposal from the OpenMP stuff and move it to it's own wiki page. supposedly I'll do that soon. --Mschnell 13:33, 10 December 2007 (CET)




What about implementing it as a conditional-type structure? FPC already has them, and it would save considerable time in coding if we have to use them explicitly to enable and disable the parallel keyword/modifier and the other directive clauses (nowait, reduction, schedule and num_threads mainly; the others can be emulated through the function header).

If you must maintain a pascal type environment, could one define a procedure "parallelize" which would take a procedure and any directive clauses for the block, and execute the procedure in parallel as instructed by the clauses? That would simplify obfuscating the openMP stuff in other compilers and disabling it with a simple Uses modification in the program header.

--Darodrigues 19:31, 8 April 2008 (CEST)