QMCPACK
determineDefaultDeviceNum.h
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) 2021 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 #ifndef QMCPLUSPLUS_DETERMINEDEFAULTDEVICENUM_H
15 #define QMCPLUSPLUS_DETERMINEDEFAULTDEVICENUM_H
16 
17 namespace qmcplusplus
18 {
19 /** distribute MPI ranks among devices
20  *
21  * the amount of MPI ranks for each device differs by 1 at maximum.
22  * larger id has more MPI ranks.
23  */
24 inline int determineDefaultDeviceNum(int num_devices, int rank_id, int num_ranks)
25 {
26  if (num_ranks < num_devices)
27  num_devices = num_ranks;
28  // ranks are equally distributed among devices
29  int min_ranks_per_device = num_ranks / num_devices;
30  int residual = num_ranks % num_devices;
31  int assigned_device_id;
32  if (rank_id < min_ranks_per_device * (num_devices - residual))
33  assigned_device_id = rank_id / min_ranks_per_device;
34  else
35  assigned_device_id = (rank_id + num_devices - residual) / (min_ranks_per_device + 1);
36  return assigned_device_id;
37 }
38 }
39 
40 #endif
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
int determineDefaultDeviceNum(int num_devices, int rank_id, int num_ranks)
distribute MPI ranks among devices