- Replace annotations with parallel framework code.
- Build a parallel version of your program.
- Before you build the Intel TBB sample, define the TBBROOT environment variable.
- Run the parallel program.
With your own program, before you add parallel framework code, you should complete developer/architect design and code reviews about the proposed parallel changes.
Add the Parallel Framework Code
In this step, you use the Visual Studio code editor to replace Intel Advisor annotations with parallel framework code. For your convenience, you only need to set the third sample project as your start-up project and build the executable:
In the 3_nqueens_tbb project, Intel® Threading Building Blocks (Intel® TBB) code has been added. Intel TBB is one of the high-level parallel frameworks supported by Intel Advisor for C++ programs. You need to set the environment variable TBBROOT as described below.
In the 3_nqueens_cilk project, Intel® Cilk™ Plus code has been added. Intel Cilk Plus is one of the high-level parallel frameworks supported by Intel Advisor for C or C++ programs. The project is already set to use the Intel® C++ Compiler.
In the 3_nqueens_omp project, OpenMP* code has been added. OpenMP is one of the high-level parallel frameworks supported by Intel Advisor for C, C++, or Fortran programs. The project is already set to use the Intel® C++ Compiler.
With your own program, select one of the high-level parallel frameworks available for your programming language:
Build and Examine the Parallel Program
Use the nqueens_Advisor sample to build and run one of the parallel programs, which use the Intel TBB, Intel Cilk Plus, or OpenMP parallel frameworks.
When using Visual Studio:
Right-click the 3_nqueens_tbb, 3_nqueens_cilk, or 3_nqueens_omp project in the Solution Explorer. Choose the project based on the installed compilers and the parallel framework(s) they support.
Choose Set as StartUp Project.
Verify that a release build has been selected.
Build > 3_nqueens_tbb. If you get compiler errors, make sure the TBB_ROOT environment variable is defined.
Build > 3_nqueens_cilk
Build > 3_nqueens_omp
From the Windows* Start menu, choose Intel Parallel Studio XE 2013 > Command Prompt > Parallel Studio XE > IA-32 Visual Studio [2008 | 2010 | 2012 | 2013] mode to set your environment.
Change directory to the nqueens_Advisor\ directory in its unzipped location.
If you choose IA-32 Visual Studio 20xx mode, type devenv nqueens_Advisor.sln to convert the nqueens_Advisor.sln solution. When conversion is complete, close the Visual Studio* IDE.
Type devenv nqueens_Advisor.sln /Build to build all projects in the solution.
Run the executable program.
- If you used the Intel Cilk Plus project, open the source file nqueens_cilk.cpp. View the Intel Cilk Plus #include files and the Intel Cilk Plus reducer declaration, and related Intel Cilk Plus code, such as the cilk_for line in the solve() function. Locate where the data race used to be at the line where variable nrOfSolutions is incremented. You will notice that the lock annotations have been replaced by a declaration of the Intel Cilk Plus reducer for the nrOfSolutions variable. For more information about Intel Cilk Plus, see Intel Advisor help topics under Adding Parallelism to Your Program or locate its documentation in your compiler documentation, such as Intel® Composer XE documentation directory.
- If you used the Intel TBB project, open the source file nqueens_tbb.cpp. View the Intel TBB #include files and related Intel TBB code, such as the parallel_for line in the solve() function. Locate where the data race used to be at the line where variable nrOfSolutions is incremented. You will notice that the lock annotations have been replaced by a scoped lock. For more information about Intel TBB, see Intel Advisor help topics under Adding Parallelism to Your Program or locate the Intel TBB documentation in the Intel Composer XE documentation directory.
- If you used the OpenMP project, open the source file nqueens_omp.cpp. View the OpenMP
#includefile and related OpenMP code, such as the
#pragma omp parallel forline in the
solve()function. Also notice that the lock annotations have been replaced by an
#pragma omp atomiclock for the
nrOfSolutions++;statement in the
setQueen()function. For more information about OpenMP, see Intel Advisor help topics under Adding Parallelism to Your Program or locate the OpenMP documentation in your compiler documentation, such as the Intel Composer XE documentation.
With your own program, while you add parallel framework code, view the Annotation Report window to help you locate the remaining Intel Advisor annotations that need to be replaced with parallel framework code. For help completing this step for your own program:
- Open the Advisor XE Workflow tab.
- Click the button below 5. Add Parallel Framework.
- View the instructions. Click the links to display topics in Intel Advisor help.
Defining the TBBROOT Environment Variable
Before you build the Intel TBB parallel sample, you need to define the TBBROOT environment variable. To define this environment variable:
Open the Control Panel.
Select System > Advanced system settings> Advanced tab > Environment variables button.
Under System variables or User variables, click New.
Specify the Variable name as: TBBROOT.
Specify the Variable value. Specify the path of the installed Intel C++ Composer XE files, including the \tbb directory. If you used the default path during installation, files are installed below: C:\Program Files (x86)\Intel\ or C:\Program Files\Intel\, such as C:\Program Files (x86)\Intel\Composer xxx\tbb.
Click OK several times.
Reboot your system for the change to take effect.
After reboot, you can test the definition by opening a command window and typing set TBBROOT.
Run the Parallel Program
If you used the Microsoft Visual Studio IDE, run the sample parallel application that you built previously using one of the parallel frameworks. Select the correct startup project and choose Debug > Start without Debugging. In the example below, the Intel Cilk Plus sample project is used on a 2-core system. Check for a display similar to the following:
The displayed execution time to run the parallel program of 3562 (on a 2-core system) is significantly less than the time required to run the serial version of the program, which was about 6188 milliseconds.
If you used the Intel Advisor Standalone GUI, change directory to nqueens_Advisor\Release, and type 3_nqueens_cilk.exe to execute the application. The time required to execute the parallel program is less than the serial version.
The difference between the serial and parallel execution time depends on multiple factors:
- The number of cores available on your system.
- How much of the original program's execution time was placed within a parallel site(s) and the characteristics of the tasks. Intel Advisor Suitability and Correctness tools use annotations to predict your serial program's parallel behavior, which lets you experiment with your sites and tasks - before you add any parallel code.
- Parallel overhead, type of locks, thread characteristics, and other factors - see Next Steps for the Parallel Program