OpenMP directive turns a statement into a real code block
Tim Prince
TimothyPrince@sbcglobal.net
Sat Jun 20 13:42:00 GMT 2009
Peter Cech wrote:
> I was adding some OpenMP paralellization into an existing code and run
> into a puzzling problem. Here is a snippet to illustrate:
>
> // Inside a parallel for loop
>
> // The code statement below modifies a shared data structure
> #pragma omp critical
> Class instance = create_and_register_new_instance()
>
> // Problem here - compiler claims that "instance" was not declared in
> // this scope
> instance.do_something()
>
> So it seems that g++ 4.3 turns the code into:
>
>
> // The code statement below modifies a shared data structure
> #pragma omp critical
> {
> Class instance = create_and_register_new_instance()
> }
>
> // "instance" not declared here
> instance.do_something()
>
This looks right. If you wish the critical region to include more than a
single statement, you need an explicit block with {}.
More information about the Gcc-help
mailing list