Commit a573b38f authored by Sylvain Thery's avatar Sylvain Thery

update //

parent 31c9ff1a
......@@ -666,6 +666,10 @@ public:
typename PFP::VEC3 n2 = Algo::Geometry::vertexNormal<PFP>(this->m_map, this->m_map.phi1(d), m_positions);
typename PFP::VEC3 n3 = Algo::Geometry::vertexNormal<PFP>(this->m_map, this->m_map.phi_1(d), m_positions);
typename PFP::VEC3 n = n1+n2+n3;
n1 = Algo::Geometry::vertexNormal<PFP>(this->m_map, d, m_positions);
n2 = Algo::Geometry::vertexNormal<PFP>(this->m_map, this->m_map.phi1(d), m_positions);
n3 = Algo::Geometry::vertexNormal<PFP>(this->m_map, this->m_map.phi_1(d), m_positions);
n += n1+n2+n3;
n.normalize();
m_normals[d] = n;
// m_normals[d] = Algo::Geometry::vertexNormal<PFP>(this->m_map, d, m_positions);
......@@ -718,32 +722,26 @@ int main(int argc, char **argv)
std::cout << " linear "<< seconds << "sec" << std::endl;
t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Geometry::computeNormalVertices<PFP>(myMap,position,normal,SelectorTrue());
t2 = glutGet(GLUT_ELAPSED_TIME);
seconds = (t2 - t1) / 1000.0f;
std::cout << " compute direct "<< seconds << "sec" << std::endl;
// t1 = glutGet(GLUT_ELAPSED_TIME);
// Algo::Geometry::computeNormalVertices<PFP>(myMap,position,normal,SelectorTrue());
// t2 = glutGet(GLUT_ELAPSED_TIME);
// seconds = (t2 - t1) / 1000.0f;
// std::cout << " compute direct "<< seconds << "sec" << std::endl;
TestFunctor<PFP> tf2(myMap,position,normal2);
t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,4);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,4);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,4);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,4);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,4,1024);
t2 = glutGet(GLUT_ELAPSED_TIME);
seconds = (t2 - t1) / 1000.0f;
std::cout << " parallel 4 "<< seconds << "sec" << std::endl;
std::cout << " parallel 4, 1024 "<< seconds << "sec" << std::endl;
t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,4,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,4,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,4,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,4,8192);
t2 = glutGet(GLUT_ELAPSED_TIME);
......@@ -753,9 +751,6 @@ int main(int argc, char **argv)
t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,8,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,8,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,8,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,8,8192);
t2 = glutGet(GLUT_ELAPSED_TIME);
......@@ -766,21 +761,6 @@ int main(int argc, char **argv)
t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,16,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,16,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,16,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,16,8192);
t2 = glutGet(GLUT_ELAPSED_TIME);
seconds = (t2 - t1) / 1000.0f;
std::cout << " parallel 16/8192 "<< seconds << "sec" << std::endl;
t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,32,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,32,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,32,8192);
Algo::Parallel::foreach_cell<PFP>(myMap,VERTEX_ORBIT, tf2,32,8192);
t2 = glutGet(GLUT_ELAPSED_TIME);
seconds = (t2 - t1) / 1000.0f;
......
Dépendences Linux:
installer les paquets suivants:
cmake libXi-dev libXmu-dev freeglut3-dev libdevil-dev libglew-dev libgmp3-dev libxml2-dev libboost-dev
cmake libXi-dev libXmu-dev freeglut3-dev libdevil-dev libglew-dev libgmp3-dev libxml2-dev libboost-dev lizip-dev
Pour compiler CGoGN:
......
......@@ -108,6 +108,26 @@ void computeNormalFaces(typename PFP::MAP& map, const typename PFP::TVEC3& posit
}
}
template <typename PFP>
class computeNormalVerticesFunctor: public FunctorMap<typename PFP::MAP>
{
protected:
typename PFP::MAP& m_map;
const typename PFP::TVEC3& m_position;
typename PFP::TVEC3& m_normal;
public:
computeNormalVerticesFunctor(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& normal):
m_map(map), m_position(position), m_normal(normal) {}
bool operator()(Dart d)
{
m_normal[d] = vertexNormal<PFP>(m_map, d, m_position) ;
return false;
}
};
template <typename PFP>
void computeNormalVertices(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& normal, const FunctorSelect& select, unsigned int thread)
{
......
......@@ -44,7 +44,7 @@ namespace Parallel
* @param map the map
* @param orbit the orbit (VERTEX_ORBIT/EDGE_ORBIT/FACE_ORBIT/..
* @param func the functor to apply
* @param nbth number of thread to use ((use twice as threads of processor)
* @param nbth number of thread to use
* @param szbuff size of buffers to store darts in each thread (default is 8192, use less for lower memory consumsion)
* @param good a selector
*/
......@@ -66,6 +66,20 @@ template <typename PFP>
void foreach_cell(typename PFP::MAP& map, unsigned int cell, FunctorType& func, unsigned int nbth, unsigned int szbuff=8192, const FunctorSelect& good= SelectorTrue());
/**
* Traverse darts of a map in parallel
* Functor application must be independant
* @param map the map
* @param func the functor to apply
* @param nbth number of thread to use
* @param szbuff size of buffers to store darts in each thread (default is 8192, use less for lower memory consumsion)
* @param good a selector
*/
template <typename PFP>
void foreach_dart(typename PFP::MAP& map, FunctorType& func, unsigned int nbth, unsigned int szbuff=8192, const FunctorSelect& good= SelectorTrue());
}
} // end namespace
}
......
......@@ -228,6 +228,78 @@ void foreach_cell(typename PFP::MAP& map, unsigned int cell, FunctorType& func,
}
template <typename PFP>
void foreach_dart(typename PFP::MAP& map, FunctorType& func, unsigned int nbth, unsigned int szbuff, const FunctorSelect& good)
{
std::vector<Dart> vd[nbth];
boost::thread* threads[nbth];
Dart d=map.begin();
// nbth new functions, new thread (with good darts !)
for (unsigned int i=0; i<nbth; ++i)
vd[i].reserve(szbuff);
// fill each vd buffers with 4096 darts
unsigned int nb =0;
while (( d != map.end()) && (nb < nbth*szbuff) )
{
if (good(d))
{
vd[nb%nbth].push_back(d);
nb++;
}
map.next(d);
}
boost::barrier sync1(nbth+1);
boost::barrier sync2(nbth+1);
bool finished=false;
// lauch threads
for (unsigned int i=0; i<nbth; ++i)
threads[i] = new boost::thread(ThreadFunctor(func, vd[i],sync1,sync2, finished));
// and continue to traverse the map
std::vector<Dart> tempo[nbth];
for (unsigned int i=0; i<nbth; ++i)
tempo[i].reserve(szbuff);
while ( d != map.end())
{
for (unsigned int i=0; i<nbth; ++i)
tempo[i].clear();
unsigned int nb =0;
while (( d != map.end()) && (nb < nbth*szbuff) )
{
if (good(d))
{
tempo[nb%nbth].push_back(d);
nb++;
}
map.next(d);
}
sync1.wait();
for (unsigned int i=0; i<nbth; ++i)
vd[i].swap(tempo[i]);
sync2.wait();
}
sync1.wait();
finished = true;
sync2.wait();
//wait for all theads to be finished
for (unsigned int i=0; i< nbth; ++i)
{
threads[i]->join();
delete threads[i];
}
}
}
} // end namespace
}
......
......@@ -69,7 +69,8 @@ GenericMap::GenericMap()
{
m_attribs[i].setRegistry(m_attributes_registry_map) ;
m_embeddings[i] = NULL ;
m_markerTables[i][0] = NULL ;
for (unsigned int j = 0; j < NBTHREAD; ++j)
m_markerTables[i][j] = NULL ;
}
}
......
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