/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include
#include
#include
namespace CGoGN
{
namespace Algo
{
namespace Parallel
{
class ThreadFunctor
{
protected:
FunctorType& m_functor;
const std::vector& m_darts;
boost::barrier& m_sync1;
boost::barrier& m_sync2;
bool& m_finished;
public:
ThreadFunctor(FunctorType& func, const std::vector& vd, boost::barrier& s1, boost::barrier& s2, bool& finished):
m_functor(func), m_darts(vd), m_sync1(s1), m_sync2(s2), m_finished(finished) {}
void operator()()
{
while (!m_finished)
{
for (std::vector::const_iterator it = m_darts.begin(); it != m_darts.end(); ++it)
m_functor(*it);
m_sync1.wait();
m_sync2.wait();
}
}
};
/**
* Traverse orbits of a map in parallel. Use topological marker
* Functor application must be independant
* @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 szbuff size of buffers to store darts in each thread (default is 8192, use less for lower memory consumsion)
* @param good a selector
*/
template
void foreach_orbit(typename PFP::MAP& map, unsigned int orbit, FunctorType& func, unsigned int nbth, unsigned int szbuff, const FunctorSelect& good)
{
std::vector vd[nbth];
boost::thread* threads[nbth];
DartMarker dm(map);
Dart d=map.begin();
// nbth new functions, new thread (with good darts !)
for (unsigned int i=0; i tempo[nbth];
for (unsigned int i=0; ijoin();
delete threads[i];
}
}
/**
* Traverse cells of a map in parallel. Use embedding marker
* Functor application must be independant
* @param map the map
* @param orbit the cell (VERTEX_CELL/EDGE_CELL/FACE_CELL/..
* @param func the functor to apply
* @param nbth number of thread to use (use twice as threads of processor)
* @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
void foreach_cell(typename PFP::MAP& map, unsigned int cell, FunctorType& func, unsigned int nbth, unsigned int szbuff, const FunctorSelect& good)
{
std::vector* vd = new std::vector[nbth];
boost::thread** threads = new boost::thread*[nbth];
CellMarker cm(map,cell);
Dart d=map.begin();
// nbth new functions, new thread (with good darts !)
for (unsigned int i=0; i* tempo = new std::vector[nbth];
for (unsigned int i=0; ijoin();
delete threads[i];
}
delete[] threads;
delete[] vd;
delete[] tempo;
}
template
void foreach_dart(typename PFP::MAP& map, FunctorType& func, unsigned int nbth, unsigned int szbuff, const FunctorSelect& good)
{
std::vector vd[nbth];
boost::thread* threads[nbth];
Dart d=map.begin();
// nbth new functions, new thread (with good darts !)
for (unsigned int i=0; i tempo[nbth];
for (unsigned int i=0; ijoin();
delete threads[i];
}
}
}
} // end namespace
}