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


Constructor & Destructor Documentation

TopoManagerWrapper::TopoManagerWrapper (  )  [inline]

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

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


Member Function Documentation

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

Definition at line 1878 of file WorkDistrib.C.

References coords().

Referenced by sortAndSplit().

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

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

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

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

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

Definition at line 1668 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

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

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

Definition at line 1899 of file WorkDistrib.C.

References coord(), and coords().

Referenced by recursive_bisect_with_curve().

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


Member Data Documentation

int TopoManagerWrapper::a_dim

Definition at line 1665 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::a_mod

Definition at line 1667 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::a_rot

Definition at line 1666 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_dim

Definition at line 1665 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_mod

Definition at line 1667 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::b_rot

Definition at line 1666 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_dim

Definition at line 1665 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_mod

Definition at line 1667 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::c_rot

Definition at line 1666 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_dim

Definition at line 1665 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_mod

Definition at line 1667 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::d_rot

Definition at line 1666 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_dim

Definition at line 1665 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_mod

Definition at line 1667 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

int TopoManagerWrapper::e_rot

Definition at line 1666 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().

TopoManager TopoManagerWrapper::tmgr

Definition at line 1664 of file WorkDistrib.C.

Referenced by coords(), and TopoManagerWrapper().


The documentation for this struct was generated from the following file:
Generated on Mon Sep 25 01:17:20 2017 for NAMD by  doxygen 1.4.7