TopoManagerWrapper Struct Reference

List of all members.

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.

01628                        {
01629 #if CMK_BLUEGENEQ
01630     int na=tmgr.getDimNA();
01631     int nb=tmgr.getDimNB();
01632     int nc=tmgr.getDimNC();
01633     int nd=tmgr.getDimND();
01634     int ne=tmgr.getDimNE();
01635 #else
01636     int na=tmgr.getDimNX();
01637     int nb=tmgr.getDimNY();
01638     int nc=tmgr.getDimNZ();
01639     int nd=1;
01640     int ne=1;
01641 #endif
01642     ResizeArray<int> a_flags(na);
01643     ResizeArray<int> b_flags(nb);
01644     ResizeArray<int> c_flags(nc);
01645     ResizeArray<int> d_flags(nd);
01646     ResizeArray<int> e_flags(ne);
01647     for ( int i=0; i<na; ++i ) { a_flags[i] = 0; }
01648     for ( int i=0; i<nb; ++i ) { b_flags[i] = 0; }
01649     for ( int i=0; i<nc; ++i ) { c_flags[i] = 0; }
01650     for ( int i=0; i<nd; ++i ) { d_flags[i] = 0; }
01651     for ( int i=0; i<ne; ++i ) { e_flags[i] = 0; }
01652     int npes = CkNumPes();
01653     for ( int pe=0; pe<npes; ++pe ) {
01654       int a,b,c,d,e,t;
01655 #if CMK_BLUEGENEQ
01656       tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
01657 #else
01658       tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
01659       d=0; e=0;
01660 #endif
01661       if ( a < 0 || a >= na ) NAMD_bug("inconsistent torus topology!");
01662       if ( b < 0 || b >= nb ) NAMD_bug("inconsistent torus topology!");
01663       if ( c < 0 || c >= nc ) NAMD_bug("inconsistent torus topology!");
01664       if ( d < 0 || d >= nd ) NAMD_bug("inconsistent torus topology!");
01665       if ( e < 0 || e >= ne ) NAMD_bug("inconsistent torus topology!");
01666       a_flags[a] = 1;
01667       b_flags[b] = 1;
01668       c_flags[c] = 1;
01669       d_flags[d] = 1;
01670       e_flags[e] = 1;
01671     }
01672     iout << iINFO << "TORUS A SIZE " << na << " USING";
01673     for ( int i=0; i<na; ++i ) { if ( a_flags[i] ) iout << " " << i; }
01674     iout << "\n" << endi;
01675     iout << iINFO << "TORUS B SIZE " << nb << " USING";
01676     for ( int i=0; i<nb; ++i ) { if ( b_flags[i] ) iout << " " << i; }
01677     iout << "\n" << endi;
01678     iout << iINFO << "TORUS C SIZE " << nc << " USING";
01679     for ( int i=0; i<nc; ++i ) { if ( c_flags[i] ) iout << " " << i; }
01680     iout << "\n" << endi;
01681 #if CMK_BLUEGENEQ
01682     iout << iINFO << "TORUS D SIZE " << nd << " USING";
01683     for ( int i=0; i<nd; ++i ) { if ( d_flags[i] ) iout << " " << i; }
01684     iout << "\n" << endi;
01685     iout << iINFO << "TORUS E SIZE " << ne << " USING";
01686     for ( int i=0; i<ne; ++i ) { if ( e_flags[i] ) iout << " " << i; }
01687     iout << "\n" << endi;
01688 #endif
01689     // find most compact representation of our subset
01690     a_rot = b_rot = c_rot = d_rot = e_rot = 0;
01691     a_mod = na; b_mod = nb; c_mod = nc; d_mod = nd; e_mod = ne;
01692 #if CMK_BLUEGENEQ
01693     if ( tmgr.absA(na) == 0 ) // torus
01694 #else
01695     if ( tmgr.absX(na) == 0 ) // torus
01696 #endif
01697       for ( int i=0, gaplen=0, gapstart=0; i<2*na; ++i ) {
01698         if ( a_flags[i%na] ) gapstart = i+1;
01699         else if ( i - gapstart >= gaplen ) {
01700           a_rot = 2*na-i-1; gaplen = i - gapstart;
01701         }
01702       }
01703 #if CMK_BLUEGENEQ
01704     if ( tmgr.absB(nb) == 0 ) // torus
01705 #else
01706     if ( tmgr.absY(nb) == 0 ) // torus
01707 #endif
01708       for ( int i=0, gaplen=0, gapstart=0; i<2*nb; ++i ) {
01709         if ( b_flags[i%nb] ) gapstart = i+1;
01710         else if ( i - gapstart >= gaplen ) {
01711           b_rot = 2*nb-i-1; gaplen = i - gapstart;
01712         }
01713       }
01714 #if CMK_BLUEGENEQ
01715     if ( tmgr.absC(nc) == 0 ) // torus
01716 #else
01717     if ( tmgr.absZ(nc) == 0 ) // torus
01718 #endif
01719       for ( int i=0, gaplen=0, gapstart=0; i<2*nc; ++i ) {
01720         if ( c_flags[i%nc] ) gapstart = i+1;
01721         else if ( i - gapstart >= gaplen ) {
01722           c_rot = 2*nc-i-1; gaplen = i - gapstart;
01723         }
01724       }
01725 #if CMK_BLUEGENEQ
01726     if ( tmgr.absD(nd) == 0 ) // torus
01727       for ( int i=0, gaplen=0, gapstart=0; i<2*nd; ++i ) {
01728         if ( d_flags[i%nd] ) gapstart = i+1;
01729         else if ( i - gapstart >= gaplen ) {
01730           d_rot = 2*nd-i-1; gaplen = i - gapstart;
01731         }
01732       }
01733     if ( tmgr.absE(ne) == 0 ) // torus
01734       for ( int i=0, gaplen=0, gapstart=0; i<2*ne; ++i ) {
01735         if ( e_flags[i%ne] ) gapstart = i+1;
01736         else if ( i - gapstart >= gaplen ) {
01737           e_rot = 2*ne-i-1; gaplen = i - gapstart;
01738         }
01739       }
01740 #endif
01741     // order dimensions by length
01742     int a_min=na, a_max=-1;
01743     int b_min=nb, b_max=-1;
01744     int c_min=nc, c_max=-1;
01745     int d_min=nd, d_max=-1;
01746     int e_min=ne, e_max=-1;
01747     for ( int pe=0; pe<npes; ++pe ) {
01748       int a,b,c,d,e,t;
01749 #if CMK_BLUEGENEQ
01750       tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
01751 #else
01752       tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
01753       d=0; e=0;
01754 #endif
01755       a = (a+a_rot)%a_mod;
01756       b = (b+b_rot)%b_mod;
01757       c = (c+c_rot)%c_mod;
01758       d = (d+d_rot)%d_mod;
01759       e = (e+e_rot)%e_mod;
01760       if ( a < a_min ) a_min = a;
01761       if ( b < b_min ) b_min = b;
01762       if ( c < c_min ) c_min = c;
01763       if ( d < d_min ) d_min = d;
01764       if ( e < e_min ) e_min = e;
01765       if ( a > a_max ) a_max = a;
01766       if ( b > b_max ) b_max = b;
01767       if ( c > c_max ) c_max = c;
01768       if ( d > d_max ) d_max = d;
01769       if ( e > e_max ) e_max = e;
01770     }
01771     int a_len = a_max - a_min + 1;
01772     int b_len = b_max - b_min + 1;
01773     int c_len = c_max - c_min + 1;
01774     int d_len = d_max - d_min + 1;
01775     int e_len = e_max - e_min + 1;
01776     int lensort[5];
01777     lensort[0] = (a_len << 3) + 0;
01778     lensort[1] = (b_len << 3) + 1;
01779     lensort[2] = (c_len << 3) + 2;
01780     lensort[3] = (d_len << 3) + 3;
01781     lensort[4] = (e_len << 3) + 4;
01782     // 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);
01783     std::sort(lensort, lensort+5);
01784     // 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);
01785     for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 0 ) a_dim = 4-i; }
01786     for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 1 ) b_dim = 4-i; }
01787     for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 2 ) c_dim = 4-i; }
01788     for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 3 ) d_dim = 4-i; }
01789     for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 4 ) e_dim = 4-i; }
01790 #if 0
01791     if ( a_len >= b_len && a_len >= c_len ) {
01792       a_dim = 0;
01793       if ( b_len >= c_len ) {
01794         b_dim = 1; c_dim = 2;
01795       } else {
01796         b_dim = 2; c_dim = 1;
01797       }
01798     } else if ( b_len >= a_len && b_len >= c_len ) {
01799       b_dim = 0;
01800       if ( a_len >= c_len ) {
01801         a_dim = 1; c_dim = 2;
01802       } else {
01803         a_dim = 2; c_dim = 1;
01804       }
01805     } else { // c is longest
01806       c_dim = 0;
01807       if ( a_len >= b_len ) {
01808         a_dim = 1; b_dim = 2;
01809       } else {
01810         a_dim = 2; b_dim = 1;
01811       }
01812     }
01813 #endif
01814     iout << iINFO << "TORUS MINIMAL MESH SIZE IS " << a_len << " BY " << b_len << " BY " << c_len
01815 #if CMK_BLUEGENEQ
01816     << " BY " << d_len << " BY " << e_len
01817 #endif
01818     << "\n" << endi;
01819     // CkPrintf("TopoManagerWrapper dims %d %d %d %d %d\n", a_dim, b_dim, c_dim, d_dim, e_dim);
01820   }


Member Function Documentation

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

Definition at line 1835 of file WorkDistrib.C.

References coords().

Referenced by sortAndSplit().

01835                              {
01836     int crds[3];
01837     coords(pe,crds);
01838     return crds[dim];
01839   }

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().

01821                                  {
01822     int a,b,c,d,e,t;
01823 #if CMK_BLUEGENEQ
01824     tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
01825 #else
01826     tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
01827     d=0; e=0;
01828 #endif
01829     if ( a_dim < 3 ) crds[a_dim] = (a+a_rot)%a_mod;
01830     if ( b_dim < 3 ) crds[b_dim] = (b+b_rot)%b_mod;
01831     if ( c_dim < 3 ) crds[c_dim] = (c+c_rot)%c_mod;
01832     if ( d_dim < 3 ) crds[d_dim] = (d+d_rot)%d_mod;
01833     if ( e_dim < 3 ) crds[e_dim] = (e+e_rot)%e_mod;
01834   }

int TopoManagerWrapper::fixpe ( int  pe  )  [inline]

Definition at line 1625 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

01625                     {  // compensate for lame fallback topology information
01626     return CmiGetFirstPeOnPhysicalNode(CmiPhysicalNodeID(pe));
01627   }

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().

01856                                                                   {
01857     if ( node_begin == node_end ) return node_begin;
01858     int tmins[3], tmaxs[3], tlens[3], sortdims[3];
01859     coords(*node_begin, tmins);
01860     coords(*node_begin, tmaxs);
01861     for ( int *peitr = node_begin; peitr != node_end; ++peitr ) {
01862       int tvals[3];
01863       coords(*peitr, tvals);
01864       for ( int i=0; i<3; ++i ) {
01865         if ( tvals[i] < tmins[i] ) tmins[i] = tvals[i];
01866         if ( tvals[i] > tmaxs[i] ) tmaxs[i] = tvals[i];
01867       }
01868     }
01869     for ( int i=0; i<3; ++i ) {
01870       tlens[i] = tmaxs[i] - tmins[i];
01871     }
01872     sortdims[0] = splitdim;
01873     for ( int i=0, j=0; i<3; ++i ) {
01874       if ( i != splitdim ) sortdims[++j] = i;
01875     }
01876     if ( tlens[sortdims[1]] < tlens[sortdims[2]] ) {
01877       int tmp = sortdims[1];
01878       sortdims[1] = sortdims[2];
01879       sortdims[2] = tmp;
01880     }
01881     std::sort(node_begin,node_end,pe_sortop_topo(*this,sortdims));
01882     int *nodes = node_begin;
01883     int nnodes = node_end - node_begin;
01884     int i_split = 0;
01885 #if 0
01886     int c_split = coord(nodes[0],splitdim);
01887     for ( int i=0; i<nnodes; ++i ) {
01888       if ( coord(nodes[i],splitdim) != c_split ) {
01889         int mid = (nnodes+1)/2;
01890         if ( abs(i-mid) < abs(i_split-mid) ) {
01891           i_split = i;
01892           c_split = coord(i,splitdim);
01893         }
01894         else break;
01895       }
01896     }
01897 #endif
01898     for ( int i=0; i<nnodes; ++i ) {
01899       if ( ! CmiPeOnSamePhysicalNode(nodes[i_split],nodes[i]) ) {
01900         int mid = (nnodes+1)/2;
01901         if ( abs(i-mid) < abs(i_split-mid) ) i_split = i;
01902         else break;
01903       }
01904     }
01905     return ( node_begin + i_split );
01906   }


Member Data Documentation

Definition at line 1622 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1624 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1623 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1622 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1624 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1623 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1622 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1624 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1623 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1622 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1624 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1623 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1622 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1624 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1623 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

Definition at line 1621 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().


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

Generated on 8 Dec 2019 for NAMD by  doxygen 1.6.1