|
| 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
| |
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.
| |
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:
% 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.
| |
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.
| |
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.
| |
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> |
| |
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.
| |
| |
| |
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.
