Open main menu

CDOT Wiki β

Changes

GPU621/Pragmatic

6,563 bytes added, 08:39, 17 November 2016
Added "Project Configuration" section a template for walkthrough and source code
*''All notes are based on the material outlined in "Debug Multithreaded Applications in Visual Studio" section of MSDN documentation at:'' [https://msdn.microsoft.com/en-us/library/ms164746.aspx https://msdn.microsoft.com/en-us/library/ms164746.aspx] ''and other related MSDN documentation.''
 
'''Entry on: November 6th 2016 by Vadym Karpenko'''
 
===Debug Multithreaded Applications in Visual Studio===
Visual Studio provides many useful tools that make multithreaded debugging tasks easier.
 
===Debug Threads and Processes===
'''NOTE:''' While debugging OpenMP in Visual Studio, we will be using ''Processes'', ''Parallel Watch'', ''Threads'', and ''Parallel Stacks'' windows, and the ''Debug Location'' toolbar.
 
===Debug Multiple Processes===
# When working with multiple projects in one solution, startup project (One or many) can be set by right clicking on solution and selecting Properties option (Or selecting a solution in ''Solution Explorer'' and pressing Alt + Enter), then (In Property pages dialog) selecting appropriate action for each project in the solution under ''Common Properties > Startup Project'' tab;
# To change how ''Stop Debugging'' affects attached processes, open to ''Processes'' window (Crtl + Alt + Z), right click on individual process and check/un-check the "Detach when debugging stopped" check box;
 
'''Entry on: November 9th 2016 by Vadym Karpenko'''
 
===How to: Use the Threads Window===
* The frame column - indicates the selected frame (Yellow arrow);
* The configurable column - displays value for the expression;
 
'''Entry on: November 15th 2016 by Vadym Karpenko'''
 
===Pointers in OpenMP Parallel Region===
* Show Line Numbers
* Show Byte Offsets
 
 
==Walkthrough: OpenMP Debugging in Visual Studio==
 
===Part I: Project configuration and debugging a simple application using Processes, Threads, and Parallel Watch windows (By Vadym Karpenko)===
 
Before we proceed, please ensure that you have installed following items:
* ''Visual Studio'' (Visual Studio 2015 Community Edition was used for this walkthrough);
* ''Intel C++ Compiler'' (Version 17.0 was used for this walkthrough);
 
When it comes to debugging a multithreaded application, project configuration is an essential factor that may affect the debugging process in most unpredictable ways. For instance, if your project is using optimization, you may notice that some of your breakpoints are being skipped (Or simply invisible) during debugging process. In most of the scenarios, this is an unacceptable behaviour during application development phase, since you may want to track your application's state and behaviour at every stage of the execution. This is why we will begin this walkthrough with configuring our walkthrough projects.
 
 
====Project Configuration====
 
Open Visual Studio and select ''New Project...'' under ''Start'' tab (Or select ''FILE > New > Project...'').
 
In ''New Project'' dialog, make sure that ''Visual C++'' sub-section is selected under ''Templates'' section (In the leftmost window), then select ''Empty Project'' template (In the middle window). Enter the name of the project "Part ONE" (''Name'' field) as well as solution name "GPU621 Walkthrough" (''Solution name'' field). Click ''OK'' to continue.
 
Debugging a multithreaded application involves keeping tack of processes and threads that belong to each process (A single instance of a program). To better illustrate relationship between processes and threads, our walkthrough solution includes two projects (Processes) that will run at the same time.
 
To add a new project to our solution, right click on solution (Solution 'GPU621 Walkthrough' (1 project)) in the ''Solution Explorer'' window and select ''Add > New Project...'', then, in ''Add New Project'' dialog, enter the name of the project "Part TWO" (''Name'' field) and ensure that ''Empty Project'' template is selected under ''Visual C++'' sub-section. Click ''OK'' to continue.
 
If everything went well, you will see two projects ("Part ONE" and "Part TWO") under our solution (Solution 'GPU621 Walkthrough' (2 projects)).
 
Now we need to add source files for each project in our solution. Right click on project "Part ONE" in ''Solution Explorer'' and select ''Add > New Item''. In ''Add New Item - Part ONE'' dialog, ensure that ''C++ File (.cpp)'' template is selected, then enter the name of the source file "mainPartOne" (We want to keep source file names different for "Part ONE" and "Part TWO" projects to avoid the confusion between processes during debugging) and click ''OK'' to continue. Copy the contents of the source file from ''Part I'' walkthrough into our newly created file and save the file (Shortcut Ctrl + S). Now add new source file to "Part TWO" project. Name the source file "mainPartTwo" and copy the contents of the source file from ''Part II'' walkthrough into it. Dont forget to save the file.
 
Now our solution has two projects that can be executed independently. However, if we start our solution (With or without debugging), only one process (Project "Part ONE") will start, and this is not what we want. We want both processes (Project "Part ONE" and project "Part TWO") to start at the same time. For that to happen, we need to configure our solution.
 
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.
 
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.
 
Excellent, next step is to enable Intel C++ Compiler. Right click on our solution (Solution 'GPU621 Walkthrough' (2 projects)) and select ''Intel Compiler > Use Intel C++''. In Use Intel C++ dialog click ''OK''. Do not rebuild the solution, since it will generate errors, because we did not enable OpenMP support yet.
 
We need to enable OpenMP support, but before we start configuring our projects, we need to switch our solution to ''Release'' mode configuration and then configure both projects in ''Release'' mode.
 
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 ''OK'' to continue.
 
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".
 
'''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====
 
 
 
====Source Code====
 
 
 
===Part II: Debugging a simple application using the Parallel Stacks window (By Oleksandr Zhurbenko)===
 
====Walkthrough====
 
 
 
 
====Source Code====
54
edits