


















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















































}
Figure credits: Intel Cilk++ Programmer’s Guide. Document # 322581-001US. 7
Automaker: hierarchical 3D CAD representation of assemblies Example source: http://www.cilk.com/multicore-blog/bid/5672/Global-Variable-Reconsidered 10 Computing a cutaway view Node *target; std::list<Node *> output_list; ... void walk(Node *x) { switch (x->kind) { case Node::LEAF: if (target->collides_with(x)) output_list.push_back(x); break; case Node::INTERNAL: for (Node::const_iterator child = x->begin(); child != x->end(); ++child) walk(child); break; } }
Global variable causes data races! 11 Computing a cutaway view in parallel Node *target; std::list<Node *> output_list; ... void walk(Node *x) { switch (x->kind) { case Node::LEAF: if (target->collides_with(x)) output_list.push_back(x); break; case Node::INTERNAL: cilk_for (Node::const_iterator child = x->begin(); child != x->end(); ++child) walk(child); break; } }
Node *target; std::list<Node *> output_list; ... void walk(Node *x, std::list<Node *> o_list) { switch (x->kind) { case Node::LEAF: if (target->collides_with(x)) o_list.push_back(x); break; case Node::INTERNAL: std::vector<std::list<Node *> > children_list(x.num_children); cilk_for (Node::const_iterator child = x->begin(); child != x->end(); ++child) walk(child, children_list[child]); for (int i=0; i < x.num_children; ++i) o_list.splice( o_list.end(), children_list[i]); break; } 13