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

Constructor & Destructor Documentation

◆ TopoManagerWrapper()

TopoManagerWrapper::TopoManagerWrapper ( )
inline

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

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

Member Function Documentation

◆ coord()

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

Definition at line 1972 of file WorkDistrib.C.

References coords().

Referenced by sortAndSplit().

1972  {
1973  int crds[3];
1974  coords(pe,crds);
1975  return crds[dim];
1976  }
void coords(int pe, int *crds)
Definition: WorkDistrib.C:1958

◆ coords()

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

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

1958  {
1959  int a,b,c,d,e,t;
1960 #if CMK_BLUEGENEQ
1961  tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
1962 #else
1963  tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
1964  d=0; e=0;
1965 #endif
1966  if ( a_dim < 3 ) crds[a_dim] = (a+a_rot)%a_mod;
1967  if ( b_dim < 3 ) crds[b_dim] = (b+b_rot)%b_mod;
1968  if ( c_dim < 3 ) crds[c_dim] = (c+c_rot)%c_mod;
1969  if ( d_dim < 3 ) crds[d_dim] = (d+d_rot)%d_mod;
1970  if ( e_dim < 3 ) crds[e_dim] = (e+e_rot)%e_mod;
1971  }
TopoManager tmgr
Definition: WorkDistrib.C:1758
int fixpe(int pe)
Definition: WorkDistrib.C:1762

◆ fixpe()

int TopoManagerWrapper::fixpe ( int  pe)
inline

Definition at line 1762 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

1762  { // compensate for lame fallback topology information
1763  return CmiGetFirstPeOnPhysicalNode(CmiPhysicalNodeID(pe));
1764  }

◆ sortAndSplit()

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

Definition at line 1993 of file WorkDistrib.C.

References coord(), and coords().

Referenced by recursive_bisect_with_curve().

1993  {
1994  if ( node_begin == node_end ) return node_begin;
1995  int tmins[3], tmaxs[3], tlens[3], sortdims[3];
1996  coords(*node_begin, tmins);
1997  coords(*node_begin, tmaxs);
1998  for ( int *peitr = node_begin; peitr != node_end; ++peitr ) {
1999  int tvals[3];
2000  coords(*peitr, tvals);
2001  for ( int i=0; i<3; ++i ) {
2002  if ( tvals[i] < tmins[i] ) tmins[i] = tvals[i];
2003  if ( tvals[i] > tmaxs[i] ) tmaxs[i] = tvals[i];
2004  }
2005  }
2006  for ( int i=0; i<3; ++i ) {
2007  tlens[i] = tmaxs[i] - tmins[i];
2008  }
2009  sortdims[0] = splitdim;
2010  for ( int i=0, j=0; i<3; ++i ) {
2011  if ( i != splitdim ) sortdims[++j] = i;
2012  }
2013  if ( tlens[sortdims[1]] < tlens[sortdims[2]] ) {
2014  int tmp = sortdims[1];
2015  sortdims[1] = sortdims[2];
2016  sortdims[2] = tmp;
2017  }
2018  std::sort(node_begin,node_end,pe_sortop_topo(*this,sortdims));
2019  int *nodes = node_begin;
2020  int nnodes = node_end - node_begin;
2021  int i_split = 0;
2022 #if 0
2023  int c_split = coord(nodes[0],splitdim);
2024  for ( int i=0; i<nnodes; ++i ) {
2025  if ( coord(nodes[i],splitdim) != c_split ) {
2026  int mid = (nnodes+1)/2;
2027  if ( abs(i-mid) < abs(i_split-mid) ) {
2028  i_split = i;
2029  c_split = coord(i,splitdim);
2030  }
2031  else break;
2032  }
2033  }
2034 #endif
2035  for ( int i=0; i<nnodes; ++i ) {
2036  if ( ! CmiPeOnSamePhysicalNode(nodes[i_split],nodes[i]) ) {
2037  int mid = (nnodes+1)/2;
2038  if ( abs(i-mid) < abs(i_split-mid) ) i_split = i;
2039  else break;
2040  }
2041  }
2042  return ( node_begin + i_split );
2043  }
int coord(int pe, int dim)
Definition: WorkDistrib.C:1972
void coords(int pe, int *crds)
Definition: WorkDistrib.C:1958

Member Data Documentation

◆ a_dim

int TopoManagerWrapper::a_dim

Definition at line 1759 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ a_mod

int TopoManagerWrapper::a_mod

Definition at line 1761 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ a_rot

int TopoManagerWrapper::a_rot

Definition at line 1760 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ b_dim

int TopoManagerWrapper::b_dim

Definition at line 1759 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ b_mod

int TopoManagerWrapper::b_mod

Definition at line 1761 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ b_rot

int TopoManagerWrapper::b_rot

Definition at line 1760 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ c_dim

int TopoManagerWrapper::c_dim

Definition at line 1759 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ c_mod

int TopoManagerWrapper::c_mod

Definition at line 1761 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ c_rot

int TopoManagerWrapper::c_rot

Definition at line 1760 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ d_dim

int TopoManagerWrapper::d_dim

Definition at line 1759 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ d_mod

int TopoManagerWrapper::d_mod

Definition at line 1761 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ d_rot

int TopoManagerWrapper::d_rot

Definition at line 1760 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ e_dim

int TopoManagerWrapper::e_dim

Definition at line 1759 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ e_mod

int TopoManagerWrapper::e_mod

Definition at line 1761 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ e_rot

int TopoManagerWrapper::e_rot

Definition at line 1760 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

◆ tmgr

TopoManager TopoManagerWrapper::tmgr

Definition at line 1758 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().


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