@@ -1,11 +1,18 @@
|
|
|
|
1 |
#include <iostream>
|
|
|
2 |
|
3 |
-
int main()
|
4 |
{
|
5 |
-
|
|
|
|
|
|
|
|
|
6 |
{
|
7 |
#pragma omp critical(cout)
|
8 |
-
std::cout << "Hello world from secondary thread" <<
|
|
|
9 |
}
|
10 |
return 0;
|
11 |
}
|
1 |
+
#include <cstdlib>
|
2 |
#include <iostream>
|
3 |
+
#include <omp.h>
|
4 |
|
5 |
+
int main(int argc, char* argv[])
|
6 |
{
|
7 |
+
int thread_count = omp_get_max_threads();
|
8 |
+
if ( argc >= 2 )
|
9 |
+
thread_count = atoi(argv[1]);
|
10 |
+
|
11 |
+
#pragma omp parallel num_threads(thread_count)
|
12 |
{
|
13 |
#pragma omp critical(cout)
|
14 |
+
std::cout << "Hello world from secondary thread " << omp_get_thread_num()
|
15 |
+
<< " of " << omp_get_num_threads() << std::endl;
|
16 |
}
|
17 |
return 0;
|
18 |
}
|