#

19. Querying Network Topology

The following calls provide information about the machine upon which the
parallel program is executed.
A processing element (PE) is a unit of mapping and scheduling, which takes the
form of an OS thread in SMP mode and an OS process in non-SMP mode.
A node (specifically, a logical node) refers to an OS process: a set of one or
more PEs that share memory (i.e. an address space).
PEs and nodes are ranked separately starting from zero: PEs are ranked from 0
to *CmiNumPes()*, and nodes are ranked from 0 to

*CmiNumNodes()*. Charm++ provides a unified abstraction for querying topology of IBM's BG/L, BG/P and BG/Q, and Cray's XT4, XT5 and XE6. Class TopoManager, which can be used by including TopoManager.h, contains following member functions:

**TopoManager():**- Default constructor.
**getDimNX(), getDimNY(), getDimNZ():**- Returns the length of X, Y and Z dimensions (except BG/Q).
**getDimNA(), getDimNB(), getDimNC(), getDimND(), getDimNE():**- Returns the length of A, B, C, D and E dimensions on BG/Q.
**getDimNT():**- Returns the length of T dimension. TopoManager uses T dimension to represent different cores that reside within a physical node.
**rankToCoordinates(int pe, int &x, int &y, int &z, int &t):**- Get the
coordinates of PE with rank
*pe*(except BG/Q). **rankToCoordinates(int pe, int &a, int &b, int &c, int &d, int &e, int &t):**- Get the coordinates of PE with rank
*pe*on BG/Q. **coordinatesToRank(int x, int y, int z, int t):**- Returns the rank of PE with given coordinates (except BG/Q).
**coordinatesToRank(int a, int b, int c, int d, int e, int t):**- Returns the rank of PE with given coordinates on BG/Q.
**getHopsBetweenRanks(int pe1, int pe2):**- Returns the distance between the given PEs in terms of the hops count on the network between the two PEs.
**printAllocation(FILE *fp):**- Outputs the allocation for a particular execution to the given file.

For example, one can obtain rank of a processor, whose coordinates are known, on BG/P as well as on Cray XE6 using the following code:

TopoManager tmgr; int rank,x,y,z,t; x = y = z = t = 2; rank = tmgr.coordinatesToRank(x,y,z,t);

For more examples, please refer to examples/charm++/topology.