#pragma omp parallel [Options...]
{ ...
... Parallel region
...
... Program statements between the braces
... are executed in parallel by all threads
...
}
|
#include <iostream.h>
#include <opm.h>
int main(int argc, char *argv[])
{
#pragma omp parallel
{
cout << "Hello World !!!" << endl;
}
}
|
export OMP_NUM_THREADS=8
a.out
You will see "Hello World !!!" printed EIGHT times !!! (Remove the #pragma line and you get ONE line)....
#include <iostream> // NO: .h !!!
#include <opm.h>
using namespace std; // You need to use this namespace
int main(int argc, char *argv[])
{
#pragma omp parallel
{
cout << "Hello World !!!" << endl;
}
}
|
|
Then the master thread T0 continue with the single-threaded execution following the PARALLEL section.