# Intel® Threading Building Blocks Samples

This directory includes example usages of Intel® Threading Building Blocks (Intel® TBB).

System Requirements:

For the most up to date system requirements, see the release notes.

Directories

GettingStarted
  Examples from the Intel TBB Getting Started Guide.
concurrent_hash_map
  Examples using `concurrent_hash_map` container.
concurrent_priority_queue
  Examples using `concurrent_priority_queue` container.
graph
  Examples using Intel TBB Flow Graph feature.
parallel_do
  Examples using `parallel_do` algorithm.
parallel_for
  Examples using `parallel_for` algorithm.
parallel_reduce
  Examples using `parallel_reduce` algorithm.
pipeline
  Examples using `pipeline` algorithm.
task
  Examples using raw `task` interface.
task_group
  Examples using `task_group` interface.
task_arena
  Examples using the `task_arena` feature.
test_all
  Examples that test various components of Intel TBB.
common
  Common files for building various examples. Should not be used directly. But if you copy an example to other place this folder should be copied also and should have the same relative path for copied example.

Build Instructions
Note: Some of the following directions refer to a shell window. This refers to the command prompt environment/window normally used on your system:

- cmd.exe command prompt window for Windows* systems
- sh, bash, csh, ksh, etc. (or compatible) shell window for Windows*, Linux* or macOS* systems

Set up the environment for using Intel TBB:

To set up the environment for Windows* OS:

It is strongly recommended to set up the environment when installing Intel TBB. Do this by selecting the appropriate check-box during the install. However, if the environment is not set up during installation, or you wish to build for an alternate architecture or Microsoft* Visual Studio* version, it may be set up, for a given type of shell window, by using one of the following commands:

For cmd.exe (command prompt):

      <installdir>/bin/tbbvars.bat (arch) [vs]

where:
  - (arch) argument represents target architecture. Its possible values are 'ia32' or 'intel64'.
  - [vs] argument represents target version of Microsoft* Visual Studio*. Its possible values are:
    - 'vs<msvs_version>' - to use Intel TBB library with Microsoft* Visual Studio* <msvs_version> runtime DLLs, e.g.: `tbbvars intel64 vs2015`
      Note: for the most up to date supported versions of Microsoft* Visual Studio*, see the release notes.
    - 'all' - to use Intel TBB binaries statically linked with Microsoft Visual C++ runtime.
      If [vs] is not set the 'all' value will be used by default.

To set up the environment for Linux* OS and macOS*:

The environment may be set up, for a given type of shell window, by using one of the following commands:

For sh, bash, ksh, dash (or compatibles):

      . <installdir>/bin/tbbvars.sh (arch) [platform [TBBROOT_detection_mode]]

For csh (or compatibles):

      source <installdir>/bin/tbbvars.csh (arch) [platform [TBBROOT_detection_mode]]

where:
  - (arch) argument represents target architecture. Its possible values are 'ia32' or 'intel64'.
  - [platform] argument represents target platform. Its possible values are 'linux' or 'android'.
  - [TBBROOT_detection_mode] argument represents TBBROOT path detection method. Its only possible value is 'auto_tbbroot'. In this case the environment variable TBBROOT is detected automatically by using the tbbvars script directory path.

Environment setup need only be performed once per shell window to be used.
Always source tbbvars.sh or tbbvars.csh rather than executing them directly.
If the arguments to the sourced script are ignored (consult documentation for your shell) the alternative way to specify target is environment variables COMPILERVARS_ARCHITECTURE to pass (arch) to the script and COMPILERVARS_PLATFORM to pass [platform].

Build each example by using one of the following methods:

To build by using a Microsoft* Visual Studio* project (Windows* systems):

1. Identify the solution (*.sln) file for the example you wish to build and run. The *.sln file for each example is in the example's msvs sub-directory.
2. Open the project by using one of the following methods:
   - Navigate to the *.sln file from My Computer, by using Windows Explorer, or by using another file browser. Double-click the *.sln file to invoke Microsoft* Visual Studio* and open the project.
   - Invoke Microsoft* Visual Studio* from the Start menu and use the "Open Project" dialog to navigate to and open the project.
3. Press <ctrl-F5> to build and run the example.
4. If you copied an example to another place separately from libraries you need to set %TBBROOT% variable pointing to <installdir> folder.

To build by using a Xcode* IDE project (macOS* systems):
Note: Xcode* project instructions are not applicable for the Intel TBB Sample Bundle for Intel® System Studio because Intel System Studio does not support macOS*. For additional information, see the Release Notes.

1. Identify the project (*.xcodeproj) file for the example you wish to build and run. The *.xcodeproj file is in the example's xcode sub-directory.
2. Open the project by using one of the following methods:
   - Navigate to the *.xcodeproj file by using the Finder.Double-click the *.xcodeproj file to invoke the Xcode* IDE and open the project.
   - Invoke the Xcode* IDE and use the "File -> Open" dialog to navigate to and open the project.
3. Press <Apple-R>, or press the "Build and Go" button in the toolbox, to build and run the example.

To build by using a Makefile (Windows*, Linux* or macOS* systems):

1. Open a shell window
   - For Windows* systems, make sure this shell window has the proper environment defined for use with Microsoft* Visual Studio*. Such shell can be invoked from the Start menu, under Microsoft* Visual Studio*, Microsoft* Visual Studio Tools*, Microsoft* Visual Studio* Command Prompt.
2. Set up the environment in this shell window for use with Intel TBB.
   See above for how to set up the environment for Windows*, Linux* or macOS* systems.
3. Unless you installed Intel TBB yourself, you may not have write permissions to the directory containing the example. In this case, make a copy of the example, and use the copy for the following steps.
4. In the shell window, navigate to the directory for the example (or to the directory for the copy of the example if you made one in the previous step).
5. Use one or more of the following commands to build and run the example. Here, make refers to the make command normally used on your system: this could be nmake, gmake, or make on Windows* systems, or make or gmake on Linux* or macOS* systems.
   `make`
     Default build and run. Equivalent to 'make release test'.
   `make release`
     Compile and link against the release version of Intel TBB runtime library. The resulting executable is left in the directory for the example.
   `make debug`
     Compile and link against the debug version of Intel TBB runtime library. The resulting executable is left in the directory for the example.
   `make profile`
     Similar to 'make release' but also enables additional support for Intel® Parallel Studio XE analysis tools.
     Note: Only flow graph examples are currently supported.
   `make test`
     Run an executable previously produced by one of the above commands.
   `make [(above options or targets)] CXX={icl, icc}`
     Build and run as above, but use Intel® C++ Compiler instead of default, native compilers (e.g., icl instead of cl.exe on Windows* systems, or icc instead of g++ on Linux* or macOS* systems).
   `make [(above options or targets)] offload=mic`
     Build and run the offload version of an example for Intel® Many Integrated Core (Intel® MIC) Architecture.
     Note: Only Intel® MIC Architecture with Linux* based host is currently supported.
   `make clean`
     Remove any executables or intermediate files produced by the above commands.

Up to parent directory (available only in the Intel® Parallel Studio and Intel® System Studio Online Samples packages and the open-source version of Intel TBB)

Legal Information:

Optimization Notice

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804

Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.
* Other names and brands may be claimed as the property of others.
© 2020, Intel Corporation