Changes

Jump to: navigation, search

OpenMP Debugging in Visual Studio / Team Debug

4,364 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.'''Multiple processes'''
The If you have more than one project in a project solution, you can choose which projects the debugger needs access to these files of the processesstarts.
To do this:*1.pdb file holds Right click your solution in solution explorer*2. Select Set Startup Projects*3. Then set the projects action to Start, Start without debugging and project state info that’s created on compileor none
[[File:Process-addprocess.png|1000px|center|Process window]]
Multiple processes
Each project is an individual process
If you have more than one project in You could also attach a project solutionprocess 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 can choose which projects the debugger startswant to attach
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 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 switch want to a processstart 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, all windows will show information for that process onlytype vsjitdebugger.exe in the Value data box.
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-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 we debug 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 program? bra bra braprogramming 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.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 to filter them.
*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==What you can see in - Using the Thread window under OpenMP project 1. config OpenMP 2. set OpenMP==
What can you see in the Thread window under OpenMP project? We will use the following program for the experiment.
// Thread.cpp
#include <iostream>
#include <stdio.h>
#include <omp.h>
using namespace std;
int main()
{ printf("num of default usable thread is %d \n\n", omp_get_max_threads()); // serialver printf("current using num of thread currently using is %d \n", omp_get_num_threads()); printf("usable working thread num of thread is %d \n", omp_get_max_threadsomp_get_thread_num()); // set openMP printf("\n"); #pragma omp parallel
{
#pragma omp single // set openMP 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());
}
// set openMP with num of threads printf("\n"); #pragma omp parallel num_threads(8) { #pragma omp single // set openMP with 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

Navigation menu