@@ -1,20 +1,28 @@
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
{
|
13 |
#pragma omp critical (print)
|
14 |
-
printf("
|
15 |
, omp_get_thread_num()
|
16 |
-
, omp_get_num_threads()
|
|
|
|
|
17 |
}
|
18 |
|
19 |
return 0;
|
20 |
}
|
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 |
+
int iterations = thread_count;
|
12 |
+
if ( argc >= 3 )
|
13 |
+
iterations = atoi( argv[2] );
|
14 |
+
|
15 |
+
#pragma omp parallel for num_threads(thread_count) \
|
16 |
+
default(none) shared(iterations)
|
17 |
+
for ( int iteration = 0; iteration < iterations; ++iteration )
|
18 |
{
|
19 |
#pragma omp critical (print)
|
20 |
+
printf("%d/%d: iteration %d/%d\n"
|
21 |
, omp_get_thread_num()
|
22 |
+
, omp_get_num_threads()
|
23 |
+
, iteration
|
24 |
+
, iterations );
|
25 |
}
|
26 |
|
27 |
return 0;
|
28 |
}
|