QMCPACK
check-affinity.cpp File Reference
+ Include dependency graph for check-affinity.cpp:

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 45 of file check-affinity.cpp.

References omp_get_max_active_levels(), omp_get_num_threads(), and omp_get_thread_num().

46 {
47  int rank = 0, world_size = 1;
48 #ifdef HAVE_MPI
49  int provided;
50  MPI_Init_thread(NULL, NULL, MPI_THREAD_FUNNELED, &provided);
51  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
52  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
53 #endif
54 
55  bool hwthread_id_supported = (get_hwthread() != -1);
56 
57  if (rank == 0)
58  std::cout << "OpenMP OMP_MAX_ACTIVE_LEVELS = " << omp_get_max_active_levels() << std::endl;
59 
60  for (int l_rank = 0; l_rank < world_size; l_rank++)
61  {
62  if (l_rank == rank)
63  {
64 #pragma omp parallel
65  {
66  int L1_thread_id = omp_get_thread_num();
67  int L1_num_thread = omp_get_num_threads();
68 #pragma omp parallel
69  {
70 #pragma omp master
71  if (L1_thread_id == 0 and l_rank == 0)
72  std::cout << "OpenMP enables " << L1_num_thread << " 1st level threads, "
73  << "and " << omp_get_num_threads() << " 2nd level threads." << std::endl
74  << std::endl;
75  }
76 #pragma omp barrier
77 
78  for (int i = 0; i < L1_num_thread; i++)
79  {
80  if (L1_thread_id == i)
81  {
82 #pragma omp parallel
83  {
84  int L2_thread_id = omp_get_thread_num();
85  int L2_num_thread = omp_get_num_threads();
86  for (int j = 0; j < L2_num_thread; j++)
87  {
88  if (L2_thread_id == j)
89  {
90  std::ostringstream o;
91  o << "MPI rank " << rank << " L1 tid " << L1_thread_id << " L2 tid " << L2_thread_id
92  << " is placed on Core ID " << get_core();
93  if (hwthread_id_supported)
94  o << " HW thread ID " << get_hwthread();
95  o << std::endl;
96  std::cout << o.str();
97  }
98 #pragma omp barrier
99  }
100  }
101  }
102 #pragma omp barrier
103  }
104  }
105  }
106 #ifdef HAVE_MPI
107  MPI_Barrier(MPI_COMM_WORLD);
108 #endif
109  }
110 #ifdef HAVE_MPI
111  MPI_Finalize();
112 #endif
113  return 0;
114 }
omp_int_t omp_get_thread_num()
Definition: OpenMP.h:25
omp_int_t omp_get_max_active_levels()
Definition: OpenMP.h:30
omp_int_t omp_get_num_threads()
Definition: OpenMP.h:27