Commit c5be02f7 authored by Sylvain Thery's avatar Sylvain Thery

Optimize & simplify parallel foreach

- use automatically orbit or cell & quicktraversal
- DartMarker & CellMarker now thread safe
parent 0c4ea341
This diff is collapsed.
......@@ -27,8 +27,20 @@
#include <iostream>
#include "Utils/Qt/qtSimple.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap3.h"
#include "Geometry/vector_gen.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/cgognStream.h"
#include "Utils/Qt/qtSimple.h"
// forward definitions (minimize includes)
namespace CGoGN { namespace Algo { namespace Render { namespace GL1 { class MapRender; } } } }
......@@ -45,21 +57,67 @@ class MyQT: public Utils::QT::SimpleQT
Q_OBJECT
public:
MyQT()
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO;
Utils::VBO* m_normalVBO;
Utils::ShaderSimpleColor* m_shader;
Utils::ShaderVectorPerVertex* m_lines;
MyQT():
m_render(NULL),
m_positionVBO(NULL),
m_normalVBO(NULL),
m_shader(NULL),
m_lines(NULL)
{}
// callbacks of simpleQT to overdefine:
protected:
void cb_redraw();
void cb_initGL();
void cb_Open();
void threadSimple();
void threadAttrib();
void threadStorage();
void cb_New();
void cb_keyPress(int code);
// callbacks (slots) locally defined
public slots:
void menu_slot1();
};
//class MyQT: public Utils::QT::SimpleQT
//{
// Q_OBJECT
//
//public:
// MyQT()
// {}
//
// // callbacks of simpleQT to overdefine:
// void cb_redraw();
//
// void cb_initGL();
//
// void cb_Open();
//
// void cb_New();
//
//// callbacks (slots) locally defined
//public slots:
// void menu_slot1();
//};
#endif
This diff is collapsed.
This diff is collapsed.
......@@ -95,7 +95,7 @@ public:
map.addEmbedding<CELL>() ;
m_mark = m_map.getMarkerSet<CELL>(m_thread).getNewMark() ;
m_markVector = m_map.getMarkVector<CELL>(m_thread) ;
m_map.cellMarkers.push_back(this) ;
m_map.cellMarkers[m_thread].push_back(this) ;
}
virtual ~CellMarkerBase()
......@@ -103,12 +103,14 @@ public:
if(releaseOnDestruct)
{
m_map.getMarkerSet<CELL>(m_thread).releaseMark(m_mark) ;
for(std::vector<CellMarkerGen*>::iterator it = m_map.cellMarkers.begin(); it != m_map.cellMarkers.end(); ++it)
std::vector<CellMarkerGen*>& cmg = m_map.cellMarkers[m_thread];
for(std::vector<CellMarkerGen*>::iterator it = cmg.begin(); it != cmg.end(); ++it)
{
if(*it == this)
{
*it = m_map.cellMarkers.back();
m_map.cellMarkers.pop_back();
*it = cmg.back();
cmg.pop_back();
return;
}
}
......
......@@ -46,6 +46,7 @@ protected:
Mark m_mark ;
AttributeMultiVector<Mark>* m_markVector ;
unsigned int m_thread ;
unsigned int m_idReg ;
bool releaseOnDestruct ;
public:
......@@ -57,7 +58,7 @@ public:
{
m_mark = m_map.getMarkerSet<DART>(m_thread).getNewMark() ;
m_markVector = m_map.getMarkVector<DART>(m_thread) ;
m_map.dartMarkers.push_back(this) ;
m_map.dartMarkers[m_thread].push_back(this) ;
}
virtual ~DartMarkerGen()
......@@ -65,12 +66,13 @@ public:
if(releaseOnDestruct)
{
m_map.getMarkerSet<DART>(m_thread).releaseMark(m_mark) ;
for(std::vector<DartMarkerGen*>::iterator it = m_map.dartMarkers.begin(); it != m_map.dartMarkers.end(); ++it)
std::vector<DartMarkerGen*>& dmg = m_map.dartMarkers[m_thread];
for(std::vector<DartMarkerGen*>::iterator it = dmg.begin(); it != dmg.end(); ++it)
{
if(*it == this)
{
*it = m_map.dartMarkers.back();
m_map.dartMarkers.pop_back();
*it = dmg.back();
dmg.pop_back();
return;
}
}
......
......@@ -432,6 +432,65 @@ public:
} ;
//
// FOR PARALLEL TRAVERSALS
//
/**
* Functor class for parallel::foreach_orbit/cell/dart
* Overload bool parallelDo
* Overload duplicate if necessary (no sharing of functors)
*/
template<typename MAP>
class FunctorMapThreaded
{
protected:
MAP& m_map ;
public:
FunctorMapThreaded(MAP& m): m_map(m) {}
virtual ~FunctorMapThreaded() {}
/**
* @return a pointer on a copy of the object.
*/
virtual FunctorMapThreaded<MAP>* duplicate() const { return NULL;}
/**
* insert your code here:
* @param d the dart on which apply functor
* @param threadID the id of thread currently running your code
*/
virtual void parallelDo(Dart d, unsigned int threadID) = 0;
};
/**
* Functor class for parallel::foreach_attrib
* Overload parallelDo
* Overload duplicate if necessary (no sharing of functors)
*/
class FunctorAttribThreaded
{
public:
virtual ~FunctorAttribThreaded() {}
/**
* @return a pointer on a copy of the object.
*/
virtual FunctorAttribThreaded* duplicate() const { return NULL;}
/**
* insert your code here:
* @param d the dart on which apply functor
* @param threadID the id of thread currently running your code
*/
virtual void parallelDo(unsigned int i, unsigned int threadID) = 0;
};
} //namespace CGoGN
#endif
......@@ -112,9 +112,11 @@ protected:
/**
* Store links to created AttributeHandlers, DartMarkers and CellMarkers
*/
std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ;
std::vector<DartMarkerGen*> dartMarkers ;
std::vector<CellMarkerGen*> cellMarkers ;
std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ; // TODO think of MT (AttributeHandler creation & release are not thread safe!
std::vector<DartMarkerGen*> dartMarkers[NB_THREAD] ;
std::vector<CellMarkerGen*> cellMarkers[NB_THREAD] ;
/**
* is map a multiresolution map
......
......@@ -43,17 +43,23 @@ void AttribMap::init()
}
}
for(unsigned int i = 0; i < cellMarkers.size(); ++i)
for (unsigned int j=0; j<NB_THREAD; ++j)
{
CellMarkerGen* cm = cellMarkers[i] ;
std::vector<CellMarkerGen*>& cmg = cellMarkers[j];
for(unsigned int i = 0; i < cmg.size(); ++i)
{
CellMarkerGen* cm = cmg[i] ;
cm->updateMarkVector(m_markTables[cm->getCell()][cm->getThread()]) ;
}
for(unsigned int i = 0; i < dartMarkers.size(); ++i)
std::vector<DartMarkerGen*>& dmg = dartMarkers[j];
for(unsigned int i = 0; i < dmg.size(); ++i)
{
DartMarkerGen* cm = dartMarkers[i] ;
DartMarkerGen* cm = dmg[i] ;
cm->updateMarkVector(m_markTables[DART][cm->getThread()]) ;
}
}
}
AttribMap::AttribMap() : GenericMap()
......
......@@ -84,8 +84,11 @@ GenericMap::GenericMap() : m_nbThreads(1)
}
}
dartMarkers.reserve(16) ;
cellMarkers.reserve(16) ;
for (unsigned int i=0; i<NB_THREAD; ++i)
{
dartMarkers[i].reserve(16) ;
cellMarkers[i].reserve(16) ;
}
// get & lock marker for boundary
m_boundaryMarker = m_marksets[DART][0].getNewMark();
......@@ -106,23 +109,21 @@ GenericMap::~GenericMap()
m_attribs[i].clear(true) ;
}
for(std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator it = attributeHandlers.begin(); it != attributeHandlers.end(); ++it)
(*it).second->setInvalid() ;
attributeHandlers.clear() ;
for(std::vector<DartMarkerGen*>::iterator it = dartMarkers.begin(); it != dartMarkers.end(); ++it)
for (unsigned int i=0; i<NB_THREAD; ++i)
{
for(std::vector<DartMarkerGen*>::iterator it = dartMarkers[i].begin(); it != dartMarkers[i].end(); ++it)
(*it)->setReleaseOnDestruct(false) ;
dartMarkers.clear() ;
dartMarkers[i].clear() ;
for(std::vector<CellMarkerGen*>::iterator it = cellMarkers.begin(); it != cellMarkers.end(); ++it)
for(std::vector<CellMarkerGen*>::iterator it = cellMarkers[i].begin(); it != cellMarkers[i].end(); ++it)
(*it)->setReleaseOnDestruct(false) ;
cellMarkers.clear() ;
// if(m_attributes_registry_map)
// {
// delete m_attributes_registry_map;
// m_attributes_registry_map = NULL;
// }
cellMarkers[i].clear() ;
}
// clean type registry if necessary
m_nbInstances--;
......
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