24
edits
Changes
→Walkthrough
=== Configuration ===
* Enable OpenMP for the current project file
'''Project''' - '''Property''' - '''C/C++''' - '''Language [Intel C++]''' - '''OpenMP Support''' - '''Generate Parallel Code (/Qiopenmp)'''
* The output of the sample program
[[File: walkthrouth_output.png]]
== Case A: Using the Thread Window ==
== Case B: Using the Parallel Stacks Window ==
=== Start Execution Until the 1st Breakpoint === When the program stops at the first break point, only the main thread exists in Parallel Stacks Window [[File: 1stExe.png]] === Resume Execution Until the 2nd Breakpoint === * The Parallel Stacks Window reveals the current status of all threads in the program* There are 2 Threads that come from `ntdll.dll`, which is a runtime library that we don't really care here* There are 2 threads that are ahead of other worker threads** They have reached the barrier (`__kmp_linear_barrier_release_template` & `__kmp_yield`)* There are 8 threads that are ready to move on [[File: 2nd.png]] === Resume Execution Until the 3rd Breakpoint === * When reaches the 3rd break point, Thanks to `#pragma omp critical`, all threads are waiting, trying to pass their result to main* As shown in the picture, there are 11 threads are ready to pass their values** They are either in the current thread or in the waiting list (`__kmp_wait_4` // https`__kmp_yield`)* According to the code, we know that there will be 11 threads passing their calculated results to the main thread* At this point, the value of `total_Sum` is 0 [[File://learn3rd.microsoftpng]] === Resume Execution Until the 4th Breakpoint === * When the program reaches this step, all calculations have been completed* As can be seen in the figure, all worker threads have reached `__kmp_linear_barrier_release_template`* This means that their work is done* And we can see that the result of the program is correct [[File: 4th.com/en-us/visualstudio/debugger/using-png]] === Resume Execution Until the-parallel-stacks-window?viewLast Breakpoint ===vs-2022 When the program ends, all threads are terminated and the program returns to only one main thread