Commit ba13f792 authored by Pierre Kraemer's avatar Pierre Kraemer

remove deprecated parallel_foreach

parent a5c5ec19
......@@ -97,8 +97,8 @@ target_link_libraries( tuto_histo
# exemple: BOOST_LIBS(boost_lib_lists "boost_thread-mt;boost_iostreams-mt")
#BOOST_LIBS(boost_lib_lists "boost_thread-mt")
QT4_WRAP_CPP(tuto_mt_moc tuto_mt.h)
add_executable( tuto_mt tuto_mt.cpp ${tuto_mt_moc})
target_link_libraries( tuto_mt
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ${Boost_THREAD_LIBRARY})
#QT4_WRAP_CPP(tuto_mt_moc tuto_mt.h)
#add_executable( tuto_mt tuto_mt.cpp ${tuto_mt_moc})
#target_link_libraries( tuto_mt
# ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ${Boost_THREAD_LIBRARY})
......@@ -39,8 +39,6 @@
//#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Tiling/Surface/square.h"
#include "Algo/Parallel/parallel_foreach.h"
#include "Utils/cgognStream.h"
#include "Utils/chrono.h"
......
......@@ -43,6 +43,6 @@ TARGET_LINK_LIBRARIES( SCHNAppsD
ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/Plugins PluginsD)
IF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins)
ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/../../Plugins ExtPluginsD)
ENDIF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins)
#IF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins)
# ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/../../Plugins ExtPluginsD)
#ENDIF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins)
......@@ -43,6 +43,6 @@ TARGET_LINK_LIBRARIES( SCHNApps
ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/Plugins Plugins)
IF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins)
ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/../../Plugins ExtPlugins)
ENDIF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins)
#IF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins)
# ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/../../Plugins ExtPlugins)
#ENDIF(IS_DIRECTORY ${SCHNApps_ROOT_DIR}/../../Plugins)
......@@ -27,7 +27,6 @@
#include "Topology/generic/traversor/traversor2.h"
#include "Topology/generic/traversor/traversorCell.h"
#include "Topology/generic/traversor/traversor3.h"
#include "Algo/Parallel/parallel_foreach.h"
namespace CGoGN
{
......
......@@ -28,8 +28,6 @@
#include "Topology/generic/traversor/traversorCell.h"
#include "Topology/generic/traversor/traversor2.h"
#include "Algo/Parallel/parallel_foreach.h"
#include <cmath>
namespace CGoGN
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, 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: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __PARALLEL_FOREACH__
#define __PARALLEL_FOREACH__
#include "Topology/generic/functor.h"
namespace CGoGN
{
namespace Algo
{
namespace Parallel
{
static unsigned int NBCORES = 0;
/// enum for optimalNbThreads parameter
enum NbParam {NB_HIGHMEMORY, NB_HIGHCOMPUTE, NB_VERYHIGHMEMORY};
/// size of buffers to store darts or indexes in each threads
const unsigned int SIZE_BUFFER_THREAD = 8192; // seems to be the best compromise
/**
* @return How much threads has you computer
*/
inline unsigned int nbThreads();
/**
* @param p can be NB_HIGHMEMORY (default) or NB_HIGHCOMPUTE or NB_VERYHIGHMEMORY
* @return Number of core in fact (work only with quad core with/without hyper threading)
*/
unsigned int optimalNbThreads( NbParam p=NB_HIGHMEMORY);
/**
* impossible to automatically determine the number of cores so ...
*/
void setNbCore(unsigned int nb);
//
//template <typename MAP>
//class Foreach
//{
// MAP& m_map;
//
// std::vector<FunctorMapThreaded<MAP>*> m_funcs;
//
// std::vector<Dart>* m_vd;
//
// unsigned int m_nbth;
//
//public:
// Foreach(MAP& map,unsigned int nbth);
//
// void clearFunctors();
//
// void addFunctor(FunctorMapThreaded<MAP>* funcPtr);
//
// template<typename T>
// T* getFunctor(unsigned int i);
//
// template <unsigned int ORBIT>
// void traverseCell(bool needMarkers = false, unsigned int currentThread = 0);
//
// template <unsigned int ORBIT>
// void traverseEachCell(bool needMarkers = false, unsigned int currentThread = 0);
//
// void traverseDart(bool needMarkers = false, unsigned int currentThread = 0);
//
// void traverseEachDart(bool needMarkers = false, unsigned int currentThread = 0);
//};
/**
* Traverse cells of a map in parallel. Use quick traversal, cell markers or dart markers if available !
* 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 to apply (size of vector determine number of threads, and all functors must be of the same type)
* @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 !!
*/
template <typename MAP, unsigned int ORBIT>
void foreach_cell(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs, bool needMarkers = false);
/**
* Traverse cells of a map in parallel. Use quick traversal, cell markers or dart markers if available !
* Use this version if you do not need to keep functors
* @param map the map
* @param func the functor to apply
* @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 !!
*/
template <typename MAP, unsigned int ORBIT>
void foreach_cell(MAP& map, FunctorMapThreaded<MAP>& func, unsigned int nbth = 0, bool needMarkers = false);
/**
* Traverse cells of a map and apply differents functors in //
* 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 to apply ( each functors can (should!) be here of different type)
* @param nbth number of threads
* @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 !!
*/
template <typename MAP, unsigned int ORBIT>
void foreach_cell_all_thread(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs, bool needMarkers = false);
/**
* Traverse darts of a map in parallel
* 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 to apply (size of vector determine number of threads, and all functors must be of the same type)
* @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 !!
*/
template <typename MAP>
void foreach_dart(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs, unsigned int nbth, bool needMarkers = false);
/**
* Traverse darts of a map in parallel
* @param map the map
* @param funcs the functor
* @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 !!
*/
template <typename MAP>
void foreach_dart(MAP& map, FunctorMapThreaded<MAP>& func, unsigned int nbth = 0, bool needMarkers = false);
/**
* Traverse all elements of an attribute container (attribute handler is placed in FunctorAttribThreaded)
* @param attr_cont the attribute container to traverse
* @param func the fonctors to use
*/
void foreach_attrib(AttributeContainer& attr_cont, std::vector<FunctorAttribThreaded*> funcs);
/**
* 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 nbth number of thread to use for computation 0 for let the system choose
*/
void foreach_attrib(AttributeContainer& attr_cont, FunctorAttribThreaded& func, unsigned int nbth = 0);
/**
* Optimized version for // foreach with to pass (2 functors), with several loops
* Use this version if you need to keep functors
* @param map the map
* @param funcsFrontnBack nbth front pass functors followed by nbth back pass functors
* @param nbLoops number of loops to execute
* @param needMarkers set to yes if you want that each thread use different markers (markers are allocated if necessary)
*/
template <typename MAP, unsigned int CELL>
void foreach_cell2Pass(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcsFrontnBack, unsigned int nbLoops, bool needMarkers = false);
/**
* Optimized version for // foreach with to pass (2 functors), with several loops
* Use this version if you do not need to keep functors
* @param map the map
* @param funcFront front pass functor
* @param funcBack back pass functor
* @param nbLoops number of loops to execute
* @param nbth number of threads to use
* @param needMarkers set to yes if you want that each thread use different markers (markers are allocated if necessary)
*/
template <typename MAP, unsigned int CELL>
void foreach_cell2Pass(MAP& map, FunctorMapThreaded<MAP>& funcFront, FunctorMapThreaded<MAP>& funcBack, unsigned int nbLoops, unsigned int nbth, bool needMarkers = false);
} // namespace Parallel
} // namespace Algo
} // namespace CGoGN
#include "Algo/Parallel/parallel_foreach.hpp"
#endif
This diff is collapsed.
......@@ -45,7 +45,7 @@ namespace CGoGN
enum TraversalOptim {AUTO=0, FORCE_DART_MARKING, FORCE_CELL_MARKING, FORCE_QUICK_TRAVERSAL};
template <typename MAP, unsigned int ORBIT, TraversalOptim OPT=AUTO>
template <typename MAP, unsigned int ORBIT, TraversalOptim OPT = AUTO>
class TraversorCell
{
protected:
......@@ -63,7 +63,7 @@ protected:
bool firstTraversal ;
// just for odd/even versions
TraversorCell(const TraversorCell<MAP, ORBIT,OPT>& tc);
TraversorCell(const TraversorCell<MAP, ORBIT, OPT>& tc);
public:
TraversorCell(const MAP& map, bool forceDartMarker = false, unsigned int thread = 0) ;
......@@ -84,24 +84,24 @@ public:
template <typename MAP, unsigned int ORBIT, TraversalOptim OPT=AUTO>
class TraversorCellEven : public TraversorCell<MAP,ORBIT,OPT>
template <typename MAP, unsigned int ORBIT, TraversalOptim OPT = AUTO>
class TraversorCellEven : public TraversorCell<MAP, ORBIT, OPT>
{
public:
TraversorCellEven(const TraversorCell<MAP,ORBIT,OPT>& tra):
TraversorCell<MAP,ORBIT,OPT>(tra) {}
~TraversorCellEven() { this->cmark = NULL; this->dmark=NULL; }
TraversorCellEven(const TraversorCell<MAP,ORBIT, OPT>& tra):
TraversorCell<MAP, ORBIT, OPT>(tra) {}
~TraversorCellEven() { this->cmark = NULL; this->dmark = NULL; }
inline Cell<ORBIT> begin() ;
} ;
template <typename MAP, unsigned int ORBIT, TraversalOptim OPT=AUTO>
class TraversorCellOdd : public TraversorCell<MAP,ORBIT,OPT>
template <typename MAP, unsigned int ORBIT, TraversalOptim OPT = AUTO>
class TraversorCellOdd : public TraversorCell<MAP, ORBIT, OPT>
{
public:
TraversorCellOdd(const TraversorCell<MAP,ORBIT,OPT>& tra):
TraversorCell<MAP,ORBIT,OPT>(tra) {}
~TraversorCellOdd() {this->cmark = NULL; this->dmark=NULL; }
TraversorCellOdd(const TraversorCell<MAP, ORBIT, OPT>& tra):
TraversorCell<MAP, ORBIT, OPT>(tra) {}
~TraversorCellOdd() {this->cmark = NULL; this->dmark = NULL; }
inline Cell<ORBIT> begin() ;
inline Cell<ORBIT> next() ;
} ;
......@@ -145,32 +145,32 @@ void foreach_cell(MAP& map, FUNC func, TraversalOptim opt = AUTO, unsigned int n
template <typename MAP, TraversalOptim OPT=AUTO>
class TraversorV : public TraversorCell<MAP, VERTEX,OPT>
template <typename MAP, TraversalOptim OPT = AUTO>
class TraversorV : public TraversorCell<MAP, VERTEX, OPT>
{
public:
TraversorV(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, VERTEX>(m, false, thread)
{}
};
template <typename MAP, TraversalOptim OPT=AUTO>
class TraversorE : public TraversorCell<MAP, EDGE,OPT>
template <typename MAP, TraversalOptim OPT = AUTO>
class TraversorE : public TraversorCell<MAP, EDGE, OPT>
{
public:
TraversorE(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, EDGE>(m, false, thread)
{}
};
template <typename MAP, TraversalOptim OPT=AUTO>
class TraversorF : public TraversorCell<MAP, FACE,OPT>
template <typename MAP, TraversalOptim OPT = AUTO>
class TraversorF : public TraversorCell<MAP, FACE, OPT>
{
public:
TraversorF(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, FACE>(m, false, thread)
{}
};
template <typename MAP, TraversalOptim OPT=AUTO>
class TraversorW : public TraversorCell<MAP, VOLUME,OPT>
template <typename MAP, TraversalOptim OPT = AUTO>
class TraversorW : public TraversorCell<MAP, VOLUME, OPT>
{
public:
TraversorW(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, VOLUME>(m, false, thread)
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, 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: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Topology/generic/genericmap.h"
#include "Algo/Parallel/parallel_foreach.h"
namespace CGoGN
{
namespace Algo
{
namespace Parallel
{
void setNbCore(unsigned int nb)
{
NBCORES = nb;
}
void foreach_attrib(AttributeContainer& attr_cont, FunctorAttribThreaded& func, unsigned int nbth)
{
if (nbth == 0)
nbth = optimalNbThreads();
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)
funcs.push_back(&func);
}
else
{
funcs.push_back(ptr);
for (unsigned int i = 1; i < nbth; ++i)
funcs.push_back(func.duplicate());
}
foreach_attrib(attr_cont,funcs);
if (!shared)
for (unsigned int i = 0; i < nbth; ++i)
delete funcs[i];
}
void foreach_attrib(AttributeContainer& attr_cont, std::vector<FunctorAttribThreaded*> funcs)
{
unsigned int nbth = funcs.size();
std::vector<unsigned int >* vid = new std::vector<unsigned int>[2*nbth];
boost::thread** threads = new boost::thread*[nbth];
for (unsigned int i = 0; i < 2*nbth; ++i)
vid[i].reserve(SIZE_BUFFER_THREAD);
// fill each vid buffers with 4096 id
unsigned int id = attr_cont.begin();
unsigned int nb = 0;
unsigned int nbm = nbth*SIZE_BUFFER_THREAD;
while ((id != attr_cont.end()) && (nb < nbm))
{
vid[nb%nbth].push_back(id);
nb++;
attr_cont.next(id);
}
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(ThreadFunctionAttrib(funcs[i], vid[i],sync1,sync2, finished,1+i));
while (id != attr_cont.end())
{
for (unsigned int i = nbth; i < 2*nbth; ++i)
vid[i].clear();
unsigned int nb = 0;
while ((id != attr_cont.end()) && (nb < nbm))
{
vid[nbth + nb%nbth].push_back(id);
nb++;
attr_cont.next(id);
}
sync1.wait();
for (unsigned int i = 0; i < nbth; ++i)
vid[i].swap(vid[nbth+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];
}
delete[] threads;
delete[] vid;
}
}
} // end namespaces
}
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