Lets say we have two classes:
class A
{
void run_all()
{
#pragma omp task
f1a();
#pragma omp task
f1b();
}
void f1a()
{ /*some code*/ }
void f1b()
{ /*some code*/ }
}
class B
{
void run_all()
{
#pragma omp task
f2a();
#pragma omp task
f2b();
}
void f2a()
{ /*some code*/ }
void f2b()
{ /*some code*/ }
}
And then we have the following code that uses these classes:
int main()
{
A *a = new A();
B *b = new B();
#pragma omp parallel
{
#pragma omp single
{
a->run_all();
b->run_all();
}
}
}
I need to ensure that the four subfunctions are executed in this order: f1a(), f1b(), f2a(), f2b(). To accomplish this I would need to use task dependencies with the in/out/inout clauses. In other words the four subfunctions would need to look something like this:
#pragma omp task depend (inout: x)
fXa();
where they all utilize a common variable x. How could I define such a variable? Would it need to be a global variable in C++ or can it be done in some other way without resorting to the use of global variables? Do I need to define a dummy variable x to define the task dependency even if I am not planning on using the variable anywhere else? It seems to me a bit odd that a variable would need to be defined for such a purpose...
BTW: yes I know that this could be trivially done by removing all the omp pragmas to define a sequential problem, but this is not the answer I am looking for as I have multiple such sub-pieces of code that I want to run in parallel