OpenMP® Forum

Discussion on the OpenMP specification run by the OpenMP ARB. OpenMP and the OpenMP logo are registered trademarks of the OpenMP Architecture Review Board in the United States and other countries. All rights reserved.

My expection is the following: by default i is declared private, and arrayA, arrayB, result, NUM_WIDGETS, VECTOR_LENGTH are shared. Also, by default, the variables local to the loop index, vecA, vecB, sum, and j are private.

Are these assumptions correct? Or do index, vecA, vecB, sum, and j need to be declared private?

If you look at the OpenMP spec, section 2.9.1.1 Data-sharing Attribute Rules for Variables Referenced in a Construct, you will find that it states:

The following variables have predetermined data-sharing attributes:...• Variables with automatic storage duration that are declared in a scope inside the construct are private

So all of your assumptions are correct and you do not need to declare anything more than you have already - if the compiler is doing what it is suppose to. The other point to remember though, is that OpenMP will make the pointer private and not what the pointer points to.

What data is being changed? Your code example doesn't seem to show anything being written to other than "sum" which is private, the loop indices which are private, and "result" which is a shared array indexed by the outer private "i". None of these look like a problem.

The piece of code I put there was toy code made up just to illustrate my question, which you have answered for me.

It turns out, in the parallelized loop I had a call that was altering member data of the class. Each thread was overwriting this data. Since the data space need be specific to each thread, it was changing the results. This is an easy fix.

Again, I appreciate your help. I've learned quite a bit on my first day of using OpenMP. Your answer reassured my shaken confidence and helped me to locate the problem.