Changes

Jump to: navigation, search

GPU621/Pragmatic

718 bytes added, 16:38, 21 November 2016
Added images to "Walkthrough" section
Pointers can be monitored by tracking the memory address of each pointer '''before''' entering the parallel region.
 
[[File:009.png|200px|thumb|right|alt| Attach to Process Window]]
===How to: Use the Memory Window===
'''Entry on: November 16th 2016 by Oleksandr Zhurbenko'''
 
===Using Parallel Stacks Window===
To select startup projects, right click on our solution (Solution 'GPU621 Walkthrough' (2 projects)) and select ''Properties'' (Shortcut Alt + Enter when solution is selected). In ''Solution 'GPU621 Walkthrough' Property Pages'' dialog, select ''Multiple startup projects'' radio button and choose ''Start'' action for both projects (Project "Part ONE" and project "Part TWO") under ''Common Properties'' section and ''Startup Project'' sub-section. Click ''Apply'' then ''OK'' to continue.
 
[[File:010.png|600px|thumb|center|alt| Configuration: Startup Projects]]
At this point, selecting ''DEBUG > Start Debugging'' (Shortcut F5) or ''Start Without Debugging'' (Shortcut Crtl + F5) will start both processes (Project "Part ONE" and project "Part TWO"), and this is exactly what we want.
To switch our solution to ''Release'' mode configuration, right click on our solution (Solution 'GPU621 Walkthrough' (2 projects)) and select ''Configuration Manager...''. In ''Configuration Manager'' dialog, select ''Release'' from ''Active solution configuration'' dropdown and click ''Close'' to continue.
 
[[File:011.png|600px|thumb|center|alt| Configuration: Active Solution Configuration]]
Now it is time to enable OpenMP support and disable optimization for both projects. Right click on project "Part ONE" in ''Solution Explorer'' and select ''Properties'' (Shortcut Alt + Enter when project "Part ONE" is selected). In ''Part ONE Property Pages'' dialog, expand ''Configuration Properties'' and select ''Language [Intel C++]'' sub-section under ''C/C++'' section (In the leftmost window), then enable OpenMP support by selecting ''Generate parallel Code (/Qopenmp)'' from ''OpenMP Support'' dropdown. Next, select Optimization sub-section under ''C/C++'' section, and disable optimization by selecting ''Disabled (/Od)'' from ''Optimization'' dropdown. Finally, enable OpenMP support and disable optimization for project "Part TWO" as we just did for project "Part ONE".
 
[[File:012.png|600px|thumb|center|alt| Configuration: OpenMP Support]]
 
[[File:013.png|600px|thumb|center|alt| Configuration: Optimization]]
'''NOTE:''' Since we will be referring to the specific lines of code by its line numbers, it is important you enable line numbers in your Visual Studio (If it's not enabled already). To enable line numbers, select ''TOOLS > Options...'', then in ''Options'' dialog expand ''Text Editor'' section and select ''All Languages'' sub-section in the leftmost window. On the right side you will see ''Line Numbers'' as one of the checkboxes. Ensure that it is checked and click ''OK''.
 
====Walkthrough====
'''NOTE:''' It is important to position each window in a way that will allow to minimize switching between tabs to access required window information. In other words, you want to see all of the tools, that we just enabled, on the screen at the same time.
 
[[File:014.png|600px|thumb|center|alt| Walkthrough: Window Positioning Example]]
Assuming that the execution stopped at a breakpoint on line 39, we should discuss ''Processes'' window and ''Location Debug'' toolbar while both process are running.
You will notice that threads that reach line 79 have their name changed to "GPU621 Thread - OpenMP ID: {OpenMP thread id}" (We take advantage of Microsoft's "void SetThreadName(DWORD dwThreadID, const char* threadName)" function to change the name of the thread). Ensure that all the flagged threads (Except "Main Thread") have their names changed (You may have to click ''Continue'' or press F5 multiple times). Changing the name of the thread may be very useful when debugging a multithreaded application with many threads, especially when using sorting by ''Name'' feature of the ''Threads'' window. Click ''Continue'' or press F5 to proceed to the next breakpoint.
 
[[File:015.png|600px|thumb|center|alt| Walkthrough: Changing Thread Name]]
On line 93 we can observe the accumulation into the thread private variable ''sum'' on each thread by using ''Parallel Watch'' window. After hitting the breakpoint on line 93 for the first time, you may notice that current thread (Yellow arrow in ''Threads'', and ''Parallel Watch'' windows indicate a current thread) has ''sum'' variable initialized to 0.0f, while other threads may have random (Garbage) value for ''sum'' variable. This happens because other threads did not reach line 87 (''sum'' declaration and initialization). You can observe the accumulation into ''sum'' on each thread later, when the execution hits line 93 breakpoint again.
Now lets see how ''#pragma omp parallel for'' breaks up the work between threads. This can be done by adding ''i'' into ''Parallel Watch''. Do it now, and observe its values change as you hold F5 or click ''Continue'' many times. You will see that the initial value of ''i'' is different on each thread, but how different? Look at ''N_SIZE'' value... The work is equally divided. Awesome!
 
[[File:016.png|600px|thumb|center|alt| Walkthrough: "parallel for" Region Work Division]]
When you are ready to proceed, remove the breakpoint on line 137 and click ''Continue'' or press F5 multiple times to pass the barrier on line 151.
One last thing that is worth mentioning about ''Parallel Watch'' window is the fact that variable values can be modified as we debug our program. Change the values of ''counterShared'' and ''counterPrivate'' (On each thread) variables to 101 by double clicking on variable values in the ''Parallel Watch'' window and modifying the value.
 
[[File:017.png|600px|thumb|center|alt| Walkthrough: Modifying Variables Using Parallel Watch Window]]
After clicking ''Continue'' or pressing F5 you will see that expression on line 154 (''if (counterPrivate == 101 && counterShared == 101)'') evaluates to true.
This concludes part one of this walkthrough.
 
====Source Code====
54
edits

Navigation menu