Changes

Jump to: navigation, search

GPU621/Pragmatic

2,351 bytes added, 22:33, 20 November 2016
Walkthrough
====Walkthrough====
In this part we will show you how to use '''Parallel Stacks''' window and how it can help you find bugs and trace the flow of the program containing multiple threads.
First of all - copy and paste the source code of the simple program we added below to the '''mainPartTwo.cpp''' file.
We will be referring to line numbers further below, so it's important that the "''// FIRST LINE''" comment is actually at the first line of the '''mainPartTwo.cpp''' file.
 
Second - check how many CPU Cores you have. In Windows 7 you can do this by going to '''Task Manager''' (Ctrl + Shift + Esc) -> '''Performance'''. Count the number of boxes under '''CPU Usage History''', if you have 4 - you don't need to change anything. If it's 8 - you might want to change a default number of threads to 8 to see a bigger picture in the Parallel Stacks Window.
 
To change the number of threads - go to the line 30 and change the number of threads from 4 to 8 here:
omp_set_num_threads(4);
 
Alright, our program contains 2 bugs, let's find them together!
 
1. Put breakpoints to the lines: 59, 106, 116, 122, 132, 138, 148, 154, 164, 169, 179, 185, 195, 201, 211, 219, 227, 231, 240.
 
2. '''Debug''' -> '''Start Debugging''' to start our program in a debug mode. It will launch 2 terminals, you can close the terminal for the partOne at this point, you don't need it anymore.
 
3. Next step would be to open Parallel Stacks window. Once you run the application in the Debug mode - go to '''Debug''' -> '''Windows''' -> '''Parallel Stacks''' and give it some space (check my screenshot below), otherwise the picture will be too small.
[[File:Project_startup_parallel_stacks.JPG|200px|thumb|right|alt| Main project Window]]
 
4. At this point you should see a picture of the program flow in the Parallel Stacks window. We have 4 threads, from which 1 thread is a Master thread (id==0) and it gets sent to the function K(). The rest of the threads (3 threads or 7 if you have 8 cores) is split into 2 parts. Threads with even IDs (threadId % 2 == 0) go to the function A, and threads with odd IDs (threadId % 2 != 0) go to the function B. From there A and B start calling functions C() D() E() and F() G() H() respectively, as well as changing the according flags for each function to false (we want to call each of them just once) and sending the rest of the threads to L or K.
====Source Code====

Navigation menu