12 lines
730 B
Markdown
12 lines
730 B
Markdown
|
We want each of the two threads in the code below to print the numbers from 5-10. With the current code this is not working as both threads use the same counter in the while loop.
|
||
|
Sometimes we want each thread to have it's own copy of a variable, when this is desired we can use OpenMPs private clause to give each thread it's own instance.
|
||
|
|
||
|
## Knowledge
|
||
|
|
||
|
To mark a variable as private you add ``private(var1, var2)`` to your directive. Some directive such as the omp for directiv assume certain variables as private by default.
|
||
|
In the omp for example it is the loop counter. Thats why you didn't had to specify a private varible befor.
|
||
|
|
||
|
## Task
|
||
|
|
||
|
Add a private clause to the code, so that both threads output the numbers 5 to 10.
|