34 static int num_ranks{-1};
35 if (num_ranks == -1) {
36 char name[MPI_MAX_PROCESSOR_NAME];
38 CALL_MPI(MPI_Get_processor_name, (name, &len));
39 std::vector<size_t>
hash(mpi::Communicator::world().size());
40 hash[mpi::Communicator::world().rank()] = std::hash<std::string>{}(std::string(name, len));
41 mpi::Communicator::world().allgather(
hash.data(), 1, mpi::Communicator::world().rank());
45 for (
int i = 1; i < (int)
hash.size(); i++) {
53 for (
int i = (
int)
hash.size() - 2; i >= 0; i--) {
60 num_ranks = std::max(n, m);
69 if (num_devices__ == 0) {
75 int r = mpi::Communicator::world().rank();
76 char name[MPI_MAX_PROCESSOR_NAME];
78 CALL_MPI(MPI_Get_processor_name, (name, &len));
79 std::vector<size_t>
hash(mpi::Communicator::world().size());
80 hash[r] = std::hash<std::string>{}(std::string(name, len));
81 mpi::Communicator::world().allgather(
hash.data(), 1, r);
82 std::map<size_t, std::vector<int>> rank_map;
83 for (
int i = 0; i < mpi::Communicator::world().size(); i++) {
84 rank_map[
hash[i]].push_back(i);
86 for (
int i = 0; i < (int)rank_map[
hash[r]].size(); i++) {
87 if (rank_map[
hash[r]][i] == r) {
88 id = i % num_devices__;
Contains declaration and implementation of mpi::Communicator class.
int get_device_id(int num_devices__)
Get GPU device id associated with the current rank.
int num_ranks_per_node()
Get number of ranks per node.
Namespace of the SIRIUS library.
auto hash(void const *buff, size_t size, uint64_t h=5381)
Simple hash function.