Open main menu

CDOT Wiki β

Changes

OpenMP Debugging in Visual Studio / Team Debug

4,624 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 *2. Go to general page and toggle "Break all processes when one process breaks" checkbox [[File:Process-config.png|1000px|center|Process window]] 
In order to add a new process you need to find the .pdb files.
The debugger needs access to these files of the '''Multiple processes'''
If you have more than one project in a project solution, you can choose which projects the debugger starts.pdb file holds the debugging and project state info that’s created on compile
To do this:
*1. Right click your solution in solution explorer
*2. Select Set Startup Projects
*3. Then set the projects action to Start, Start without debugging or none
Multiple processes[[File:Process-addprocess.png|1000px|center|Process window]]
Each project is an individual process
If you have more than one project in a project solution, you can choose which projects the debugger starts
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.*1. Choose the Debug menu ant click Attach to Process*2. Select the process you want to attach
You could also set process to automatically start in the debugger – useful for services and custom setup actions[[File:Process-addprocess.png|1000px|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 be in break mode
When you switch to a process, all windows will show information for that process only
When you stop debugging, if the current You could also set process was launched from to automatically start in the debugger it will terminate, however if 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 attached 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 to .*6. Right clikc the new value and choose Modify.*7. On the current process (attach to a process outside of vs2017)Edit String dialog box, type vsjitdebugger.exe in the debugger will detach and leave that process runningValue 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. ==Thread=Background=How Multiple Threads A process can have multiple threads.   difference 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 =
[[File:process_windowprocess_window2.png|1000px|center|Process window1window]]
'''Setup:'''
1. When you start debug (F5), click on DEBUG > Windows > Processes.
'''How to Use:'''
Select threads
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_windowthread_window2.png|1000px|center|Thread window1window]]
'''Setup:'''
1. When you start debug (F5), click on DEBUG > Windows > Threads.
'''How to Use:'''
Turn on flags on the thread you want to see, and choose "Show Flag Threads Only" to filter them.
'''Columns:'''
*flag column: you can mark a thread with red flags to pay attention or thread list filteringto 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.
*Name: thread name if it has, otherwise shows <No Name>.
*Location: where the thread is running(function name that is associated with the thread, or the address).
*Priority: the priority or precedence of the scheduling of the thread that the system has assigned to each thread.
*Affinity Mask: determines which processors on which a thread can run In a multiprocessor system.
*Suspended Count: The number of times that the count determines whether a thread can runsuspended.
*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==
= 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