49
edits
Changes
→Case A - Using the Thread window
<syntaxhighlight lang="cpp">
// Thread Window Example
int max_threads = omp_get_max_threads();
cout << "the maximum amount of threads available is: " << max_threads << endl;
{
cout << endl << "~~~~~ Inside Serial Block ~~~~~" << endl;
cout << "the amount of threads available in this block is: " << omp_get_num_threads() << endl;
cout << "current thread is: " << omp_get_thread_num() << endl;
}
#pragma omp parallel
{
#pragma omp single
{
cout << endl << "~~~~~~ Inside Parallel Block (num_threads unspecified) ~~~~~~" << endl;
cout << "the amount of threads available in this block is: " << omp_get_num_threads() << endl;
}
cout << "current thread is: " << omp_get_thread_num() << endl;
}
#pragma omp parallel num_threads(max_threads/2)
{
#pragma omp single
{ cout << endl << "~~~~~~ Inside Parallel Block (num_threads specified as " << max_threads / 2 << ") ~~~~~~" << endl; cout << "the amount of threads available in this block is: " << omp_get_num_threads() << endl; } cout << "current thread is: " << omp_get_thread_num() << endl;
}
}