TopoManagerWrapper Struct Reference

List of all members.

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

Classes

struct  pe_sortop_topo

Detailed Description

Definition at line 1665 of file WorkDistrib.C.


Constructor & Destructor Documentation

TopoManagerWrapper::TopoManagerWrapper (  )  [inline]

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

01673                        {
01674 #if CMK_BLUEGENEQ
01675     int na=tmgr.getDimNA();
01676     int nb=tmgr.getDimNB();
01677     int nc=tmgr.getDimNC();
01678     int nd=tmgr.getDimND();
01679     int ne=tmgr.getDimNE();
01680 #else
01681     int na=tmgr.getDimNX();
01682     int nb=tmgr.getDimNY();
01683     int nc=tmgr.getDimNZ();
01684     int nd=1;
01685     int ne=1;
01686 #endif
01687     ResizeArray<int> a_flags(na);
01688     ResizeArray<int> b_flags(nb);
01689     ResizeArray<int> c_flags(nc);
01690     ResizeArray<int> d_flags(nd);
01691     ResizeArray<int> e_flags(ne);
01692     for ( int i=0; i<na; ++i ) { a_flags[i] = 0; }
01693     for ( int i=0; i<nb; ++i ) { b_flags[i] = 0; }
01694     for ( int i=0; i<nc; ++i ) { c_flags[i] = 0; }
01695     for ( int i=0; i<nd; ++i ) { d_flags[i] = 0; }
01696     for ( int i=0; i<ne; ++i ) { e_flags[i] = 0; }
01697     int npes = CkNumPes();
01698     for ( int pe=0; pe<npes; ++pe ) {
01699       int a,b,c,d,e,t;
01700 #if CMK_BLUEGENEQ
01701       tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
01702 #else
01703       tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
01704       d=0; e=0;
01705 #endif
01706       if ( a < 0 || a >= na ) NAMD_bug("inconsistent torus topology!");
01707       if ( b < 0 || b >= nb ) NAMD_bug("inconsistent torus topology!");
01708       if ( c < 0 || c >= nc ) NAMD_bug("inconsistent torus topology!");
01709       if ( d < 0 || d >= nd ) NAMD_bug("inconsistent torus topology!");
01710       if ( e < 0 || e >= ne ) NAMD_bug("inconsistent torus topology!");
01711       a_flags[a] = 1;
01712       b_flags[b] = 1;
01713       c_flags[c] = 1;
01714       d_flags[d] = 1;
01715       e_flags[e] = 1;
01716     }
01717     iout << iINFO << "TORUS A SIZE " << na << " USING";
01718     for ( int i=0; i<na; ++i ) { if ( a_flags[i] ) iout << " " << i; }
01719     iout << "\n" << endi;
01720     iout << iINFO << "TORUS B SIZE " << nb << " USING";
01721     for ( int i=0; i<nb; ++i ) { if ( b_flags[i] ) iout << " " << i; }
01722     iout << "\n" << endi;
01723     iout << iINFO << "TORUS C SIZE " << nc << " USING";
01724     for ( int i=0; i<nc; ++i ) { if ( c_flags[i] ) iout << " " << i; }
01725     iout << "\n" << endi;
01726 #if CMK_BLUEGENEQ
01727     iout << iINFO << "TORUS D SIZE " << nd << " USING";
01728     for ( int i=0; i<nd; ++i ) { if ( d_flags[i] ) iout << " " << i; }
01729     iout << "\n" << endi;
01730     iout << iINFO << "TORUS E SIZE " << ne << " USING";
01731     for ( int i=0; i<ne; ++i ) { if ( e_flags[i] ) iout << " " << i; }
01732     iout << "\n" << endi;
01733 #endif
01734     // find most compact representation of our subset
01735     a_rot = b_rot = c_rot = d_rot = e_rot = 0;
01736     a_mod = na; b_mod = nb; c_mod = nc; d_mod = nd; e_mod = ne;
01737 #if CMK_BLUEGENEQ
01738     if ( tmgr.absA(na) == 0 ) // torus
01739 #else
01740     if ( tmgr.absX(na) == 0 ) // torus
01741 #endif
01742       for ( int i=0, gaplen=0, gapstart=0; i<2*na; ++i ) {
01743         if ( a_flags[i%na] ) gapstart = i+1;
01744         else if ( i - gapstart >= gaplen ) {
01745           a_rot = 2*na-i-1; gaplen = i - gapstart;
01746         }
01747       }
01748 #if CMK_BLUEGENEQ
01749     if ( tmgr.absB(nb) == 0 ) // torus
01750 #else
01751     if ( tmgr.absY(nb) == 0 ) // torus
01752 #endif
01753       for ( int i=0, gaplen=0, gapstart=0; i<2*nb; ++i ) {
01754         if ( b_flags[i%nb] ) gapstart = i+1;
01755         else if ( i - gapstart >= gaplen ) {
01756           b_rot = 2*nb-i-1; gaplen = i - gapstart;
01757         }
01758       }
01759 #if CMK_BLUEGENEQ
01760     if ( tmgr.absC(nc) == 0 ) // torus
01761 #else
01762     if ( tmgr.absZ(nc) == 0 ) // torus
01763 #endif
01764       for ( int i=0, gaplen=0, gapstart=0; i<2*nc; ++i ) {
01765         if ( c_flags[i%nc] ) gapstart = i+1;
01766         else if ( i - gapstart >= gaplen ) {
01767           c_rot = 2*nc-i-1; gaplen = i - gapstart;
01768         }
01769       }
01770 #if CMK_BLUEGENEQ
01771     if ( tmgr.absD(nd) == 0 ) // torus
01772       for ( int i=0, gaplen=0, gapstart=0; i<2*nd; ++i ) {
01773         if ( d_flags[i%nd] ) gapstart = i+1;
01774         else if ( i - gapstart >= gaplen ) {
01775           d_rot = 2*nd-i-1; gaplen = i - gapstart;
01776         }
01777       }
01778     if ( tmgr.absE(ne) == 0 ) // torus
01779       for ( int i=0, gaplen=0, gapstart=0; i<2*ne; ++i ) {
01780         if ( e_flags[i%ne] ) gapstart = i+1;
01781         else if ( i - gapstart >= gaplen ) {
01782           e_rot = 2*ne-i-1; gaplen = i - gapstart;
01783         }
01784       }
01785 #endif
01786     // order dimensions by length
01787     int a_min=na, a_max=-1;
01788     int b_min=nb, b_max=-1;
01789     int c_min=nc, c_max=-1;
01790     int d_min=nd, d_max=-1;
01791     int e_min=ne, e_max=-1;
01792     for ( int pe=0; pe<npes; ++pe ) {
01793       int a,b,c,d,e,t;
01794 #if CMK_BLUEGENEQ
01795       tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
01796 #else
01797       tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
01798       d=0; e=0;
01799 #endif
01800       a = (a+a_rot)%a_mod;
01801       b = (b+b_rot)%b_mod;
01802       c = (c+c_rot)%c_mod;
01803       d = (d+d_rot)%d_mod;
01804       e = (e+e_rot)%e_mod;
01805       if ( a < a_min ) a_min = a;
01806       if ( b < b_min ) b_min = b;
01807       if ( c < c_min ) c_min = c;
01808       if ( d < d_min ) d_min = d;
01809       if ( e < e_min ) e_min = e;
01810       if ( a > a_max ) a_max = a;
01811       if ( b > b_max ) b_max = b;
01812       if ( c > c_max ) c_max = c;
01813       if ( d > d_max ) d_max = d;
01814       if ( e > e_max ) e_max = e;
01815     }
01816     int a_len = a_max - a_min + 1;
01817     int b_len = b_max - b_min + 1;
01818     int c_len = c_max - c_min + 1;
01819     int d_len = d_max - d_min + 1;
01820     int e_len = e_max - e_min + 1;
01821     int lensort[5];
01822     lensort[0] = (a_len << 3) + 0;
01823     lensort[1] = (b_len << 3) + 1;
01824     lensort[2] = (c_len << 3) + 2;
01825     lensort[3] = (d_len << 3) + 3;
01826     lensort[4] = (e_len << 3) + 4;
01827     // 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);
01828     std::sort(lensort, lensort+5);
01829     // 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);
01830     for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 0 ) a_dim = 4-i; }
01831     for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 1 ) b_dim = 4-i; }
01832     for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 2 ) c_dim = 4-i; }
01833     for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 3 ) d_dim = 4-i; }
01834     for ( int i=0; i<5; ++i ) { if ( (lensort[i] & 7) == 4 ) e_dim = 4-i; }
01835 #if 0
01836     if ( a_len >= b_len && a_len >= c_len ) {
01837       a_dim = 0;
01838       if ( b_len >= c_len ) {
01839         b_dim = 1; c_dim = 2;
01840       } else {
01841         b_dim = 2; c_dim = 1;
01842       }
01843     } else if ( b_len >= a_len && b_len >= c_len ) {
01844       b_dim = 0;
01845       if ( a_len >= c_len ) {
01846         a_dim = 1; c_dim = 2;
01847       } else {
01848         a_dim = 2; c_dim = 1;
01849       }
01850     } else { // c is longest
01851       c_dim = 0;
01852       if ( a_len >= b_len ) {
01853         a_dim = 1; b_dim = 2;
01854       } else {
01855         a_dim = 2; b_dim = 1;
01856       }
01857     }
01858 #endif
01859     iout << iINFO << "TORUS MINIMAL MESH SIZE IS " << a_len << " BY " << b_len << " BY " << c_len
01860 #if CMK_BLUEGENEQ
01861     << " BY " << d_len << " BY " << e_len
01862 #endif
01863     << "\n" << endi;
01864     // CkPrintf("TopoManagerWrapper dims %d %d %d %d %d\n", a_dim, b_dim, c_dim, d_dim, e_dim);
01865   }


Member Function Documentation

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

Definition at line 1880 of file WorkDistrib.C.

References coords().

Referenced by sortAndSplit().

01880                              {
01881     int crds[3];
01882     coords(pe,crds);
01883     return crds[dim];
01884   }

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

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

01866                                  {
01867     int a,b,c,d,e,t;
01868 #if CMK_BLUEGENEQ
01869     tmgr.rankToCoordinates(fixpe(pe),a,b,c,d,e,t);
01870 #else
01871     tmgr.rankToCoordinates(fixpe(pe),a,b,c,t);
01872     d=0; e=0;
01873 #endif
01874     if ( a_dim < 3 ) crds[a_dim] = (a+a_rot)%a_mod;
01875     if ( b_dim < 3 ) crds[b_dim] = (b+b_rot)%b_mod;
01876     if ( c_dim < 3 ) crds[c_dim] = (c+c_rot)%c_mod;
01877     if ( d_dim < 3 ) crds[d_dim] = (d+d_rot)%d_mod;
01878     if ( e_dim < 3 ) crds[e_dim] = (e+e_rot)%e_mod;
01879   }

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

Definition at line 1670 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

01670                     {  // compensate for lame fallback topology information
01671     return CmiGetFirstPeOnPhysicalNode(CmiPhysicalNodeID(pe));
01672   }

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

Definition at line 1901 of file WorkDistrib.C.

References coord(), and coords().

Referenced by recursive_bisect_with_curve().

01901                                                                   {
01902     if ( node_begin == node_end ) return node_begin;
01903     int tmins[3], tmaxs[3], tlens[3], sortdims[3];
01904     coords(*node_begin, tmins);
01905     coords(*node_begin, tmaxs);
01906     for ( int *peitr = node_begin; peitr != node_end; ++peitr ) {
01907       int tvals[3];
01908       coords(*peitr, tvals);
01909       for ( int i=0; i<3; ++i ) {
01910         if ( tvals[i] < tmins[i] ) tmins[i] = tvals[i];
01911         if ( tvals[i] > tmaxs[i] ) tmaxs[i] = tvals[i];
01912       }
01913     }
01914     for ( int i=0; i<3; ++i ) {
01915       tlens[i] = tmaxs[i] - tmins[i];
01916     }
01917     sortdims[0] = splitdim;
01918     for ( int i=0, j=0; i<3; ++i ) {
01919       if ( i != splitdim ) sortdims[++j] = i;
01920     }
01921     if ( tlens[sortdims[1]] < tlens[sortdims[2]] ) {
01922       int tmp = sortdims[1];
01923       sortdims[1] = sortdims[2];
01924       sortdims[2] = tmp;
01925     }
01926     std::sort(node_begin,node_end,pe_sortop_topo(*this,sortdims));
01927     int *nodes = node_begin;
01928     int nnodes = node_end - node_begin;
01929     int i_split = 0;
01930 #if 0
01931     int c_split = coord(nodes[0],splitdim);
01932     for ( int i=0; i<nnodes; ++i ) {
01933       if ( coord(nodes[i],splitdim) != c_split ) {
01934         int mid = (nnodes+1)/2;
01935         if ( abs(i-mid) < abs(i_split-mid) ) {
01936           i_split = i;
01937           c_split = coord(i,splitdim);
01938         }
01939         else break;
01940       }
01941     }
01942 #endif
01943     for ( int i=0; i<nnodes; ++i ) {
01944       if ( ! CmiPeOnSamePhysicalNode(nodes[i_split],nodes[i]) ) {
01945         int mid = (nnodes+1)/2;
01946         if ( abs(i-mid) < abs(i_split-mid) ) i_split = i;
01947         else break;
01948       }
01949     }
01950     return ( node_begin + i_split );
01951   }


Member Data Documentation

int TopoManagerWrapper::a_dim

Definition at line 1667 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::a_mod

Definition at line 1669 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::a_rot

Definition at line 1668 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_dim

Definition at line 1667 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_mod

Definition at line 1669 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_rot

Definition at line 1668 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_dim

Definition at line 1667 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_mod

Definition at line 1669 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_rot

Definition at line 1668 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_dim

Definition at line 1667 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_mod

Definition at line 1669 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_rot

Definition at line 1668 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_dim

Definition at line 1667 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_mod

Definition at line 1669 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_rot

Definition at line 1668 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

TopoManager TopoManagerWrapper::tmgr

Definition at line 1666 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().


The documentation for this struct was generated from the following file:
Generated on Thu Nov 23 01:17:20 2017 for NAMD by  doxygen 1.4.7