# Using Intel Threading Building Blocks to add parallelism to a recursive class

## Recommended Posts

What would be the best way to add parallelism(using tbb) to the class below? Is it a good candidate, due to the fact that it's set up like a tree, for parallelism(using tbb)? Or should I maintain two vectors with one being a tree like below and the other being a flat layout?
struct Directory
{
{
C = A * B;

}

Matrix A, B, C;
std::vector<std::tr1::shared_ptr<Directory>> m_vChild;
}



##### Share on other sites
shared_ptr is thread-safe, so passing it around means incurring an interlocked increment. This is undesirable.

Ideally, for good paralellism, the code would be structured for streaming processing.
struct Transform {  Matrix a,b,c;};vector<Transform> transforms;someTreeStructure relations;

In the example you have no dependencies between parents/children, which means there is no reason to cram that information in same structure. Using above hot/cold separation means all transformations are processed in parallel, and in a very memory efficient manner (which could be improved).

The tree depends. If transforms are stored externally, then it avoids the need for shared pointers, just use raw pointers or even indices into transform array. Unless the hierarchy needs to be modified frequently, this is not a problem.

If hierarchy does need to be modified at all, then keeping a rich, linked hierarchy separately might be better, and on each change it is serialized into above structures.

##### Share on other sites
Quote:
 Original post by Antheusshared_ptr is thread-safe, so passing it around means incurring an interlocked increment. This is undesirable.

Quote:
 Original post by AntheusIdeally, for good paralellism, the code would be structured for streaming processing.struct Transform { Matrix a,b,c;};vector transforms;someTreeStructure relations;In the example you have no dependencies between parents/children, which means there is no reason to cram that information in same structure. Using above hot/cold separation means all transformations are processed in parallel, and in a very memory efficient manner (which could be improved).The tree depends. If transforms are stored externally, then it avoids the need for shared pointers, just use raw pointers or even indices into transform array. Unless the hierarchy needs to be modified frequently, this is not a problem.If hierarchy does need to be modified at all, then keeping a rich, linked hierarchy separately might be better, and on each change it is serialized into above structures.

I really wish I had thought about all of this(as well as some of the things in intel docs) way before starting my first simple game. I would have done things entirely differently...With task scheduler, pipelines, etc.

You really have to take this stuff into account from the start. [Giant pain in the arse to work it in later]

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628350
• Total Posts
2982211

• 10
• 9
• 24
• 11
• 9