Changes

Jump to: navigation, search

DPS921/Intel Parallel Studio Inspector

5,944 bytes added, 19:44, 30 November 2020
Progress
- Hard and confusing to configurating projects
- It doesn’t support Microsoft OpenMP and TBB
- It can provide false positive and false negative
[[File:FalsePositiveEdited.png|800px]]
 
 
 
= How to use Intel Parallel Studio Inspector =
 
There are two ways to use the Intel Parallel Studio Inspector
 
== Run Inspector directly from Visual Studio ==
 
This is the '''easiest and fastest''' way that requires no additional configuration.
 
Once you downloaded intel Inspector application, you need to restart your Visual Studio for the feature to work.
 
Inside Visual Studio, there are two ways of accessing the inspector debugger.
 
The first way is to go to the tools drop down menu and locate “Intel Inspector”, then you should be able to click on what you want to debug.
 
[[File:VSInspector.png|800px]]
 
Second way is to locate the inspector icon, few directions right on tools. There will be a drop down menu that should lets you choice what choice of debugging you want to do or start a new analysis.
 
[[File:VSInspector2.png|800px]]
 
== Run the application via Inspector ==
 
Before we start, I want to be able to show you how the Inspector UI looks like as a whole.
 
[[File:InspectorUI2.png|900px]]
 
Working with intel inspector application requires passing it a compiled version of your program. Additionally, you may need to link some libraries (lib, dll, and etc.)
 
[[File:InspectorApp.png|500px]]
 
=== Configure a Project ===
 
Intel suggests using small data set sizes and load threads with small chunks of work.
 
This will reduce the run time and the speed of the analysis.
 
On the left side, right click on the project so that you get a drop-down menu and click “new analysis” to configure a project the way you want it.
 
[[File:analysis.png|500px]]
 
=== Choose Analysis Type ===
 
Inspector allows you to choose between predefined types of analysis.
 
[[File:ConfAnalysis.png|800px]]
 
Choose the type of analysis using a drop down menu
 
[[File:AnalysisType.png|200px]]
 
'''Memory Error Analysis:'''
 
• Detect Leaks
 
• Detect Memory Problems
 
• Locate Memory Problems
 
'''Threading Error Analysis:'''
 
• Detect Deadlocks
 
• Detect Deadlocks and Data Races
 
• Locate Deadlocks and Data Races
 
'''Custom Analysis types:''' users can create their own types based on selected preset type.
 
[[File:MemoryLevs.png|500px]]
 
In this screenshot, it show cases the different levels for memory error analysis.
 
Types at the top have smaller scope but faster in execution.
 
Types at the bottom have larger scope but they are considerably slower.
 
 
=== How it works ===
 
Inspector performs the analysis in multiple steps:
 
1. The program is executed
 
2. It identifies problems that may need to be resolved
 
3. Gathers problems
 
4. Converts symbol information into filenames and line numbers
 
5. Applies suppresion rules
 
6. Remove duplicates
 
7. Create problem sets
 
8. Opens a debugging session
 
 
=== Making it work ===
 
First you need an executable file. You get that building your solution on Visual Studio. Once you have your executable file, you import that to Intel Inspector by using “Project Properties” when you right click on the project located on the left side.
 
[[File:ProjectProperties.png|500px]]
 
Once you are in the Project Properties section, you need to locate the executable file.
 
[[File:ProjectProperties2.png|700px]]
 
Application section is the executable file. Application section is the command argument, if the application has a command argument.
 
 
=== Interpreting Results ===
 
After the analysis completes, IPS XE Inspector will show you information on 2 pages:
 
'''Collection Log'''
 
Gives a general information about the execution of the program.
From there you can see execution time, number of threads, the caller of threads, if they were active or not.
 
[[File:CollectionLogRes.png|700px]]
 
'''Summary'''
 
The summary window is divided into 4 parts:
 
'''1. Problems section'''
 
It shows problems (if any found) that we asked the inspector to look for.
It provides you with a name of the problem, the file where the problem is located, the executable module which contains it, and the state of problem (which changes when do you a rescan).
 
[[File:SummaryResults.png|800px]]
 
'''2. Filters''' (On the right side of the problems section)
 
Gives the summary of all problems (Sources file affect, total of problems by types, etc)
 
[[File:FiltersResults.png|800px]]
 
'''3. Code Locations'''
 
When we select a problem, code locations will show a preview of a source file and highlights and line on which the problems was detected.
 
[[File:CodeLocationResults.png|800px]]
 
Moreover, it shows the operation that is performed (Read, Write), including thread operations.
Source files can be opened and edited directly from the Inspector by double clicking the problem
 
'''4. Timeline'''
 
Shows threads that involved at the certain step.
There is a thread and timeline information for all code locations in one or all occurrences of the problem(s) highlighted in the Problems pane
 
[[File:TimelineResults.png|800px]]
= Code for Intel Inspector =
== Pointer Miss Management {Memory Leak} ==
The Below code creates a dynamically allocated array of Integer pointers and allocates a new integer into each index.
In the Second For loop, the code goes onto make every even-numbered pointer point towards the next highest odd-numbered pointers memory address.
This Effectively causes a memory leak where half of the allocated memory locations no longer have any pointers pointing to them. After this, the code goes onto perform a delete operation on every pointer in an attempt to fool the Parallel Studio debugger.
 
<syntaxhighlight lang="cpp" line='line'>
}
</syntaxhighlight>
 
As can be seen Below the Intel Parallel Inspector debugging tool was not fooled by the attempt to misguide it and effectively detected the leak. However it should also be pointed out that it did not detect where the leak occurs, but instead, where the pointer which is leaking is instantiated, furthermore, the debugging tool seems to be misdiagnosing memory errors having to do with improper instantiation, where none exist. This can be caused by the nature of the array having the same signature as a 2D array but being treated as a one dimensional array.
[[File:FalsePositive.png]]
 
== False Positive ==
The code below attempts to fool the Intel Parallel Inspector into assuming that the pointer allocated pointers have not been deleted when they have. The pointers address' are copied into a temporary pointer called deletor, which then is used to delete the allocated memory without directly calling the delete operation on the raw pointers themselves. The intel parallel studio does not fall for this attempt either. It accurately does not find a memory leak. However, it still shows a false positive for an uninitialized access error due to the nature of the array.
<syntaxhighlight lang="cpp" line='line'>
</syntaxhighlight>
 
The image below showcases how The intel Parallel Inspector can show false positives. If you into the yellow highlighted section you will see that the error occurs on line 18 when we try to access *mypointer, which the inspector falsely claims not to have been initialized, however if we look at line 17 we can see that the pointer was properly initialized.
 
[[File:FalsePositiveCode.jpg]]
== Thread Race Conditions ==
The below code does three things. The fisrt is to define a class counter. This class has three functions and one member variable. the Variable is the counter which is meant to be iterated. The three functions are the constructor, which sets the counter to 0. The getter which returns the value of the counter and lastly the increment function add(), which when called increments the counter by the specified amount. Secondly the code defines the function runCounter() which is responsible for creating a counter type object, creating ten threads and assigning them all to increment the counter by 1,000 simultaneously. This creates the optimal conditions for a race condition to occur within the add() member function of the counter object. And lastly the main() function is responsible for running the runcounterFunction 10,000 times.
<syntaxhighlight lang="cpp" line='line'>
</syntaxhighlight>
= How to use As the image below shows, the Intel Parallel Studio Inspector =manages to accurately detect the race condition, and properly highlight it in the showcase window. It should be noted that this view creates the perfect perspective to guide a programmer to implement either a lock or a mutex on this particular segment of code.
There are two ways to use the Intel Parallel Studio Inspector[[File:ThreadRC.jpg]]
== Run Inspector directly from Visual Studio OMP Race Conditions ==
This The code below attempts to create a race condition using the OMP parallel construct. The race codnition is created by the variable temp, which is supposed to be a local variable for the specific thread which is used to collect the total sum for the calculations done by the thread. however if the variable is put outside the '''easiest OMP parallel construct it becomes accessible by all the threads and fastest''' way that requires is no additional configurationlonger a local variable. This causes a race condition.
Once you downloaded intel Inspector application, you need to restart your Visual Studio for the feature to work. <syntaxhighlight lang="cpp" line='line'>
Inside Visual Studio, there are two ways of accessing the inspector debugger#include <iostream>#include <iomanip>#include <omp. h>
The first way is to go to the tools drop down menu and locate “Intel Inspector”, then you should be able to click on what you want to debug.
// Race Condition int main() { int numThreads = 6; int numSteps = 1000000; omp_set_num_threads(numThreads); double* sum = new double[[File:VSInspectornumThreads]; double pi, totalSum = 0.0; const double stepSize = 1.png|800px]]0 / numSteps;
Second way is // Creates The Race Condition, Place within the OMP Parallel to locate the inspector icon, few directions right on toolsundo race condition double temp = 0.0;#pragma omp parallel { int ID = omp_get_thread_num(); int incriment = ID; double x; for (int i = ID; i < numSteps; i = i + numThreads) { x = ((double)i + 0.5) * stepSize; temp += 1. There will be a drop down menu that should lets you choice what choice of debugging you want to do or start a new analysis0 / (1.0 + x * x); }
sum[[File:VSInspector2.png|800px]ID]= temp; }
for (int i =0; i < numThreads; i++) { totalSum = Run the application via Inspector ==totalSum + sum[i]; }
Before we start, I want to be able to show you how the Inspector UI looks like as a whole pi = (4.0) * totalSum * stepSize; delete[] sum;
[[File std:InspectorUI2:cout << "Expexted Number : 3.png|900px]]14___" << std::endl; std::cout << "REceived Number : " << pi << std::endl;
Working with intel inspector application requires passing it a compiled version of your program. Additionally, you may need to link some libraries (lib, dll, and etc.)} [[File:InspectorApp.png|500px]] === Configure a Project === Intel suggests using small data set sizes and load threads with small chunks of work. This will reduce the run time and the speed of the analysis.  On the left side, right click on the project so that you get a drop-down menu and click “new analysis” to configure a project the way you want it. [[File:analysis.png|500px]] === Choose Analysis Type === Inspector allows you to choose between predefined types of analysis. [[File:ConfAnalysis.png|800px]] Choose the type of analysis using a drop down menu [[File:AnalysisType.png|200px]] '''Memory Error Analysis:'''</syntaxhighlight>
• Detect Leaks
• Detect Memory Problems
• Locate Memory ProblemsThere are two images below, One is an image of the results of an analysis of the above code by the Intel Parallel Inspector which as can be seen has flagged race conditions in the file, however, upon closer examination it becomes apparent that the details about the race conditions are nonsensical and cannot be interpreted (this can be seen by looking at the highlighted portion of the code view). This can be explained by the second image below. Highlighted in that image in the red box a warning message can be seen warning the user that Microsoft OMP is not supported by the Intel Parallel Inspector which might cause false positives or inaccurate diagnostics
'''Threading Error Analysis[[File:'''OMPRC.jpg]]
• Detect DeadlocksOMP Error Message Below
• Detect Deadlocks and Data Races
• Locate Deadlocks and Data Races[[File:OMPError.jpg]]
'''Custom Analysis types:''' users can create their own types based on selected preset type.
[[File:MemoryLevs.png|500px]]
In this screenshotHowever, it show cases should also be mentioned that should the different levels for memory error code be fixed and analysisis re-run the number of positives goes down from 4 to 2.This means that there is internal code generated by the OMP addon that results in the Inspector flagging false positives, but also that the Inspector is capable of detecting race-conditions in OMP code (MS Version), it's just not able to effectively pinpoint their location and communicate it to the programmer. (Image of analysis on fixed code below)
Types at the top have smaller scope but faster in execution. Types at the bottom have larger scope but they are considerably slower.  === How it works === Inspector performs the analysis in multiple steps: 1. The program is executed 2. It identifies problems that may need to be resolved 3. Gathers problems 4. Converts symbol information into filenames and line numbers 5. Applies suppresion rules 6. Remove duplicates 7. Create problem sets 8. Opens a debugging session  === Making it work === First you need an executable file. You get that building your solution on Visual Studio. Once you have your executable file, you import that to Intel Inspector by using “Project Properties” when you right click on the project located on the left side. [[File:ProjectProperties.png|500px]] Once you are in the Project Properties section, you need to locate the executable file.  [[File:ProjectProperties2.png|700px]] Application section is the executable file. Application section is the command argument, if the application has a command argument.  === Interpreting Results === After the analysis completes, IPS XE Inspector will show you information on 2 pages: '''Collection Log''' Gives a general information about the execution of the program. From there you can see execution time, number of threads, the caller of threads, if they were active or not.  [[File:CollectionLogRes.png|700px]] '''Summary''' The summary window is divided into 4 parts: '''1. Problems section''' It shows problems (if any found) that we asked the inspector to look for.It provides you with a name of the problem, the file where the problem is located, the executable module which contains it, and the state of problem (which changes when do you a rescan). [[File:SummaryResults.png|800px]] '''2. Filters''' (On the right side of the problems section) Gives the summary of all problems (Sources file affect, total of problems by types, etc) [[File:FiltersResults.png|800px]] '''3. Code Locations'''  When we select a problem, code locations will show a preview of a source file and highlights and line on which the problems was detected. [[File:CodeLocationResults.png|800px]] Moreover, it shows the operation that is performed (Read, Write), including thread operations.Source files can be opened and edited directly from the Inspector by double clicking the problem '''4. Timeline'''  Shows threads that involved at the certain step.There is a thread and timeline information for all code locations in one or all occurrences of the problem(s) highlighted in the Problems pane [[File:TimelineResultsOMPFixed.png|800pxjpg]]
= Reference =
Update 3: Sunday November 29th 2020 - Adding all the information for the report
 
Update 4: Monday November 30th 2020 - Made final edits to the Wiki
150
edits

Navigation menu