openmp/{hello/hello.cpp → hello_w/hello_w.cpp} RENAMED
@@ -1,14 +1,28 @@
 
 
 
 
 
 
 
 
1
  #include <iostream>
2
 
3
- int main() {
 
 
 
 
 
4
  // ...
5
- #pragma omp parallel
6
  {
7
  // ...
8
  #pragma omp critical(cout)
9
- std::cout << "Hello from a thread" << std::endl;
 
10
  // ...
11
  }
12
  // ...
13
  return 0;
14
  }
1
+ /*
2
+ * Copyright 2021 Jeisson Hidalgo-Cespedes - Universidad de Costa Rica
3
+ * Creates a secondary thread that greets in the standard output
4
+ */
5
+
6
+ #include <omp.h>
7
+
8
+ #include <cstdlib>
9
  #include <iostream>
10
 
11
+ int main(int argc, char* argv[]) {
12
+ int thread_count = omp_get_max_threads();
13
+ if (argc >= 2) {
14
+ thread_count = atoi(argv[1]);
15
+ }
16
+
17
  // ...
18
+ #pragma omp parallel num_threads(thread_count) default(none) shared(std::cout)
19
  {
20
  // ...
21
  #pragma omp critical(cout)
22
+ std::cout << "Hello from " << omp_get_thread_num() << " thread of "
23
+ << omp_get_num_threads() << std::endl;
24
  // ...
25
  }
26
  // ...
27
  return 0;
28
  }