|
@@ -1,10 +1,17 @@
|
|
| 1 |
// Copyright 2021 Jeisson Hidalgo <jeisson.hidalgo@ucr.ac.cr> CC-BY 4.0
|
|
|
|
| 2 |
#include <iostream>
|
| 3 |
|
| 4 |
-
int main() {
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
{
|
| 7 |
-
#pragma omp critical
|
| 8 |
-
std::cout << "Hello from secondary thread" <<
|
|
|
|
| 9 |
}
|
| 10 |
}
|
| 1 |
// Copyright 2021 Jeisson Hidalgo <jeisson.hidalgo@ucr.ac.cr> CC-BY 4.0
|
| 2 |
+
#include <omp.h>
|
| 3 |
#include <iostream>
|
| 4 |
|
| 5 |
+
int main(int argc, char* argv[]) {
|
| 6 |
+
int thread_count = omp_get_max_threads();
|
| 7 |
+
if (argc == 2) {
|
| 8 |
+
thread_count = atoi(argv[1]);
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
#pragma omp parallel num_threads(thread_count)
|
| 12 |
{
|
| 13 |
+
#pragma omp critical(stdout)
|
| 14 |
+
std::cout << "Hello from secondary thread " << omp_get_thread_num()
|
| 15 |
+
<< " of " << omp_get_num_threads() << std::endl;
|
| 16 |
}
|
| 17 |
}
|