Changes

Jump to: navigation, search

GPU621/OpenMP Debugging

2,039 bytes added, 04:19, 9 December 2021
Case B - Using the Parallel Stacks and the Parallel Watch Window
==Case B - Using the Parallel Stacks and the Parallel Watch Window==
```
#include <iostream>
#include <thread>
#include <vector>
#include<omp.h>
#include <chrono>
#include <string>
 
using namespace std;
void print(int n, const std::string& str) {
std::string msg = std::to_string(n) + " : " + str;
std::cout << msg << std::endl;
}
 
int main() {
std::vector<std::string> s = {
"Hello World",
"Hello",
"This",
"is",
"a testing",
"code",
"for",
"multithread",
"debugging"
};
std::vector<std::thread> threads;
 
for (int i = 0; i < s.size(); i++) {
threads.push_back(std::thread(print, i, s[i]));
}
 
for (auto& th : threads) {
th.join();
}
return 0;
}
```
 
The main program calls the print function for the size of the string vector.
Threads are open when it is called and join back on line 33.
'''Setup:'''
Set breakpoints at the definition of the function, and when join() is called.
Debug using F5 or by clicking debug from the top menu bar.
 
Here is the output of the program:
```
0 : Hello World
3 : is
6 : for
2 : This
5 : code
7 : multithread
8 : debugging
1 : Hello
4 : a testing
```
 
There are 9 different threads that were being created and used every time print() is called.
Using Parallel Stacks Windows, we are able to see the call stack information through a UI.
 
'''Walkthrough:'''
 
First call
[[File:parallelstackswalkthrough1]]
It is being called at the definition of the function "print()"
'''WalkthroughThe yellow arrow means the currently executing thread. By advancing more threads, [[File:parallelstackswalkthrough2]]   more threads are created by the system. [[File:parallelstackswalkthrough3]]   When triggering the method view, it shows the related threads [[File:parallelstackswalkthrough4]]  [[File:parallelstackswalkthrough5]] Indicates the current thread that is being processed, and also lists the other threads. In the left bottom, shows the value of the current thread'''s n(number), and its string(which is "a testing" in the picture) 
Forked threads are being joined after their usage.
'''Setup[[File:''' parallelstackswalkthrough6]]
'''Walkthrough:'''
https://en.wikipedia.org/wiki/Help:Cheatsheet
49
edits

Navigation menu