Quantcast
Channel: Parallel Computing in C++ and Native Code forum
Viewing all articles
Browse latest Browse all 856

Using PPL with CArray and Quad tree for parallel processing

$
0
0

InShort 2 issues:
1. use ppl with MFC so that each branch of a quad tree can be processed independently, store the results in a shared static CArray
2. use ppl with MFC so that each node of the quad tree when processed can also write to a shared static array of data

I have a quad tree, and what I want to do is have either PPL, or OMP to do each quad to execute down it's own branch doing there respective quad
so I'm using MFC and I have an CArray that stores each final leaves of each quad tree branch.

I was trying to do it in PPL or OMP but not very successful. It works fine non parallel it just takes a while on large data sets.

I'm new to this idea, but hopefully someone that is savy with PPL can tell me how to do MFC.
so:
static CArray <PtrArray,CNodes> m_NodesPtrArray;
QuadTree::BuildQuadTree(Triangle atriangle[], double width, double length)
{
 depth=0;
 root->Rectangle.SetSize(width,length);
 CArray<int,int>Node_indexes_of_Triangles;//this has total cnt as well as 0->N triangle indexes
 root -> SplitNode(atriangle, Node_indexes_of_Triangles,depth);
}
CNode::SplitNode(Triangle * Array, CArray<int,int)*pArrayIndexs, int depth)
{
 depth++;
 if(depth=0)
 {// run in parallel
  CPoints apt;
  GetCenterofQuad( &apt)
  CArray <int,int>QArray1,QArray2,QArray3, QArray4;
  GetTrianglesPerNewQuads(apt,&QArray1,&QArray2,&QArray3, &QArray4);
  parallel_invoke(
          [&]{SplitNode(atriangle,QArray1, depth);},
          [&]{SplitNode(atriangle,QArray2, depth);},
          [&]{SplitNode(atriangle,QArray3, depth);},
          [&]{SplitNode(atriangle,QArray4, depth);}
  );
 }
 else if(depth<4)
 {
  CPoints apt;
  GetCenterofQuad( &apt)
  CArray <int,int>QArray1,QArray2,QArray3, QArray4;
  GetTrianglesPerNewQuads(apt,&QArray1,&QArray2,&QArray3, &QArray4);

  SplitNode(atriangle,QArray1, depth);
         SplitNode(atriangle,QArray2, depth);
         SplitNode(atriangle,QArray3, depth);
         SplitNode(atriangle,QArray4, depth);
 }
 else
 {//at final depth
  //write this node to PtrArray for processing later...
  this->SetIndex(pArrayIndexs);
  m_NodesPtrArray.Add(this);
  return;
 }
}

I have another obvious issue, is how do you then process each node after this in parallel AND also have an array that each thread can write to???

E



Viewing all articles
Browse latest Browse all 856


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>