4

Is it possible that the -O2 optimization flag re-arranges code, thereby possibly making a multi-threaded application work as un-intended?

As an example of what I mean by un-intended behavior when code is re-arranged: A variable declared (by the programmer) to be created for each thread is moved outside the #pragma omp parallal such that only one single copy is created, shared by all threads.

2
  • 2
    No. The compiler could be horrifically broken if did what you have described. Commented Apr 22, 2013 at 21:42
  • have a look at this question stackoverflow.com/questions/11626928/… Commented Apr 25, 2013 at 6:35

1 Answer 1

3

No, this cannot happen. OpenMP would not be very useful if the compiler was unrolling the loops or if the program crashed when the compiler reorders loops. The OpenMP directive must specify the dependencies and side effects of the variables and parallel scopes, and the compiler takes them into account when applying the optimization passes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.