Open main menu

CDOT Wiki β

Changes

OpenMP Debugging in Visual Studio / Team Debug

6,383 bytes added, 10:31, 15 December 2017
m
Group Members
# [mailto:oasturiano@myseneca.ca?subject=GPU621 Orlandson Asturiano]
please feel free to change the contents=Process and thread===Multiple Processes=='''Processes''' depth!!!
= test1 =
==test==
===Processes(Rough)===
Processes
Why would you have multiple projects in one solution?
https://stackoverflow.com/questions/8678251/benefits-of-multiple-projects-and-one-solution
*Use of services *custom Custom setup actions*working Working multiple languages*creating Creating libraries used in different places*large Large programs could be made up of many smaller projects for better management*working Working with multiple applications that interact with each other
 '''Configuration'''
https://msdn.microsoft.com/en-us/library/jj919165.aspx
By default breaking/stepping/stopping applies to all other processes, but can be changed if you needed'''Changing this option:''' *1. On debug menu, pick options and settings
In order *2. Go to add a new general page and toggle "Break all processes when one process you need to find the .pdb files.breaks" checkbox
The debugger needs access to these files of the processes[[File:Process-config.png|1000px|center|Process window]]
.pdb file holds the debugging and project state info that’s created on compile
'''Multiple processes'''
Each If you have more than one project is an individual processin a project solution, you can choose which projects the debugger starts.
If you have more than one project To do this:*1. Right click your solution in a project solutionexplorer*2. Select Set Startup Projects*3. Then set the projects action to Start, you can choose which projects the debugger startsStart without debugging or none
You could also attach a process outside of the debugger to the debugger, including processes on a remote device but your inspection ability is limited[[File:Process-addprocess.png|1000px|center|Process window]]
You could also set process to automatically start in the debugger – useful for services and custom setup actions
When you have multiple processes, only one process is active in the debugger, but in order to switch between processes, you must be in break mode
When you switch to You could also attach a processoutside of the debugger to the debugger, all windows will show information for that including processes on a remote device but your inspection ability is limited.*1. Choose the Debug menu ant click Attach to Process*2. Select the process onlyyou want to attach
When you stop debugging, if the current process was launched from the debugger it will terminate, however if you attached the debugger to the current process (attach to a process outside of vs2017), the debugger will detach and leave that process running[[File:Process-addprocess.png|1000px|center|Process window]]
  You could also set process to automatically start in the debugger which is useful for services and custom setup actions.*1. Start regedit*2. Got to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options*3. Select the folder of the application you want to start in debugger*4. In the folder right click and choose New, String Value.*5. Set name of new value from New Value to debugger.*6. Right clikc the new value and choose Modify.*7. On the Edit String dialog box, type vsjitdebugger.exe in the Value data box. [[File:Process-startupprocess.png|center|Process window]]   When you have multiple processes, only one process is active in the debugger, but in order to switch between processes you must also be in break mode.[[File:Process-switchprocess.png|1000px|center|Process window]]  When you switch to a process, all windows will show information for that process only. When you stop debugging, if the current process was launched from the debugger it will terminate, however if you attached the debugger to the current process (attach to a process outside of Visual Studios), then the debugger will detach and leave that process running. =Background=Thread==Multiple Threads A process can have multiple threads.   difference How Multiple Processes doesn't share memory, while multiple Threads share memory. They can we debug access the same data easily.  Thread enable the parallel programming but the parallel program? bra bra bracondition can have risks*Race Conditions - The results go wrong way by the order of thread work*Dead Lock - All thread wait for the other thread forever.Our test environment is "visual studio 2015" and "Intel Parallel Studio XE 2016"
= User Interface =
==Processes window==
[[File:process_window.png|700px|center|Process window1]]
-shortcutThe Process Window shows processes attached to the Visual Studio debugger  [[File:process_window2.png|1000px|center|Process window]]
-how to open
-description/How to use
-info you can see'''Setup:'''
-what is attach1. When you start debug (F5), click on DEBUG > Windows > Processes.
-what is detach2.  3. Terminate or Attach the process by using "Terminate Process" and "Attach to Process "icon.  '''How to Use:''' Select threads
==Threads window==
The Thread Window shows Thread list with the detailed information in your application, You can filter thread list and see the particular information.
 
[[File:thread_window2.png|1000px|center|Thread window]]
 
 
 
 
'''Setup:'''
 
1. When you start debug (F5), click on DEBUG > Windows > Threads.
 
2. You can filter by using flag and "Show Flag Threads Only" icon on the top of the Thread window.
 
3. You can show and hide the information columns by using "Columns" dropdown list on the top of the Thread window.
 
 
'''How to Use:'''
 
Turn on flags on the thread you want to see, and choose "Show Flag Threads Only" to filter them.
Choose which information to show or hide from the "Columns" dropdown list.
Sort the list by the information on the column by using "Group by" dropdown list if it is necessary.
 
 
'''Columns:'''
 
*flag column: you can mark a thread with red flags to pay attention or to filter them.
 
*active thread column: a yellow arrow indicates an active thread. An outline of an arrow indicates the thread where execution broke into the debugger.
 
*ID: the identification number for each thread. (It is DWORD: a typedef of 32bit integer)
*Managed ID: the managed identification numbers for managed threads.
[[File*Category:thread_window.png|700px|center|Thread window1]]categorizes threads as user interface threads, remote procedure call handlers, or worker threads and main threads
-shortcut*Name: thread name if it has, otherwise shows <No Name>.
-how to open *Location: where the thread is running (function name that is associated with the thread, or the address).
-description/how *Priority: the priority of the scheduling of the thread that the system has assigned to use each.
-info you *Affinity Mask: determines which processors on which a thread can seerun In a multiprocessor system.
==Source window== *Suspended Count: The number of times that the thread suspended.
*Process Name: the process to which each thread belongs. ==Source window== The Source window displays source code [[File:source_window2.png|1000px|center|Source window]]   '''Setup:''' 1. When you start debug (F5), it shows up automatically  2. If you closed the window, you can open by clicking any related information on the other windows.  '''How to Use:''' On the top of the window, Turn on an icon called "Show Threads in Source" that is off by default.[[File:op_off.png|50px|center|off]] [[File:op_on.png|50px|center|on]]Or you can do on and off from right-click menu on the thread window.[[File:show_op.png|300px|center|show]] On the gutter, you can see thread icon where the threads are currently working.Also, you can check the detail of the threads with mouse over. When the thread is single (at the beginning of the threading):[[File:tt_1.png|400px|center|1]] [[File:tt1_d.png|200px|center|1]]  When the thread is multiple.[[File:tt_2.png|400px|center|2]] [[File:tt2_d.png|400px|center|2]]
==Debug Location toolbar==
On the top right corner, there is a box where you can put a Boolean expression on which the window will filter the threads. So in our example, if we put i == 1, it will only show the one thread that has i = 1.
[[File:Parallelwatch-boolean.PNG|300px500px|center|Parallel Watch]]
==GPU Threads window==
= Walkthrough =
test environment: "visual studio 2015" with "Intel Parallel Studio XE 2016" with C++
==Case A- Using the Thread window==How to use Process window and thread window under multiple OpenMP project
1What can you see in the Thread window under OpenMP project? We will use the following program for the experiment. set OpenMP
2. create multiple subprojects in one project
 
3. set up multiple start up
 
4. how debug windows shows the status of multiple projects
 
5. how you can use each tool to find helpful info
 
project1: test1.cpp
// Thread.cpp
#include <iostream>
#include <omp.h>
using namespace std;
int main() { printf("num of default usable thread is %d \n\n", omp_get_max_threads()); // serial ver printf("num of thread currently using is %d \n", omp_get_num_threads());
printf("working thread num is %d \n", omp_get_thread_num()); printf("\n"); #pragma omp parallel
{
#pragma omp for single // set openMP ver { printf("num of thread currently using is %d \n", omp_get_num_threads()); } printf("working thread num is %d \n", omp_get_thread_num()); for } printf(int i = 0"\n"); i < 10; i++ #pragma omp parallel num_threads(8) { #pragma omp single // set openMP with num of threads ver { printf("num of thread currently using is %d \n", omp_get_num_threads()); cout << } printf(" now i at test1= working thread num is %d \n" << i << endl, omp_get_thread_num());
}
printf("\n");
return 0;
}
Project2: test2.cpp
#include <iostreamTo use OpenMP in visual studio, it is essential to turn on the OpenMP option. Debug>projectName option>C/C++>language>OpenMP support:YES  [[File:setting.png|600px|center|setting]] If the option was off, the result goes this. OpenMP doesn't work.[[File:noopenResult.png|400px|center|noopenResult]] If the option was on, the result is this.[[File:openResult.png|400px|center|openResult]] Abobe code consists of three part. The first is a serial region, the second is an OpenMP parallel region, the third is an OpenMP parallel region and the number of thread is decided by the code.TO check each region, we put markers on the lines that print the number of the thread currently using. Once click "start debugging", the debugger stops at the first breakpoint. You can chase the steps by using namespace std;"Continue" button. '''serial region''' int On the Threads window, you can see "main thread" line and some worker threads. The yellow arrow points only main() {thread. and go the next region. Apparently, ntdll.. threads are not used.[[File:serial.png|1000px|center|serial]]  #pragma omp '''auto OpenMP parallel region ''' { #pragma You can see "Stack Frame" name on the top screen is changed to main\omp for \1On the Threads window, you can see "main thread" and other new three thread which same as default usable thread number 4 (it is printed at the serial region as "omp_get_max_threads()"). after hitting 4 times (you can see the count on the breakpoint Window), the step goes to the next region.[[File:open.png|1000px|center|open]]  for '''OpenMP parallel region thread number decided (int j = 0; j < 10; j++8)''' cout << You can see " now j at test2= Stack Frame" << j << endl;name on the top screen is changed to main\omp\2 }On the Threads window, you can see "main thread" and other new seven thread which same as the thread number decided inside of the code. after hitting 8 times, the debugging is terminated. }[[File:open+.png|1000px|center|open+]]
==Case B - Using the Parallel Stacks and the Parallel Watch Window==
190
edits