#928: openmp parallelization within Exact broken ---------------------+------------------------------------------------------ Reporter: knarf | Owner: Type: defect | Status: new Priority: major | Milestone: ET_2012_05 Component: Other | Version: Resolution: | Keywords: ---------------------+------------------------------------------------------
Comment (by eschnett):
No, this is not safe. Concurrent write access is not permitted by OpenMP. For example, a compiler may detect that this variable will be written to, and then use it as temporary storage for some other quantity, which may even have a different type. I believe gcc 4.7 has a respective optimisation (re-use of stack slots to reduce the size of stack frames), although I don't know whether it would be triggered in this case.
In this case, the problem is that thread A begins to initialise this variable, then thread B notices this and will skip the initialisation and go on to use the presumed-initialised value only it hasn't actually finished being initialised.
There are two other ways to correct this: either one does not "save" these variables (because the initialisation is very cheap anyway), or one initialises them in an "openmp single" region.