Hello, I have just started to learn omp tasks and have a question about final clause. I compiled the following code based on the example from https://software.intel.com/sites/products/documentation/doclib/iss/2013/... with Intel C++ 15.0.0.108 and ran it on simple binary tree of level 3.
#include <iostream> #include <omp.h> const int MAX_LEVEL = 3; using namespace std; struct node { struct node *left; struct node *right; int nodeNumber; }; void process(node * pNode) { #pragma omp critical { cout<<omp_get_thread_num()<<""<<pNode->nodeNumber<<endl; } } void traverse( struct node *p, int lev, int finLevel ) { if (p->left) #pragma omp task final(1) // p is firstprivate by default traverse(p->left,lev+1,finLevel); if (p->right) #pragma omp task final(1)// p is firstprivate by default traverse(p->right,lev+1, finLevel); process(p); } void allocateNodes(node **p, int level, int *nodeNumber) { *p = new node; (*p)->nodeNumber = *nodeNumber; if (level < MAX_LEVEL) { (*nodeNumber)++; allocateNodes(&(*p)->left, level+1, nodeNumber); (*nodeNumber)++; allocateNodes(&(*p)->right, level+1, nodeNumber); } else { (*p)->left = NULL; (*p)->right = NULL; } } int main() { node *p; int nodeNumber = 0; allocateNodes(&p,0,&nodeNumber); #pragma omp parallel #pragma omp single traverse(p,0,-1); }
And get strange output:
0 0
1 1
2 8
0 9
1 5
2 12
0 11
1 7
2 14
0 10
1 6
2 13
0 2
1 3
2 4
But If I compile the same code with g++ I get another output:
2 3
0 0
2 4
0 10
2 2
0 11
2 6
0 9
2 7
2 5
0 13
2 1
0 14
0 12
0 8