nouveau fichier : include/ArrayTree/ArrayTreeBuilder.tpp nouveau fichier : include/ArrayTree/Border.hpp nouveau fichier : include/ArrayTree/GraphWalker.hpp nouveau fichier : include/ArrayTree/Leader.hpp nouveau fichier : include/ArrayTree/Weight.hpp nouveau fichier : include/ArrayTree/Weight.tpp nouveau fichier : include/ArrayTree/triskeleArrayTreeBase.hpp nouveau fichier : include/ArrayTree/triskeleSort.hpp nouveau fichier : include/ArrayTree/triskeleSort.tpp modifié : include/Attribute.hpp modifié : include/Attributes/AreaAttribute.hpp supprimé : include/BuildTree.hpp supprimé : include/DAPTree/Border.hpp supprimé : include/DAPTree/DAPTreeBuilder.hpp supprimé : include/DAPTree/DAPTreeBuilder.tpp supprimé : include/DAPTree/GraphWalker.hpp supprimé : include/DAPTree/ParRnk.hpp supprimé : include/DAPTree/Weight.hpp supprimé : include/DAPTree/baseDAPTree.hpp supprimé : include/DAPTree/sort.hpp nouveau fichier : include/IImage.hpp nouveau fichier : include/IImage.tpp supprimé : include/ImageInterface.hpp supprimé : include/ImageInterface.tpp modifié : include/QuadTree/QuadTreeBuilder.hpp modifié : include/Tree.hpp nouveau fichier : include/TreeBuilder.hpp supprimé : include/TreeOfShapesGeraud/ToSBuilder.hpp supprimé : include/TreeOfShapesGeraud/ToSutils.hpp modifié : include/XMLTree/XMLTreeBuilder.hpp supprimé : include/baseDef.hpp supprimé : include/getType.hpp nouveau fichier : include/triskeleBase.hpp renommé : include/dealThreads.hpp -> include/triskeleDealThreads.hpp nouveau fichier : include/triskeleDealThreads.tpp renommé : include/debug.hpp -> include/triskeleDebug.hpp nouveau fichier : include/triskeleGdalGetType.hpp modifié : otb-module.cmake nouveau fichier : src/ArrayTree/triskeleArrayTreeBase.cpp modifié : src/Attribute.cpp modifié : src/Attributes/AreaAttribute.cpp modifié : src/CMakeLists.txt supprimé : src/DAPTree/GraphWalker.cpp supprimé : src/DAPTree/ParRnk.cpp supprimé : src/DAPTree/baseDAPTree.cpp supprimé : src/DAPTree/sort.cpp modifié : src/QuadTree/QuadTreeBuilder.cpp modifié : src/Tree.cpp supprimé : src/TreeOfShapesGeraud/ToSBuilder.cpp supprimé : src/TreeOfShapesGeraud/ToSutils.cpp modifié : src/XMLTree/XMLTreeBuilder.cpp supprimé : src/debug.cpp modifié : src/testMain.cpp nouveau fichier : src/triskeleDebug.cpp supprimé : tests/ToSGeraudCoord.txt supprimé : tests/ToSGeraudIdx.ods
142 lines
5.0 KiB
C++
142 lines
5.0 KiB
C++
#ifndef _TRISKELE_DEAL_THREADS_TPP
|
|
#define _TRISKELE_DEAL_THREADS_TPP
|
|
|
|
// ----------------------------------------
|
|
template<typename DimImg, typename WeightT, typename WeightFunct, typename CmpFunct, typename CallFunct>
|
|
inline void
|
|
callOnSortedSets (const std::vector<DimImg> &sizes,
|
|
const WeightFunct &getWeight/* getWeight (vectId, itemId) */,
|
|
CmpFunct isWeightInf/* isWeightInf (w1, w2) */,
|
|
const CallFunct &callIdId/* callIdId (vectId, itemId) */);
|
|
|
|
// ========================================
|
|
template<typename DimImg, typename FunctId>
|
|
inline void
|
|
dealThreadRange (const DimImg &maxId, const unsigned int &coreCount, const FunctId &functId/* functId (id) */) {
|
|
dealThread (maxId, coreCount, [&functId] (const unsigned int &threadId, const DimImg &minVal, const DimImg &maxVal) {
|
|
for (DimImg id = minVal; id < maxVal; ++id)
|
|
functId (id);
|
|
});
|
|
}
|
|
|
|
// ----------------------------------------
|
|
template<typename DimImg, typename FunctThreadId>
|
|
inline void
|
|
dealThreadThreadRange (const DimImg &maxId, const unsigned int &coreCount, const FunctThreadId &functThreadId/* functThreadId (threadId, id) */) {
|
|
dealThread (maxId, coreCount, [&functThreadId] (const unsigned int &threadId, const DimImg &minVal, const DimImg &maxVal) {
|
|
for (DimImg id = minVal; id < maxVal; ++id)
|
|
functThreadId (threadId, id);
|
|
});
|
|
}
|
|
|
|
// ----------------------------------------
|
|
template<typename DimImg, typename FunctMinMax>
|
|
inline void
|
|
dealThreadBound (const DimImg &maxId, const unsigned int &coreCount, const FunctMinMax &functMinMax/* functMinMax (minVal, maxVal) */) {
|
|
dealThread (maxId, coreCount, [&functMinMax] (const unsigned int &threadId, const DimImg &minVal, const DimImg &maxVal) {
|
|
functMinMax (minVal, maxVal);
|
|
});
|
|
}
|
|
|
|
// ----------------------------------------
|
|
template<typename DimImg>
|
|
inline std::vector<DimImg>
|
|
getDealThreadBounds (const DimImg &maxId, const unsigned int &coreCount) {
|
|
if (!maxId || !coreCount)
|
|
return std::vector<DimImg> (0);
|
|
DimImg average = maxId/coreCount;
|
|
std::vector<DimImg> maxIds (coreCount+1, average);
|
|
|
|
for (unsigned int core = 0; core < coreCount; ++core)
|
|
maxIds[core] = DimImg (core*average);
|
|
maxIds[coreCount] = maxId;
|
|
return maxIds;
|
|
}
|
|
|
|
// ----------------------------------------
|
|
template<typename DimImg, typename FunctThreadMinMax>
|
|
inline void
|
|
dealThread (const DimImg &maxId, unsigned int coreCount, const FunctThreadMinMax &functThreadMinMax/* functThreadMinMax (threadId, minVal, maxVal) */) {
|
|
//DEF_LOG ("dealThreadBound", "coreCount:" << coreCount << " maxId:" << maxId);
|
|
if (!maxId || !coreCount)
|
|
return;
|
|
if (DimImg (coreCount) > maxId)
|
|
coreCount = (unsigned int) maxId;
|
|
if (coreCount == 1) {
|
|
functThreadMinMax (0, 0, maxId);
|
|
return;
|
|
}
|
|
|
|
std::vector<DimImg> maxIds = getDealThreadBounds (maxId, coreCount);
|
|
boost::thread tasks [coreCount];
|
|
for (unsigned int idCopyValInThread = 0; idCopyValInThread < coreCount; ++idCopyValInThread) {
|
|
tasks[idCopyValInThread] = boost::thread ([/*no ref!!!*/idCopyValInThread, &maxIds, &functThreadMinMax] () {
|
|
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
|
|
});
|
|
}
|
|
|
|
for (unsigned int i = 0; i < coreCount; ++i)
|
|
tasks[i].join ();
|
|
}
|
|
|
|
// ========================================
|
|
template<typename DimImg, typename WeightT, typename WeightFunct, typename CmpFunct, typename CallFunct>
|
|
inline void
|
|
callOnSortedSets (const std::vector<DimImg> &sizes,
|
|
const WeightFunct &getWeight/* getWeight (vectId, itemId) */,
|
|
CmpFunct isWeightInf/* isWeightInf (w1, w2) */,
|
|
const CallFunct &callIdId/* callIdId (vectId, itemId) */) {
|
|
DimImg size = sizes.size ();
|
|
DEF_LOG ("callOnSortedSets", "size:" << size);
|
|
if (!size)
|
|
return;
|
|
std::vector<DimImg> vectIds (size, 0);
|
|
std::vector<DimImg> vectCounts (sizes);
|
|
// get min
|
|
bool found = false;
|
|
DimImg minVectIdx = 0;
|
|
WeightT minWeight = 0;
|
|
for (DimImg vectId = 0; vectId < size; ++vectId) {
|
|
if (!vectCounts [vectId])
|
|
continue;
|
|
WeightT tmpWeight = getWeight (vectId, 0);
|
|
if (found && !isWeightInf (tmpWeight, minWeight))
|
|
continue;
|
|
minVectIdx = vectId;
|
|
minWeight = tmpWeight;
|
|
found = true;
|
|
}
|
|
LOG ("found:" << found << " minVectIdx:" << minVectIdx << " minWeight:" << minWeight);
|
|
// loop
|
|
for ( ; found; ) {
|
|
// get next min
|
|
found = false;
|
|
DimImg nextMinVectIdx = 0;
|
|
WeightT nextMinWeight = 0;
|
|
for (DimImg vectId = minVectIdx; ; ) {
|
|
if (vectCounts [vectId]) {
|
|
WeightT tmpWeight = getWeight (vectId, vectIds [vectId]);
|
|
if (!isWeightInf (minWeight, tmpWeight)) {
|
|
// minWeight == tmpWeight
|
|
callIdId (vectId, vectIds [vectId]);
|
|
++vectIds [vectId];
|
|
--vectCounts [vectId];
|
|
continue;
|
|
}
|
|
if (!found || isWeightInf (tmpWeight, nextMinWeight)) {
|
|
nextMinVectIdx = vectId;
|
|
nextMinWeight = tmpWeight;
|
|
found = true;
|
|
}
|
|
}
|
|
vectId = (vectId+1)%size;
|
|
if (vectId == minVectIdx)
|
|
break;
|
|
}
|
|
minVectIdx = nextMinVectIdx;
|
|
minWeight = nextMinWeight;
|
|
}
|
|
}
|
|
|
|
#endif // _TRISKELE_DEAL_THREADS_TPP
|