www.mooseframework.org
Public Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
RankMap Class Reference

Builds lists and maps that help in knowing which physical hardware nodes each rank is on. More...

#include <RankMap.h>

Inheritance diagram for RankMap:
[legend]

Public Member Functions

 RankMap (const Parallel::Communicator &comm, PerfGraph &perf_graph)
 Constructs and fills the map. More...
 
unsigned int hardwareID (processor_id_type pid) const
 Returns the "hardware ID" (a unique ID given to each physical compute node in the job) for a given processor ID (rank) More...
 
const std::vector< processor_id_type > & ranks (unsigned int hardware_id) const
 Returns the ranks that are on the given hardwareID (phsical node in the job) More...
 
const std::vector< unsigned int > & rankHardwareIds () const
 Vector containing the hardware ID for each PID. More...
 

Protected Attributes

std::unordered_map< unsigned int, std::vector< processor_id_type > > _hardware_id_to_ranks
 Map of hardware_id -> ranks on that node. More...
 
std::vector< unsigned int_rank_to_hardware_id
 Each entry corresponds to the hardware_id for that PID. More...
 

Private Member Functions

PerfGraphperfGraph ()
 Get the PerfGraph. More...
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 Call to register a named section for timing. More...
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 Call to register a named section for timing. More...
 
std::string timedSectionName (const std::string &section_name) const
 

Static Private Member Functions

static InputParameters validParams ()
 

Private Attributes

MooseApp_pg_moose_app
 The MooseApp that owns the PerfGraph. More...
 
const std::string _prefix
 A prefix to use for all sections. More...
 

Detailed Description

Builds lists and maps that help in knowing which physical hardware nodes each rank is on.

Note: large chunks of this code were originally committed by in PR #12351

https://github.com/idaholab/moose/pull/12351

Definition at line 23 of file RankMap.h.

Constructor & Destructor Documentation

◆ RankMap()

RankMap::RankMap ( const Parallel::Communicator &  comm,
PerfGraph perf_graph 
)

Constructs and fills the map.

Definition at line 17 of file RankMap.C.

18  : ParallelObject(comm), PerfGraphInterface(perf_graph, "RankMap")
19 {
20  TIME_SECTION("construct", 2, "Constructing RankMap");
21 
22  auto num_procs = n_processors();
23  _rank_to_hardware_id.resize(num_procs);
24 
25  Parallel::Communicator shmem_comm;
26  _communicator.split_by_type(MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, shmem_comm);
27 
28  // This will be the world rank of the root process
29  // from the shared memory communicator we're getting ready to create
30  // Each process on the same node will end up with the same world_rank
31  processor_id_type world_rank = processor_id();
32 
33  // Broadcast the world rank of the sub group root to all processes within this communicator
34  shmem_comm.broadcast(world_rank, 0);
35 
36  // Send the info to everyone
37  std::vector<processor_id_type> world_ranks(num_procs);
38  _communicator.allgather(world_rank, world_ranks);
39 
40  // Map of world_rank to hardware_id
41  std::map<unsigned int, unsigned int> world_rank_to_hardware_id;
42 
43  // Assign a contiguous unique numerical id to each shared memory group
44  unsigned int next_id = 0;
45 
46  for (MooseIndex(world_ranks) pid = 0; pid < world_ranks.size(); pid++)
47  {
48  auto world_rank = world_ranks[pid];
49 
50  auto it = world_rank_to_hardware_id.lower_bound(world_rank);
51 
52  unsigned int current_id = 0;
53 
54  // If we've seen this world_rank before then use its already given ID
55  if (it != world_rank_to_hardware_id.end() && it->first == world_rank)
56  current_id = it->second;
57  else // Create the new ID
58  {
59  current_id = next_id++;
60 
61  world_rank_to_hardware_id.emplace_hint(it, world_rank, current_id);
62  }
63 
64  _rank_to_hardware_id[pid] = current_id;
65 
66  // Side-effect insertion utilized
67  _hardware_id_to_ranks[current_id].emplace_back(pid);
68  }
69 }
std::vector< unsigned int > _rank_to_hardware_id
Each entry corresponds to the hardware_id for that PID.
Definition: RankMap.h:63
std::unordered_map< unsigned int, std::vector< processor_id_type > > _hardware_id_to_ranks
Map of hardware_id -> ranks on that node.
Definition: RankMap.h:60
uint8_t processor_id_type
PerfGraphInterface(const MooseObject *moose_object)
For objects that are MooseObjects with a default prefix of type()

Member Function Documentation

◆ hardwareID()

unsigned int RankMap::hardwareID ( processor_id_type  pid) const
inline

Returns the "hardware ID" (a unique ID given to each physical compute node in the job) for a given processor ID (rank)

Definition at line 35 of file RankMap.h.

Referenced by HardwareIDAux::computeValue().

36  {
37  mooseAssert(pid < _communicator.size(), "PID out of range");
38  return _rank_to_hardware_id[pid];
39  }
std::vector< unsigned int > _rank_to_hardware_id
Each entry corresponds to the hardware_id for that PID.
Definition: RankMap.h:63

◆ perfGraph()

PerfGraph & PerfGraphInterface::perfGraph ( )
inherited

Get the PerfGraph.

Definition at line 78 of file PerfGraphInterface.C.

Referenced by CommonOutputAction::act(), PerfGraphData::finalize(), and PerfGraphOutput::output().

79 {
80  return _pg_moose_app.perfGraph();
81 }
MooseApp & _pg_moose_app
The MooseApp that owns the PerfGraph.
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition: MooseApp.h:133

◆ rankHardwareIds()

const std::vector<unsigned int>& RankMap::rankHardwareIds ( ) const
inline

Vector containing the hardware ID for each PID.

Definition at line 56 of file RankMap.h.

56 { return _rank_to_hardware_id; }
std::vector< unsigned int > _rank_to_hardware_id
Each entry corresponds to the hardware_id for that PID.
Definition: RankMap.h:63

◆ ranks()

const std::vector<processor_id_type>& RankMap::ranks ( unsigned int  hardware_id) const
inline

Returns the ranks that are on the given hardwareID (phsical node in the job)

Definition at line 44 of file RankMap.h.

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  }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
std::unordered_map< unsigned int, std::vector< processor_id_type > > _hardware_id_to_ranks
Map of hardware_id -> ranks on that node.
Definition: RankMap.h:60

◆ registerTimedSection() [1/2]

PerfID PerfGraphInterface::registerTimedSection ( const std::string &  section_name,
const unsigned int  level 
) const
protectedinherited

Call to register a named section for timing.

Parameters
section_nameThe name of the code section to be timed
levelThe importance of the timer - lower is more important (0 will always come out)
Returns
The ID of the section - use when starting timing

Definition at line 53 of file PerfGraphInterface.C.

55 {
56  const auto timed_section_name = timedSectionName(section_name);
57  if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
58  return moose::internal::getPerfGraphRegistry().registerSection(timed_section_name, level);
59  else
60  return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
61 }
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
std::string timedSectionName(const std::string &section_name) const
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID The name of the section.
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.

◆ registerTimedSection() [2/2]

PerfID PerfGraphInterface::registerTimedSection ( const std::string &  section_name,
const unsigned int  level,
const std::string &  live_message,
const bool  print_dots = true 
) const
protectedinherited

Call to register a named section for timing.

Parameters
section_nameThe name of the code section to be timed
levelThe importance of the timer - lower is more important (0 will always come out)
live_messageThe message to be printed to the screen during execution
print_dotsWhether or not progress dots should be printed for this section
Returns
The ID of the section - use when starting timing

Definition at line 64 of file PerfGraphInterface.C.

68 {
69  const auto timed_section_name = timedSectionName(section_name);
70  if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
72  timedSectionName(section_name), level, live_message, print_dots);
73  else
74  return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
75 }
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
std::string timedSectionName(const std::string &section_name) const
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID The name of the section.
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.

◆ timedSectionName()

std::string PerfGraphInterface::timedSectionName ( const std::string &  section_name) const
protectedinherited
Returns
The name of the timed section with the name section_name.

Optionally adds a prefix if one is defined.

Definition at line 47 of file PerfGraphInterface.C.

Referenced by PerfGraphInterface::registerTimedSection().

48 {
49  return _prefix.empty() ? "" : (_prefix + "::") + section_name;
50 }
const std::string _prefix
A prefix to use for all sections.

◆ validParams()

InputParameters PerfGraphInterface::validParams ( )
staticinherited

Definition at line 16 of file PerfGraphInterface.C.

17 {
19  return params;
20 }
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters emptyInputParameters()

Member Data Documentation

◆ _hardware_id_to_ranks

std::unordered_map<unsigned int, std::vector<processor_id_type> > RankMap::_hardware_id_to_ranks
protected

Map of hardware_id -> ranks on that node.

Definition at line 60 of file RankMap.h.

Referenced by RankMap(), and ranks().

◆ _pg_moose_app

MooseApp& PerfGraphInterface::_pg_moose_app
protectedinherited

The MooseApp that owns the PerfGraph.

Definition at line 124 of file PerfGraphInterface.h.

Referenced by PerfGraphInterface::perfGraph().

◆ _prefix

const std::string PerfGraphInterface::_prefix
protectedinherited

A prefix to use for all sections.

Definition at line 127 of file PerfGraphInterface.h.

Referenced by PerfGraphInterface::timedSectionName().

◆ _rank_to_hardware_id

std::vector<unsigned int> RankMap::_rank_to_hardware_id
protected

Each entry corresponds to the hardware_id for that PID.

Definition at line 63 of file RankMap.h.

Referenced by hardwareID(), rankHardwareIds(), and RankMap().


The documentation for this class was generated from the following files: