Changes

Jump to: navigation, search

GPU621/Pragmatic

22 bytes removed, 23:54, 20 November 2016
Walkthrough
'''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.
 
[[File:Project_startup_parallel_stacks.JPG|200px|thumb|right|alt| Main project Window]]
[[File:Parallel_stacks_1.JPG|200px|thumb|right|alt| Program Flow]]
We'd like to say a few words about our program. We kept it simple, it consists of 11 functions + main function. In the main function we create a parallel region, send Master thread (with threadId == 0) to one place, and the rest of the threads is split between functions A() and B(). All the even threadIds go to A(), and all the odd threadIds go to B(). A() and B() in their turns create one more fork and split the threads further into a few functions, which makes a nice looking diagram in the Parallel Stacks window.
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 (see Main Project Window screenshot on the rightbelow), otherwise the diagram will be too small.[[File:Project_startup_parallel_stacks.JPG|450px|thumb|center|alt| Main project Window]]4. At this point you should be able to see something similar to our Main project Window screenshot (on the rightabove). In the '''Parallel Stacks''' window we can see that in the root we have a box with 5 threads. In fact it is just 4 threads. The fifth thread is related to debugging, it stays in the __kmp_launch_monitor task till the end of the program.
As you can see 1 thread went to the left, this is our Master thread with id == 0. And the rest, which is just 2 threads in our case (third hasn't been created yet), went to the right. Then they split and one went to function A() and another went to function B(). A, B, F etc - are function names, we kept it simple. Also, you can see on the screenshot (and hopefully in your Visual Studio as well) - in the top right box, in the function A is says "External Code". Our function A invoked printf() to print a Hello message in the console, and this is how it is displayed in the '''Parallel Stacks''' window.
5. Let's hit '''Continue'''(or '''F5''') button 3 times. Now you should be able to see something similar to the Program Flow screenshot from the right (below) in your Parallel Stacks window. This is how you can trace and see what each thread is currently doing. In our case Master thread went to the left and is currently in the function K(). 3 other threads went to the right, one of them wen to A() and further to C(), and the other 2 threads got into B() which then split them and sent to functions G() and F().[[File:Parallel_stacks_1.JPG|450px|thumb|center|alt| Program Flow]]
6. Click '''Continue''' button '''6 more times''', observe the changes and stop here for a moment (give it some time between the clicks since there are long for loops which can take 1-3 seconds to execute). While you were going through the breakpoints you probably saw how our Master thread went from function L to function K, functions C() and G() executed '''#pragma omp barrier''' statements and are in a waiting mode now, and you saw that our function F() finished its work and went back to main.

Navigation menu