00001 00002 #include "pose.h" 00003 00005 void adapt4::Step() 00006 { 00007 Event *ev; 00008 POSE_TimeType lastGVT = localPVT->getGVT(); 00009 POSE_TimeType offset=POSE_UnsetTS, theMaxLeash=POSE_TimeMax/2; 00010 double critStart; 00011 00012 rbFlag = 0; 00013 if (!parent->cancels.IsEmpty()) CancelUnexecutedEvents(); 00014 if (eq->RBevent) Rollback(); 00015 if (!parent->cancels.IsEmpty()) CancelEvents(); 00016 parent->Status(); 00017 00018 if (rbFlag) { // adjust leash according to rollback 00019 timeLeash = avgRBoffset; 00020 } 00021 else if (timeLeash < theMaxLeash) { // adjust according to state 00022 if (eq->currentPtr->timestamp > POSE_UnsetTS) { // adjust to next event 00023 if (eq->currentPtr->timestamp - lastGVT > timeLeash) 00024 timeLeash = eq->currentPtr->timestamp - lastGVT; 00025 // else leave it alone 00026 } 00027 // no next event; leave it alone 00028 } 00029 // Put leash back into reasonable bounds 00030 if (timeLeash > theMaxLeash) { 00031 timeLeash = theMaxLeash; 00032 } 00033 else if (timeLeash < 0) timeLeash = 0; 00034 00035 if (itersAllowed < 1) { 00036 itersAllowed = 1; 00037 } 00038 else { 00039 itersAllowed = (int)((double)specEventCount * specTol); 00040 itersAllowed -= specEventCount - eventCount; 00041 if (itersAllowed < 1) itersAllowed = 1; 00042 } 00043 00044 // Prepare to execute an event 00045 offset = lastGVT + timeLeash; 00046 // Shorten the leash as we near POSE_endtime 00047 if ((POSE_endtime > POSE_UnsetTS) && ((offset > POSE_endtime) || 00048 (offset <= POSE_UnsetTS))) 00049 offset = POSE_endtime; 00050 00051 ev = eq->currentPtr; 00052 while ((ev->timestamp > POSE_UnsetTS) && (ev->timestamp <= offset) && 00053 (itersAllowed > 0)) { 00054 #ifdef MEM_COARSE 00055 // Check to see if we should hold off on forward execution to save on 00056 // memory. 00057 // NOTE: to avoid deadlock, make sure we have executed something 00058 // beyond current GVT before worrying about memory usage 00059 if (((ev->timestamp > lastGVT) || (userObj->OVT() > lastGVT)) 00060 && (eq->mem_usage > objUsage)) // don't deadlock 00061 break; 00062 #endif 00063 iter++; 00064 itersAllowed--; 00065 currentEvent = ev; 00066 ev->done = 2; 00067 localPVT->incSpecEventCount(); 00068 localPVT->incEventCount(); 00069 specEventCount++; 00070 eventCount++; 00071 #if !CMK_TRACE_DISABLED 00072 if(pose_config.trace) 00073 critStart = CmiWallTimer(); // trace timing 00074 #endif 00075 parent->ResolveFn(ev->fnIdx, ev->msg); // execute it 00076 #if !CMK_TRACE_DISABLED 00077 if(pose_config.trace) 00078 traceUserBracketEvent(10, critStart, CmiWallTimer()); 00079 #endif 00080 ev->done = 1; // flag the event as executed 00081 eq->mem_usage++; 00082 eq->ShiftEvent(); // shift to next event 00083 ev = eq->currentPtr; 00084 } 00085 #if !CMK_TRACE_DISABLED 00086 if(pose_config.stats) 00087 if (iter > 0) localStats->Loop(); 00088 #endif 00089 } 00090