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

Constructor & Destructor Documentation

◆ TopoManagerWrapper()

TopoManagerWrapper::TopoManagerWrapper ( )
inline

Definition at line 1753 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(), and tmgr.

1753  {
1754 #if CMK_BLUEGENEQ
1755  int na=tmgr.getDimNA();
1756  int nb=tmgr.getDimNB();
1757  int nc=tmgr.getDimNC();
1758  int nd=tmgr.getDimND();
1759  int ne=tmgr.getDimNE();
1760 #else
1761  int na=tmgr.getDimNX();
1762  int nb=tmgr.getDimNY();
1763  int nc=tmgr.getDimNZ();
1764  int nd=1;
1765  int ne=1;
1766 #endif
1767  ResizeArray<int> a_flags(na);
1768  ResizeArray<int> b_flags(nb);
1769  ResizeArray<int> c_flags(nc);
1770  ResizeArray<int> d_flags(nd);
1771  ResizeArray<int> e_flags(ne);
1772  for ( int i=0; i<na; ++i ) { a_flags[i] = 0; }
1773  for ( int i=0; i<nb; ++i ) { b_flags[i] = 0; }
1774  for ( int i=0; i<nc; ++i ) { c_flags[i] = 0; }
1775  for ( int i=0; i<nd; ++i ) { d_flags[i] = 0; }
1776  for ( int i=0; i<ne; ++i ) { e_flags[i] = 0; }
1777  int npes = CkNumPes();
1778  for ( int pe=0; pe<npes; ++pe ) {
1779  int a,b,c,d,e,t;
1780 #if CMK_BLUEGENEQ
1781  tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
1782 #else
1783  tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
1784  d=0; e=0;
1785 #endif
1786  if ( a < 0 || a >= na ) NAMD_bug("inconsistent torus topology!");
1787  if ( b < 0 || b >= nb ) NAMD_bug("inconsistent torus topology!");
1788  if ( c < 0 || c >= nc ) NAMD_bug("inconsistent torus topology!");
1789  if ( d < 0 || d >= nd ) NAMD_bug("inconsistent torus topology!");
1790  if ( e < 0 || e >= ne ) NAMD_bug("inconsistent torus topology!");
1791  a_flags[a] = 1;
1792  b_flags[b] = 1;
1793  c_flags[c] = 1;
1794  d_flags[d] = 1;
1795  e_flags[e] = 1;
1796  }
1797  iout << iINFO << "TORUS A SIZE " << na << " USING";
1798  for ( int i=0; i<na; ++i ) { if ( a_flags[i] ) iout << " " << i; }
1799  iout << "\n" << endi;
1800  iout << iINFO << "TORUS B SIZE " << nb << " USING";
1801  for ( int i=0; i<nb; ++i ) { if ( b_flags[i] ) iout << " " << i; }
1802  iout << "\n" << endi;
1803  iout << iINFO << "TORUS C SIZE " << nc << " USING";
1804  for ( int i=0; i<nc; ++i ) { if ( c_flags[i] ) iout << " " << i; }
1805  iout << "\n" << endi;
1806 #if CMK_BLUEGENEQ
1807  iout << iINFO << "TORUS D SIZE " << nd << " USING";
1808  for ( int i=0; i<nd; ++i ) { if ( d_flags[i] ) iout << " " << i; }
1809  iout << "\n" << endi;
1810  iout << iINFO << "TORUS E SIZE " << ne << " USING";
1811  for ( int i=0; i<ne; ++i ) { if ( e_flags[i] ) iout << " " << i; }
1812  iout << "\n" << endi;
1813 #endif
1814  // find most compact representation of our subset
1815  a_rot = b_rot = c_rot = d_rot = e_rot = 0;
1816  a_mod = na; b_mod = nb; c_mod = nc; d_mod = nd; e_mod = ne;
1817 #if CMK_BLUEGENEQ
1818  if ( tmgr.absA(na) == 0 ) // torus
1819 #else
1820  if ( tmgr.absX(na) == 0 ) // torus
1821 #endif
1822  for ( int i=0, gaplen=0, gapstart=0; i<2*na; ++i ) {
1823  if ( a_flags[i%na] ) gapstart = i+1;
1824  else if ( i - gapstart >= gaplen ) {
1825  a_rot = 2*na-i-1; gaplen = i - gapstart;
1826  }
1827  }
1828 #if CMK_BLUEGENEQ
1829  if ( tmgr.absB(nb) == 0 ) // torus
1830 #else
1831  if ( tmgr.absY(nb) == 0 ) // torus
1832 #endif
1833  for ( int i=0, gaplen=0, gapstart=0; i<2*nb; ++i ) {
1834  if ( b_flags[i%nb] ) gapstart = i+1;
1835  else if ( i - gapstart >= gaplen ) {
1836  b_rot = 2*nb-i-1; gaplen = i - gapstart;
1837  }
1838  }
1839 #if CMK_BLUEGENEQ
1840  if ( tmgr.absC(nc) == 0 ) // torus
1841 #else
1842  if ( tmgr.absZ(nc) == 0 ) // torus
1843 #endif
1844  for ( int i=0, gaplen=0, gapstart=0; i<2*nc; ++i ) {
1845  if ( c_flags[i%nc] ) gapstart = i+1;
1846  else if ( i - gapstart >= gaplen ) {
1847  c_rot = 2*nc-i-1; gaplen = i - gapstart;
1848  }
1849  }
1850 #if CMK_BLUEGENEQ
1851  if ( tmgr.absD(nd) == 0 ) // torus
1852  for ( int i=0, gaplen=0, gapstart=0; i<2*nd; ++i ) {
1853  if ( d_flags[i%nd] ) gapstart = i+1;
1854  else if ( i - gapstart >= gaplen ) {
1855  d_rot = 2*nd-i-1; gaplen = i - gapstart;
1856  }
1857  }
1858  if ( tmgr.absE(ne) == 0 ) // torus
1859  for ( int i=0, gaplen=0, gapstart=0; i<2*ne; ++i ) {
1860  if ( e_flags[i%ne] ) gapstart = i+1;
1861  else if ( i - gapstart >= gaplen ) {
1862  e_rot = 2*ne-i-1; gaplen = i - gapstart;
1863  }
1864  }
1865 #endif
1866  // order dimensions by length
1867  int a_min=na, a_max=-1;
1868  int b_min=nb, b_max=-1;
1869  int c_min=nc, c_max=-1;
1870  int d_min=nd, d_max=-1;
1871  int e_min=ne, e_max=-1;
1872  for ( int pe=0; pe<npes; ++pe ) {
1873  int a,b,c,d,e,t;
1874 #if CMK_BLUEGENEQ
1875  tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
1876 #else
1877  tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
1878  d=0; e=0;
1879 #endif
1880  a = (a+a_rot)%a_mod;
1881  b = (b+b_rot)%b_mod;
1882  c = (c+c_rot)%c_mod;
1883  d = (d+d_rot)%d_mod;
1884  e = (e+e_rot)%e_mod;
1885  if ( a < a_min ) a_min = a;
1886  if ( b < b_min ) b_min = b;
1887  if ( c < c_min ) c_min = c;
1888  if ( d < d_min ) d_min = d;
1889  if ( e < e_min ) e_min = e;
1890  if ( a > a_max ) a_max = a;
1891  if ( b > b_max ) b_max = b;
1892  if ( c > c_max ) c_max = c;
1893  if ( d > d_max ) d_max = d;
1894  if ( e > e_max ) e_max = e;
1895  }
1896  int a_len = a_max - a_min + 1;
1897  int b_len = b_max - b_min + 1;
1898  int c_len = c_max - c_min + 1;
1899  int d_len = d_max - d_min + 1;
1900  int e_len = e_max - e_min + 1;
1901  int lensort[5];
1902  lensort[0] = (a_len << 3) + 0;
1903  lensort[1] = (b_len << 3) + 1;
1904  lensort[2] = (c_len << 3) + 2;
1905  lensort[3] = (d_len << 3) + 3;
1906  lensort[4] = (e_len << 3) + 4;
1907  // 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);
1908  std::sort(lensort, lensort+5);
1909  // 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);
1910  for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 0 ) a_dim = 4-i; }
1911  for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 1 ) b_dim = 4-i; }
1912  for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 2 ) c_dim = 4-i; }
1913  for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 3 ) d_dim = 4-i; }
1914  for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 4 ) e_dim = 4-i; }
1915 #if 0
1916  if ( a_len >= b_len && a_len >= c_len ) {
1917  a_dim = 0;
1918  if ( b_len >= c_len ) {
1919  b_dim = 1; c_dim = 2;
1920  } else {
1921  b_dim = 2; c_dim = 1;
1922  }
1923  } else if ( b_len >= a_len && b_len >= c_len ) {
1924  b_dim = 0;
1925  if ( a_len >= c_len ) {
1926  a_dim = 1; c_dim = 2;
1927  } else {
1928  a_dim = 2; c_dim = 1;
1929  }
1930  } else { // c is longest
1931  c_dim = 0;
1932  if ( a_len >= b_len ) {
1933  a_dim = 1; b_dim = 2;
1934  } else {
1935  a_dim = 2; b_dim = 1;
1936  }
1937  }
1938 #endif
1939  iout << iINFO << "TORUS MINIMAL MESH SIZE IS " << a_len << " BY " << b_len << " BY " << c_len
1940 #if CMK_BLUEGENEQ
1941  << " BY " << d_len << " BY " << e_len
1942 #endif
1943  << "\n" << endi;
1944  // CkPrintf("TopoManagerWrapper dims %d %d %d %d %d\n", a_dim, b_dim, c_dim, d_dim, e_dim);
1945  }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
TopoManager tmgr
Definition: WorkDistrib.C:1746
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:195
int fixpe(int pe)
Definition: WorkDistrib.C:1750

Member Function Documentation

◆ coord()

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

Definition at line 1960 of file WorkDistrib.C.

References coords().

Referenced by sortAndSplit().

1960  {
1961  int crds[3];
1962  coords(pe,crds);
1963  return crds[dim];
1964  }
void coords(int pe, int *crds)
Definition: WorkDistrib.C:1946

◆ coords()

void TopoManagerWrapper::coords ( int  pe,
int *  crds 
)
inline

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

1946  {
1947  int a,b,c,d,e,t;
1948 #if CMK_BLUEGENEQ
1949  tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
1950 #else
1951  tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
1952  d=0; e=0;
1953 #endif
1954  if ( a_dim < 3 ) crds[a_dim] = (a+a_rot)%a_mod;
1955  if ( b_dim < 3 ) crds[b_dim] = (b+b_rot)%b_mod;
1956  if ( c_dim < 3 ) crds[c_dim] = (c+c_rot)%c_mod;
1957  if ( d_dim < 3 ) crds[d_dim] = (d+d_rot)%d_mod;
1958  if ( e_dim < 3 ) crds[e_dim] = (e+e_rot)%e_mod;
1959  }
TopoManager tmgr
Definition: WorkDistrib.C:1746
int fixpe(int pe)
Definition: WorkDistrib.C:1750

◆ fixpe()

int TopoManagerWrapper::fixpe ( int  pe)
inline

Definition at line 1750 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

1750  { // compensate for lame fallback topology information
1751  return CmiGetFirstPeOnPhysicalNode(CmiPhysicalNodeID(pe));
1752  }

◆ sortAndSplit()

int* TopoManagerWrapper::sortAndSplit ( int *  node_begin,
int *  node_end,
int  splitdim 
)
inline

Definition at line 1981 of file WorkDistrib.C.

References coord(), and coords().

Referenced by recursive_bisect_with_curve().

1981  {
1982  if ( node_begin == node_end ) return node_begin;
1983  int tmins[3], tmaxs[3], tlens[3], sortdims[3];
1984  coords(*node_begin, tmins);
1985  coords(*node_begin, tmaxs);
1986  for ( int *peitr = node_begin; peitr != node_end; ++peitr ) {
1987  int tvals[3];
1988  coords(*peitr, tvals);
1989  for ( int i=0; i<3; ++i ) {
1990  if ( tvals[i] < tmins[i] ) tmins[i] = tvals[i];
1991  if ( tvals[i] > tmaxs[i] ) tmaxs[i] = tvals[i];
1992  }
1993  }
1994  for ( int i=0; i<3; ++i ) {
1995  tlens[i] = tmaxs[i] - tmins[i];
1996  }
1997  sortdims[0] = splitdim;
1998  for ( int i=0, j=0; i<3; ++i ) {
1999  if ( i != splitdim ) sortdims[++j] = i;
2000  }
2001  if ( tlens[sortdims[1]] < tlens[sortdims[2]] ) {
2002  int tmp = sortdims[1];
2003  sortdims[1] = sortdims[2];
2004  sortdims[2] = tmp;
2005  }
2006  std::sort(node_begin,node_end,pe_sortop_topo(*this,sortdims));
2007  int *nodes = node_begin;
2008  int nnodes = node_end - node_begin;
2009  int i_split = 0;
2010 #if 0
2011  int c_split = coord(nodes[0],splitdim);
2012  for ( int i=0; i<nnodes; ++i ) {
2013  if ( coord(nodes[i],splitdim) != c_split ) {
2014  int mid = (nnodes+1)/2;
2015  if ( abs(i-mid) < abs(i_split-mid) ) {
2016  i_split = i;
2017  c_split = coord(i,splitdim);
2018  }
2019  else break;
2020  }
2021  }
2022 #endif
2023  for ( int i=0; i<nnodes; ++i ) {
2024  if ( ! CmiPeOnSamePhysicalNode(nodes[i_split],nodes[i]) ) {
2025  int mid = (nnodes+1)/2;
2026  if ( abs(i-mid) < abs(i_split-mid) ) i_split = i;
2027  else break;
2028  }
2029  }
2030  return ( node_begin + i_split );
2031  }
int coord(int pe, int dim)
Definition: WorkDistrib.C:1960
void coords(int pe, int *crds)
Definition: WorkDistrib.C:1946

Member Data Documentation

◆ a_dim

int TopoManagerWrapper::a_dim

Definition at line 1747 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ a_mod

int TopoManagerWrapper::a_mod

Definition at line 1749 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ a_rot

int TopoManagerWrapper::a_rot

Definition at line 1748 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ b_dim

int TopoManagerWrapper::b_dim

Definition at line 1747 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ b_mod

int TopoManagerWrapper::b_mod

Definition at line 1749 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ b_rot

int TopoManagerWrapper::b_rot

Definition at line 1748 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ c_dim

int TopoManagerWrapper::c_dim

Definition at line 1747 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ c_mod

int TopoManagerWrapper::c_mod

Definition at line 1749 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ c_rot

int TopoManagerWrapper::c_rot

Definition at line 1748 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ d_dim

int TopoManagerWrapper::d_dim

Definition at line 1747 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ d_mod

int TopoManagerWrapper::d_mod

Definition at line 1749 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ d_rot

int TopoManagerWrapper::d_rot

Definition at line 1748 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ e_dim

int TopoManagerWrapper::e_dim

Definition at line 1747 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ e_mod

int TopoManagerWrapper::e_mod

Definition at line 1749 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ e_rot

int TopoManagerWrapper::e_rot

Definition at line 1748 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ tmgr

TopoManager TopoManagerWrapper::tmgr

Definition at line 1746 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().


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