Commit 22d81ee3 authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'thread++11' into develop

Conflicts:
	src/Topology/generic/genericmap.cpp
parents dc4c5b2d c4c16e07
......@@ -459,55 +459,35 @@ void Viewer::cb_keyPress(int keycode)
Utils::Chrono ch;
ch.start();
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
CGoGN::Parallel::NumberOfThreads = 1;
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices1 "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
CGoGN::Parallel::NumberOfThreads = 2;
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices2 "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
CGoGN::Parallel::NumberOfThreads = 3;
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices3 "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
CGoGN::Parallel::NumberOfThreads = 4;
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices4 "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
CGoGN::Parallel::NumberOfThreads = 8;
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices8 "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
for (unsigned int i=0; i<4; ++i)
Parallel::foreach_cell<VERTEX>(myMap, [&] (Vertex v, unsigned int th)
{
normal[v] = Algo::Surface::Geometry::vertexNormal<PFP>(myMap,v,position);
}, false, FORCE_CELL_MARKING);
std::cout << "Parallel::foreach_cell "<< ch.elapsed()<< " ms "<< std::endl;
// ch.start();
// Parallel::foreach_cell_EO<VERTEX>(myMap,[&](Vertex v, unsigned int thr)
......
......@@ -439,8 +439,8 @@ int main(int argc, char **argv)
position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
int nb = 8;
Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, nb, nb, nb);
cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f);
Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, nb, nb, 1);
cubic.embedIntoGrid(position, 1.0f, 1.0f, 0.0f);
for (unsigned int i = position.begin(); i != position.end(); position.next(i))
{
......
......@@ -108,7 +108,7 @@ int main()
{
position[v] += VEC3(0.0, 0.0, PFP::REAL(thread) * 0.1f);
// WARNING thread vary here from 1 to 4 (and not from 0 to 3) !!!!
}, false); // 4:4 thread, false for no need for markers in threaded code.
}); // 4:4 thread, false for no need for markers in threaded code.
std::cout << "After // processing"<< std::endl;
foreach_cell<VERTEX>(myMap, [&] (Vertex v) // for each Vertex v of the MAP myMap
......@@ -132,7 +132,7 @@ int main()
{
// for each face add surface to accumulator (-1 because counter between 1-3 not 0-3)
surf[thr-1] += Algo::Surface::Geometry::convexFaceArea<PFP>(myMap, f, position);
}, false);
});
std::cout << surf[0]<< "/"<< surf[1]<< "/"<< surf[2]<< "/"<< std::endl;
std::cout << "Total="<<surf[0]+surf[1]+surf[2]<< std::endl;
......
......@@ -113,6 +113,8 @@ IF(WIN32)
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "Only Release or Debug" FORCE)
ELSE(WIN32)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fPIC -std=c++11")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
if(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
......
......@@ -236,7 +236,7 @@ void computeAreaFaces(typename PFP::MAP& map, const VertexAttribute<typename PFP
CGoGN::Parallel::foreach_cell<FACE>(map,[&](Face f, unsigned int thr)
{
area[f] = convexFaceArea<PFP>(map, f, position) ;
},false,AUTO);
});
}
......@@ -246,7 +246,7 @@ void computeOneRingAreaVertices(typename PFP::MAP& map, const VertexAttribute<ty
CGoGN::Parallel::foreach_cell<VERTEX>(map,[&](Vertex v, unsigned int thr)
{
area[v] = vertexOneRingArea<PFP>(map, v, position) ;
},false,FORCE_CELL_MARKING);
},FORCE_CELL_MARKING);
}
template <typename PFP>
......@@ -256,7 +256,7 @@ void computeBarycentricAreaVertices(typename PFP::MAP& map, const VertexAttribut
{
vertex_area[v] = vertexBarycentricArea<PFP>(map, v, position) ;
}
,false,FORCE_CELL_MARKING);
,FORCE_CELL_MARKING);
}
template <typename PFP>
......@@ -265,7 +265,7 @@ void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute<ty
CGoGN::Parallel::foreach_cell<VERTEX>(map,[&](Vertex v, unsigned int thr)
{
area[v] = vertexVoronoiArea<PFP>(map, v, position) ;
},false,FORCE_CELL_MARKING);
},FORCE_CELL_MARKING);
}
} // namespace Parallel
......
......@@ -187,7 +187,7 @@ void computeCentroidFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT&
CGoGN::Parallel::foreach_cell<FACE>(map,[&](Face f, unsigned int thr)
{
face_centroid[f] = faceCentroid<PFP>(map, f, position) ;
},false,AUTO);
});
}
template <typename PFP, typename V_ATT, typename F_ATT>
......@@ -196,7 +196,7 @@ void computeCentroidELWFaces(typename PFP::MAP& map, const V_ATT& position, F_AT
CGoGN::Parallel::foreach_cell<FACE>(map,[&](Face f, unsigned int thr)
{
face_centroid[f] = faceCentroidELW<PFP>(map, f, position) ;
},false,AUTO);
});
}
......@@ -207,7 +207,7 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
CGoGN::Parallel::foreach_cell<VERTEX>(map,[&](Vertex v, unsigned int thr)
{
vertex_centroid[v] = vertexNeighborhoodCentroid<PFP>(map, v, position) ;
},false,FORCE_CELL_MARKING);
},FORCE_CELL_MARKING);
}
} // namespace Parallel
......@@ -297,7 +297,7 @@ void computeCentroidVolumes(typename PFP::MAP& map, const V_ATT& position, W_ATT
CGoGN::Parallel::foreach_cell<VOLUME>(map,[&](Vol v, unsigned int thr)
{
vol_centroid[v] = Surface::Geometry::volumeCentroid<PFP,V_ATT>(map, v, position, thr) ;
},true,AUTO);
});
}
template <typename PFP, typename V_ATT, typename W_ATT>
......@@ -306,7 +306,7 @@ void computeCentroidELWVolumes(typename PFP::MAP& map, const V_ATT& position, W_
CGoGN::Parallel::foreach_cell<VOLUME>(map,[&](Vol v, unsigned int thr)
{
vol_centroid[v] = Surface::Geometry::volumeCentroidELW<PFP,V_ATT>(map, v, position, thr) ;
},true,AUTO);
});
}
......
......@@ -667,7 +667,7 @@ void computeCurvatureVertices_NormalCycles(
CGoGN::Parallel::foreach_cell<VERTEX>(map,[&](Vertex v, unsigned int threadID)
{
computeCurvatureVertex_NormalCycles<PFP>(map, v, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal, threadID) ;
},true,FORCE_CELL_MARKING);
},FORCE_CELL_MARKING);
}
template <typename PFP>
......@@ -696,7 +696,7 @@ void computeCurvatureVertices_NormalCycles_Projected(
CGoGN::Parallel::foreach_cell<VERTEX>(map,[&](Vertex v, unsigned int threadID)
{
computeCurvatureVertex_NormalCycles_Projected<PFP>(map, v, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal, threadID) ;
},true,FORCE_CELL_MARKING);
},FORCE_CELL_MARKING);
}
......@@ -714,7 +714,7 @@ void computeCurvatureVertices_QuadraticFitting(
CGoGN::Parallel::foreach_cell<VERTEX>(map,[&](Vertex v, unsigned int threadID)
{
computeCurvatureVertex_QuadraticFitting<PFP>(map, v, position, normal, kmax, kmin, Kmax, Kmin, threadID) ;
},true,FORCE_CELL_MARKING);
},FORCE_CELL_MARKING);
}
......
......@@ -235,7 +235,7 @@ void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT&
CGoGN::Parallel::foreach_cell<VERTEX>(map,[&](Vertex v, unsigned int /*thr*/)
{
normal[v] = vertexNormal<PFP>(map, v, position) ;
},true,FORCE_CELL_MARKING);
},FORCE_CELL_MARKING);
}
template <typename PFP, typename V_ATT, typename F_ATT>
......@@ -244,7 +244,7 @@ void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& no
CGoGN::Parallel::foreach_cell<FACE>(map,[&](Face f, unsigned int thr)
{
normal[f] = faceNormal<PFP>(map, f, position) ;
},true,AUTO);
});
}
......@@ -254,7 +254,7 @@ void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const V_ATT& pos
CGoGN::Parallel::foreach_cell<EDGE>(map,[&](Edge e, unsigned int thr)
{
angles[e] = computeAngleBetweenNormalsOnEdge<PFP>(map, e, position) ;
},true,AUTO);
});
}
} // namespace Parallel
......
......@@ -177,14 +177,7 @@ void foreach_cell(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs, bool n
boost::barrier sync1(nbth+1);
boost::barrier sync2(nbth+1);
bool finished=false;
// lauch threads
if (needMarkers)
{
unsigned int nbth_prec = map.getNbThreadMarkers();
if (nbth_prec < nbth+1)
map.addThreadMarker(nbth+1-nbth_prec);
}
// launch threads
boost::thread** threads = new boost::thread*[nbth];
ThreadFunction<MAP>** tfs = new ThreadFunction<MAP>*[nbth];
......
......@@ -128,7 +128,7 @@ public:
virtual unsigned int getNbBlocks() const = 0;
virtual void addBlocksBefore(unsigned int nbb) = 0;
// virtual void addBlocksBefore(unsigned int nbb) = 0;
virtual bool copy(const AttributeMultiVectorGen* atmvg) = 0;
......@@ -311,6 +311,7 @@ public:
} // namespace CGoGN
#include "attributeMultiVectorBool.hpp"
#include "attributeMultiVector.hpp"
#endif
/*******************************************************************************
* 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 <cstring>
namespace CGoGN
{
class MarkerBool
{
public:
std::string CGoGNnameOfType() const
{
return "MarkerBool";
}
};
//template <>
//class AttributeMultiVector<MarkerBool> : public AttributeMultiVectorGen
//{
// /**
// * table of blocks of data pointers: vectors!
// */
// std::vector< unsigned char* > m_tableData;
//public:
// AttributeMultiVector(const std::string& strName, const std::string& strType):
// AttributeMultiVectorGen(strName, strType)
// {
// m_tableData.reserve(1024);
// }
// AttributeMultiVector()
// {
// m_tableData.reserve(1024);
// }
// ~AttributeMultiVector() {}
// AttributeMultiVectorGen* new_obj()
// {
// AttributeMultiVectorGen* ptr = new AttributeMultiVector<MarkerBool>;
// ptr->setTypeName(m_typeName);
// return ptr;
// }
// /**************************************
// * MULTI VECTOR MANAGEMENT *
// **************************************/
// void addBlock()
// {
// unsigned char* ptr = new unsigned char[_BLOCKSIZE_];
// memset(ptr,0,_BLOCKSIZE_);
// m_tableData.push_back(ptr);
// }
// void setNbBlocks(unsigned int nbb)
// {
// if (nbb >= m_tableData.size())
// {
// for (unsigned int i= m_tableData.size(); i <nbb; ++i)
// addBlock();
// }
// else
// {
// for (unsigned int i = m_tableData.size()-1; i>=nbb; --i)
// delete[] m_tableData[i];
// m_tableData.resize(nbb);
// }
// }
// unsigned int getNbBlocks() const
// {
// return m_tableData.size();
// }
//// void addBlocksBefore(unsigned int nbb);
// bool copy(const AttributeMultiVectorGen* atmvg)
// {
// const AttributeMultiVector<MarkerBool>* atmv = dynamic_cast<const AttributeMultiVector<MarkerBool>*>(atmvg);
// if (atmv == NULL)
// {
// CGoGNerr << "trying to copy attributes of different type" << CGoGNendl;
// return false;
// }
//// if (atmv->m_typeName != m_typeName)
//// {
//// CGoGNerr << "trying to copy attributes with different type names" << CGoGNendl;
//// return false;
//// }
// m_tableData.resize( atmv->m_tableData.size() );
// for (unsigned int i = 0; i < atmv->m_tableData.size(); ++i)
// m_tableData[i] = atmv->m_tableData[i];
// return true;
// }
// bool swap(AttributeMultiVectorGen* atmvg)
// {
// AttributeMultiVector<MarkerBool>* atmv = dynamic_cast<AttributeMultiVector<MarkerBool>*>(atmvg);
// if (atmv == NULL)
// {
// CGoGNerr << "trying to swap attributes of different type" << CGoGNendl;
// return false;
// }
// if (atmv->m_typeName != m_typeName)
// {
// CGoGNerr << "trying to swap attributes with different type names" << CGoGNendl;
// return false;
// }
// m_tableData.swap(atmv->m_tableData) ;
// return true;
// }
// bool merge(const AttributeMultiVectorGen& att)
// {
// const AttributeMultiVector<MarkerBool>* attrib = dynamic_cast< const AttributeMultiVector<MarkerBool>* >(&att);
// if (attrib==NULL)
// {
// CGoGNerr << "trying to merge attributes of different type" << CGoGNendl;
// return false;
// }
// if (attrib->m_typeName != m_typeName)
// {
// CGoGNerr << "trying to merge attributes with different type names" << CGoGNendl;
// return false;
// }
// for (auto it = attrib->m_tableData.begin(); it != attrib->m_tableData.end(); ++it)
// m_tableData.push_back(*it);
// return true;
// }
// void clear()
// {
// m_tableData.clear();
// }
// int getSizeOfType() const
// {
// return sizeof(bool); // ?
// }
// void allFalse()
// {
//// std::cout << "Marker "<<this->getName()<<" - allFalse"<< std::endl;
// for (unsigned int i = 0; i < m_tableData.size(); ++i)
// {
// memset(m_tableData[i],0,_BLOCKSIZE_);
// }
// }
// /**************************************
// * DATA ACCESS *
// **************************************/
// void setFalse(unsigned int i)
// {
// m_tableData[i / _BLOCKSIZE_][i % _BLOCKSIZE_] = 0;
//// std::cout << "Marker "<<this->getName()<<" - ";
//// std::cout << "SET FALSE: "<< this->operator[](i)<< std::endl;
// }
// void setTrue(unsigned int i)
// {
// m_tableData[i / _BLOCKSIZE_][i % _BLOCKSIZE_] = 1;
//// std::cout << "Marker "<<this->getName()<<" - ";
//// std::cout << "SET TRUE: "<< this->operator[](i)<< std::endl;
// }
// void setVal(unsigned int i, bool b)
// {
// m_tableData[i / _BLOCKSIZE_][i % _BLOCKSIZE_] = b;
//// std::cout << "Marker "<<this->getName()<<" - ";
//// std::cout << "SET VAL: "<< b << " -> "<< this->operator[](i)<< std::endl;
// }
// /**
// * get a const reference on a elt
// * @param i index of element
// */
// bool operator[](unsigned int i) const
// {
//// std::cout << "BITS="<<std::hex<< m_tableData[jj][x]<< " MASK="<<mask<<" ~MASK="<<~mask<<std::endl;
// return m_tableData[i / _BLOCKSIZE_][i % _BLOCKSIZE_] !=0;
// }
// /**
// * Get the addresses of each block of data
// */
// unsigned int getBlocksPointers(std::vector<void*>& addr, unsigned int& /*byteBlockSize*/) const
// {
// CGoGNerr << "DO NOT USE getBlocksPointers with bool attribute"<< CGoGNendl;
// return 0;
//// addr.reserve(m_tableData.size());
//// addr.clear();
//// for (auto it = m_tableData.begin(); it != m_tableData.end(); ++it)
//// addr.push_back(NULL );
//// return addr.size();
// }
// /**************************************
// * LINES MANAGEMENT *
// **************************************/
// void initElt(unsigned int id)
// {
//// std::cout << "Marker "<<this->getName()<<" - InitElt"<< std::endl;
// setFalse(id);
// }
// void copyElt(unsigned int dst, unsigned int src)
// {
//// std::cout << "Marker "<<this->getName()<<" - CopyElt"<< std::endl;
// setVal(dst,this->operator [](src));
// }
// void swapElt(unsigned int id1, unsigned int id2)
// {
//// std::cout << "Marker "<<this->getName()<<" - SwapElt"<< std::endl;
// bool data = this->operator [](id1);
// setVal(id1,this->operator [](id2));
// setVal(id2,data);
// }
// /**
// * swap two elements in container (useful for compact function)
// * @param src_b block index of source element
// * @param src_id index in block of source element
// * @param dst_b block index of destination element
// * @param dst_id index in block of destination element
// */
// void overwrite(unsigned int src_b, unsigned int src_id, unsigned int dst_b, unsigned int dst_id)
// {
//// std::cout << "Marker "<<this->getName()<<" - overwrite"<< std::endl;
// m_tableData[dst_b][dst_id] = m_tableData[src_b][src_id];
// }
// /**************************************
// * SAVE & LOAD *
// **************************************/
// /**
// * Sauvegarde binaire
// * @param fs filestream
// * @param id id of mv
// */
// void saveBin(CGoGNostream& fs, unsigned int id)
// {
//// unsigned int nbs[3];
//// nbs[0] = id;
//// int len1 = m_attrName.size()+1;
//// int len2 = m_typeName.size()+1;
//// nbs[1] = len1;
//// nbs[2] = len2;
//// fs.write(reinterpret_cast<const char*>(nbs),3*sizeof(unsigned int));
//// // store names
//// char buffer[256];
//// const char* s1 = m_attrName.c_str();
//// memcpy(buffer,s1,len1);
//// const char* s2 = m_typeName.c_str();
//// memcpy(buffer+len1,s2,len2);
//// fs.write(reinterpret_cast<const char*>(buffer),(len1+len2)*sizeof(char));
//// nbs[0] = m_tableData.size();
//// nbs[1] = nbs[0] * _BLOCKSIZE_/32;
//// fs.write(reinterpret_cast<const char*>(nbs),2*sizeof(unsigned int));
//// for (auto ptrIt = m_tableData.begin(); ptrIt!=m_tableData.end(); ++ptrIt)
//// fs.write(reinterpret_cast<const char*>(*ptrIt),_BLOCKSIZE_/8);
// }
// /**
// * lecture binaire
// * @param fs filestream
// */
// bool loadBin(CGoGNistream& fs)
// {
//// unsigned int nbs[2];
//// fs.read(reinterpret_cast<char*>(nbs), 2*sizeof(unsigned int));
//// unsigned int nb = nbs[0];
//// bool *bbuff = new bool[nb*_BLOCKSIZE_];
//// fs.read(reinterpret_cast<char*>(bbuff),nb*_BLOCKSIZE_*sizeof(bool));
//// // load data blocks
//// m_tableData.resize(nb);
//// for(unsigned int i = 0; i < nb; ++i)
//// {
//// m_tableData[i] = new unsigned int[_BLOCKSIZE_/32];
//// for (unsigned int j=0; j<_BLOCKSIZE_;++j)
//// fs.read(reinterpret_cast<char*>(m_tableData[i]),_BLOCKSIZE_/8);
//// }
// return true;
// }
// /**
// * lecture binaire
// * @param fs filestream
// */
// virtual void dump(unsigned int i) const
// {
// CGoGNout << this->operator[](i);
// }
//};
template <>
class AttributeMultiVector<MarkerBool> : public AttributeMultiVectorGen
{
/**
* table of blocks of data pointers: vectors!
*/
std::vector< unsigned int* > m_tableData;
public:
AttributeMultiVector(const std::string& strName, const std::string& strType):
AttributeMultiVectorGen(strName, strType)
{
m_tableData.reserve(1024);
}
AttributeMultiVector()
{
m_tableData.reserve(1024);