Commit 99598040 authored by Sylvain Thery's avatar Sylvain Thery

removing shared parameter from parallel_foreach, replaced by testing duplicate return value

parent 8ae37553
......@@ -182,7 +182,7 @@ public:
void MyQT::threadAttrib()
{
UnshrinkFunctor<PFP> funct(position,position2);
Algo::Parallel::foreach_attrib(myMap.getAttributeContainer<VERTEX>(), funct, true);
Algo::Parallel::foreach_attrib(myMap.getAttributeContainer<VERTEX>(), funct);
myMap.swapAttributes(position,position2);
m_positionVBO->updateData(position);
......@@ -226,7 +226,7 @@ public:
void MyQT::threadSimple()
{
ShrinkFunctor<PFP> funct(myMap,position,position2);
Algo::Parallel::foreach_cell<PFP::MAP,VERTEX>(myMap, funct,true);
Algo::Parallel::foreach_cell<PFP::MAP,VERTEX>(myMap, funct);
myMap.swapAttributes(position,position2);
m_positionVBO->updateData(position);
......
......@@ -137,7 +137,7 @@ void computeCentroidVolumes(typename PFP::MAP& map,
const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeCentroidVolumes<PFP> funct(map,position,vol_centroid);
Algo::Parallel::foreach_cell<typename PFP::MAP,VOLUME>(map, funct, true, nbth, true, select, current_thread);
Algo::Parallel::foreach_cell<typename PFP::MAP,VOLUME>(map, funct, nbth, true, select, current_thread);
}
......@@ -190,7 +190,7 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeNeighborhoodCentroidVertices<PFP> funct(map,position,vertex_centroid);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, true, nbth, false, select, current_thread);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, nbth, false, select, current_thread);
}
}
......
......@@ -439,7 +439,7 @@ void computeCurvatureVertices_NormalCycles(
const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeCurvatureVertices_NormalCycles<PFP> funct(map, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, true, nbth, true, select, current_thread);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, nbth, true, select, current_thread);
}
}
......
......@@ -190,7 +190,7 @@ template <typename PFP>
void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& normal, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeNormalVertices<PFP> funct(map,position,normal);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, true, nbth, false, select, current_thread);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, nbth, false, select, current_thread);
}
......@@ -214,11 +214,36 @@ template <typename PFP>
void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& normal, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeNormalFaces<PFP> funct(map,position,normal);
Algo::Parallel::foreach_cell<typename PFP::MAP,FACE>(map, funct, true, nbth, false, select, current_thread);
Algo::Parallel::foreach_cell<typename PFP::MAP,FACE>(map, funct, nbth, false, select, current_thread);
}
template <typename PFP>
class FunctorComputeAngleBetweenNormalsOnEdge: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
FaceAttribute<typename PFP::VEC3>& m_angles;
public:
FunctorComputeAngleBetweenNormalsOnEdge<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, EdgeAttribute<typename PFP::VEC3>& angles):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_angles(angles)
{ }
void run(Dart d, unsigned int threadID)
{
m_angles[d] = computeAngleBetweenNormalsOnEdge<PFP>(this->m_map, d, m_position) ;
}
};
template <typename PFP>
void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, EdgeAttribute<typename PFP::REAL>& angles, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeAngleBetweenNormalsOnEdge<PFP> funct(map,position,angles);
Algo::Parallel::foreach_cell<typename PFP::MAP,EDGE>(map, funct, nbth, false, select, current_thread);
}
} // endnamespace Parallel
template <typename PFP>
......
......@@ -40,36 +40,15 @@ namespace Parallel
const unsigned int SIZE_BUFFER_THREAD = 8192; // seems to be the best compromise
/**
* How much threads has you computer
* @return How much threads has you computer
*/
inline unsigned int nbThreads();
inline unsigned int optimalNbThreads();
/**
* Traverse orbits of a map in parallel. Use DartMarker
* Use this version if you need to have acces to each functors after the traversal (to compute a sum or an average for example)
* @param map the map
* @param funcs the functors (one for each thread) to apply (size of vector must be equal to nbth)
* @param nbth number of thread to use
* @param needMarkers set to yes if you want that each thread use different markers. Warning if set to false do not use thread id in algo !!
* @param good a selector
* @return Number of core in fact (work only with quad core with/without hyper threading)
*/
//template <typename MAP, unsigned int ORBIT>
//void foreach_orbit(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs, unsigned int nbth, bool needMarkers = false, const FunctorSelect& good = allDarts);
inline unsigned int optimalNbThreads();
/**
* Traverse orbits of a map in parallel. Use DartMarker
* Use this version if you do not need to keep functors
* @param map the map
* @param func the functor
* @param shared set to true if functors can be shared over the different thread (if false a copy will be used)
* @param nbth number of thread to use
* @param needMarkers set to yes if you want that each thread use different markers. Warning if set to false do not use thread id in algo !!
* @param good a selector
*/
//template <typename MAP, unsigned int ORBIT>
//void foreach_orbit(MAP& map, FunctorMapThreaded<MAP>& func, bool shared, unsigned int nbth, bool needMarkers = false, const FunctorSelect& good = allDarts);
/**
* Traverse cells of a map in parallel. Use quick traversal, cell markers or dart markers if available !
......@@ -88,13 +67,12 @@ void foreach_cell(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs, unsign
* Use this version if you do not need to keep functors
* @param map the map
* @param func the functor to apply
* @param shared set to true if functors can be shared over the different thread (if false a copy will be used)
* @param nbth number of threads 0 for let the system choose
* @param needMarkers set to yes if you want that each thread use different markers. Warning if set to false (default) do not use algo with thread id or markers !!
* @param good a selector
*/
template <typename MAP, unsigned int ORBIT>
void foreach_cell(MAP& map, FunctorMapThreaded<MAP>& func, bool shared, unsigned int nbth = 0, bool needMarkers = false, const FunctorSelect& good = allDarts, unsigned int currentThread = 0);
void foreach_cell(MAP& map, FunctorMapThreaded<MAP>& func, unsigned int nbth = 0, bool needMarkers = false, const FunctorSelect& good = allDarts, unsigned int currentThread = 0);
/**
* Traverse darts of a map in parallel
......@@ -113,13 +91,12 @@ void foreach_dart(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs, unsig
* Traverse darts of a map in parallel
* @param map the map
* @param funcs the functor
* @param shared set to true if functors can be shared over the different thread (if false a copy will be used)
* @param nbth number of thread to use, 0 for let the system choose
* @param needMarkers set to yes if you want that each thread use different markers. Warning if set to false (default) do not use algo with thread id or markers !!
* @param good a selector
*/
template <typename MAP>
void foreach_dart(MAP& map, FunctorMapThreaded<MAP>& func, bool shared, unsigned int nbth = 0, bool needMarkers = false, const FunctorSelect& good = allDarts);
void foreach_dart(MAP& map, FunctorMapThreaded<MAP>& func, unsigned int nbth = 0, bool needMarkers = false, const FunctorSelect& good = allDarts);
/**
......@@ -134,10 +111,9 @@ void foreach_attrib(AttributeContainer& attr_cont, std::vector<FunctorAttribThre
* Traverse all elements of an attribute container (attribute handler is placed in FunctorAttribThreaded
* @param attr_cont the attribute container to traverse
* @param func the functor to use
* @param shared if true the internal functors pointers are used as address of functor param, else copies are done with duplicate
* @param nbth number of thread to use for computation 0 for let the system choose
*/
void foreach_attrib(AttributeContainer& attr_cont, FunctorAttribThreaded& func, bool shared, unsigned int nbth = 0);
void foreach_attrib(AttributeContainer& attr_cont, FunctorAttribThreaded& func, unsigned int nbth = 0);
/**
......@@ -165,7 +141,7 @@ void foreach_cell2Pass(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcsFro
* @param good a selector
*/
template <typename MAP, unsigned int CELL>
void foreach_cell2Pass(MAP& map, FunctorMapThreaded<MAP>& funcFront, FunctorMapThreaded<MAP>& funcBack, bool shared, unsigned int nbLoops, unsigned int nbth, bool needMarkers = false, const FunctorSelect& good = allDarts);
void foreach_cell2Pass(MAP& map, FunctorMapThreaded<MAP>& funcFront, FunctorMapThreaded<MAP>& funcBack, unsigned int nbLoops, unsigned int nbth, bool needMarkers = false, const FunctorSelect& good = allDarts);
} // namespace Parallel
......
......@@ -121,7 +121,7 @@ inline unsigned int optimalNbThreads()
template <typename MAP, unsigned int ORBIT>
void foreach_cell(MAP& map, FunctorMapThreaded<MAP>& func, bool shared, unsigned int nbth, bool needMarkers, const FunctorSelect& good, unsigned int currentThread)
void foreach_cell(MAP& map, FunctorMapThreaded<MAP>& func, unsigned int nbth, bool needMarkers, const FunctorSelect& good, unsigned int currentThread)
{
if (nbth == 0)
nbth = optimalNbThreads();
......@@ -129,6 +129,9 @@ void foreach_cell(MAP& map, FunctorMapThreaded<MAP>& func, bool shared, unsigned
std::vector<FunctorMapThreaded<MAP>*> funcs;
funcs.reserve(nbth);
FunctorMapThreaded<MAP>* ptr = func.duplicate();
bool shared = (ptr == NULL);
if (shared)
{
for (unsigned int i = 0; i < nbth; ++i)
......@@ -136,7 +139,8 @@ void foreach_cell(MAP& map, FunctorMapThreaded<MAP>& func, bool shared, unsigned
}
else
{
for (unsigned int i = 0; i < nbth; ++i)
funcs.push_back(ptr);
for (unsigned int i = 1; i < nbth; ++i)
funcs.push_back(func.duplicate());
}
......@@ -339,7 +343,7 @@ void foreach_cell(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs, unsign
template <typename MAP>
void foreach_dart(MAP& map, FunctorMapThreaded<MAP>& func, bool shared, unsigned int nbth, bool needMarkers, const FunctorSelect& good)
void foreach_dart(MAP& map, FunctorMapThreaded<MAP>& func, unsigned int nbth, bool needMarkers, const FunctorSelect& good)
{
if (nbth == 0)
nbth = optimalNbThreads();
......@@ -347,6 +351,9 @@ void foreach_dart(MAP& map, FunctorMapThreaded<MAP>& func, bool shared, unsigned
std::vector<FunctorMapThreaded<MAP>*> funcs;
funcs.reserve(nbth);
FunctorMapThreaded<MAP>* ptr = func.duplicate();
bool shared = (ptr == NULL);
if (shared)
{
for (unsigned int i = 0; i < nbth; ++i)
......@@ -354,7 +361,8 @@ void foreach_dart(MAP& map, FunctorMapThreaded<MAP>& func, bool shared, unsigned
}
else
{
for (unsigned int i = 0; i < nbth; ++i)
funcs.push_back(ptr);
for (unsigned int i = 1; i < nbth; ++i)
funcs.push_back(func.duplicate());
}
......@@ -454,7 +462,7 @@ void foreach_dart(MAP& map, std::vector<FunctorMapThreaded<MAP>*> funcs, unsigne
inline void foreach_attrib(AttributeContainer& attr_cont, FunctorAttribThreaded& func, bool shared, unsigned int nbth)
inline void foreach_attrib(AttributeContainer& attr_cont, FunctorAttribThreaded& func, unsigned int nbth)
{
if (nbth == 0)
nbth = optimalNbThreads();
......@@ -462,6 +470,9 @@ inline void foreach_attrib(AttributeContainer& attr_cont, FunctorAttribThreaded&
std::vector<FunctorAttribThreaded*> funcs;
funcs.reserve(nbth);
FunctorAttribThreaded* ptr = func.duplicate();
bool shared = (ptr == NULL);
if (shared)
{
for (unsigned int i = 0; i < nbth; ++i)
......@@ -469,7 +480,8 @@ inline void foreach_attrib(AttributeContainer& attr_cont, FunctorAttribThreaded&
}
else
{
for (unsigned int i = 0; i < nbth; ++i)
funcs.push_back(ptr);
for (unsigned int i = 1; i < nbth; ++i)
funcs.push_back(func.duplicate());
}
......@@ -696,7 +708,7 @@ void foreach_cell2Pass(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcsFro
template <typename MAP, unsigned int CELL>
void foreach_cell2Pass(MAP& map, FunctorMapThreaded<MAP>& funcFront, FunctorMapThreaded<MAP>& funcBack, bool shared, unsigned int nbLoops, unsigned int nbth, bool needMarkers, const FunctorSelect& good)
void foreach_cell2Pass(MAP& map, FunctorMapThreaded<MAP>& funcFront, FunctorMapThreaded<MAP>& funcBack, unsigned int nbLoops, unsigned int nbth, bool needMarkers, const FunctorSelect& good)
{
if (nbth == 0)
nbth = optimalNbThreads();
......@@ -704,6 +716,9 @@ void foreach_cell2Pass(MAP& map, FunctorMapThreaded<MAP>& funcFront, FunctorMapT
std::vector<FunctorMapThreaded<MAP>*> funcs;
funcs.reserve(nbth);
FunctorMapThreaded<MAP>* ptr = funcFront.duplicate();
bool shared = (ptr == NULL);
if (shared)
{
for (unsigned int i = 0; i < nbth; ++i)
......@@ -713,19 +728,19 @@ void foreach_cell2Pass(MAP& map, FunctorMapThreaded<MAP>& funcFront, FunctorMapT
}
else
{
for (unsigned int i = 0; i < nbth; ++i)
funcs.push_back(ptr);
for (unsigned int i = 1; i < nbth; ++i)
funcs.push_back(funcFront.duplicate());
for (unsigned int i = 0; i < nbth; ++i)
funcs.push_back(funcBack.duplicate());
}
}
foreach_cell2Pass<MAP,CELL>(map,funcs,nbLoops,nbth,needMarkers,good);
if (!shared)
for (unsigned int i = 0; i < nbth; ++i)
for (unsigned int i = 0; i < 2*nbth; ++i)
delete funcs[i];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment