QMCPACK
OMPDeviceManager.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2023 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #include "OMPDeviceManager.h"
15 #include <stdexcept>
16 #include <omp.h>
17 #include "OutputManager.h"
19 
20 namespace qmcplusplus
21 {
22 
23 OMPDeviceManager::OMPDeviceManager(int& default_device_num, int& num_devices, int local_rank, int local_size)
24  : omp_default_device_num(-1), omp_device_count(omp_get_num_devices())
25 {
26  if (num_devices == 0)
27  num_devices = omp_device_count;
28  else if (num_devices != omp_device_count)
29  throw std::runtime_error("Inconsistent number of OpenMP devices with the previous record!");
30  if (omp_device_count > local_size)
31  app_warning() << "More OpenMP devices than the number of MPI ranks. "
32  << "Some devices will be left idle.\n"
33  << "There is potential performance issue with the GPU affinity.\n";
34  if (num_devices > 0)
35  {
37  if (default_device_num < 0)
38  default_device_num = omp_default_device_num;
39  else if (default_device_num != omp_default_device_num)
40  throw std::runtime_error("Inconsistent assigned OpenMP devices with the previous record!");
41  omp_set_default_device(omp_default_device_num);
42  }
43 }
44 } // namespace qmcplusplus
std::ostream & app_warning()
Definition: OutputManager.h:69
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Declaration of OutputManager class.
OMPDeviceManager(int &default_device_num, int &num_devices, int local_rank, int local_size)
int determineDefaultDeviceNum(int num_devices, int rank_id, int num_ranks)
distribute MPI ranks among devices