[Omp] atomic directive semantics

Sven Karlsson svenka-lists at sven.karlsson.name
Fri Sep 23 01:50:10 PDT 2005


Hi Dieter,

Dieter an Mey wrote:

 > Why can't we just go abandon atomic and let the compiler try to 
optimize the critical region?


Well, I know you have that opinion! :-) A compiler will, however, most 
probably not see the possibility of optimizing the following:

#pragma omp critical some_atomic_region
{
  a=a+
some_very_hairy_function_with_potentially_lots_of_side_effects_located_in_some_other_compilation_unit(b,c,d);
}

into

#pragma omp atomic

a=a+some_very_hairy_function_with_potentially_lots_of_side_effects_located_in_some_other_compilation_unit(b,c,d);

although the function could be executed in parallel.

This because it cannot see, at least not with any analysis method I know 
of, that the function need not be inside the critical. Naturally, the 
programmer can rewrite the code to make it easier for the compiler but 
then we loose source code transparency.

If someone knows about any way to let the compiler realize the 
optimization above please let me know.

Best regards
  Sven





More information about the Omp mailing list