Using Intel's Threaded Building Blocks (TBB) With Sun Studio Express

   
By Deepankar Bairagi, May 2008  

Learn to use Sun Studio compilers and tools to build Intel's TBB, an open-source runtime library that facilitates parallelism in C++ programs.

Contents

Introduction

Intel's Threading Building Block (TBB) is a leading-edge, open-source runtime library with a rich set of templates that significantly lowers the effort required to express parallelism in C++ programs. A version of TBB that can run on the Solaris platform (x86) has been recently released. This version of TBB can be built using Sun Studio Express compilers and tools, the latest set of compilers and tools from Sun Microsystems that are geared towards simplifying multi-core development and that provide industry-leading application performance.

This article describes the steps involved in obtaining the right sets of tools to build TBB using Sun Studio software. It also illustrates how to build and run an example program that uses TBB. The Intel TBB distribution includes excellent documentation about how to develop an application using TBB. This article focuses on issues specific to using TBB with Sun Studio software on the Solaris OS and can be considered supplemental to such documentation.

Downloading Sun Studio Express Compilers and Tools

It is assumed that you already have an x86 machine running the Solaris 10 OS.

To build TBB on the Solaris OS and to build applications using TBB, you must use the Sun Studio Express February 2008 build.

To download Sun Studio Express software:

  1. On the SDN web site, click the Products tab and choose Sun Studio Compilers and Tools.
     
  2. On the Sun Studio web page, click the link for the Sun Studio Express - February 2008 Build.
     
  3. The latest Sun Studio software including the express builds can be downloaded for free. Scroll down the Sun Studio Express web page, provide your email address in the box, and click the "Download Now" box.
     
  4. Follow the instructions to download the product tar file. You need to choose the appropriate platform (for example, Solaris 9/10, x86) and agree to the Software License Agreement.
     
  5. It is recommended to use the Sun Download Manager to download the tar file.
     
  6. After the tar file is downloaded, you can extract and install the compiler using the following command.
 % bzcat StudioExpress-sol-x86-2008-02-25.ii.tar.bz2 | tar xf -
 

TBB can also be built using the Sun Studio 12 compilers. However, the Sun Studio 12 compilers require a patch that is not yet available for download. This information will be made available as soon as the patch is ready.

Downloading TBB for the Solaris OS

You can download TBB. Remember to choose the stable version of TBB. Download both the source version and the Sun binaries available at the TBB download site.

Use gunzip to unzip the tbb source archive and then extract from the tar archive. If available, use gtar to extract the tar file. A directory named tbb20_010oss_src is created. Similarly extract the Sun binaries and place them adjacent to the src directory of the source distribution.

It is also strongly recommended to download the Getting Started Guide and TBB Tutorial from the documentation page.

Building TBB Using Sun Studio Express Compilers and Tools

Make sure that Sun Studio Express compilers and gmake are on your path. In a typical Solaris 10 distribution, gmake is often installed in /usr/sfw/bin or opt/sfw/bin. You can also download and install gmake.

Assuming Sun Studio Express Compilers are installed in /opt/SUNWspro/bin, to build the TBB library and place it in the build directory:

% setenv PATH /opt/SUNWspro/bin:/usr/sfw/bin:${PATH}

% which CC
/opt/SUNWspro/bin/cc

% which gmake
/usr/sfw/bin/gmake


% cd tbb20_010_oss_src

% gmake
 

This builds the TBB library and places it in the build directory, for example, tbb20_010oss_src/build/SunOS_ia32_suncc_cc5.9_kernel5.10_release.

This directory contains the files libtbb.so and libtbbmalloc.so.

The TBB build also generates two files, tbbvars.csh and tbbvars.sh. These two files contain useful settings of environment variables such as LD_LIBRARY_PATH, which are needed for building an example.

If you downloaded the Sun binaries for TBB, the shared objects for the library are available in the directory tbb20_20080408oss_src/sun/ia32/cc3.4.3_kernel5.10/lib. The tbbvars.csh and tbbvars.sh scripts are in the directory tbb20_20080408oss_src/sun/ia32/cc3.4.3_kernel5.10/bin.

Building and Running Examples

The TBB distribution consists of several examples that illustrate the use of the templates provided by the TBB library.

To build all the examples:

% cd tbb20_010oss_src/examples

% gmake
 

This results in all the examples being built and run. This assumes that you have already built the TBB sources and the library is available, for example in tbb20_20080408oss_src/build/SunOS_ia32_suncc_cc3.4.3_kernel5.11_release.

If you would like to use the pre-built TBB libraries to build the examples, remember to edit the tbbvars.sh or .csh script file, fill in the appropriate directory name for TBB20_INSTALL_DIR, and then source the script.

To build a specific example, let's take the example of the Sub string finder in the GettingStarted sub-directory. The Getting Started Guide on the TBB documentation page gives step-by-step directions for how to use the parallel_for template in TBB to write this substring matching program.

Make sure that the tbbvars.csh[sh] file is already source in, because the TBB20_INSTALL_DIR and tbb_bin and LIBRARY_PATH need to be defined correctly in the user's environment.

% source tbbvars.csh

% cd examples/GettingStarted/sub_string_finder

% setenv TBB_SOURCE_DIR <complete path of tbb20_20080408oss_src>

% setenv CXXFLAGS "-I${TBB_SOURCE}/include -library=stlport4 -M${TBB_SOURCE}/build/suncc.map.pause"

% gmake CXX=CC
 

This builds and runs the sub_string_finder executable.

It is also necessary to use the link-time flag -library=stlport4, because the Sun Studio CC compiler builds the TBB library, which happens to use STL extensively, with the STLport's implementation of the standard library.

If the program includes any of the include files that are part of the TBB distribution, it is necessary to explicitly specify the include path in the compile time flags. For example:

-I${TBB20_INSTALL_DIR}/include
 

These settings either need to be defined in the makefile in addition to the user's environment (for example, through the tbbvars.csh file) or passed on directly in the command-line compilation or make command, for example:

gmake CXX=CC CXX_FLAGS=<flags> INCLUDES=<include flags>
 

Conclusion

The availability of Threading Building Blocks built with Sun Studio compilers on the Solaris OS opens up very exciting opportunities for application developers to develop parallel applications. The Solaris OS has long been an excellent platform for parallel application development and deployment with proven records of performance, scalability, and a system stack fine-tuned to harness the computing power offered by multi-core and multi-processor systems. Sun Studio compilers and tools have been an industry leader not only in setting performance records, but also in offering a rich feature set such as auto-parallelization, Open MP support, a thread analysis tool, and a performance analyzer and debugger to develop, debug, and tune applications for multi-threading and multi-core. TBB has significantly enhanced the state of the art in multi-threading application development by providing a framework where programmers can elegantly express parallelism. The confluence of these technologies leads to very interesting possibilities as programmers can attempt to exploit the parallelism offered by the latest multi-core systems, by developing applications using the TBB parallel programming model with Sun Studio compilers on the Solaris OS.

 
 
Related Links
 
 
Videos
 
 
About the Author

Deepankar Bairagi is a Staff Engineer with the Sun Studio Compiler team at Sun Microsystems, where he works on code generation and compiler optimizations for the compiler back end for x86/x64 platforms. Prior to his current position Deepankar worked at Sun Microsystems Laboratories. Deepankar holds a PhD in Computer Engineering from North Carolina State University.

Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.
Left Curve
System Administrator
Right Curve
Left Curve
Developer and ISVs
Right Curve
Left Curve
Related Products
Right Curve
solaris-online-forum-banner