arma::vec SingleSampleTrajectory::getStartingPos() { vec ret(getDegreesOfFreedom()); for(int i = 0; i < getDegreesOfFreedom(); ++i) { ret(i) = getDataPoint(i, 0); } return ret; }
int getExit (float level, CONTOUR_POINT *point) { int exit_heading, adjFace, nextFace; float same,next,opp,adj; float samePt,nextPt,oppPt,adjPt; float same2next,next2opp,opp2adj,adj2same; adjFace = faceInUse(point,CONTOUR_ADJACENT); nextFace = faceInUse(point,CONTOUR_NEXT); if (nextFace && adjFace) { /* BOTH FACES USED, CONTOUR WILL CLOSE, EXIT FACE UNKNOWN */ exit_heading = CONTOUR_UNKNOWN; } else if (adjFace) { exit_heading = CONTOUR_NEXT; } else if (nextFace) { exit_heading = CONTOUR_ADJACENT; } else { /* GET FOUR CORNERS OF CELL */ same = getDataPoint(point,CONTOUR_SAME); next = getDataPoint(point,CONTOUR_NEXT); opp = getDataPoint(point,CONTOUR_OPPOSITE); adj = getDataPoint(point,CONTOUR_ADJACENT); /* COMPUTE OFFSET TO CONTOUR LEVEL FOR EACH FACE */ samePt = (level-same)/(next-same); nextPt = (level-opp)/(next-opp); oppPt = (level-opp)/(adj-opp); adjPt = (level-same)/(adj-same); /* COMPUTE DISTANCE OF EACH LINE */ same2next = (float) sqrt((double)((1-samePt)*(1-samePt)) +((1-nextPt)*(1-nextPt))); next2opp = (float) sqrt((double)(oppPt * oppPt) + (nextPt * nextPt)); opp2adj = (float) sqrt((double)((1-oppPt)*(1-oppPt)) + ((1-adjPt)*(1-adjPt))); adj2same = (float) sqrt((double)(samePt * samePt) + (adjPt * adjPt)); /* SELECT EXIT HEADING BASED IN SHORTEST LINE */ if (same2next < next2opp) { if (same2next < adj2same) { exit_heading = CONTOUR_NEXT; } else { exit_heading = CONTOUR_ADJACENT; } } else { if (next2opp < opp2adj) { exit_heading = CONTOUR_ADJACENT; } else { exit_heading = CONTOUR_NEXT; } } } return exit_heading; }
int startContour (float level, CONTOUR_POINT *point) { int *index, inc, end, no_contour; float last, next; index = 0; end = 0; inc = 0; no_contour = CONTOUR_TRUE; while (no_contour && REF.heading <= CONTOUR_NORTH) { /* SET LOOP VARIABLES BASED ON PRESENT HEADING */ switch (REF.heading) { case CONTOUR_EAST: index = &REF.y; end = MAX_Y - 1; inc = 1; break; case CONTOUR_SOUTH: index = &REF.x; end = MAX_X - 1; inc = 1; break; case CONTOUR_WEST: index = &REF.y; end = -1; inc = -1; break; case CONTOUR_NORTH: index = &REF.x; end = -1; inc = -1; break; } next = getDataPoint(&REF,CONTOUR_SAME); /* LOOP THROUGH PRESENT ROW/COLUMN FOR CONTOURS OF THE PRESENT LEVEL */ while ((*index != end) && no_contour) { last = next; next = getDataPoint(&REF,CONTOUR_NEXT); /* CHECK IF LEVEL IS BETWEEN TWO GRID POINTS */ if ((last <= level) && (level < next)) { /* CHECK IF CONTOUR FOUND EARLIER */ if (!faceInUse(&REF,CONTOUR_SAME)) { /* SET RETURN VALUES */ no_contour = CONTOUR_FALSE; point->x = REF.x; point->y = REF.y; point->heading = REF.heading; } } *index += inc; } /* CHECK IF A CONTOUR WAS FOUND */ if (no_contour) { /* SET REF VALUES FOR THEN NEXT ROW/COLUMN */ if (REF.heading != CONTOUR_NORTH) { REF.heading++; if (REF.heading == CONTOUR_NORTH) REF.y = -1; } switch (REF.heading) { case CONTOUR_SOUTH: REF.x = 0; REF.y = MAX_Y - 2; break; case CONTOUR_WEST: REF.x = MAX_X - 2; REF.y = MAX_Y -2; break; case CONTOUR_NORTH: if (REF.y < MAX_Y -2) { REF.y++; REF.x = MAX_X - 2; } else { REF.heading++; } } } } /* IF NO_CONTOUR, ENTIRE GRID SEARCHED, RESET REF TO START NEXT LEVEL */ if (no_contour) { REF.x = 0; REF.y = 0; REF.heading = CONTOUR_EAST; } return ! no_contour; }
int follow(float level, CONTOUR_POINT *point) { int segment, start_heading, exitFace, adj, opp; float fadj,fopp; exitFace = CONTOUR_UNKNOWN; segment = -1; start_heading = point->heading; while (segment == -1) { /* SAVE PRESENT POINT IF VALID */ if (savePoint(level,point)) { /* HAS THE CONTOUR CLOSED */ if (!(faceInUse(point,CONTOUR_SAME))) { markInUse(point); /* HAS THE CONTOUR REACHED AN EDGE */ if (cellExists(point)) { /* COMPUTE THE EXIT FACE RELATIVE TO THE PRESENT FACE */ fadj = getDataPoint(point,CONTOUR_ADJACENT); fopp = getDataPoint(point,CONTOUR_OPPOSITE); adj = (fadj > level) ? 2 : 0; opp = (fopp <= level) ? 1 : 0; switch (adj+opp) { case 0: exitFace = CONTOUR_OPPOSITE; break; case 1: exitFace = CONTOUR_NEXT; break; case 2: exitFace = CONTOUR_ADJACENT; break; case 3: exitFace = getExit(level,point); break; } if (exitFace == CONTOUR_UNKNOWN) { point->heading = start_heading; } else { point->heading = (point->heading + exitFace + 2) % 4; } /* UPDATE THE INDEXES BASE ON THE NEW HEADING */ switch (point->heading) { case CONTOUR_EAST: point->x++; break; case CONTOUR_NORTH: point->y++; break; case CONTOUR_WEST: point->x--; break; case CONTOUR_SOUTH: point->y--; break; } } else { /* CONTOUR HAS REACHED AN EDGE, EXIT */ segment = CONTOUR_FALSE; } } else { /* CONTOUR HAS CLOSED, EXIT */ segment = CONTOUR_FALSE; } } else { /* CONTOUR IS SEGMENTED BY INVALID DATA OR MAX CONTOUR POINTS */ segment = CONTOUR_TRUE; } } return segment; }
// // generate a data point across a time range (clocks) // if ctlr is 8, generating a point using data from all 8 controllers, b0-15 is ctlr0 b0-127 // if ctlr 0-7, generating a point using data from a specific ctlr // rtn = number of requests outstanding // item = first item found // the first item found that matches is returned // returns the average latency // int // return requests outstanding DataItem::getDataPoint(int64_t time, int64_t clocks, int ctlr, int bank, DataItem **item, int &retireBytes, int &latency) { int bankStart; int requests = 0; int ctlrRequests = 0; int64_t t; int64_t maxRt; int64_t latencyR; DataItem *itemP = 0; DataItem *ctlrItemP = 0; map<int64_t, DataItem *>::iterator itr; int localBR; int localLA; int latencyCtr; requests = 0; retireBytes = 0; latency = 0; latencyCtr = 0; if(lastRetire == 0) { // no file loaded yet itemP = 0; requests = 0; } else if(ctlr <= 7) { // // getting data for a single memory controller dataMap[CTLR_MAX][BANKS] // must get the max across clocks // return the first item // maxRt = -1; unsigned short *fp = ctlrBandTimeReq[ctlr][bank]; int64_t tm = time - firstStart; int64_t tst = tm; int64_t tsp = tm + clocks; for(t=tst; t<tsp; t++) { if(fp[t] > requests) { requests = fp[t]; maxRt = t - tm + time; } } #ifdef NEVER for(t=0; t<clocks; t++) { if(fp[t + time - firstStart] > requests) { requests = fp[t + time - firstStart]; maxRt = t + time; } } #endif // // now generate the latency // start at end time and work backwards // map<int64_t, DataItem *>::iterator itr; map<int64_t, DataItem *> *map; map = &dataMap[ctlr][bank]; itr = map->lower_bound(time + clocks); // first >= t if(itr == map->end() || itr->second->getRetireTime() > time + clocks) { if(itr != map->begin()) { itr--; // point to a valid one } } while(itr != map->begin() && itr->second->getRetireTime() > time) { retireBytes += 8; latencyR = itr->second->getRetireTime() - itr->second->getStartTime(); if(LATENCY == L_MAX) { if(latencyR > latency) { latency = latencyR; // return max } latencyCtr = 1; } else { latency += latencyR; // return avg latencyCtr++; } itr--; } if(latencyCtr) { latency /= latencyCtr; // cntr=1 for max } if(maxRt >= 0) { itr = dataMap[ctlr][bank].upper_bound(maxRt - 1); // need minus, only finds > } if(maxRt < 0 || itr == dataMap[ctlr][bank].end()) { itemP = 0; } else { itemP = itr->second; } } else if(ctlr == CTLR_ALL_B) { // all_b // // getting data for all memory controllers, merge 128 lines into 16 (8:1) // bank0=ctlr_0-7 bank 0 bank1=ctlr_0-7 bank 1 ... // for(ctlr=0; ctlr<8; ctlr++) { ctlrRequests = getDataPoint(time, clocks, ctlr, bank, &ctlrItemP, localBR, localLA); if(ctlrRequests > requests) { requests = ctlrRequests; itemP = ctlrItemP; } retireBytes += localBR; if(localLA) { latencyCtr++; } latency += localLA; } if(latencyCtr != 0) { latency /= latencyCtr; } } else { // all_c // // getting data for all memory controllers, merge 128 lines into 16 (8:1) // bank0=ctlr_0 banks0-7 bank1=ctlr_0 banks 8-15 ... // ctlr = bank / 16; bankStart = (bank % 16) * 8; // what bank to start with for(bank=0; bank<8; bank++) { ctlrRequests = getDataPoint(time, clocks, ctlr, bank + bankStart, &ctlrItemP, localBR, localLA); if(ctlrRequests > requests) { requests = ctlrRequests; itemP = ctlrItemP; } retireBytes += localBR; if(localLA) { latencyCtr++; } latency += localLA; } if(latencyCtr != 0) { latency /= latencyCtr; } } *item = itemP; return(requests); }