int main() { int S,i; srand((int)getpid()); S=(int)rand()%390; for(i=0; i<total_instruction; i+=1) /*产生指令队列*/ { a[i]=S; /*任选一指令访问点*/ a[i+1]=a[i]+1; /*顺序执行一条指令*/ a[i+2]=(int)rand()%390; /*执行前地址指令m’*/ a[i+3]=a[i+2]+1; /*执行后地址指令*/ S=(int)rand()%390; } for(i=0; i<total_instruction; i++) /*将指令序列变换成页地址流*/ { page[i]=a[i]/10; offset[i]=a[i]%10; } for(i=4; i<=32; i++) /*用户内存工作区从4个页面到32个页面*/ { printf("%2d page frames",i); FIFO(i); LRU(i); OPT(i); LFU(i); NUR(i); printf("\n"); } return 0; }
void OpenGLWindow::resizeGl() { context->makeCurrent(this); renderer->setSize(width(), height()); renderer->pMatrix.setToIdentity(); float FOVvert = 60.0; float aspectRatio = (float) width() / (float) height(); float nearPlane = 0.1; float farPlane = 1000; renderer->pMatrix.perspective(FOVvert, aspectRatio, nearPlane, farPlane); #define PI 3.14159265359 //Near float nearVert = nearPlane*tanf(FOVvert/2 * PI/180); float nearHorz = nearVert*aspectRatio; //qDebug() << "nearVert" << nearVert; //qDebug() << "nearHorz" << nearHorz; QVector4D NLL(-nearHorz,-nearVert,-nearPlane,1); QVector4D NLR(nearHorz,-nearVert,-nearPlane,1); QVector4D NUL(-nearHorz,nearVert,-nearPlane,1); QVector4D NUR(nearHorz,nearVert,-nearPlane,1); //Far float farVert = farPlane*tanf(FOVvert/2 * PI/180); float farHorz = farVert*aspectRatio; //qDebug() << "farVert" << farVert; //qDebug() << "farHorz" << farHorz; QVector4D FLL(-farHorz,-farVert,-farPlane,1); QVector4D FLR(farHorz,-farVert,-farPlane,1); QVector4D FUL(-farHorz,farVert,-farPlane,1); QVector4D FUR(farHorz,farVert,-farPlane,1); renderer->frustumCorners.clear(); renderer->frustumCorners.push_back(NLL); renderer->frustumCorners.push_back(NLR); renderer->frustumCorners.push_back(NUL); renderer->frustumCorners.push_back(NUR); renderer->frustumCorners.push_back(FLL); renderer->frustumCorners.push_back(FLR); renderer->frustumCorners.push_back(FUL); renderer->frustumCorners.push_back(FUR); /* qDebug() << "NLL" << NLL; qDebug() << "NLR" << NLR; qDebug() << "NUL" << NUL; qDebug() << "NUR" << NUR; qDebug() << "FLL" << FLL; qDebug() << "FLR" << FLR; qDebug() << "FUL" << FUL; qDebug() << "FUR" << FUR; */ renderer->pMatrixInv = renderer->pMatrix; renderer->pMatrixInv.inverted(); glViewport(0, 0, width(), height()); }
void main() { int s, i, j; srand(10*getpid()); s=(float)319*rand()/32767/32767/2+1; // 前面两位是页号,后面是偏移地址 for (i=0; i<total_instruction; i+=4) { if (s<0||s>319) { printf("When i==%d, Error, s==%d\n",i,s); exit(0); } a[i] = s; a[i+1] = a[i]+1; a[i+2] = (float)a[i]*rand()/32767/32767/2; a[i+3] = a[i+2]+1; s=(float)(318-a[i+2])*rand()/32767/32767/2+a[i+2]+2; if ((a[i+2]>318)||(s>319)) printf("a[%d+2], a number which is: %d and s==%d\n", i, a[i+2], s); } for (i=-1; i<total_instruction; i++) { page[i] = a[i]/10; offset[i] = a[i]%10; } for (i=4; i<=32; i++) { printf("%2d page frames", i); FIFO(i); LRU(i); OPT(i); LFU(i); NUR(i); printf("\n"); } }
int main() { int s, i, j; srand(10 * getpid()); /*由于每次运行时进程号不同,故可用来作为初始化随机数队列的“种子”*/ s = (float)319 * rand() / 32767 / 32767 / 2 + 1; // for (i = 0; i < total_instruction; i += 4) /*产生指令队列*/ { if (s < 0 || s > 319) { printf("When i==%d,Error,s==%d\n", i, s); exit(0); } a[i] = s; /*任选一指令访问点m*/ a[i + 1] = a[i] + 1; /*顺序执行一条指令*/ a[i + 2] = (float)a[i] * rand() / 32767 / 32767 / 2; /*执行前地址指令m' */ a[i + 3] = a[i + 2] + 1; /*顺序执行一条指令*/ s = (float)(318 - a[i + 2]) * rand() / 32767 / 32767 / 2 + a[i + 2] + 2; if ((a[i + 2] > 318) || (s > 319)) printf("a[%d+2],a number which is :%d and s==%d\n", i, a[i + 2], s); } for (i = 0; i < total_instruction; i++) /*将指令序列变换成页地址流*/ { page[i] = a[i] / 10; offset[i] = a[i] % 10; } for (i = 4; i <= 32; i++) /*用户内存工作区从4个页面到32个页面*/ { printf("---%2d page frames---\n", i); FIFO(i); LRU(i); LFU(i); NUR(i); OPT(i); } return 0; }