+ All Categories
Home > Documents > Debugging Parallel Programs Final

Debugging Parallel Programs Final

Date post: 22-Nov-2014
Category:
Upload: gvgnaidu-golivi
View: 85 times
Download: 2 times
Share this document with a friend
47
Debugging Parallel Programs on Windows HPC Server 2008 Author: Mark O’Connor, Project Leader, Allinea Software Published: June 6, 2022 Abstract It’s widely acknowledged that greatness is only achieved by making use of the best tools available. Our species itself is a prime example of the competitive advantage conferred by excellent tools. Unfortunately, the learning curve for state-of-the-art tools can be rather steep. Overcoming installation and setup issues is often a significant hurdle. This is especially true in HPC. With the introduction of Windows ® HPC Server 2008 and Allinea DDTLite for Visual Studio ® , this learning curve has been dramatically flattened. This tutorial explains how to set up Visual Studio ® 2008 to debug MPI programs and introduces you to state-of-the-art parallel debugging techniques using Allinea DDTLite for Visual Studio 2008.
Transcript
Page 1: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008

Author: Mark O’Connor, Project Leader, Allinea SoftwarePublished: April 8, 2023

Abstract

It’s widely acknowledged that greatness is only achieved by making use of the best tools available. Our species itself is a prime example of the competitive advantage conferred by excellent tools. Unfortunately, the learning curve for state-of-the-art tools can be rather steep. Overcoming installation and setup issues is often a significant hurdle. This is especially true in HPC.

With the introduction of Windows® HPC Server 2008 and Allinea DDTLite for Visual Studio®, this learning curve has been dramatically flattened. This tutorial explains how to set up Visual Studio® 2008 to debug MPI programs and introduces you to state-of-the-art parallel debugging techniques using Allinea DDTLite for Visual Studio 2008.

Page 2: Debugging Parallel Programs Final

1

Debugging Parallel Programs on Windows HPC Server 2008

Contributors and AcknowledgementsMark O’Connor, Project Leader, Allinea Software

Nick Forrington, Allinea Software

David Lecomber, Allinea Software

Jacques Philouze, Allinea Software

Page 3: Debugging Parallel Programs Final

2

Debugging Parallel Programs on Windows HPC Server 2008

ContentsAllinea DDTLite............................................................................................................................................... 1

How to Download....................................................................................................................................... 1How to Install the Add-in............................................................................................................................. 1How to Purchase........................................................................................................................................ 1How to Unlock DDTLite using your Serial Key............................................................................................1

Visual Studio MPI Configuration..................................................................................................................... 2MS-MPI....................................................................................................................................................... 2

Debugger to Launch................................................................................................................................ 3Additional Include Directories.................................................................................................................. 4Additional Library Directories................................................................................................................... 5Additional Dependencies......................................................................................................................... 6

MPICH2...................................................................................................................................................... 6Debugger to Launch................................................................................................................................ 7Additional Include Directories.................................................................................................................. 8Additional Library Directories................................................................................................................... 9Additional Dependencies....................................................................................................................... 10

Setting up and Debugging with Allinea DDTLite...........................................................................................11How to load the example Visual Studio solution.......................................................................................11Enabling DDTLite in Visual Studio............................................................................................................11

Enabling the Allinea DDTLite plug-in.....................................................................................................11Showing the Allinea DDTLite Windows..................................................................................................12Arranging the Allinea DDTLite Windows................................................................................................12The Allinea DDTLite Window Icons.......................................................................................................14Check Your Visual Studio Options.........................................................................................................14

Features Added to Visual Studio by Allinea DDTLite....................................................................................16Allinea DDTLite Windows......................................................................................................................... 16

Selected Processes and Threads..........................................................................................................16Variable – Parallel View......................................................................................................................... 20Location – Parallel View........................................................................................................................ 21

Auto-detection of MPI rank.......................................................................................................................21

Using DDTLite: A Walk-Through................................................................................................................... 23

Source Code for Example Program..............................................................................................................32

Feedback..................................................................................................................................................... 37More Information and Downloads.............................................................................................................37

Page 4: Debugging Parallel Programs Final

Allinea DDTLiteAllinea DDTLite is a true parallel debugging plug-in for Microsoft Visual Studio from Allinea Software and has been designed to simplify the task of debugging parallel and multi-threaded code.

How to DownloadAllinea DDTLite is available for download on the Allinea website at the following URL: http://www.allinea.com/downloads/ Allinea DDTLite.msi

How to Install the Add-inOnce downloaded, Allinea DDTLite can be installed by simply double clicking on the “Allinea DDTLite.msi” file and answering a few simple questions. After installation, an option for DDTLite should appear in Visual Studio 2008's “Add-in Manager” window (Tools->Add-in Manager). Before you can use DDTLite, you must enable it in this window – see the “Setting up and Debugging with Allinea DDTLite” section later in this document for details.

After install, DDTLite is in evaluation mode. This allows you to try the software with a limited number of processes and threads for 30 days. To use the full capabilities, or to continue using DDTLite beyond this period, you must purchase a licence.

How to PurchaseAn Allinea DDTLite licence can be purchased in several ways: through Allinea’s worldwide resellers, by contacting [email protected] or simply by going to the http://www.allinea.com/ddtlite. You will subsequently be emailed your serial key to input to the DDTLite register window.

How to Unlock DDTLite using your Serial KeyDuring the 30-day evaluation period, a window will appear prompting you to register DDTLite whenever you start Visual Studio or enable the Add-in (see the “Setting up and Debugging with Allinea DDTLite” section later in this document for details). Once you have a serial key from Allinea, click on the “Register” button and enter your details, including the serial key emailed to you when you purchased your DDTLite licence. This will unlock DDTLite.

If your serial key is rejected or if you have any other problems, please contact [email protected] making sure you quote your purchase reference number included in the email sent to you when you purchased Allinea DDTLite.

Page 5: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 1

Visual Studio MPI ConfigurationThis section details the additional configuration changes that will be required to use a specific MPI with Visual Studio. Allinea DDTLite itself works with all the MPI implementations supported by Visual Studio and does not need any special configuration.

If Visual Studio is already set-up to use MPI, or if you do not intend to develop MPI programs, you can skip this section.

Details of how to configure Visual Studio to use one of two common MPI implementations are included below. When configuring your project inside Visual Studio, check that “All Configurations” is selected inside the “Configuration” box, so that these settings are applied both to Debug and Release builds.

MS-MPITo obtain Microsoft® MPI (MS-MPI) you will first need to install Microsoft® HPC Pack 2008 SDK. This can be obtained from here. Make sure your PATH environment variable has MS-MPI first and not another MPI implementation by checking “My Computer > Properties > Advanced > Environment Variables”. You will need to make sure that PATH includes both the debugging binaries and the MPI binaries:

C:\Program Files\Microsoft Compute Cluster Pack\Bin\ C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger\x86

Make sure that the Remote Debugger directory you pick matches your system architecture, e.g. “x86” for 32-bit systems, “x64” for 64-bit Pentium/Opteron systems and ia64 for Itanium systems.

In your project properties (“Project > ProjectName Properties”) you must make sure that the following have been configured prior to starting your debugging session:

Page 6: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 2

Debugger to LaunchSelect “Configuration Properties > Debugging” and set to “MPI Cluster Debugger” instead of “Windows Local Debugger”. Also make sure you are using the correct executable with the appropriate command line arguments. It is sometimes useful to set the “MPIRun Working Directory” to the macro “$(ProjectDir)”.

Figure 1: MS-MPI – Debugger to Launch

Page 7: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 3

Additional Include DirectoriesSelect “Configuration Properties > C/C++ > General” and make sure that the path to the MS-MPI include directory has been added i.e. "C:\Program Files\Microsoft Compute Cluster Pack\Include"

Figure 2: MS-MPI - Additional Include Directories

Page 8: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 4

Additional Library DirectoriesSelect “Configuration Properties > Linker > General” and make sure that the path to the correct MS-MPI libraries directory has been added i.e. "C:\Program Files\Microsoft Compute Cluster Pack\Lib\i386". Make sure that the directory you pick matches your system architecture, e.g. “i386” for 32-bit systems, “amd64” for 64-bit Pentium/Opteron systems and so on.

Figure 3: MS-MPI - Additional Library Directories

Page 9: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 5

Additional DependenciesSelect “Configuration Properties > Linker > Input” and make sure that the MS-MPI library (msmpi.lib) has been added in:

Figure 4: MS-MPI - Additional Dependencies

MPICH2To obtain MPICH2 for windows you will need to visit the Argonne website which is located here. Make sure your PATH environment variable has MPICH2 first and not another MPI implementation by checking “My Computer > Properties > Advanced > Environment Variables”. You will need to make sure that PATH includes both the debugging binaries and the MPI binaries:

C:\Program Files\MPICH2\Bin\ C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger\x86

Make sure that the Remote Debugger directory you pick matches your system architecture, e.g. “x86” for 32-bit systems, “x64” for 64-bit Pentium/Opteron systems and ia64 for Itanium systems.

In your project properties (“Project > ProjectName Properties”) you must make sure that the following have been configured prior to starting your debugging session:

Page 10: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 6

Debugger to LaunchSelect “Configuration Properties > Debugging” and set to “MPI Cluster Debugger” instead of “Windows Local Debugger”.

Figure 5: MPICH2 – Debugger to Launch

Page 11: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 7

Additional Include DirectoriesSelect “Configuration Properties > C/C++ > General” and make sure that the path to the MPICH2 include directory has been added.

Figure 6: MPICH2 - Additional Include Directories

Page 12: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 8

Additional Library DirectoriesSelect “Configuration Properties > Linker > General” and make sure that the path to the MPICH2 libraries directory has been added.

Figure 7: MPICH2 - Additional Library Directories

Page 13: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 9

Additional DependenciesSelect “Configuration Properties > Linker > Input” and make sure that the MPICH2 library (mpi.lib) has been added in:

Figure 8: MPICH2 - Additional Dependencies

Page 14: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 10

Setting up and Debugging with Allinea DDTLite How to load the example Visual Studio solutionDouble-click on the example Visual Studio solution “ParallelSort.sln”. Visual Studio will start up and load the solution into the working area as shown by the figure below:

If you haven't already done so, follow the step-by-step guide in the Visual Studio MPI Configuration section of this document and make sure that the correct paths for your MPI environment have been added to the example project's settings.

Enabling DDTLite in Visual StudioEnabling the Allinea DDTLite plug-inThe Allinea DDTLite plug-in first needs to be enabled before it can be used. This is done by going to “Tools > Add-in Manager” and placing a tick in the box next to “Allinea DDTLite” in the list of available Add-ins.

Note: If “Allinea DDTLite” is not present in the list, it may not have been installed correctly. See the “How to Install the Add-in” section earlier in this document or contact [email protected] for assistance.

Figure 9: Loading the example Visual Studio® Project

Page 15: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 11

Selecting this line displays the version of the Add-in installed and the email address for Allinea support. There are also the following checkboxes, as seen in the screenshot below:

Start-up – tick here to load DDTLite whenever Visual Studio is started. If you do not tick this box, then you will have to return to this window every time you start Visual Studio and want to debug using DDTLite.

Command Line – this is not applicable to DDTLite and should be left blank.

Once the Add-in has been installed the Welcome to DDTLite window will be shown. From here you have access to the user guide, support and licence information. You can display this window at any time by going to “Debug > Welcome to DDTLite” in the main menu.

Showing the Allinea DDTLite WindowsPut a breakpoint after MPI_Init in your program and enter debug mode (F5). If the Allinea DDTLite windows do not display automatically then go to “Debug > Windows > DDTLite Windows” in the main menu. This will reset the DDTLite window locations, and they will need to be manually docked into place (see below).

Note: Visual Studio uses different window layouts for debugging design, so it is important to make sure that you are debugging a program before displaying and repositioning the Allinea DDTLite windows.

Arranging the Allinea DDTLite WindowsThe first time you run DDTLite its new windows may appear floating on top of the main visual Studio display:

Figure 10: Enabling the Allinea DDTLite plug-in

Page 16: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 12

These windows can be resized, dragged and dropped in any desired location. This is done by grabbing the window's title bar with the mouse and dragging over the visual Studio interface. While you're dragging the window Visual Studio will display a set of docking points – four arrows and a central square with tabs in one corner. Drag the window onto one of these icons to place it relative to the central window. As you drag over other Visual Studio windows, the same icons will appear over them instead:

To add windows together as tabs, drag them onto the middle icon (just below the cursor in Figure 12).

The recommended arrangement for the Allinea DDTLite windows is shown here for reference:

Figure 11: Floating DDTLite Windows after Install

Figure 12: Dragging the Selected Processes and Threads Window into Place

Page 17: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 13

Once you have set up your preferred window layout, Visual Studio will remember it for future sessions.

The Allinea DDTLite Window IconsThese icons should be a purple a on a transparent background. If you see a bright pink or bright green background then you can fix this by running regedit.exe and searching for the “UseMakeTransparent” key. Its value will be “true” or “false”. Try swapping this value to fix any transparency issues. The key is usually found in:

HKEY_CURRENT_USER\Software\Microsoft Corporation\Microsoft® Visual Studio® 2008\9.0.30729.1

If you need to do this then we would like to hear from you – please send an email with the subject “Tool Window Transparency” to [email protected].

Check Your Visual Studio OptionsVisual Studio's “Break all processes when one process breaks” must be turned on in order for DDTLite to work properly. This option can be found in “Tools > Options” under the “Debugging” section:

Figure 13: Recommended Allinea DDTLite Window Layout

Page 18: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 14

Figure 14: Checking Visual Studio's Debugger Options

Page 19: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 15

Features Added to Visual Studio by Allinea DDTLiteThe following are the new features that Allinea DDTLite brings to Visual Studio.

Allinea DDTLite WindowsThere are a number of new windows which the DDTLite add-in brings to Visual Studio. These are described in more detail in the following sections and are shown in the figure below:

1. Selected Processes and Threads2. Parallel Stack view3. Parallel View (Groups, Variable and Location in separate tabs)

Selected Processes and ThreadsThis window is the control centre for DDTLite. It shows the processes and threads that DDTLite is currently looking at. Only these processes and threads will be allowed to execute, and only these processes and threads will be shown in the other DDTLite windows. The only exception to this is the Groups window, which is explained in its own section. Processes are listed by their MPI rank, where appropriate, and threads are indexed from 0:

Figure 15: Overview of the Allinea DDTLite Windows

Page 20: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 16

The same is available for both processes and threads if programming with hybrid code - see below for an example showing 2 processes and 3 threads selected from a 16 process job:

Your DDTLite licence determines the maximum number of processes or threads that you can work with at once. If this limit is exceeded, the following message is displayed:

You can upgrade your licence by visiting http://www.allinea.com/ddtlite.

The first three buttons in the window allow you to lock-step the selected processes or threads; the first is “Step Into”, second is “Step Over” and the third “Step Out”. Clicking on one of these will step each selected thread once. Since Visual Studio cannot perform this stepping in parallel, you will not be able to step past code that contains synchronization, such as MPI calls or into and out of OpenMP loops. To do this, place a breakpoint and use the Visual Studio “Continue” (F5) command.

If stepping takes more than half a second or so, a small window will open showing the status of the “Lock Stepping”, similar to the figure below. This allows you to either skip an individual thread/process or try stepping it again later. Typically this is shown when one thread is waiting for synchronization. Clicking on “Cancel” skips all threads.

Figure 16: Selected Processes and Threads (MPI)

Figure 17: Selected Processes and Threads (Hybrid)

Figure 18: Warning when Licence Limit Exceeded

Page 21: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 17

The “Break when ... reaches a breakpoint” box, shown below, is used to control how Visual Studio's breakpoints behave with parallel processes and threads.

The possible settings are:1. Break when every selected process/thread reaches a breakpoint (default). When this is

chosen, breakpoints behave like barriers, holding the selected processes that reach them in place until every process has stopped.

2. Break when any selected process/thread reaches a breakpoint. Stops as soon as one of the selected processes or threads reaches a breakpoint.

3. Break when any process/thread reaches a breakpoint. Stops as soon as any process or thread reaches a breakpoint.

Parallel Stack ViewThe Parallel Stack View (PSV) shows a hierarchical view of all the selected processes or threads. Processes or threads that do not appear in the “Selected Processes and Threads” window will not be shown. The PSV shows a tree of functions, merged from each selected process/thread. If there's only one branch in this tree – one list of functions – then all your processes/threads are at the same place. If there are several different branches, then your program has split up and is in different parts of the code. Click on any branch in the PSV to see its location in the Source Code Viewer.

Figure 20: Breakpoint Options

Figure 19: Lock Stepping

Page 22: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 18

The PSV also has the ability to create groups, which then appear in the “Groups – Parallel View” window. Right-click on any function in the PSV list and select “Create Group” to automatically gather the processes at that function together, labelled by the function's own name. It also allows you to just use “Select”, which changes the focus in the “Selected Processes and Threads” window to those processes or threads that you

are most interested in. The Parallel Stack View's ability to display and select large numbers of processes based on their location in your code is invaluable when dealing with moderate to large numbers of processes.

Groups – Parallel ViewThis is where all the groups created from other views are gathered together. It allows quick access to different groups of processes or threads. Once the group has been selected the focus in the “Selected Processes and Threads” window changes, along with the detail displayed in the Parallel Stack View. This is shown to its full potential in the figure below, along with the different options available when selecting a group and then right-clicking.

Figure 22: Parallel Stack View - Options

Figure 21: Parallel Stack View (PSV)

Page 23: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 19

Variable – Parallel ViewHave you ever wanted to see the value of a variable or expression across multiple processes or threads? Now you can. This window evaluates the given expression on all selected processes and threads, and then displays the results grouped by value. In the example below, we have evaluated “rank%3” in an MPI program. 6 processes have the value 0 (processes 0, 3, 6, 9, 12, and 15), 5 processes have the value 1 and 5 processes have the value 2. Grouping the processes and threads by their result gives you an instant overview without having to scroll through a long list of values.

If many processes or threads have unique values, they are shown in a single “Unique Values” grouping. In this case the value from each process or thread is shown next to its name, e.g. Process 0 (90), see Figure 28.

Figure 23: Groups - Parallel View

Figure 24: Variable - Parallel View

Page 24: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 20

Location – Parallel ViewThis window shows you where your processes or threads are located in your code. It is an overview of the PSV showing only the current location and not the entire stack. Expanding each location shows you exactly which processes and threads are currently at that point in your code.

Auto-detection of MPI rankEvery time you start an MPI program, DDTLite automatically detects the MPI rank of your processes and replaces the system process ID with a clearer MPI rank label. During this process, the system IDs will be displayed:

If DDTLite can find the MPI rank for each process, it will relabel the processes as shown below. This usually takes between 1 and 5 seconds, depending on system load.

Figure 25: Location - Parallel View

Figure 27: After Automatic Detection of MPI Ranks

Figure 26: Before Automatic Detection of MPI Ranks

Page 25: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 21

The auto-detection feature is only available when using compatible MPI implementations, such as the Microsoft MPI or MPICH2.

If your MPI does not support this feature, then you can use the additional button for labelling the MPI rank of the processes. It is located in the "Variable - Parallel View" window, called "Use as MPI Rank":

Simply evaluate your rank variable (e.g. “rank”) and then click “Use as MPI Rank” to rename the processes. In fact, any unique expression can be used to label your processes. The button is only enabled when the values returned will result in unique names for the processes, such as 0 to 15 in this case.

Figure 28: Use as MPI Rank

Page 26: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 22

Using DDTLite: A Walk-ThroughA copy of the ParallelSort example program is available in the DDTLite installation directory (C:\Program Files\Allinea Software\DDTLite for Visual Studio\ParallelSort.zip by default). Extract the zip file in your own projects directory and double-click on the “ParallelSort.sln” file to open the project in Visual Studio 2008.

NOTE: You may have to set the correct MPI paths in the example project before you can run it in Visual Studio. See the Visual Studio MPI Configuration section of this document for a step-by-step description of how to do this.

You can then follow this working example to see how Allinea DDTLite can help debug parallel programs.

1. Once you have loaded the ParallelSort solution, make sure DDTLite is loaded by going to Tools->Add-in Manager and make sure there’s a tick next to the Allinea DDTLite entry.

Step 1: Check DDTLite is selected in the Add-in Manager

2. Find the "main" function and put a normal breakpoint after the MPI_Init line, sort.cpp line 144.

Step 2: Add a breakpoint at line 144

3. Press F5 to start debugging - just like debugging any other program.

Page 27: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 23

4. The DDTLite windows appear, neatly docked into place. If they are not already docked, see the Arranging the Allinea DDTLite Windows section of this document for assistance.

Step 4: The recommended window layout

5. Now we'll do something simple, but almost impossible without DDTLite. Start by scrolling down to sort.cpp line 166 and click in the margin to add a breakpoint.

Step 5: Add a breakpoint at line 166

Page 28: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 24

6. Click Continue (F5) – DDTLite now synchronizes all the processes at this line of code – you can check by looking in the Location window or the Parallel Stack View window. Without DDTLite there’s no guarantee that these processes will all reach the breakpoint at the same time.

Step 6: The Parallel Stack View after stepping

7. Open the VS Autos tab and find the 'rank' variable. Now click on some of the processes in DDTLite's Selected Processes and Threads window to see how the value of rank changes as each is selected, and is highlighted in red to show it is different between the processes.

Step 7: Variables in the Autos Window

8. An easier way to view a variable across the selected processes is to type its name into the “Expression” box of the Variable – Parallel View window and press Enter. Try this with “rank” now and see what happens.

Step 8: Evaluate "rank" in the Variable View

Page 29: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 25

9. Now for some stepping – click on the middle of the three lock-stepping buttons in DDTLite's Selected Processes and Threads window (“Lock-Step Over”). This steps all of the selected processes to the next line.

Step 9: Lock-Step Over

10. Now click the “Lock-Step Into” button (the first of the three). Make sure you waited for the processes to finish stopping the first time.

Step 10: Lock-Step Into

11. Now the processes have stepped into different functions – this is shown in DDTLite's Parallel Stack View – one process is in init_root and the rest are in init_workers. Click on these nodes to see how the source view is updated to show the location. The Location – Parallel View window also shows the current functions and lists the processes in them by rank.

Step 11: Parallel Stack View after stepping

Step 11: Location View after stepping

Page 30: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 26

12. Now right-click on the “init_root” node and choose “Select” – the “Selected Processes and Threads” window now shows only process 0 selected. You can now control this process without affecting any of the others.

Step 12: Select the init_root processes in the Location View

Step 12: The init_root processes in the Selected Processes and Threads Window

13. Scroll down and put a normal breakpoint at line 122 “if(bigBuffer)”

Step 13: Add a breakpoint at line 122

14. Click Continue (F5) – the root process runs straight there, over the MPI calls. You can debug a single interesting process just as if it was the only one running, using all your favourite VS windows and tools.

15. Now click on the “Select all N processes in program” button – an easy way to get back to controlling your whole program at once.

Page 31: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 27

Step 15: Click the “Select all processes in program” button

16. Scroll down to line 194 “mysort(inBuf, bufSize);” and add a breakpoint there.

Step 16: Add a breakpoint at line 194

17. Press Continue (F5) to gather all the processes together at this line.18. Open DDTLite's Variable – Parallel View window (it's usually tabbed with Groups and Location on

the right), type "mysort" into the text box and press Enter or click on Evaluate.

Step 18: Evaluate “mysort” in the Variable View

19. DDTLite evaluates the variable across all selected processes and shows the results grouped by answer. We can instantly see that half the processes are going to go into bubbleSort and half into qSort. Expand one or both of these nodes to see the list of processes that will go into each.

20. Click on the “Lock-Step Into” button in the Selected Processes and Threads window – DDTLite now steps all the processes into their respective functions. This can be seen immediately in the Parallel Stack View.

Step 20: Lock-Step Into

Page 32: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 28

Step 20: Parallel Stack View after Lock-Stepping Into

21. Now show the Location - Parallel View window (it's usually tabbed with Groups and Variables on the right) and expand the nodes there for an at-a-glance view of which processes are in which functions.

Step 21: Location View after stepping

22. Right-click on the “bubbleSort” node and choose Create Group – DDTLite jumps you to the group window and lets you rename the group if you want to. This is now a short cut to those processes, which you can select at any time by right-clicking and choosing Select.

Step 22: Create a “bubbleSort” Group from the Location View

Page 33: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 29

23. Do this now (right-click on the “bubbleSort” group in the Group window and choose Select) – DDTLite lets you narrow down on problem areas by focusing on processes/threads in specific functions. (Check out "Selected Processes and Threads" window, which now shows just the bubbleSort processes).

Step 23: Select “bubbleSort” in the Groups View

Step 23: The newly-selected “bubbleSort” group

24. Now switch to the variable view and type in “buf[0]” and press Enter – DDTLite shows you the first value that each process is going to sort, restricted to the processes that are selected (the unselected processes in qSort are not shown).

Step 24: Evaluate buf[0] in the Variable View

25. Change the expression to “buf[0]>5” and press Enter – DDTLite also evaluates expressions and groups the answers accordingly.

Step 25: Evaluate buf[0]>5 in the Variable View

Page 34: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 30

26. We can also use variables and expressions to narrow down the processes we're looking at. Right-click on “True” and choose Create Group

Step 26: Create a group from the Variable View

27. Again DDTLite takes you to the Groups view. Make the default name more descriptive by adding “in bubbleSort” to it.

Step 27: Renaming a group in the Groups View

28. Expand this node and click on each of the processes in it to see how this also allows you to quickly change the current process in Visual Studio's other windows, such as the Locals and Autos windows.

Step 28: Expanding to show processes in the Groups View

You've just seen how you can start by debugging a lot of processes and narrow down your focus to a group of processes of interest or problem processes, and can select representatives from that group to investigate more deeply using Visual Studio's excellent single-process mechanisms. Happy debugging!

Page 35: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 31

Source Code for Example ProgramThe example ParallelSort program (sort.cpp) is included here for reference purposes. You can find a copy of this in <DDTLite installation path>\ParallelSort.zip after installing Allinea DDTLite.

1 /* 2 * This is a MPI based sorting program. 3 * Copyright (c) Microsoft Corporation. All rights reserved. 4 */ 5 6 #include "mpi.h" 7 #include <stdio.h> 8 #include <stdlib.h> 9 #include <string.h> 10 #include <math.h> 11 12 int rank, size; 13 14 #define MAX_ALLOC_SIZE 1000000000 15 16 int isValidAlloc(int alloc){ 17 return (alloc>0&&alloc<MAX_ALLOC_SIZE); 18 } 19 20 void swap(int* data, int i, int j){ 21 int t; 22 t = data[i]; 23 data[i] = data[j]; 24 data[j] = t; 25 } 26 27 // Q-sort algorithm 28 void myqsort(int* data, int left, int right){ 29 int i,last; 30 if(left>=right||left<0||right<0) 31 return; 32 swap(data,left,(left+right)/2); 33 last = left; 34 for(i=left+1;i<=right;i++) 35 if(data[i]<data[left]) 36 swap(data,++last,i); 37 swap(data,left,last); 38 myqsort(data,left,last-1); 39 myqsort(data,last+1,right); 40 } 41 42 void qSort(int* buf , int bufSize){ 43 myqsort(buf, 0, bufSize-1); 44 } 45 46 // Bubble sort algorithm 47 void bubbleSort(int* buf, int bufSize){ 48 for(int i=0;i<bufSize;i++) 49 for(int j=0;j<bufSize-i-1;j++){

Page 36: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 32

50 if(buf[j]>buf[j+1]) 51 swap(buf, j, j+1); 52 } 53 } 54 55 // Merging sort algorithm 56 void merge(int* input, int* output, int bufSize, int totalSize){ 57 int* track=(int*)calloc(size, sizeof(int)); 58 if(!track) 59 MPI_Abort(MPI_COMM_WORLD, -1); 60 for(int i=0;i<totalSize;i++){ 61 int min=INT_MAX; 62 int minsite=-1; 63 for(int j=0;j<size;j++){ 64 if(track[j]<bufSize&&*(input+bufSize*j+track[j])<=min){ 65 min=*(input+bufSize*j+track[j]); 66 minsite=j; 67 } 68 } 69 output[i]=min; 70 track[minsite]++; 71 } 72 if(track) 73 free(track); 74 } 75 76 // Reads the sequence data and scatters to all the processes. 77 void init_root(char* input_fn, int** smallBuffer, int* bufSize, int* cnt){ 78 FILE* fp=fopen(input_fn, "r"); 79 80 if(!fp){ 81 printf("Can't find the file: %s\n.", input_fn); 82 fflush(stdout); 83 MPI_Abort(MPI_COMM_WORLD, -1); 84 } 85 86 fscanf_s(fp, "%d", cnt); 87 88 *bufSize=*cnt/size+1; 89 90 int toAlloc=sizeof(int)**bufSize*size; 91 if(!isValidAlloc(toAlloc)) 92 MPI_Abort(MPI_COMM_WORLD, -1); 93 int* bigBuffer=(int*)malloc(toAlloc); 94 if(!bigBuffer) 95 MPI_Abort(MPI_COMM_WORLD, -1); 96 97 for(int i=0;i<*bufSize*size;i++) 98 *(bigBuffer+i)=INT_MAX; 99 100 toAlloc=sizeof(int)**bufSize;101 if(!isValidAlloc(toAlloc))102 MPI_Abort(MPI_COMM_WORLD, -1);103 *smallBuffer=(int*)malloc(toAlloc);104 if(!smallBuffer)105 MPI_Abort(MPI_COMM_WORLD, -1);

Page 37: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 33

106 107 int proc=0;108 int iter=0;109 for(int i=0;i<*cnt;i++){110 fscanf_s(fp, "%d", bigBuffer+proc**bufSize+iter);111 if(++proc==size){112 proc=0;113 iter++;114 }115 }116 117 if(fp)118 fclose(fp);119 120 MPI_Bcast(bufSize, 1, MPI_INT, 0, MPI_COMM_WORLD);121 MPI_Scatter(bigBuffer, *bufSize, MPI_INT, *smallBuffer, *bufSize, MPI_INT, 0, MPI_COMM_WORLD);122 if(bigBuffer)123 free(bigBuffer);124 125 }126 127 // Gets the sequence data scattered from the root process.128 void init_worker(int** smallBuffer, int* bufSize){129 int* bigBuffer=NULL;130 MPI_Bcast(bufSize, 1, MPI_INT, 0, MPI_COMM_WORLD);131 132 int toAlloc=sizeof(int)**bufSize;133 if(!isValidAlloc(toAlloc))134 MPI_Abort(MPI_COMM_WORLD, -1);135 *smallBuffer=(int*)malloc(toAlloc);136 if(!smallBuffer)137 MPI_Abort(MPI_COMM_WORLD, -1);138 139 MPI_Scatter(bigBuffer, *bufSize, MPI_INT, *smallBuffer, *bufSize, MPI_INT, 0, MPI_COMM_WORLD);140 }141 142 void main(int argc, char* argv[]){143 MPI_Init(&argc, 0);144 MPI_Comm_rank(MPI_COMM_WORLD, &rank);145 MPI_Comm_size(146 MPI_COMM_WORLD,147 &size148 );149 150 if(argc!=3){151 if(rank==0){152 printf("Usage: mpiexec -np <nProcs> sort.exe <input_file> <output_file>\n");153 fflush(stdout);154 }155 MPI_Finalize();156 return;157 }158 159 char* input_fn=argv[1];160 char* output_fn=argv[2];161

Page 38: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 34

162 int* inBuf=NULL;163 int bufSize=0;164 int totalSize=0;165 166 if(rank==0)167 init_root(input_fn, &inBuf, &bufSize, &totalSize);168 else169 init_worker(&inBuf, &bufSize);170 171 int *tmpBuf,*finalBuf;172 tmpBuf=finalBuf=NULL;173 if(rank==0){174 int toAlloc=sizeof(int)*bufSize*size;175 if(!isValidAlloc(toAlloc))176 MPI_Abort(MPI_COMM_WORLD, -1);177 tmpBuf=(int*)malloc(toAlloc);178 if(!tmpBuf)179 MPI_Abort(MPI_COMM_WORLD, -1);180 181 toAlloc=sizeof(int)*totalSize;182 if(!isValidAlloc(toAlloc))183 MPI_Abort(MPI_COMM_WORLD, -1);184 finalBuf=(int*)malloc(toAlloc);185 if(!finalBuf)186 MPI_Abort(MPI_COMM_WORLD, -1);187 188 }189 190 // Chooses a sorting algorithm for each process respectively.191 void (*mysort)(int*, int)=(rank%2?qSort:bubbleSort);192 193 // Sorting194 mysort(inBuf, bufSize);195 196 // Gathers all the sorted sections back to the root process.197 MPI_Gather(inBuf, bufSize, MPI_INT, tmpBuf, bufSize, MPI_INT, 0, MPI_COMM_WORLD);198 199 if(rank==0){200 201 // Merges all the well-sorted sequence sections together to the final result.202 merge(tmpBuf, finalBuf, bufSize, totalSize);203 204 // Outputs to file.205 FILE* fp=fopen(output_fn, "w");206 if(!fp)207 MPI_Abort(MPI_COMM_WORLD, -1);208 fprintf(fp, "%d\n", totalSize);209 for(int i=0;i<totalSize;i++){210 fprintf(fp, "%d ", *(finalBuf+i));211 }212 if(fp)213 fclose(fp);214 }215 216 if(inBuf)217 free(inBuf);

Page 39: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 35

218 MPI_Finalize();219 }

Page 40: Debugging Parallel Programs Final

Debugging Parallel Programs on Windows HPC Server 2008 36

FeedbackDid you find problems with this tutorial? Do you have suggestions that would improve it? Send us your feedback or report a bug on the HPC developer forum.

More Information and DownloadsMore information on both DDT and DDTLite for Visual Studio 2008 can be found at www.allinea.com/ddtlite.

Allinea DDTLite requires the use of Visual Studio 2008 SP1.

This document was developed prior to the product’s release to manufacturing, and as such, we cannot guarantee that all details included herein will be exactly as what is found in the shipping product.

The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication.

This White Paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT.

Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

© 2008 Microsoft Corporation. All rights reserved.

Microsoft, Visual Studio, Windows, and the Windows logo are trademarks of the Microsoft group of companies.

All other trademarks are property of their respective owners.


Recommended