Re: OpenMP directive turns a statement into a real code block

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 {}.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux