Page 1 of 1

tasks and C++ references

PostPosted: Wed May 07, 2008 4:40 am
by jakub
While variables with reference type are not permitted in private/firstprivate clauses and thus before introduction of #pragma omp task they were always shared, I'm wondering how they should behave in tasks where some variables are firstprivate even when they aren't mentioned in the firstprivate clause. E.g. in:
Code: Select all
struct A { A (); ~A (); A (const A &); };
void foo (A &);

void bar ()
{
  A a;
  A &b = a;
  #pragma omp task
    foo (b);
  #pragma omp barrier
  #pragma omp taskwait
}

b has reference type and is private in the enclosing context. Should it be firstprivate then, and be a reference to a shared variable a (given that a isn't mentioned in the task construct), so if the task is scheduled in a different thread than the thread that encountered the task construct, a firstprivate var b would reference variable a in the thread that encountered the task construct?

Re: tasks and C++ references

PostPosted: Wed May 07, 2008 9:18 am
by Federico
All firstprivate restrictions apply to variables which can be implicitly determined firstprivate in a task construct.
In your example, I'd expect the compiler to give a compile time error and abort, forcing me to make b shared (and take the responsibility of this) or to take other appropriate measure.