Remove Intel TBB threading support.
- In light of the C++11 threads threading option this is no longer
necessary for cross-platform threading support and did not offer a
noticeable performance gain over either the C++11 threads
implementation or OpenMP.
Change-Id: Icb588d520888c19a1775171795b55bcaffb3d256
diff --git a/bazel/ceres.bzl b/bazel/ceres.bzl
index 28eef28..cbd2c51 100644
--- a/bazel/ceres.bzl
+++ b/bazel/ceres.bzl
@@ -93,7 +93,6 @@
"normal_prior.cc",
"parallel_for_cxx.cc",
"parallel_for_openmp.cc",
- "parallel_for_tbb.cc",
"parallel_utils.cc",
"parameter_block_ordering.cc",
"partitioned_matrix_view.cc",
diff --git a/cmake/CeresCompileOptionsToComponents.cmake b/cmake/CeresCompileOptionsToComponents.cmake
index 971b833..e2e8ec8 100644
--- a/cmake/CeresCompileOptionsToComponents.cmake
+++ b/cmake/CeresCompileOptionsToComponents.cmake
@@ -84,8 +84,6 @@
CERES_RESTRICT_SCHUR_SPECIALIZATION "SchurSpecializations")
add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
CERES_USE_OPENMP "OpenMP;Multithreading")
- add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
- CERES_USE_TBB "TBB;Multithreading")
# Remove duplicates of SparseLinearAlgebraLibrary if multiple sparse backends
# are present.
list(REMOVE_DUPLICATES ${CERES_COMPONENTS_VAR})
diff --git a/cmake/CeresThreadingModels.cmake b/cmake/CeresThreadingModels.cmake
index 910f4a8..24e8aab 100644
--- a/cmake/CeresThreadingModels.cmake
+++ b/cmake/CeresThreadingModels.cmake
@@ -29,7 +29,7 @@
# Author: alexs.mac@gmail.com (Alex Stewart)
# Ordered by expected preference.
-set(CERES_THREADING_MODELS "CXX11_THREADS;OPENMP;TBB;NO_THREADS")
+set(CERES_THREADING_MODELS "CXX11_THREADS;OPENMP;NO_THREADS")
function(find_available_ceres_threading_models CERES_THREADING_MODELS_AVAILABLE_VAR)
set(CERES_THREADING_MODELS_AVAILABLE ${CERES_THREADING_MODELS})
@@ -38,10 +38,6 @@
if (NOT OPENMP_FOUND)
list(REMOVE_ITEM CERES_THREADING_MODELS_AVAILABLE "OPENMP")
endif()
- find_package(TBB QUIET)
- if (NOT TBB_FOUND)
- list(REMOVE_ITEM CERES_THREADING_MODELS_AVAILABLE "TBB")
- endif()
if (NOT CERES_THREADING_MODELS_AVAILABLE)
# At least NO_THREADS should never be removed. This check is purely
# protective against future threading model updates.
@@ -62,12 +58,6 @@
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
endmacro()
-macro(set_ceres_threading_model_to_tbb)
- find_package(TBB REQUIRED)
- list(APPEND CERES_COMPILE_OPTIONS CERES_USE_TBB)
- include_directories(${TBB_INCLUDE_DIRS})
-endmacro()
-
macro(set_ceres_threading_model_to_no_threads)
list(APPEND CERES_COMPILE_OPTIONS CERES_NO_THREADS)
endmacro()
@@ -77,8 +67,6 @@
set_ceres_threading_model_to_cxx11_threads()
elseif ("${CERES_THREADING_MODEL_TO_SET}" STREQUAL "OPENMP")
set_ceres_threading_model_to_openmp()
- elseif ("${CERES_THREADING_MODEL_TO_SET}" STREQUAL "TBB")
- set_ceres_threading_model_to_tbb()
elseif ("${CERES_THREADING_MODEL_TO_SET}" STREQUAL "NO_THREADS")
set_ceres_threading_model_to_no_threads()
else()
diff --git a/cmake/FindSuiteSparse.cmake b/cmake/FindSuiteSparse.cmake
index e887e3b..e4de8b0 100644
--- a/cmake/FindSuiteSparse.cmake
+++ b/cmake/FindSuiteSparse.cmake
@@ -105,12 +105,6 @@
# == Serial Graph Partitioning and Fill-reducing Matrix Ordering (METIS)
# METIS_FOUND
# METIS_LIBRARY
-#
-# == Intel Thread Building Blocks (TBB)
-# TBB_FOUND
-# TBB_LIBRARY
-# TBB_MALLOC_FOUND
-# TBB_MALLOC_LIBRARY
# Reset CALLERS_CMAKE_FIND_LIBRARY_PREFIXES to its value when
# FindSuiteSparse was invoked.
diff --git a/cmake/config.h.in b/cmake/config.h.in
index f766c5c..1caacfe 100644
--- a/cmake/config.h.in
+++ b/cmake/config.h.in
@@ -75,8 +75,6 @@
@CERES_NO_THREADS@
// If defined Ceres was compiled with OpenMP multithreading support.
@CERES_USE_OPENMP@
-// If defined Ceres was compiled with TBB multithreading support.
-@CERES_USE_TBB@
// If defined Ceres was compiled with C++11 thread support.
@CERES_USE_CXX11_THREADS@
diff --git a/docs/source/features.rst b/docs/source/features.rst
index 6a4b652..579875e 100644
--- a/docs/source/features.rst
+++ b/docs/source/features.rst
@@ -54,7 +54,7 @@
of Non-linear Conjugate Gradients, BFGS and LBFGS.
* **Speed** - Ceres Solver has been extensively optimized, with C++
- templating, hand written linear algebra routines and OpenMP or TBB
+ templating, hand written linear algebra routines and OpenMP or C++11 threads
based multithreading of the Jacobian evaluation and the linear solvers.
* **Solution Quality** Ceres is the `best performing`_ solver on the NIST
diff --git a/docs/source/installation.rst b/docs/source/installation.rst
index 24ccc0c..51ad156 100644
--- a/docs/source/installation.rst
+++ b/docs/source/installation.rst
@@ -98,10 +98,6 @@
``SuiteSparse``, and optionally used by Ceres directly for some
operations.
-- `TBB <https://www.threadingbuildingblocks.org/>`_ is a C++11 template
- library for parallel programming that optionally can be used as an
- alternative to OpenMP. **Optional**
-
On ``UNIX`` OSes other than Mac OS X we recommend `ATLAS
<http://math-atlas.sourceforge.net/>`_, which includes ``BLAS`` and
``LAPACK`` routines. It is also possible to use `OpenBLAS
@@ -728,17 +724,11 @@
gains in the ``SPARSE_SCHUR`` solver, you can disable some of the
template specializations by turning this ``OFF``.
-#. ``CERES_THREADING_MODEL [Default: CXX11_THREADS > OPENMP > TBB > NO_THREADS]``:
+#. ``CERES_THREADING_MODEL [Default: CXX11_THREADS > OPENMP > NO_THREADS]``:
Multi-threading backend Ceres should be compiled with. This will
automatically be set to only accept the available subset of threading
options in the CMake GUI.
- .. NOTE::
-
- Up to and including version 4.4, TBB was licensed under
- GPL/Commercial terms. From 2017.x versions onwards, TBB is licensed under
- the Apache 2.0 license (and commerical terms).
-
#. ``BUILD_SHARED_LIBS [Default: OFF]``: By default Ceres is built as
a static library, turn this ``ON`` to instead build Ceres as a
shared library.
@@ -926,9 +916,6 @@
#. ``OpenMP``: Ceres built with OpenMP (``CERES_THREADING_MODEL=OPENMP``).
-#. ``TBB``: Ceres built with Intel Thread Building Blocks (TBB)
- (``CERES_THREADING_MODEL=TBB``).
-
#. ``Multithreading``: Ceres built with *a* multithreading library.
This is equivalent to (``CERES_THREAD != NO_THREADS``).
diff --git a/docs/source/nnls_solving.rst b/docs/source/nnls_solving.rst
index 4a34b83..713d54d 100644
--- a/docs/source/nnls_solving.rst
+++ b/docs/source/nnls_solving.rst
@@ -2210,8 +2210,8 @@
Number of threads actually used by the solver for Jacobian and
residual evaluation. This number is not equal to
- :member:`Solver::Summary::num_threads_given` if none of `OpenMP`,
- `TBB` or `CXX11_THREADS` is available.
+ :member:`Solver::Summary::num_threads_given` if none of `OpenMP`
+ or `CXX11_THREADS` is available.
.. member:: LinearSolverType Solver::Summary::linear_solver_type_given
diff --git a/include/ceres/internal/port.h b/include/ceres/internal/port.h
index f579028..07bb505 100644
--- a/include/ceres/internal/port.h
+++ b/include/ceres/internal/port.h
@@ -35,23 +35,19 @@
#include "ceres/internal/config.h"
#if defined(CERES_USE_OPENMP)
-# if defined(CERES_USE_TBB) || defined(CERES_USE_CXX11_THREADS) || defined(CERES_NO_THREADS)
-# error CERES_USE_OPENMP is mutually exclusive to CERES_USE_TBB, CERES_USE_CXX11_THREADS, and CERES_NO_THREADS
-# endif
-#elif defined(CERES_USE_TBB)
-# if defined(CERES_USE_OPENMP) || defined(CERES_USE_CXX11_THREADS) || defined(CERES_NO_THREADS)
-# error CERES_USE_TBB is mutually exclusive to CERES_USE_OPENMP, CERES_USE_CXX11_THREADS and CERES_NO_THREADS
+# if defined(CERES_USE_CXX11_THREADS) || defined(CERES_NO_THREADS)
+# error CERES_USE_OPENMP is mutually exclusive to CERES_USE_CXX11_THREADS and CERES_NO_THREADS
# endif
#elif defined(CERES_USE_CXX11_THREADS)
-# if defined(CERES_USE_OPENMP) || defined(CERES_USE_TBB) || defined(CERES_NO_THREADS)
+# if defined(CERES_USE_OPENMP) || defined(CERES_NO_THREADS)
# error CERES_USE_CXX11_THREADS is mutually exclusive to CERES_USE_OPENMP, CERES_USE_CXX11_THREADS and CERES_NO_THREADS
# endif
#elif defined(CERES_NO_THREADS)
-# if defined(CERES_USE_OPENMP) || defined(CERES_USE_TBB) || defined(CERES_USE_CXX11_THREADS)
-# error CERES_NO_THREADS is mutually exclusive to CERES_USE_OPENMP, CERES_USE_TBB and CERES_USE_CXX11_THREADS
+# if defined(CERES_USE_OPENMP) || defined(CERES_USE_CXX11_THREADS)
+# error CERES_NO_THREADS is mutually exclusive to CERES_USE_OPENMP and CERES_USE_CXX11_THREADS
# endif
#else
-# error One of CERES_USE_OPENMP, CERES_USE_TBB,CERES_USE_CXX11_THREADS or CERES_NO_THREADS must be defined.
+# error One of CERES_USE_OPENMP, CERES_USE_CXX11_THREADS or CERES_NO_THREADS must be defined.
#endif
// CERES_NO_SPARSE should be automatically defined by config.h if Ceres was
diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt
index a6999d8..0b0fc7d 100644
--- a/internal/ceres/CMakeLists.txt
+++ b/internal/ceres/CMakeLists.txt
@@ -43,13 +43,6 @@
# Add thread library dependencies for OpenMP to the Ceres target.
list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CMAKE_THREAD_LIBS_INIT})
endif()
-elseif (CERES_THREADING_MODEL STREQUAL "TBB")
- set(CERES_PARALLEL_FOR_SRC parallel_for_tbb.cc)
- list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${TBB_LIBRARIES})
- if (NOT MSVC)
- # Add thread library dependencies for OpenMP to the Ceres target.
- list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CMAKE_THREAD_LIBS_INIT})
- endif (NOT MSVC)
elseif (CERES_THREADING_MODEL STREQUAL "NO_THREADS")
set(CERES_PARALLEL_FOR_SRC parallel_for_nothreads.cc)
endif()
diff --git a/internal/ceres/covariance_impl.cc b/internal/ceres/covariance_impl.cc
index f7f1dc9..4804173 100644
--- a/internal/ceres/covariance_impl.cc
+++ b/internal/ceres/covariance_impl.cc
@@ -77,7 +77,7 @@
#ifdef CERES_NO_THREADS
if (options_.num_threads > 1) {
LOG(WARNING)
- << "Neither OpenMP nor TBB support is compiled into this binary; "
+ << "No threading support is compiled into this binary; "
<< "only options.num_threads = 1 is supported. Switching "
<< "to single threaded mode.";
options_.num_threads = 1;
diff --git a/internal/ceres/parallel_for_openmp.cc b/internal/ceres/parallel_for_openmp.cc
index b64f3d7..ae35d6b 100644
--- a/internal/ceres/parallel_for_openmp.cc
+++ b/internal/ceres/parallel_for_openmp.cc
@@ -31,7 +31,7 @@
// This include must come before any #ifndef check on Ceres compile options.
#include "ceres/internal/port.h"
-#if !(defined(CERES_USE_TBB) || defined(CERES_USE_CXX11_THREADS))
+#if defined(CERES_USE_OPENMP)
#include "ceres/parallel_for.h"
@@ -80,4 +80,4 @@
} // namespace internal
} // namespace ceres
-#endif // !(defined(CERES_USE_TBB) || defined(CERES_USE_CXX11_THREADS))
+#endif // defined(CERES_USE_OPENMP)
diff --git a/internal/ceres/parallel_for_tbb.cc b/internal/ceres/parallel_for_tbb.cc
deleted file mode 100644
index e235b50..0000000
--- a/internal/ceres/parallel_for_tbb.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// Ceres Solver - A fast non-linear least squares minimizer
-// Copyright 2018 Google Inc. All rights reserved.
-// http://ceres-solver.org/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// * Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-// * Neither the name of Google Inc. nor the names of its contributors may be
-// used to endorse or promote products derived from this software without
-// specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: vitus@google.com (Michael Vitus)
-
-// This include must come before any #ifndef check on Ceres compile options.
-#include "ceres/internal/port.h"
-
-#ifdef CERES_USE_TBB
-
-#include "ceres/parallel_for.h"
-
-#include <tbb/parallel_for.h>
-#include <tbb/task_arena.h>
-
-#include "ceres/scoped_thread_token.h"
-#include "ceres/thread_token_provider.h"
-#include "glog/logging.h"
-
-namespace ceres {
-namespace internal {
-
-void ParallelFor(ContextImpl* context,
- int start,
- int end,
- int num_threads,
- const std::function<void(int)>& function) {
- CHECK_GT(num_threads, 0);
- CHECK(context != NULL);
- if (end <= start) {
- return;
- }
-
- // Fast path for when it is single threaded.
- if (num_threads == 1) {
- for (int i = start; i < end; ++i) {
- function(i);
- }
- return;
- }
-
- tbb::task_arena task_arena(num_threads);
- task_arena.execute([&]{
- tbb::parallel_for(start, end, function);
- });
-}
-
-void ParallelFor(ContextImpl* context,
- int start,
- int end,
- int num_threads,
- const std::function<void(int thread_id, int i)>& function) {
- CHECK(context != NULL);
-
- ThreadTokenProvider thread_token_provider(num_threads);
- ParallelFor(context, start, end, num_threads, [&](int i) {
- const ScopedThreadToken scoped_thread_token(&thread_token_provider);
- const int thread_id = scoped_thread_token.token();
- function(thread_id, i);
- });
-}
-
-
-} // namespace internal
-} // namespace ceres
-
-#endif // CERES_USE_TBB
diff --git a/internal/ceres/preprocessor.cc b/internal/ceres/preprocessor.cc
index 74627a5..08eacc8 100644
--- a/internal/ceres/preprocessor.cc
+++ b/internal/ceres/preprocessor.cc
@@ -59,7 +59,7 @@
#ifdef CERES_NO_THREADS
if (options->num_threads > 1) {
LOG(WARNING)
- << "Neither OpenMP nor TBB support is compiled into this binary; "
+ << "No threading support is compiled into this binary; "
<< "only options.num_threads = 1 is supported. Switching "
<< "to single threaded mode.";
options->num_threads = 1;
diff --git a/internal/ceres/problem_impl.cc b/internal/ceres/problem_impl.cc
index 94af8ad..3fdbfed 100644
--- a/internal/ceres/problem_impl.cc
+++ b/internal/ceres/problem_impl.cc
@@ -812,7 +812,7 @@
evaluator_options.linear_solver_type = SPARSE_NORMAL_CHOLESKY;
#ifdef CERES_NO_THREADS
LOG_IF(WARNING, evaluate_options.num_threads > 1)
- << "Neither OpenMP nor TBB support is compiled into this binary; "
+ << "No threading support is compiled into this binary; "
<< "only evaluate_options.num_threads = 1 is supported. Switching "
<< "to single threaded mode.";
evaluator_options.num_threads = 1;
diff --git a/internal/ceres/program_evaluator.h b/internal/ceres/program_evaluator.h
index 13f2e83..6781eb7 100644
--- a/internal/ceres/program_evaluator.h
+++ b/internal/ceres/program_evaluator.h
@@ -43,7 +43,7 @@
// residual jacobians are written directly into their final position in the
// block sparse matrix by the user's CostFunction; there is no copying.
//
-// The evaluation is threaded with OpenMP or TBB.
+// The evaluation is threaded with OpenMP or C++11 threads.
//
// The EvaluatePreparer and JacobianWriter interfaces are as follows:
//
@@ -118,7 +118,7 @@
#ifdef CERES_NO_THREADS
if (options_.num_threads > 1) {
LOG(WARNING)
- << "Neither OpenMP nor TBB support is compiled into this binary; "
+ << "No threading support is compiled into this binary; "
<< "only options.num_threads = 1 is supported. Switching "
<< "to single threaded mode.";
options_.num_threads = 1;
diff --git a/internal/ceres/solver_utils.cc b/internal/ceres/solver_utils.cc
index 4b400d3..177a928 100644
--- a/internal/ceres/solver_utils.cc
+++ b/internal/ceres/solver_utils.cc
@@ -33,9 +33,6 @@
#include "ceres/internal/config.h"
#include "Eigen/Core"
-#ifdef CERES_USE_TBB
-#include "tbb/tbb_stddef.h"
-#endif // CERES_USE_TBB
#include "ceres/internal/port.h"
#include "ceres/solver_utils.h"
#include "ceres/version.h"
@@ -48,10 +45,6 @@
CERES_TO_STRING(EIGEN_MAJOR_VERSION) "." \
CERES_TO_STRING(EIGEN_MINOR_VERSION)
-#define CERES_TBB_VERSION \
- CERES_TO_STRING(TBB_VERSION_MAJOR) "." \
- CERES_TO_STRING(TBB_VERSION_MINOR)
-
std::string VersionString() {
std::string value = std::string(CERES_VERSION_STRING);
value += "-eigen-(" + std::string(CERES_EIGEN_VERSION) + ")";
@@ -88,12 +81,6 @@
value += "-no_openmp";
#endif
-#ifdef CERES_USE_TBB
- value += "-tbb-(" + std::string(CERES_TBB_VERSION) + ")";
-#else
- value += "-no_tbb";
-#endif
-
#ifdef CERES_NO_CUSTOM_BLAS
value += "-no_custom_blas";
#endif
diff --git a/internal/ceres/thread_token_provider.cc b/internal/ceres/thread_token_provider.cc
index 61a16e0..337217b 100644
--- a/internal/ceres/thread_token_provider.cc
+++ b/internal/ceres/thread_token_provider.cc
@@ -39,13 +39,6 @@
ThreadTokenProvider::ThreadTokenProvider(int num_threads) {
(void)num_threads;
-#ifdef CERES_USE_TBB
- pool_.set_capacity(num_threads);
- for (int i = 0; i < num_threads; i++) {
- pool_.push(i);
- }
-#endif
-
#ifdef CERES_USE_CXX11_THREADS
for (int i = 0; i < num_threads; i++) {
pool_.Push(i);
@@ -63,12 +56,6 @@
return 0;
#endif
-#ifdef CERES_USE_TBB
- int thread_id;
- pool_.pop(thread_id);
- return thread_id;
-#endif
-
#ifdef CERES_USE_CXX11_THREADS
int thread_id;
CHECK(pool_.Wait(&thread_id));
@@ -79,10 +66,6 @@
void ThreadTokenProvider::Release(int thread_id) {
(void)thread_id;
-#ifdef CERES_USE_TBB
- pool_.push(thread_id);
-#endif
-
#ifdef CERES_USE_CXX11_THREADS
pool_.Push(thread_id);
#endif
diff --git a/internal/ceres/thread_token_provider.h b/internal/ceres/thread_token_provider.h
index e4c9cd8..f6298b7 100644
--- a/internal/ceres/thread_token_provider.h
+++ b/internal/ceres/thread_token_provider.h
@@ -34,10 +34,6 @@
#include "ceres/internal/config.h"
#include "ceres/internal/port.h"
-#ifdef CERES_USE_TBB
-#include <tbb/concurrent_queue.h>
-#endif
-
#ifdef CERES_USE_CXX11_THREADS
#include "ceres/concurrent_queue.h"
#endif
@@ -45,8 +41,8 @@
namespace ceres {
namespace internal {
-// Helper for TBB and C++11 thread number identification that is similar to
-// omp_get_thread_num() behaviour. This is necessary to support TBB and C++11
+// Helper for C++11 thread number identification that is similar to
+// omp_get_thread_num() behaviour. This is necessary to support C++11
// threading with a sequential thread id. This is used to access preallocated
// resources in the parallelized code parts. The sequence of tokens varies from
// 0 to num_threads - 1 that can be acquired to identify the thread in a thread
@@ -76,22 +72,12 @@
// Returns the first token from the queue. The acquired value must be
// given back by Release().
- //
- // With TBB this function will block if all the tokens are aquired by
- // concurent threads.
int Acquire();
// Makes previously acquired token available for other threads.
void Release(int thread_id);
private:
-#ifdef CERES_USE_TBB
- // This queue initially holds a sequence from 0..num_threads-1. Every
- // Acquire() call the first number is removed from here. When the token is not
- // needed anymore it shall be given back with corresponding Release() call.
- tbb::concurrent_bounded_queue<int> pool_;
-#endif
-
#ifdef CERES_USE_CXX11_THREADS
// This queue initially holds a sequence from 0..num_threads-1. Every
// Acquire() call the first number is removed from here. When the token is not