tp_network.cpp 5.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
#include "tp_network.hpp"

#define MAX_IONODES 1

/**********************/
/*  |-- Nodes         */
/**********************/
int Topology::IONodeId () {
  return MPIX_IO_node_id ();
}


int Topology::BridgeNodeId () {
  return MPIX_IO_link_id ();
}


int Topology::ComputeNodeId () {
  return 0;
}


int Topology::ProcessPerNode () {
  MPIX_Hardware_t hw;
  MPIX_Hardware(&hw);
  
  return hw.ppn;
}


int Topology::IONodesPerFile ( char* filename, int *nodesList ) {
  return 1;
}


/**********************/
/*  |-- Network       */
/**********************/
int Topology::NetworkDimensions () {
  MPIX_Hardware_t hw;
  MPIX_Hardware(&hw);
  
  return hw.torus_dimension;
}


/*  |---- Coordinates */
void Topology::RankToCoordinates ( int rank, int* coord ) {
  MPIX_Rank2torus( rank, coord );
}


void Topology::IONodeCoordinates ( int* coord ) {
  Personality_t personality;
  Kernel_GetPersonality(&personality, sizeof(personality));
  
  coord[0] = personality.Network_Config.cnBridge_A;
  coord[1] = personality.Network_Config.cnBridge_B;
  coord[2] = personality.Network_Config.cnBridge_C;
  coord[3] = personality.Network_Config.cnBridge_D;
  coord[4] = personality.Network_Config.cnBridge_E;
}


/*  |---- Distance    */
int Topology::DistanceToIONode ( int srcRank ) {
  return MPIX_IO_distance ();
}

 
int Topology::DistanceBetweenRanks ( int srcRank, int destRank ) {
  int srcCoords[6], destCoords[6];
  int dim, d, hops, distance;
  MPIX_Hardware_t hw;
  
  RankToCoordinates ( srcRank, srcCoords );
  RankToCoordinates ( destRank, destCoords );
  
  dim = NetworkDimensions ();
  distance = 0;
  MPIX_Hardware( &hw );
  
  for ( d = 0; d < dim; d++ ) {
    hops = abs ( destCoords[d] - srcCoords[d] );
    if ( hw.isTorus[d] == 1 )
      hops = std::min ( hops, (int)hw.Size[d] - hops );
    distance += hops;
  }
  
  return distance;
}


/*  |---- Routes      */
int Topology::RouteToIONode ( int srcRank, int* path ) {
  int srcCoords[6], IOCoords[6];
  
  RankToCoordinates ( srcRank, srcCoords );
  IONodeCoordinates ( IOCoords );
  
  return RouteBetweenCoords ( srcCoords, IOCoords, path );
}


int Topology::RouteBetweenRanks ( int srcRank, int destRank, int* path ) {
  int srcCoords[6], destCoords[6];
  RankToCoordinates (srcRank, srcCoords);
  RankToCoordinates (destRank, destCoords);
  
  return RouteBetweenCoords ( srcCoords, destCoords, path );
}


void Topology::LinksList ( int* list ) {
  return;
}


int Topology::getRoutingOrder ( int *ro ) {
  uint64_t dcr_det_order = DCRReadUser(ND_500_DCR(CTRL_DET_ORDER));
  
  int A = ND_500_DCR__CTRL_DET_ORDER__MASK0_get(dcr_det_order);
  int B = ND_500_DCR__CTRL_DET_ORDER__MASK1_get(dcr_det_order);
  int C = ND_500_DCR__CTRL_DET_ORDER__MASK2_get(dcr_det_order);
  int D = ND_500_DCR__CTRL_DET_ORDER__MASK3_get(dcr_det_order);
  int E = ND_500_DCR__CTRL_DET_ORDER__MASK4_get(dcr_det_order);
  
  int torus[5] = {A, B, C, D, E};
  
  int index = 0;
  for (int i=0; i<5 ; i++) {
    if (torus[i] == 1)            index = 4;
    else if (torus[i] == 2)       index = 3;
    else if (torus[i] == 4)       index = 2;
    else if (torus[i] == 8)       index = 1;
    else if (torus[i] == 16)      index = 0;
    ro[i] = index;
  }
  
  return 0;
}


int Topology::RouteBetweenCoords ( int *srcCoords, int *destCoords, int *path ) {
  int i, interNode = 0;
  int unitHop = 1;
  int childCoords[6], intmdtCoords[6];
  char buf[64];
  MPIX_Hardware_t hw;
  int dimSize[MPIX_TORUS_MAX_DIMS];
  int isTorus[MPIX_TORUS_MAX_DIMS];
  int *routingOrder;
  int srcRank, destRank;
  
  MPIX_Torus2rank ( srcCoords, &srcRank );
  MPIX_Torus2rank ( destCoords, &destRank );
  
  routingOrder = new int[MPIX_TORUS_MAX_DIMS];
  getRoutingOrder(routingOrder);
  
  MPIX_Hardware(&hw);
  
  for (i=0; i<MPIX_TORUS_MAX_DIMS ; i++) {
    isTorus[i] = hw.isTorus[i];
    dimSize[i] = hw.Size[i];
  }
  
  //Initialize intermediate nodes in original path to the destination node
  for (int dim=0; dim < MPIX_TORUS_MAX_DIMS; dim++)
    intmdtCoords[dim] = srcCoords[dim];
  intmdtCoords[MPIX_TORUS_MAX_DIMS] = destCoords[MPIX_TORUS_MAX_DIMS];  //T
  
  int hopnum = 0;
  int hopDiff, intmdt_rank, child, parent;
  
  child = srcRank;
  for (int dim=0; dim<MPIX_TORUS_MAX_DIMS; dim++) {
    
    int dimID = routingOrder[dim];
    hopDiff = abs(destCoords[dimID] - srcCoords[dimID]);
    
    if (hw.isTorus[dimID] == 1)
      hopDiff = std::min (hopDiff, (int)hw.Size[dimID] - hopDiff) ;
    
    for(int diff=0; diff<hopDiff ;diff++) {
      if (hw.isTorus[dimID] == 0) {
	if(destCoords[dimID] < srcCoords[dimID])
	  intmdtCoords[dimID] -= unitHop;
	else intmdtCoords[dimID] += unitHop;
      }
      else {            // torus
	if (abs(destCoords[dimID] - srcCoords[dimID])*2 > hw.Size[dimID])
	  {
	    if (destCoords[dimID] > srcCoords[dimID])
	      intmdtCoords[dimID] = ((intmdtCoords[dimID] - unitHop) + hw.Size[dimID]) % hw.Size[dimID];
	    else
	      intmdtCoords[dimID] = (intmdtCoords[dimID] + unitHop) % hw.Size[dimID];
	  }
	else if (abs(destCoords[dimID] - srcCoords[dimID])*2 < hw.Size[dimID])
	  {
	    if (destCoords[dimID] < srcCoords[dimID])
	      intmdtCoords[dimID] = ((intmdtCoords[dimID] - unitHop) + hw.Size[dimID]) % hw.Size[dimID];
	    else
	      intmdtCoords[dimID] = (intmdtCoords[dimID] + unitHop) % hw.Size[dimID];
	  }
	else
	  {
	    //if source coord is even, plus direction
	    if (srcCoords[dimID]%2 == 0)
	      intmdtCoords[dimID] = (intmdtCoords[dimID] + unitHop) % hw.Size[dimID];
	    //even source coord: traverse in plus direction
	    else
	      intmdtCoords[dimID] = ((intmdtCoords[dimID] - unitHop) + hw.Size[dimID]) % hw.Size[dimID];
	  }
      }
      
      ++hopnum;
      
      //get the rank
      MPIX_Torus2rank (intmdtCoords, &intmdt_rank);
      parent = intmdt_rank;
      
      path[interNode] = child;
      interNode++;
      
      MPIX_Rank2torus (child, childCoords);
      child = parent;
    }
  }
  
  path[interNode] = destRank;
  interNode++;
  
  return interNode;
}