ITK build with TBB

Hi everyone,

I am trying to build ITK-5.0.0 with TBB.
I have already successfully built TBB.
After cmake config I get this error

 Could not find a package configuration file provided by "TBB" with any of
  the following names:


  Add the installation prefix of "TBB" to CMAKE_PREFIX_PATH or set "TBB_DIR"
  to a directory containing one of the above files.

I have tried to compile by command line also

-DCMAKE_PREFIX_PATH=/home/hs/Dcuments/TBB \

still the same error.
Can someone tell how to fix this?

Thank you

TBB is not a normal CMake-managed library. Instead of creating a TBBConfig.cmake file when you build it, they provide a way for you to generate a customized version of TBBConfig.cmake. But the binary release of TBB does contain TBBConfig.cmake, which is what you are supposed to point at when configuring ITK.

@hjmjohnson has tried to convince TBB people to add better CMake support, and might have further suggestions.

But ITK-4.13 did not require TBBConfig.cmake
It only has TBBFind.cmake file.
I want to understand what is the difference between this two versions.
Thank you

Plain ITK-4.13 did not make use of TBB at all. Only the remote module TBBImageToImageFilter did. And the drawback of FindTBB.cmake approach is necessity of specifying about 20 paths for include directories and release and debug libraries for TBB components (tbb, tbb_malloc, tbbmalloc_proxy etc). Also, there is an outstanding PR which adds back FindTBB.cmake. It would be good if you tested and reviewed that PR - it might be a solution you are looking for.

Right, but 5.0.0 version does not come with FindTBB.cmake file.
How can I generate that file for 5.0.0 version

Would it be possible to use a newer version of TBB? Versions of TBB since about late 2017 come with a TBBConfig.cmake file which does away with the need for the FindTBB.cmake at all.

@imikejackson Precompiled versions of TBB. He compiled his own.

@nm97 The patch should be easy to apply to 5.0.0. Try to apply it, and use such patched ITK. Then let us know how it went.

I am testing it right now.
And one more question.
When I configure with cmake it has variable with name TBB_MALLOC_PROXY_LIBRARY. Is it required to give path to that file?

I don’t know. I always gave it the paths to all the libraries that appeared in CMake cache.

I applied patch to 5.0.0, it compiles fine, but for running examples it still causes error

CMake Error at /usr/local/lib/cmake/ITK-5.0/Modules/ITKTBB.cmake:15 (find_package):
  Could not find a package configuration file provided by "TBB" with any of
  the following names:


  Add the installation prefix of "TBB" to CMAKE_PREFIX_PATH or set "TBB_DIR"
  to a directory containing one of the above files.  If "TBB" provides a
  separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
  /usr/local/lib/cmake/ITK-5.0/ITKModuleAPI.cmake:76 (include)
  /usr/local/lib/cmake/ITK-5.0/ITKModuleAPI.cmake:31 (itk_module_load)
  /usr/local/lib/cmake/ITK-5.0/ITKModuleAPI.cmake:129 (_itk_module_config_recurse)
  /usr/local/lib/cmake/ITK-5.0/ITKConfig.cmake:82 (itk_module_config)
  CMakeLists.txt:19 (find_package)

how can I test binareies in this case?

And the last question please.
When I am building there is TBB_DIR variable. I can not understand which directory path I have to give to that variable.
Do you have any idea?

On my Linux computer, TBB_DIR path is /home/dzenan/tbb2019_20190206oss/cmake. I am using binary distribution.

Just to make it clear.
As I understand 4.13 version does not have TBB_DIR variable, so we don’t need to have TBBConfig.cmake file.
And 5.0.0 requires TBBConfig.cmake file.
Am I right?

ITK 4.13 did not have TBB support. ITK 5.0 has support for TBB, and requires TBBConfig.cmake which comes with newer binary distributions of TBB. TBB also has a procedure to generate TBBConfig.cmake for a TBB you compiled yourself, but that is not easy. PR991 tries to alleviate the restriction of requiring TBBConfig.cmake.

And you don’t have to build with TBB - that is an optional feature which allows better load balancing, and is supposed to ease general parallel performance, especially when ITK-based program is not the only one making high CPU use.

I have tried this version already, the problem is I can not run examples to see if library has been built successfully or not, because it anyway needs TBB_DIR( TBBConfig.cmake).
In this case how can i test libraries?

Can you run the prebuilt binaries from Intel? You can download them from Github. The precompiled binaries work with all the compilers that ITK 5 supports so in general this should not be an issue. The only reason I can think of is that your internal IT policy forbids you to download precompiled binaries. Could you elaborate more on why you cannot use the precompiled binaries for TBB?

1 Like

The reason why, is that we are using a commercial thirdparty library which comes with tbb. To avoid conflicts, we build tbb ourselves, adding a prefix to the library names. The build process of TBB (for Windows), however, does not generate the appropriate TBBConfig.cmake file.

1 Like

If you build TBB on Windows it does not generate a TBBConfig.cmake.

We build TBB with a prefix for all libs, to avoid any conflict with TBB coming from a package we license from Spatial. This was the purpose of the patch, so I can manually specify the different library paths.

So, the solution on building TBB from the source code in a way to generate TBBConfig.cmake:

download and unpack tbb sources into ( I am using tbb_2019 branch from ), then


cd <TBB directory>
make stdver=c++0x stdlib=libc++ tbb_build_prefix=lib
mkdir lib
cp build/lib_release/*.dylib lib
cmake -DTBB_ROOT=<TBB directory> -DTBB_OS=Darwin -DSAVE_TO=<TBB directory>/lib/ -P cmake/tbb_config_generator.cmake

Linux (64bit with gcc):

cd <TBB directory>
make stdver=c++0x tbb_build_prefix=lib
mkdir -p lib/intel64/gcc4.8/
cp build/lib_release/*.so.2 lib/intel64/gcc4.8/
cmake -DTBB_ROOT=<TBB directory> -DTBB_OS=Linux -DSAVE_TO=<TBB directory>/lib/ -P cmake/tbb_config_generator.cmake

Then TBB can be specified in ITK build as

-DTBB_DIR:PATH=<TBB directory>/lib