Changes

Jump to: navigation, search

GPU621/CamelCaseTeam

547 bytes added, 03:55, 22 July 2021
Added OpenMP thread creation example
The construct identifies what block of code is being executed in parallel and the clause qualifies the parallel construct. In comparison to the C++ 11 thread library, the threads are performed in a region while the C++ 11 thread library have to be specifically created and joined back to the parent thread.
 
<syntaxhighlight lang="cpp>
#include <iostream>
#include <omp.h>
 
void main() {
omp_set_num_threads(3);
#pragma omp parallel
{
int tid = omp_get_thread_num();
#pragma omp critical
std::cout << "Thread " << tid + 1 << std::endl;
}
}
 
//Thread 1
//Thread 2
//Thread 3
</syntaxhighlight>
 
The code above shows the creation of 3 threads in a parallel region which are performed in sequence using critical. This highlights the difference between the c++11 thread library as no joining is required after
the threads concludes their function.
== References ==
Thread Support Library https://en.cppreference.com/w/cpp/thread
16
edits

Navigation menu