Open main menu

CDOT Wiki β

Changes

OpenMP Debugging in Visual Studio / Team Debug

4,375 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!!!
 
=???=
==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 . '''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]]   '''Multiple processes''' If you neededhave more than one project in a project solution, you can choose which projects the debugger starts. 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 [[File:Process-addprocess.png|1000px|center|Process window]]  
In order to add You could also attach a new process you need outside of the debugger to find the debugger, including processes on a remote device but your inspection ability is limited.pdb files*1.Choose the Debug menu ant click Attach to Process*2. Select the process you want to attach
The debugger needs access to these files of the processes[[File:Process-addprocess.png|1000px|center|Process window]]
.pdb file holds the debugging and project state info that’s created on compile
Multiple processesYou 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.
Each project is an individual process[[File:Process-startupprocess.png|center|Process window]]
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
You could also set When you have multiple processes, only one process to automatically start is active in the debugger – useful for services and custom setup actions, but in order to switch between processes you must also be in break mode.[[File:Process-switchprocess.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 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 vs2017Visual Studios), then the debugger will detach and leave that process running.
==Thread==
Multiple Threads
 
A process can have multiple threads.
difference
 
Multiple Processes doesn't share memory, while multiple Threads share memory. They can access the same data easily.
 
 
Thread enable the parallel programming but the parallel condition 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.
= User Interface =
[[File:process_window2.png|1000px|center|Process 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_windowthread_window2.png|1000px|center|Thread window1window]]
*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==
What can you can see in the Thread window under OpenMP project 1? We will use the following program for the experiment. config OpenMP 2. set OpenMP 
// Thread.cpp
#include <iostream>
#include <stdio.h>
#include <omp.h>
using namespace std;
int main()
{ // ***serial*** printf("current using num of default usable thread is %d \n\n", omp_get_num_threadsomp_get_max_threads()); // serial ver printf("usable num of thread currently using is %d \n", omp_get_max_threadsomp_get_num_threads());
printf("working thread num is %d \n", omp_get_thread_num()); printf("\n"); #pragma omp parallel
{
#pragma omp single // set openMP ver { // ***openMP*** printf("current using num of thread currently using is %d \n", omp_get_num_threads()); printf("usable num of thread is %d \n", omp_get_max_threads());
}
printf("working thread num is %d \n", omp_get_thread_num());
}
printf("\n"); #pragma omp parallel num_threads(8) { #pragma omp single { // ***set openMP with a setting of the num of threads***ver { printf("current using num of thread currently using is %d \n", omp_get_num_threads()); printf("usable num of thread is %d \n", omp_get_max_threads());
}
printf("working thread num is %d \n", omp_get_thread_num());
}
printf("\n");
return 0;
}
 
 
 
To 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 "Continue" button.
 
'''serial region'''
 
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]]
 
 
'''auto OpenMP parallel region '''
 
You can see "Stack Frame" name on the top screen is changed to main\omp\1
On 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]]
 
 
'''OpenMP parallel region thread number decided (8)'''
 
You can see "Stack Frame" 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