mpi/{hello/hello.cpp → hello_hybrid/hello_hybrid.cpp} RENAMED
@@ -1,22 +1,31 @@
1
- #include <mpi.h>
2
  #include <iostream>
 
 
3
 
4
  int main(int argc, char* argv[])
5
  {
6
  MPI_Init(&argc, &argv);
7
 
8
  int my_rank = -1;
9
  int process_count = -1;
10
 
11
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
12
  MPI_Comm_size(MPI_COMM_WORLD, &process_count);
13
 
14
  char hostname[MPI_MAX_PROCESSOR_NAME];
15
  int hostname_length = -1;
16
  MPI_Get_processor_name(hostname, &hostname_length);
17
 
18
  std::cout << "Hello from main thread of process " << my_rank
19
- << " of " << process_count << " on " << hostname << "\n"; //std::endl;
 
 
 
 
 
 
 
 
20
 
21
  MPI_Finalize();
22
  }
 
1
  #include <iostream>
2
+ #include <mpi.h>
3
+ #include <omp.h>
4
 
5
  int main(int argc, char* argv[])
6
  {
7
  MPI_Init(&argc, &argv);
8
 
9
  int my_rank = -1;
10
  int process_count = -1;
11
 
12
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
13
  MPI_Comm_size(MPI_COMM_WORLD, &process_count);
14
 
15
  char hostname[MPI_MAX_PROCESSOR_NAME];
16
  int hostname_length = -1;
17
  MPI_Get_processor_name(hostname, &hostname_length);
18
 
19
  std::cout << "Hello from main thread of process " << my_rank
20
+ << " of " << process_count << " on " << hostname << std::endl;
21
+
22
+ #pragma omp parallel default(none) shared(my_rank, hostname, std::cout)
23
+ {
24
+ #pragma omp critical(stdout)
25
+ std::cout << "\tHello from thread " << omp_get_thread_num()
26
+ << " of " << omp_get_num_threads() << " of process "
27
+ << my_rank << " on " << hostname << std::endl;
28
+ }
29
 
30
  MPI_Finalize();
31
  }