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 1620 of file WorkDistrib.C.

Constructor & Destructor Documentation

TopoManagerWrapper::TopoManagerWrapper ( )
inline

Definition at line 1628 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.

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

Member Function Documentation

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

Definition at line 1835 of file WorkDistrib.C.

References coords().

Referenced by sortAndSplit().

1835  {
1836  int crds[3];
1837  coords(pe,crds);
1838  return crds[dim];
1839  }
void coords(int pe, int *crds)
Definition: WorkDistrib.C:1821
void TopoManagerWrapper::coords ( int  pe,
int *  crds 
)
inline

Definition at line 1821 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().

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

Definition at line 1625 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

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

Definition at line 1856 of file WorkDistrib.C.

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

Referenced by recursive_bisect_with_curve().

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

Member Data Documentation

int TopoManagerWrapper::a_dim

Definition at line 1622 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::a_mod

Definition at line 1624 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::a_rot

Definition at line 1623 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_dim

Definition at line 1622 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_mod

Definition at line 1624 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_rot

Definition at line 1623 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_dim

Definition at line 1622 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_mod

Definition at line 1624 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_rot

Definition at line 1623 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_dim

Definition at line 1622 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_mod

Definition at line 1624 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_rot

Definition at line 1623 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_dim

Definition at line 1622 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_mod

Definition at line 1624 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_rot

Definition at line 1623 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

TopoManager TopoManagerWrapper::tmgr

Definition at line 1621 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().


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