Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include "PerfGraphInterface.h" 13 : 14 : #include "libmesh/parallel_object.h" 15 : 16 : /** 17 : * Builds lists and maps that help in knowing which physical hardware nodes each rank is on. 18 : * 19 : * Note: large chunks of this code were originally committed by @dschwen in PR #12351 20 : * 21 : * https://github.com/idaholab/moose/pull/12351 22 : */ 23 : class RankMap : libMesh::ParallelObject, PerfGraphInterface 24 : { 25 : public: 26 : /** 27 : * Constructs and fills the map 28 : */ 29 : RankMap(const libMesh::Parallel::Communicator & comm, PerfGraph & perf_graph); 30 : 31 : /** 32 : * Returns the "hardware ID" (a unique ID given to each physical compute node in the job) 33 : * for a given processor ID (rank) 34 : */ 35 60673 : unsigned int hardwareID(processor_id_type pid) const 36 : { 37 : mooseAssert(pid < _communicator.size(), "PID out of range"); 38 60673 : return _rank_to_hardware_id[pid]; 39 : } 40 : 41 : /** 42 : * Returns the ranks that are on the given hardwareID (phsical node in the job) 43 : */ 44 : const std::vector<processor_id_type> & ranks(unsigned int hardware_id) const 45 : { 46 : auto item = _hardware_id_to_ranks.find(hardware_id); 47 : if (item == _hardware_id_to_ranks.end()) 48 : mooseError("hardware_id not found"); 49 : 50 : return item->second; 51 : } 52 : 53 : /** 54 : * Vector containing the hardware ID for each PID 55 : */ 56 548 : const std::vector<unsigned int> & rankHardwareIds() const { return _rank_to_hardware_id; } 57 : 58 : protected: 59 : /// Map of hardware_id -> ranks on that node 60 : std::unordered_map<unsigned int, std::vector<processor_id_type>> _hardware_id_to_ranks; 61 : 62 : /// Each entry corresponds to the hardware_id for that PID 63 : std::vector<unsigned int> _rank_to_hardware_id; 64 : };