@@ -1,14 +1,20 @@
|
|
1 |
#include <omp.h>
|
2 |
#include <stdio.h>
|
|
|
3 |
|
4 |
-
int main(
|
5 |
{
|
6 |
-
|
|
|
|
|
|
|
|
|
7 |
{
|
8 |
#pragma omp critical (print)
|
9 |
printf("Hello from thread %d of %d\n"
|
10 |
, omp_get_thread_num()
|
11 |
, omp_get_num_threads() );
|
12 |
}
|
|
|
13 |
return 0;
|
14 |
}
|
1 |
#include <omp.h>
|
2 |
#include <stdio.h>
|
3 |
+
#include <stdlib.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 (print)
|
14 |
printf("Hello from thread %d of %d\n"
|
15 |
, omp_get_thread_num()
|
16 |
, omp_get_num_threads() );
|
17 |
}
|
18 |
+
|
19 |
return 0;
|
20 |
}
|