https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 libMesh::Parallel::Communicator &comm, PerfGraph &perf_graph)
 Constructs and fills the map.
 
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)
 
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)
 
const std::vector< unsigned int > & rankHardwareIds () const
 Vector containing the hardware ID for each PID.
 

Protected Attributes

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

Private Member Functions

const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
PerfGraphperfGraph ()
 Get the PerfGraph.
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 Call to register a named section for timing.
 
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.
 
std::string timedSectionName (const std::string &section_name) const
 

Static Private Member Functions

static InputParameters validParams ()
 

Private Attributes

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

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 @dschwen 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 libMesh::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}
Interface for objects interacting with the PerfGraph.
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
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
void split_by_type(int split_type, int key, info i, Communicator &target) const
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
const Parallel::Communicator & _communicator
ParallelObject(const Parallel::Communicator &comm_in)
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
uint8_t processor_id_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.

36 {
37 mooseAssert(pid < _communicator.size(), "PID out of range");
38 return _rank_to_hardware_id[pid];
39 }
processor_id_type size() const

Referenced by HardwareIDAux::computeValue().

◆ perfGraph()

PerfGraph & PerfGraphInterface::perfGraph ( )
inherited

Get the PerfGraph.

Definition at line 86 of file PerfGraphInterface.C.

87{
88 return _pg_moose_app.perfGraph();
89}
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition MooseApp.h:179
MooseApp & _pg_moose_app
The MooseApp that owns the PerfGraph.

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

◆ 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; }

◆ 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:311

◆ 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 61 of file PerfGraphInterface.C.

63{
64 const auto timed_section_name = timedSectionName(section_name);
65 if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
66 return moose::internal::getPerfGraphRegistry().registerSection(timed_section_name, level);
67 else
68 return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
69}
std::string timedSectionName(const std::string &section_name) const
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID @section_name The name of the section.
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
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 72 of file PerfGraphInterface.C.

76{
77 const auto timed_section_name = timedSectionName(section_name);
78 if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
80 timedSectionName(section_name), level, live_message, print_dots);
81 else
82 return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
83}

◆ 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 55 of file PerfGraphInterface.C.

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

Referenced by PerfGraphInterface::registerTimedSection(), and PerfGraphInterface::registerTimedSection().

◆ validParams()

InputParameters PerfGraphInterface::validParams ( )
staticinherited

Definition at line 16 of file PerfGraphInterface.C.

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

Referenced by Convergence::validParams().

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 135 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 138 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: