1.. _next_steps: 2 3Next Steps 4=========== 5 6After installing oneTBB, complete the following steps to start working with the library. 7 8Set the Environment Variables 9***************************** 10 11After installing |short_name|, set the environment variables: 12 13#. Go to the oneTBB installation directory. 14 15#. Set the environment variables using the script in ``<install_dir>`` by running: 16 17 * On Linux* OS: ``vars.{sh|csh} in <install_dir>/tbb/latest/env`` 18 * On Windows* OS: ``vars.bat in <install_dir>/tbb/latest/env`` 19 20.. tip:: 21 22 oneTBB can coordinate with Intel(R) OpenMP on CPU resources usage 23 to avoid excessive oversubscription when both runtimes are used within a process. 24 To enable this feature set up ``TCM_ENABLE`` environment variable to ``1``. 25 26 27Build and Run a Sample 28********************** 29 30.. tabs:: 31 32 .. group-tab:: Windows* OS 33 34 #. Create a new C++ project using your IDE. In this example, Microsoft* Visual Studio* Code is used. 35 #. Create an ``example.cpp`` file in the project. 36 #. Copy and paste the code below. It is a typical example of a |short_name| algorithm. The sample calculates a sum of all integer numbers from 1 to 100. 37 38 .. code:: 39 40 #include <oneapi/tbb.h> 41 42 int main (){ 43 int sum = oneapi::tbb::parallel_reduce( 44 oneapi::tbb::blocked_range<int>(1,101), 0, 45 [](oneapi::tbb::blocked_range<int> const& r, int init) -> int { 46 for (int v = r.begin(); v != r.end(); v++) { 47 init += v; 48 } 49 return init; 50 }, 51 [](int lhs, int rhs) -> int { 52 return lhs + rhs; 53 } 54 ); 55 56 printf("Sum: %d\n", sum); 57 return 0; 58 } 59 60 #. Open the ``tasks.json`` file in the ``.vscode`` directory and paste the following lines to the args array: 61 62 * ``-Ipath/to/oneTBB/include`` to add oneTBB include directory. 63 * ``path/to/oneTBB/`` to add oneTBB. 64 65 For example: 66 67 .. code-block:: 68 69 { 70 "tasks": [ 71 { 72 "label": "build & run", 73 "type": "cppbuild", 74 "group": { 75 "args": [ 76 "/IC:\\Program Files (x86)\\Intel\\oneAPI\\tbb\\2021.9.0\\include", 77 "C:\\Program Files (x86)\\Intel\\oneAPI\\tbb\\2021.9.0\\lib\\ia32\\vc14\\tbb12.lib" 78 79 80 #. Build the project. 81 #. Run the example. 82 #. If oneTBB is configured correctly, the output displays ``Sum: 5050``. 83 84 .. group-tab:: Linux* OS 85 86 #. Create an ``example.cpp`` file in the project. 87 #. Copy and paste the code below. It is a typical example of a |short_name| algorithm. The sample calculates a sum of all integer numbers from 1 to 100. 88 89 .. code:: 90 91 #include <oneapi/tbb.h> 92 93 int main(){ 94 int sum = oneapi::tbb::parallel_reduce( 95 oneapi::tbb::blocked_range<int>(1,101), 0, 96 [](oneapi::tbb::blocked_range<int> const& r, int init) -> int { 97 for (int v = r.begin(); v != r.end(); v++) { 98 init += v; 99 } 100 return init; 101 }, 102 [](int lhs, int rhs) -> int { 103 return lhs + rhs; 104 } 105 ); 106 107 printf("Sum: %d\n", sum); 108 return 0; 109 } 110 111 #. Compile the code using oneTBB. For example, 112 113 .. code-block:: 114 115 g++ -std=c++11 example.cpp -o example -ltbb 116 117 118 #. Run the executable: 119 120 .. code-block:: 121 122 ./example 123 124 #. If oneTBB is configured correctly, the output displays ``Sum: 5050``. 125 126 127Hybrid CPU and NUMA Support 128**************************** 129 130If you need NUMA/Hybrid CPU support in oneTBB, you need to make sure that HWLOC* is installed on your system. 131 132HWLOC* (Hardware Locality) is a library that provides a portable abstraction of the hierarchical topology of modern architectures (NUMA, hybrid CPU systems, etc). oneTBB relies on HWLOC* to identify the underlying topology of the system to optimize thread scheduling and memory allocation. 133 134Without HWLOC*, oneTBB may not take advantage of NUMA/Hybrid CPU support. Therefore, it's important to make sure that HWLOC* is installed before using oneTBB on such systems. 135 136Check HWLOC* on the System 137^^^^^^^^^^^^^^^^^^^^^^^^^^^ 138To check if HWLOC* is already installed on your system, run ``hwloc-ls``: 139 140* For Linux* OS, in the command line. 141* For Windows* OS, in the command prompt. 142 143If HWLOC* is installed, the command displays information about the hardware topology of your system. If it is not installed, you receive an error message saying that the command ``hwloc-ls`` could not be found. 144 145.. note:: For Hybrid CPU support, make sure that HWLOC* is version 2.5 or higher. For NUMA support, install HWLOC* version 1.11 or higher. 146 147Install HWLOC* 148^^^^^^^^^^^^^^ 149 150To install HWLOC*, visit the official Portable Hardware Locality website (https://www-lb.open-mpi.org/projects/hwloc/). 151 152* For Windows* OS, binaries are available for download. 153* For Linux* OS, only the source code is provided and binaries should be built. 154 155On Linux* OS, HWLOC* can be also installed with package managers, such as APT*, YUM*, etc. To do so, run: sudo apt install hwloc. 156 157.. note:: For Hybrid CPU support, make sure that HWLOC* is version 2.5 or higher. For NUMA support, install HWLOC* version 1.11 or higher. 158