0

Suppose I have the following function:

void fun (){

#pragma omp parallel private(i, x, d0, d1)
    {
        #pragma omp for
        for (i = 0; i < n; i++) {

            d0 = calc_dist();
            d1 = calc_dist();
            x = ((d0 < d1) ? 0 : 1);
            buffer1[i] = x;

            #pragma omp atomic update
            group_size[x] += 1;


        } 

    }
}

I want to know if accessing buffer1 buffer1[i] = x is still private having the fact that i and x are set to be private variables in the pragma section? If not, is it possible to allow buffer access private?

1 Answer 1

1

Your example access to buffer1[i] = x; is fine. It works because in the work-sharing loop, no two threads will ever get the same i and therefore no two threads will ever access the same memory.

Note that technically, buffer1[i] is not private, private applies only to variables. buffer1 is a shared variable.

You must not access any other element of buffer1 in any way within the loop. E.g. do not do anything like foo = buffer1[i-1].

This all works for regular C arrays or pointers, but there must not be any aliasing in effect.

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.