c++ - openmp: recursive task slower than sequential even with depth limit -
i have big binary tree on want expensive calculations. want parallelize these methods using openmp , task pragmas. as test, have parallelized freetree function , have created big example test tree. in order prevent spawning many tasks, have limited tasks creation top 2 levels of tree. 4 tasks created. below minimal working example: #include <chrono> #include <iostream> class node { public: int data; node* l; node* r; node(node* left, node* right) : l(left), r(right) {} }; node* createrandomtree(int depth) { if (depth == 0) return new node(null, null); return new node(createrandomtree(depth - 1), createrandomtree(depth - 1)); } void freetree(node* tree) { if (tree == null) return; freetree(tree->l); freetree(tree->r); delete tree; } void freetreepar(node* tree, int n = 0) { if (tree == null) return; node *l = tree->l, *r = tree->r; if (n < 2) { #pragma omp task fre...