Building the Intel® Threading Building Blocks (TBB) Version

To build the Intel® TBB version, you will modify the sample application to use Intel® TBB and then compile the modified code. You will then start the application and then compare the time with the baseline performance time.

  1. Set the build_with_tbb project as the startup project.

  2. For project build_with_tbb, change the compiler to the Intel® C++ Compiler (Project > Intel Compiler > Use Intel C++).

  3. For the project build_with_tbb click Project > Intel Compiler > Select Build Components > Use TBB to set the TBB environment variables. The environment variables that are set is defined in Notes section.

  4. Open the source file build_with_tbb.cpp in the project build_with_tbb.

  5. Remove the comment marks for the TBB headers to declare the TBB functions that will be used in the sample application.

    #include "tbb/task_scheduler_init.h"
    #include "tbb/parallel_for.h"
    #include "tbb/blocked_range.h"

  6. Remove the comment marks from the draw_task class definition. This class replaces the draw_task() function with a class that defines a function object. Note the similarity of the code in the operator() member function in the draw_task class and the draw_task() function. The operator() member function takes the argument const tbb:blocked_range<int> &r. This argument is the iteration range passed to the Intel® TBB thread executing this function object.

  7. Add comment marks to the draw_task() function since the tasks in this function are now defined in the draw_task class.

  8. Remove the comment marks from the following in the thread_trace() function:

    • The lines regarding Intel® TBB schedule and number of threads. these lines allow you to manually define the number of threads in the environment variable TACHYON_NUM_THREADS.

    • The lines regarding the grain size if you want to experiment by changing the grain size. The grain size is the lower limit on the number of loop iterations that can be divided among threads.

    • The Intel® TBB parallel_for function. This function is where the parallelization call happens. The first argument in this function defines the iteration space the loop executes along from starty to stopy. If you want to manually specify a grain size, you would pass grain_size to the tbb::blocked_range constructor as the third parameter. The second parameter is the draw_task() function object. The last parameter is the Intel® TBB auto_partitioner which controls the loop iteration partitioning automatically.

  9. Add comment marks to the draw_task() function since the parallel_for() replaces this function.

  10. Build build_with_tbb in release configuration.

  11. Start the sample application.

Compare the time to render the image to the baseline performance time.

Note

Open the Building the Building the Intel Cilk Plus Version topic