Open main menu

CDOT Wiki β

Changes

DPS921/Intel Parallel Studio Inspector

3,312 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 =
}
</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>
As the image below shows, the Intel Parallel 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.
[[File:ThreadRC.jpg]]
== OMP Race Conditions ==
 
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 OMP parallel construct it becomes accessible by all the threads and is no longer a local variable. This causes a race condition.
<syntaxhighlight lang="cpp" line='line'>
</syntaxhighlight>
[[File:OMPWarning.png|800px]]
= How to use Intel Parallel Studio Inspector =
 
There are two ways to use the Intel Parallel Studio Inspector
== Run There are two images below, One is an image of the results of an analysis of the above code by the Intel Parallel Inspector directly from Visual Studio ==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
This is the '''easiest and fastest''' way that requires no additional configuration[[File:OMPRC.jpg]]
Once you downloaded intel Inspector application, you need to restart your Visual Studio for the feature to work. OMP Error Message Below
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:OMPError.jpg]]
[[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:VSInspector2However, it should also be mentioned that should the code be fixed and analysis is re-run the number of positives goes down from 4 to 2.png|800px]]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)
== 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: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