Installing TBB from Source on Linux: A Step-by-Step Guide

Installing TBB from Source on Linux: A Step-by-Step Guide

Learning how to install Intel’s Threading Building Blocks (TBB) from source on Linux is crucial for developers aiming to harness the full power of multi-core processors. TBB simplifies parallel programming by abstracting low-level threading details, allowing you to write efficient, scalable, and portable code. Mastering this installation process ensures you can leverage TBB’s capabilities for improved performance and future-proof scalability in your applications.

Prerequisites

To install TBB (Threading Building Blocks) from source on Linux, follow these steps:

  1. Prerequisites:

    • CMake: Ensure you have CMake installed. You can install it using:
      sudo apt-get install cmake
      

    • GNU Make: Install GNU Make if it’s not already installed:
      sudo apt-get install build-essential
      

    • Git: Install Git to clone the TBB repository:
      sudo apt-get install git
      

  2. Clone the TBB Repository:

    git clone https://github.com/oneapi-src/oneTBB.git
    cd oneTBB
    

  3. Build TBB:

    mkdir build
    cd build
    cmake ..
    make -j$(nproc)
    

  4. Install TBB:

    sudo make install
    

  5. Verify Installation:

    • Ensure the TBB libraries are in your library path. You can add the following to your .bashrc or .profile:
      export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
      

  6. Compile a Sample Program:

    • Create a sample TBB program (e.g., sample.cpp):
      #include <tbb/tbb.h>
      #include <iostream>
      
      int main() {
          tbb::parallel_for(0, 100,  {
              std::cout << i << " ";
          });
          return 0;
      }
      

    • Compile the program:
      g++ -std=c++11 -ltbb sample.cpp -o sample
      

  7. Run the Sample Program:

    ./sample
    

These steps should help you install TBB from source and verify its functionality on your Linux system.

Downloading TBB Source Code

Here are the steps to download and install TBB (Threading Building Blocks) from the official repository on Linux:

  1. Clone the Repository:

    git clone https://github.com/oneapi-src/oneTBB.git
    cd oneTBB
    

  2. Install Required Dependencies:

    sudo apt-get update
    sudo apt-get install build-essential cmake
    

  3. Build TBB:

    mkdir build
    cd build
    cmake ..
    make
    

  4. Install TBB:

    sudo make install
    

  5. Verify Installation:

    tbb_version
    

These steps will download the TBB source code, build it, and install it on your Linux system.

Preparing the Build Environment

Here’s a step-by-step guide to set up the build environment and install TBB from source on Linux:

  1. Install Required Packages:

    sudo apt-get update
    sudo apt-get install build-essential cmake
    

  2. Download TBB Source Code:

    git clone https://github.com/oneapi-src/oneTBB.git
    cd oneTBB
    

  3. Build TBB:

    mkdir build
    cd build
    cmake ..
    make -j$(nproc)
    

  4. Install TBB:

    sudo make install
    

  5. Set Environment Variables:
    Add the following lines to your ~/.bashrc or ~/.zshrc file:

    export TBBROOT=/usr/local
    export LD_LIBRARY_PATH=$TBBROOT/lib:$LD_LIBRARY_PATH
    export LIBRARY_PATH=$TBBROOT/lib:$LIBRARY_PATH
    export CPATH=$TBBROOT/include:$CPATH
    

  6. Apply Changes:

    source ~/.bashrc  # or source ~/.zshrc
    

This will set up the build environment, install TBB, and configure the necessary environment variables and paths.

Building TBB from Source

Sure, here’s a step-by-step guide to compile and build Intel TBB (Threading Building Blocks) from source on Linux:

  1. Install Required Packages:

    sudo apt-get update
    sudo apt-get install -y build-essential cmake git
    

  2. Clone the TBB Repository:

    git clone https://github.com/oneapi-src/oneTBB.git
    cd oneTBB
    

  3. Create a Build Directory:

    mkdir build
    cd build
    

  4. Configure the Build with CMake:

    cmake ..
    

  5. Compile the Source Code:

    make -j$(nproc)
    

  6. Install TBB:

    sudo make install
    

  7. Verify the Installation:

    tbb_version
    

This should compile and install TBB on your Linux system. If you encounter any issues, make sure you have all the necessary dependencies installed and that your system is up to date.

Installing TBB

Sure, here’s a step-by-step guide to install TBB (Threading Building Blocks) from source on Linux:

  1. Download the Source Code:

    git clone https://github.com/oneapi-src/oneTBB.git
    cd oneTBB
    

  2. Build the Library:

    mkdir build
    cd build
    cmake ..
    make -j$(nproc)
    

  3. Install the Library:

    sudo make install
    

  4. Copy Necessary Files:

    • Libraries:
      sudo cp build/*/libtbb*.so* /usr/local/lib/
      sudo ldconfig
      

    • Headers:
      sudo cp -r include/tbb /usr/local/include/
      

This process will compile and install TBB, making it available for your projects. If you encounter any issues, make sure you have the necessary build tools and dependencies installed, such as cmake and gcc.

Verifying the Installation

To verify that Intel’s Threading Building Blocks (TBB) is installed correctly and working as expected, follow these steps:

  1. Check Installation:

    • On Linux, use the command: dpkg -L libtbb-dev to list installed files.
    • On Windows, ensure the TBB environment variables are set correctly, such as TBB20_INSTALL_DIR.
  2. Run Test Programs:

    • Compile and run a simple TBB example program. For instance, create a C++ file with a basic TBB parallel loop:
      #include <tbb/tbb.h>
      #include <iostream>
      
      int main() {
          tbb::parallel_for(0, 100,  {
              std::cout << i << " ";
          });
          return 0;
      }
      

    • Compile with: g++ -std=c++11 -ltbb test.cpp -o test (Linux) or use Visual Studio for Windows.
  3. Check for Common Issues:

    • Ensure your compiler and TBB versions are compatible.
    • Verify environment variables and paths are set correctly.
    • Look for any missing dependencies or libraries.

Running the test program should output numbers from 0 to 99 in parallel, indicating TBB is functioning correctly.

Installing Intel’s Threading Building Blocks (TBB) on Linux

To install Intel’s Threading Building Blocks (TBB) from source on Linux, follow these steps:

  1. Clone the repository using git clone https://github.com/oneapi-src/oneTBB.git
  2. Navigate to the cloned directory with cd oneTBB
  3. Build the library by running mkdir build, cd build, cmake .., and make -j$(nproc)
  4. Install the library using sudo make install followed by copying necessary files including libraries and headers.

To verify that TBB is installed correctly, check the installation, run test programs, and troubleshoot common issues such as compatibility with compiler versions, environment variables, and missing dependencies. Running a simple TBB example program should output numbers from 0 to 99 in parallel, indicating TBB is functioning correctly.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *