NAMD
Classes | Public Member Functions | Public Attributes | List of all members
TopoManagerWrapper Struct Reference

Classes

struct  pe_sortop_topo
 

Public Member Functions

int fixpe (int pe)
 
 TopoManagerWrapper ()
 
void coords (int pe, int *crds)
 
int coord (int pe, int dim)
 
int * sortAndSplit (int *node_begin, int *node_end, int splitdim)
 

Public Attributes

TopoManager tmgr
 
int a_dim
 
int b_dim
 
int c_dim
 
int d_dim
 
int e_dim
 
int a_rot
 
int b_rot
 
int c_rot
 
int d_rot
 
int e_rot
 
int a_mod
 
int b_mod
 
int c_mod
 
int d_mod
 
int e_mod
 

Detailed Description

Definition at line 1624 of file WorkDistrib.C.

Constructor & Destructor Documentation

TopoManagerWrapper::TopoManagerWrapper ( )
inline

Definition at line 1632 of file WorkDistrib.C.

References a_dim, a_mod, a_rot, b_dim, b_mod, b_rot, c_dim, c_mod, c_rot, d_dim, d_mod, d_rot, e_dim, e_mod, e_rot, endi(), fixpe(), iINFO(), iout, NAMD_bug(), sort, and tmgr.

1632  {
1633 #if CMK_BLUEGENEQ
1634  int na=tmgr.getDimNA();
1635  int nb=tmgr.getDimNB();
1636  int nc=tmgr.getDimNC();
1637  int nd=tmgr.getDimND();
1638  int ne=tmgr.getDimNE();
1639 #else
1640  int na=tmgr.getDimNX();
1641  int nb=tmgr.getDimNY();
1642  int nc=tmgr.getDimNZ();
1643  int nd=1;
1644  int ne=1;
1645 #endif
1646  ResizeArray<int> a_flags(na);
1647  ResizeArray<int> b_flags(nb);
1648  ResizeArray<int> c_flags(nc);
1649  ResizeArray<int> d_flags(nd);
1650  ResizeArray<int> e_flags(ne);
1651  for ( int i=0; i<na; ++i ) { a_flags[i] = 0; }
1652  for ( int i=0; i<nb; ++i ) { b_flags[i] = 0; }
1653  for ( int i=0; i<nc; ++i ) { c_flags[i] = 0; }
1654  for ( int i=0; i<nd; ++i ) { d_flags[i] = 0; }
1655  for ( int i=0; i<ne; ++i ) { e_flags[i] = 0; }
1656  int npes = CkNumPes();
1657  for ( int pe=0; pe<npes; ++pe ) {
1658  int a,b,c,d,e,t;
1659 #if CMK_BLUEGENEQ
1660  tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
1661 #else
1662  tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
1663  d=0; e=0;
1664 #endif
1665  if ( a < 0 || a >= na ) NAMD_bug("inconsistent torus topology!");
1666  if ( b < 0 || b >= nb ) NAMD_bug("inconsistent torus topology!");
1667  if ( c < 0 || c >= nc ) NAMD_bug("inconsistent torus topology!");
1668  if ( d < 0 || d >= nd ) NAMD_bug("inconsistent torus topology!");
1669  if ( e < 0 || e >= ne ) NAMD_bug("inconsistent torus topology!");
1670  a_flags[a] = 1;
1671  b_flags[b] = 1;
1672  c_flags[c] = 1;
1673  d_flags[d] = 1;
1674  e_flags[e] = 1;
1675  }
1676  iout << iINFO << "TORUS A SIZE " << na << " USING";
1677  for ( int i=0; i<na; ++i ) { if ( a_flags[i] ) iout << " " << i; }
1678  iout << "\n" << endi;
1679  iout << iINFO << "TORUS B SIZE " << nb << " USING";
1680  for ( int i=0; i<nb; ++i ) { if ( b_flags[i] ) iout << " " << i; }
1681  iout << "\n" << endi;
1682  iout << iINFO << "TORUS C SIZE " << nc << " USING";
1683  for ( int i=0; i<nc; ++i ) { if ( c_flags[i] ) iout << " " << i; }
1684  iout << "\n" << endi;
1685 #if CMK_BLUEGENEQ
1686  iout << iINFO << "TORUS D SIZE " << nd << " USING";
1687  for ( int i=0; i<nd; ++i ) { if ( d_flags[i] ) iout << " " << i; }
1688  iout << "\n" << endi;
1689  iout << iINFO << "TORUS E SIZE " << ne << " USING";
1690  for ( int i=0; i<ne; ++i ) { if ( e_flags[i] ) iout << " " << i; }
1691  iout << "\n" << endi;
1692 #endif
1693  // find most compact representation of our subset
1694  a_rot = b_rot = c_rot = d_rot = e_rot = 0;
1695  a_mod = na; b_mod = nb; c_mod = nc; d_mod = nd; e_mod = ne;
1696 #if CMK_BLUEGENEQ
1697  if ( tmgr.absA(na) == 0 ) // torus
1698 #else
1699  if ( tmgr.absX(na) == 0 ) // torus
1700 #endif
1701  for ( int i=0, gaplen=0, gapstart=0; i<2*na; ++i ) {
1702  if ( a_flags[i%na] ) gapstart = i+1;
1703  else if ( i - gapstart >= gaplen ) {
1704  a_rot = 2*na-i-1; gaplen = i - gapstart;
1705  }
1706  }
1707 #if CMK_BLUEGENEQ
1708  if ( tmgr.absB(nb) == 0 ) // torus
1709 #else
1710  if ( tmgr.absY(nb) == 0 ) // torus
1711 #endif
1712  for ( int i=0, gaplen=0, gapstart=0; i<2*nb; ++i ) {
1713  if ( b_flags[i%nb] ) gapstart = i+1;
1714  else if ( i - gapstart >= gaplen ) {
1715  b_rot = 2*nb-i-1; gaplen = i - gapstart;
1716  }
1717  }
1718 #if CMK_BLUEGENEQ
1719  if ( tmgr.absC(nc) == 0 ) // torus
1720 #else
1721  if ( tmgr.absZ(nc) == 0 ) // torus
1722 #endif
1723  for ( int i=0, gaplen=0, gapstart=0; i<2*nc; ++i ) {
1724  if ( c_flags[i%nc] ) gapstart = i+1;
1725  else if ( i - gapstart >= gaplen ) {
1726  c_rot = 2*nc-i-1; gaplen = i - gapstart;
1727  }
1728  }
1729 #if CMK_BLUEGENEQ
1730  if ( tmgr.absD(nd) == 0 ) // torus
1731  for ( int i=0, gaplen=0, gapstart=0; i<2*nd; ++i ) {
1732  if ( d_flags[i%nd] ) gapstart = i+1;
1733  else if ( i - gapstart >= gaplen ) {
1734  d_rot = 2*nd-i-1; gaplen = i - gapstart;
1735  }
1736  }
1737  if ( tmgr.absE(ne) == 0 ) // torus
1738  for ( int i=0, gaplen=0, gapstart=0; i<2*ne; ++i ) {
1739  if ( e_flags[i%ne] ) gapstart = i+1;
1740  else if ( i - gapstart >= gaplen ) {
1741  e_rot = 2*ne-i-1; gaplen = i - gapstart;
1742  }
1743  }
1744 #endif
1745  // order dimensions by length
1746  int a_min=na, a_max=-1;
1747  int b_min=nb, b_max=-1;
1748  int c_min=nc, c_max=-1;
1749  int d_min=nd, d_max=-1;
1750  int e_min=ne, e_max=-1;
1751  for ( int pe=0; pe<npes; ++pe ) {
1752  int a,b,c,d,e,t;
1753 #if CMK_BLUEGENEQ
1754  tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
1755 #else
1756  tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
1757  d=0; e=0;
1758 #endif
1759  a = (a+a_rot)%a_mod;
1760  b = (b+b_rot)%b_mod;
1761  c = (c+c_rot)%c_mod;
1762  d = (d+d_rot)%d_mod;
1763  e = (e+e_rot)%e_mod;
1764  if ( a < a_min ) a_min = a;
1765  if ( b < b_min ) b_min = b;
1766  if ( c < c_min ) c_min = c;
1767  if ( d < d_min ) d_min = d;
1768  if ( e < e_min ) e_min = e;
1769  if ( a > a_max ) a_max = a;
1770  if ( b > b_max ) b_max = b;
1771  if ( c > c_max ) c_max = c;
1772  if ( d > d_max ) d_max = d;
1773  if ( e > e_max ) e_max = e;
1774  }
1775  int a_len = a_max - a_min + 1;
1776  int b_len = b_max - b_min + 1;
1777  int c_len = c_max - c_min + 1;
1778  int d_len = d_max - d_min + 1;
1779  int e_len = e_max - e_min + 1;
1780  int lensort[5];
1781  lensort[0] = (a_len << 3) + 0;
1782  lensort[1] = (b_len << 3) + 1;
1783  lensort[2] = (c_len << 3) + 2;
1784  lensort[3] = (d_len << 3) + 3;
1785  lensort[4] = (e_len << 3) + 4;
1786  // CkPrintf("TopoManagerWrapper lensort before %d %d %d %d %d\n", lensort[0] & 7, lensort[1] & 7, lensort[2] & 7, lensort[3] & 7, lensort[4] & 7);
1787  std::sort(lensort, lensort+5);
1788  // CkPrintf("TopoManagerWrapper lensort after %d %d %d %d %d\n", lensort[0] & 7, lensort[1] & 7, lensort[2] & 7, lensort[3] & 7, lensort[4] & 7);
1789  for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 0 ) a_dim = 4-i; }
1790  for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 1 ) b_dim = 4-i; }
1791  for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 2 ) c_dim = 4-i; }
1792  for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 3 ) d_dim = 4-i; }
1793  for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 4 ) e_dim = 4-i; }
1794 #if 0
1795  if ( a_len >= b_len && a_len >= c_len ) {
1796  a_dim = 0;
1797  if ( b_len >= c_len ) {
1798  b_dim = 1; c_dim = 2;
1799  } else {
1800  b_dim = 2; c_dim = 1;
1801  }
1802  } else if ( b_len >= a_len && b_len >= c_len ) {
1803  b_dim = 0;
1804  if ( a_len >= c_len ) {
1805  a_dim = 1; c_dim = 2;
1806  } else {
1807  a_dim = 2; c_dim = 1;
1808  }
1809  } else { // c is longest
1810  c_dim = 0;
1811  if ( a_len >= b_len ) {
1812  a_dim = 1; b_dim = 2;
1813  } else {
1814  a_dim = 2; b_dim = 1;
1815  }
1816  }
1817 #endif
1818  iout << iINFO << "TORUS MINIMAL MESH SIZE IS " << a_len << " BY " << b_len << " BY " << c_len
1819 #if CMK_BLUEGENEQ
1820  << " BY " << d_len << " BY " << e_len
1821 #endif
1822  << "\n" << endi;
1823  // CkPrintf("TopoManagerWrapper dims %d %d %d %d %d\n", a_dim, b_dim, c_dim, d_dim, e_dim);
1824  }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
TopoManager tmgr
Definition: WorkDistrib.C:1625
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
void NAMD_bug(const char *err_msg)
Definition: common.C:129
BlockRadixSort::TempStorage sort
int fixpe(int pe)
Definition: WorkDistrib.C:1629

Member Function Documentation

int TopoManagerWrapper::coord ( int  pe,
int  dim 
)
inline

Definition at line 1839 of file WorkDistrib.C.

References coords().

Referenced by sortAndSplit().

1839  {
1840  int crds[3];
1841  coords(pe,crds);
1842  return crds[dim];
1843  }
void coords(int pe, int *crds)
Definition: WorkDistrib.C:1825
void TopoManagerWrapper::coords ( int  pe,
int *  crds 
)
inline

Definition at line 1825 of file WorkDistrib.C.

References a_dim, a_mod, a_rot, b_dim, b_mod, b_rot, c_dim, c_mod, c_rot, d_dim, d_mod, d_rot, e_dim, e_mod, e_rot, fixpe(), and tmgr.

Referenced by coord(), TopoManagerWrapper::pe_sortop_topo::operator()(), recursive_bisect_with_curve(), and sortAndSplit().

1825  {
1826  int a,b,c,d,e,t;
1827 #if CMK_BLUEGENEQ
1828  tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
1829 #else
1830  tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
1831  d=0; e=0;
1832 #endif
1833  if ( a_dim < 3 ) crds[a_dim] = (a+a_rot)%a_mod;
1834  if ( b_dim < 3 ) crds[b_dim] = (b+b_rot)%b_mod;
1835  if ( c_dim < 3 ) crds[c_dim] = (c+c_rot)%c_mod;
1836  if ( d_dim < 3 ) crds[d_dim] = (d+d_rot)%d_mod;
1837  if ( e_dim < 3 ) crds[e_dim] = (e+e_rot)%e_mod;
1838  }
TopoManager tmgr
Definition: WorkDistrib.C:1625
int fixpe(int pe)
Definition: WorkDistrib.C:1629
int TopoManagerWrapper::fixpe ( int  pe)
inline

Definition at line 1629 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

1629  { // compensate for lame fallback topology information
1630  return CmiGetFirstPeOnPhysicalNode(CmiPhysicalNodeID(pe));
1631  }
int* TopoManagerWrapper::sortAndSplit ( int *  node_begin,
int *  node_end,
int  splitdim 
)
inline

Definition at line 1860 of file WorkDistrib.C.

References coord(), coords(), and sort.

Referenced by recursive_bisect_with_curve().

1860  {
1861  if ( node_begin == node_end ) return node_begin;
1862  int tmins[3], tmaxs[3], tlens[3], sortdims[3];
1863  coords(*node_begin, tmins);
1864  coords(*node_begin, tmaxs);
1865  for ( int *peitr = node_begin; peitr != node_end; ++peitr ) {
1866  int tvals[3];
1867  coords(*peitr, tvals);
1868  for ( int i=0; i<3; ++i ) {
1869  if ( tvals[i] < tmins[i] ) tmins[i] = tvals[i];
1870  if ( tvals[i] > tmaxs[i] ) tmaxs[i] = tvals[i];
1871  }
1872  }
1873  for ( int i=0; i<3; ++i ) {
1874  tlens[i] = tmaxs[i] - tmins[i];
1875  }
1876  sortdims[0] = splitdim;
1877  for ( int i=0, j=0; i<3; ++i ) {
1878  if ( i != splitdim ) sortdims[++j] = i;
1879  }
1880  if ( tlens[sortdims[1]] < tlens[sortdims[2]] ) {
1881  int tmp = sortdims[1];
1882  sortdims[1] = sortdims[2];
1883  sortdims[2] = tmp;
1884  }
1885  std::sort(node_begin,node_end,pe_sortop_topo(*this,sortdims));
1886  int *nodes = node_begin;
1887  int nnodes = node_end - node_begin;
1888  int i_split = 0;
1889 #if 0
1890  int c_split = coord(nodes[0],splitdim);
1891  for ( int i=0; i<nnodes; ++i ) {
1892  if ( coord(nodes[i],splitdim) != c_split ) {
1893  int mid = (nnodes+1)/2;
1894  if ( abs(i-mid) < abs(i_split-mid) ) {
1895  i_split = i;
1896  c_split = coord(i,splitdim);
1897  }
1898  else break;
1899  }
1900  }
1901 #endif
1902  for ( int i=0; i<nnodes; ++i ) {
1903  if ( ! CmiPeOnSamePhysicalNode(nodes[i_split],nodes[i]) ) {
1904  int mid = (nnodes+1)/2;
1905  if ( abs(i-mid) < abs(i_split-mid) ) i_split = i;
1906  else break;
1907  }
1908  }
1909  return ( node_begin + i_split );
1910  }
int coord(int pe, int dim)
Definition: WorkDistrib.C:1839
BlockRadixSort::TempStorage sort
void coords(int pe, int *crds)
Definition: WorkDistrib.C:1825

Member Data Documentation

int TopoManagerWrapper::a_dim

Definition at line 1626 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::a_mod

Definition at line 1628 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::a_rot

Definition at line 1627 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_dim

Definition at line 1626 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_mod

Definition at line 1628 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_rot

Definition at line 1627 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_dim

Definition at line 1626 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_mod

Definition at line 1628 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_rot

Definition at line 1627 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_dim

Definition at line 1626 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_mod

Definition at line 1628 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_rot

Definition at line 1627 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_dim

Definition at line 1626 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_mod

Definition at line 1628 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_rot

Definition at line 1627 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

TopoManager TopoManagerWrapper::tmgr

Definition at line 1625 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().


The documentation for this struct was generated from the following file: