Changes

Jump to: navigation, search

OpenMP Debugging in Visual Studio / Team Debug

186 bytes added, 15:52, 6 December 2017
Case B - Using the Parallel Stacks and the Parallel Watch Window
}
In the above code, the main program calls functions that may themselves call other functions. At each cilk_spawn keyword, we can expect a new child thread to call the function. However, if the function functions have very short operations each, then the different spawns may not even be distributed to different child threads, since each function call may take very fast. That was originally the case, where all of the function calls were done by one thread. Therefore, the functions were adjusted to sleep for 1 second within the function itself. This way, the functions took long enough so that the program did spawn into multiple child threads.
Here is the output of the program, with the cilk_for loop commented out:
[[File:CilkOutput.PNG|300px|center|Output]]
From the output , we can see that for this run, 4 different threads (child threads) occupied the 6 function calls. In order of the function calls in the code, worker 0 took foo(), worker 3 took coo(), worker 2 took boo(), worker 1 took doo(), worker 0 took zoo(), and finally worker 3 took the remaining foo() function. Worker 0 in this case actually refers to the Main Thread.  
The Parallel Stacks window allows us to see the call stack information for all active threads at any point in our program.
Setup:
1. Put a breakpoint at all function calls, all function definitions, and cilk_sync, and cilk_for.<br/>
Hovering above "main" in the Main "1 Thread", we can see which line in the code the current stack frame is at.
As we keep hitting F5, we go through each stack frame as determined by at the point of our breakpoints. Here, our foo() function was executed. We can see the sleep_for function that was executed, all within the Main thread:
[[File:Stacks-step1b.PNG|500px|center|Step 1b - stacks]]
cilk_spawn boo();
Now worker Worker 1 has taken charge of the next spawned thread, highlighted in blue:
[[File:Stacks-step3.PNG|500px|center|Worker 1]]
cilk_spawn doo();
Finally, worker Worker 2 picks up the next spawned thread:
[[File:Stacks-step4.PNG|500px|center|Worker 2]]
At this point, the Main thread, in function foo, has already printed its line.
cilk_sync;
At this point, all spawned threads have synced up, as indicated in the right box, and the main thread Main Thread continues, on the left side box.
[[File:Stacks-step8.PNG|500px|center|Synced up]]
The Parallel Stacks Window is a valuable tool in debugging multi-threaded applications as we can have a view of all threads at once and their call stacks in any given time. It allows us to see the delegation of work to different threads as they are made free and as they are indicated by the compiler to work.
 
 
Now we will use the Parallel Watch Window to view the variable i, and its value in the different threads as we go through the stack frames as determined by our breakpoints.
==Case C==
92
edits

Navigation menu