Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,15 @@ endif()
# TBB (optional)
# Must come before CGAL so it can use TBB properly
if ( CCCORELIB_USE_TBB )
find_package( TBB COMPONENTS tbb CONFIG )
find_package( TBB COMPONENTS tbb 2022.0.0 CONFIG )

set( CCCORELIB_USE_QT_CONCURRENT OFF )
if ( TBB_FOUND )
if ( ${TBB_VERSION} VERSION_GREATER 2021.0.0 )
target_link_libraries( CCCoreLib
PUBLIC
TBB::tbb
)
else()
target_link_libraries( CCCoreLib
PUBLIC
${TBB_IMPORTED_TARGETS}
)
endif()
target_link_libraries( CCCoreLib
PUBLIC
TBB::tbb
)

target_compile_definitions( CCCoreLib
PUBLIC
CC_CORE_LIB_USES_TBB
Expand All @@ -192,14 +187,7 @@ if ( CCCORELIB_USE_CGAL )

if ( CCCORELIB_USE_TBB )
if ( TBB_FOUND )
# Once Linux libcgal-dev >= 5.0, target_compile_definitions replaced by:
# CGAL_target_use_TBB( CCCoreLib )

target_compile_definitions( CCCoreLib
PRIVATE
CGAL_LINKED_WITH_TBB
NOMINMAX
)
CGAL_target_use_TBB( CCCoreLib )
else()
message( WARNING "CGAL cannot compile with TBB (TBB not found)" )
endif()
Expand Down Expand Up @@ -232,7 +220,7 @@ if ( CCCORELIB_USE_QT_CONCURRENT )

target_link_libraries( CCCoreLib
PUBLIC
Qt6::Concurrent
Qt6::Concurrent
)

target_compile_definitions( CCCoreLib
Expand Down Expand Up @@ -268,9 +256,9 @@ install(
include( CMakePackageConfigHelpers )

configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

write_basic_package_version_file( CCCoreLibConfigVersion.cmake
Expand Down
31 changes: 15 additions & 16 deletions include/ParallelSort.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@

#if defined(_MSC_VER) && (_MSC_VER >= 1800)

//Parallel Patterns Library (for parallel sort)
#include <ppl.h>
//Parallel Patterns Library (for parallel sort)
#include <ppl.h>

#define ParallelSort Concurrency::parallel_sort
#define ParallelSort Concurrency::parallel_sort

#elif CC_CORE_LIB_USES_TBB

#ifndef Q_MOC_RUN
#if defined(emit)
#undef emit
#include <tbb/parallel_sort.h>
#define emit // restore the macro definition of "emit", as it was defined in gtmetamacros.h
#else
#include <tbb/parallel_sort.h>
#endif // defined(emit)
#endif // Q_MOC_RUN
#ifndef Q_MOC_RUN
#if defined(emit)
#undef emit
#include <oneapi/tbb/parallel_sort.h>
#define emit // restore the macro definition of "emit", as it was defined in gtmetamacros.h
#else
#include <oneapi/tbb/parallel_sort.h>
#endif // defined(emit)
#endif // Q_MOC_RUN

#define ParallelSort tbb::parallel_sort
#define ParallelSort oneapi::tbb::parallel_sort

#else

#include <algorithm>

#define ParallelSort std::sort
#include <algorithm>
#define ParallelSort std::sort

#endif
36 changes: 23 additions & 13 deletions src/DgmOctree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
#ifndef Q_MOC_RUN
#if defined(emit)
#undef emit
#include <tbb/parallel_for.h>
#include <oneapi/tbb/parallel_for.h>
#include <oneapi/tbb/task_arena.h>
#define emit // restore the macro definition of "emit", as it was defined in gtmetamacros.h
#else
#include <tbb/parallel_for.h>
#include <oneapi/tbb/parallel_for.h>
#include <oneapi/tbb/task_arena.h>
#endif // defined(emit)
#endif // Q_MOC_RUN
using namespace oneapi;
#endif
//#endif // #ifndef CC_DEBUG

Expand Down Expand Up @@ -3111,7 +3114,7 @@ unsigned DgmOctree::executeFunctionForAllCellsAtLevel( unsigned char level,
progressCb->update(0);
progressCb->start();
}

NormalizedProgress nprogress(progressCb, m_theAssociatedCloud->size());

#ifdef COMPUTE_NN_SEARCH_STATISTICS
Expand Down Expand Up @@ -3250,8 +3253,10 @@ unsigned DgmOctree::executeFunctionForAllCellsAtLevel( unsigned char level,
progressCb->update(0);
m_MT_wrapper.normProgressCb = new NormalizedProgress(progressCb, m_theAssociatedCloud->size());
progressCb->start();
#if defined(CC_CORE_LIB_USES_QT_CONCURRENT)
#ifndef __APPLE__
QCoreApplication::processEvents(QEventLoop::EventLoopExec); // to allow the GUI to refresh itself
#endif
#endif
}

Expand All @@ -3266,15 +3271,17 @@ unsigned DgmOctree::executeFunctionForAllCellsAtLevel( unsigned char level,
QThreadPool::globalInstance()->setMaxThreadCount(maxThreadCount);
QtConcurrent::blockingMap(cells, [this](const octreeCellDesc& desc) { m_MT_wrapper.launchOctreeCellFunc(desc); });
#elif defined(CC_CORE_LIB_USES_TBB)
tbb::task_scheduler_init init(maxThreadCount != 0 ? maxThreadCount : tbb::task_scheduler_init::automatic);
tbb::parallel_for(tbb::blocked_range<int>(0, cells.size()),
[&](tbb::blocked_range<int> r)
tbb::task_arena local_arena(maxThreadCount != 0 ? maxThreadCount : tbb::info::default_concurrency());
local_arena.execute([&] {
tbb::parallel_for(tbb::blocked_range<std::size_t>(0, cells.size()),
[&](tbb::blocked_range<std::size_t> r)
{
for (auto i = r.begin(); i < r.end(); ++i)
{
m_MT_wrapper.launchOctreeCellFunc(cells[i]);
}
for (auto i = r.begin(); i < r.end(); ++i)
{
m_MT_wrapper.launchOctreeCellFunc(cells[i]);
}
});
});
#endif
#ifdef COMPUTE_NN_SEARCH_STATISTICS
FILE* fp = fopen("octree_log.txt", "at");
Expand Down Expand Up @@ -3873,15 +3880,18 @@ unsigned DgmOctree::executeFunctionForAllCellsStartingAtLevel(unsigned char star
QtConcurrent::blockingMap(cells, [this](const octreeCellDesc& desc) { m_MT_wrapper.launchOctreeCellFunc(desc); } );
#elif defined(CC_CORE_LIB_USES_TBB)
// Otherwise we use TBB if we can
tbb::task_scheduler_init init(maxThreadCount != 0 ? maxThreadCount : tbb::task_scheduler_init::automatic);
tbb::parallel_for(tbb::blocked_range<int>(0, cells.size()),
[&](tbb::blocked_range<int> r)
tbb::task_arena local_arena(maxThreadCount != 0 ? maxThreadCount : tbb::info::default_concurrency());
local_arena.execute([&]
{
tbb::parallel_for(tbb::blocked_range<std::size_t>(0, cells.size()),
[&](tbb::blocked_range<std::size_t> r)
{
for (auto i = r.begin(); i < r.end(); ++i)
{
m_MT_wrapper.launchOctreeCellFunc(cells[i]);
}
});
});
#endif

#ifdef COMPUTE_NN_SEARCH_STATISTICS
Expand Down
34 changes: 21 additions & 13 deletions src/DistanceComputationTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@
#elif defined(CC_CORE_LIB_USES_TBB)
//enables multi-threading handling with TBB
#define ENABLE_CLOUD2MESH_DIST_MT
#include <mutex>
#ifndef Q_MOC_RUN
#if defined(emit)
#undef emit
#include <tbb/parallel_for.h>
#include <oneapi/tbb/parallel_for.h>
#include <oneapi/tbb/task_arena.h>
#include <oneapi/tbb/mutex.h>
#define emit // restore the macro definition of "emit", as it was defined in gtmetamacros.h
#else
#include <tbb/parallel_for.h>
#include <oneapi/tbb/parallel_for.h>
#include <oneapi/tbb/task_arena.h>
#include <oneapi/tbb/mutex.h>
#endif // defined(emit)
#endif // Q_MOC_RUN
using namespace oneapi;
#else
//Note that there is the case CC_DEBUG=OFF and neither TBB nor Qt
#undef ENABLE_CLOUD2MESH_DIST_MT
Expand Down Expand Up @@ -934,7 +938,7 @@ namespace CCCoreLib
#if defined(CC_CORE_LIB_USES_QT_CONCURRENT)
QMutex currentBitMaskMutex;
#elif defined(CC_CORE_LIB_USES_TBB)
std::mutex currentBitMaskMutex;
tbb::mutex currentBitMaskMutex;
#endif
};
}
Expand All @@ -956,8 +960,9 @@ static void CloudMeshDistCellFunc_MT(const DgmOctree::IndexAndCode& desc)

if (s_multiThreadingWrapper.normProgressCb)
{
#if defined(CC_CORE_LIB_USES_QT_CONCURRENT)
QCoreApplication::processEvents(QEventLoop::EventLoopExec); // to allow the GUI to refresh itself

#endif
if (!s_multiThreadingWrapper.normProgressCb->oneStep())
{
s_multiThreadingWrapper.cellFunc_success = false;
Expand Down Expand Up @@ -1565,7 +1570,7 @@ int DistanceComputationTools::computePoint2MeshDistancesWithOctree( const CCVect
return DISTANCE_COMPUTATION_RESULTS::SUCCESS;
}

int DistanceComputationTools::computeCloud2MeshDistancesWithOctree( const DgmOctree* octree,
int DistanceComputationTools::computeCloud2MeshDistancesWithOctree( const DgmOctree* octree,
const GridAndMeshIntersection& intersection,
Cloud2MeshDistancesComputationParams& params,
GenericProgressCallback* progressCb/*=nullptr*/)
Expand Down Expand Up @@ -1819,15 +1824,18 @@ int DistanceComputationTools::computeCloud2MeshDistancesWithOctree( const DgmOct
QThreadPool::globalInstance()->setMaxThreadCount(params.maxThreadCount);
QtConcurrent::blockingMap(cellsDescs, CloudMeshDistCellFunc_MT);
#elif defined(CC_CORE_LIB_USES_TBB)
tbb::parallel_for(tbb::blocked_range<int>(0, cellsDescs.size()),
[&](tbb::blocked_range<int> r)
tbb::task_arena local_arena(params.maxThreadCount != 0 ? params.maxThreadCount : tbb::info::default_concurrency());
local_arena.execute([&]
{
tbb::parallel_for(tbb::blocked_range<std::size_t>(0, cellsDescs.size()),
[&](tbb::blocked_range<std::size_t> r)
{
for (auto i = r.begin(); r.end(); ++i)
for (auto i = r.begin(); i < r.end(); ++i)
{
CloudMeshDistCellFunc_MT(cellsDescs[i]);
}
}
);
});
});
#endif

s_multiThreadingWrapper.octree = nullptr;
Expand Down Expand Up @@ -1859,7 +1867,7 @@ int DistanceComputationTools::computeCloud2MeshDistances( GenericIndexedCloudPer
DgmOctree* cloudOctree/*=nullptr*/)
{
//check the input
if (!pointCloud)
if (!pointCloud)
{
assert(false);
return DISTANCE_COMPUTATION_RESULTS::ERROR_NULL_COMPAREDCLOUD;
Expand Down Expand Up @@ -1921,7 +1929,7 @@ int DistanceComputationTools::computeCloud2MeshDistances( GenericIndexedCloudPer
maxBB.u[k] = std::max(meshMaxBB.u[k], cloudMaxBB.u[k]);
}

//max cubical bounding-box
//max cubical bounding-box
cubicalMinBB = minBB;
cubicalMaxBB = maxBB;

Expand Down
Loading