计算机体系结构实验-单功能流水线调度机构模拟

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

CENTRALSOUTHUNIVERSITY计算机体系结构实验报告题目单功能流水线调度机构模拟一、实验目的结合数据结构的相关知识,编写流水线调度模拟程序。二、实验环境EclipseIDEforJavaDevelopers(Version:KeplerRelease)Win7三、实验内容程序通过模拟单功能流水线调度过程,掌握流水线技术,学会计算流水线的吞吐率、加速比、效率。1流水线的表示法有三种:连接图、时空图、预约表。对于线性流水线,主要考虑前二种。2流水线的主要特点:在流水线的每一个功能部件的后面都要有一个缓冲器,称为锁存器、闸门寄存器等,它的作用是保存本流水段的执行结果。各流水段的时间应尽量相等,否则回引起阻塞、断流等。只有连续提供同类任务才能充分发挥流水线的效率。在流水线的每一个流水线段中都要设置一个流水锁存器。流水线需要有“装入时间”和“排空时间”。只有流水线完全充满时,整个流水线的效率才能得到充分发挥。四、关键代码//构筑主窗体大小颜色:publicvoidlauchFrame(){this.setLayout(null);this.setBounds(100,100,600,500);this.setBackground(Color.cyan);this.setVisible(true);//当输入为3时,显示的是此时的流水线if(Integer.parseInt(timeslice)==3){newPainting(200,380,25,20,Color.gray,ED1,true).draw(g);newPainting(225,380,25,20,Color.gray,ED2,true).draw(g);newPainting(250,380,25,20,Color.gray,ED3,true).draw(g);newPainting(225,360,25,20,Color.gray,EA1,true).draw(g);newPainting(250,360,25,20,Color.gray,EA2,true).draw(g);newPainting(250,340,25,20,Color.gray,MA1,true).draw(g);}这个程序运行的流水线的模拟,依靠的是Java对于界面的编写,流水线的时空图并不是由程序得出,而是由预先设计好的时空图通过编程输出为图像。比如这个当输入为3时,时空图中有6块,每块用newPainting输出。五、运行截图及源代码输入为空的时候:输入超出规定范围的时候:输入正常的范围,比如t=8的时候的流水线时空图:源代码:packagewaterline;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.table.*;publicclasswaterlineextendsFrame{publicstaticvoidmain(String[]args){waterlinelruc=newwaterline();lruc.lauchFrame();}Graphicsg;Labeljlabel1;//Labeljlabel2;TextAreajta1;TextFieldjtf2;//TextFieldjtf3;Buttonjb_input;//Buttonrun;JScrollPanejsp;JTablejt;DefaultTableModeldtm;staticStringtimeslice;publicvoidlauchFrame(){this.setLayout(null);this.setBounds(100,100,600,500);this.setBackground(Color.cyan);this.setVisible(true);jlabel1=newLabel(请输入时间t:);//jlabel2=newLabel(请输入设备内容:);jta1=newTextArea();jtf2=newTextField();//jtf3=newTextField();jb_input=newButton(确定);//run=newButton(运行通道管理器);jlabel1.setBounds(50,50,110,20);//jlabel2.setBounds(230,50,90,20);jta1.setBounds(50,100,500,150);jtf2.setBounds(170,50,70,20);//jtf3.setBounds(330,50,90,20);jb_input.setBounds(450,50,60,20);//run.setBounds(450,260,100,20);this.add(jlabel1);//this.add(jlabel2);this.add(jta1);this.add(jtf2);//this.add(jtf3);this.add(jb_input);//this.add(run);this.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});jb_input.addActionListener(newInputActionListener());jb_input.addActionListener(newRunActionListener());jta1.addKeyListener(newTextAreaThread());g=this.getGraphics();newThread(newPaintThread()).start();jta1.append(---------------------Denothepiplineforfloatpointadd.---------------------\n);jta1.append(-----------------Wewanttoexecute5floatpoinginstructions-----------------\n);jta1.append(Here,wedisplayallthecontentinthepipline:\n);jta1.append(Pleaseinputatimeslice:\n);//jta1.append(+NL[0]++NL[1]++NL[2]);}classInputActionListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){if(jtf2.getText().equals()){Object[]options={OK};JOptionPane.showOptionDialog(null,你的输入存在“”,请按提示输入!,警告,JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE,null,options,options[0]);}timeslice=jtf2.getText();jta1.append(jtf2.getText()+\n);jtf2.setText();}}classRunActionListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){newThread(newTextAreaThread()).start();}}classPainting{intx,y,width,height;Colorcolor;Strings;Booleanflag;publicPainting(intx,inty,intwidth,intheight,Colorcolor,Strings,Booleanflag){this.x=x;this.y=y;this.width=width;this.height=height;this.color=color;this.s=s;this.flag=flag;}publicvoiddraw(Graphicsg){Colorc=g.getColor();g.setColor(color);if(flag==true){g.fillRect(x,y,width,height);g.setColor(Color.red);g.drawRect(x,y,width,height);}elseif(flag==false){g.drawLine(x,y,width,height);}g.setColor(Color.red);g.drawString(s,x+2,y+15);g.setColor(c);}}privateclassPaintThreadimplementsRunnable{publicvoidrun(){while(true){repaint();try{Thread.sleep(500);}catch(InterruptedExceptione){e.printStackTrace();}}}}publicvoidpaint(Graphicsg){newPainting(50,280,500,180,Color.orange,,true).draw(g);newPainting(150,400,450,400,Color.red,,false).draw(g);newPainting(200,300,200,430,Color.red,,false).draw(g);if(timeslice!=null&&Integer.parseInt(timeslice)=8){if(Integer.parseInt(timeslice)==1){newPainting(200,380,25,20,Color.gray,ED1,true).draw(g);}if(Integer.parseInt(timeslice)==2){newPainting(200,380,25,20,Color.gray,ED1,true).draw(g);newPainting(225,380,25,20,Color.gray,ED2,true).draw(g);newPainting(225,360,25,20,Color.gray,EA1,true).draw(g);}if(Integer.parseInt(timeslice)==3){newPainting(200,380,25,20,Color.gray,ED1,true).draw(g);newPainting(225,380,25,20,Color.gray,ED2,true).draw(g);newPainting(250,380,25,20,Color.gray,ED3,true).draw(g);newPainting(225,360,25,20,Color.gray,EA1,true).draw(g);newPainting(250,360,25,20,Color.gray,EA2,true).draw(g);newPainting(250,340,25,20,Color.gray,MA1,true).draw(g);}if(Integer.parseInt(timeslice)==4){newPainting(200,380,25,20,Color.gray,ED1,true).draw(g);newPainting(225,380,25,20,Color.gray,ED2,true).draw(g);newPainting(250,380,25,20,Color.gray,ED3,true).draw(g);newPainting(275,

1 / 13
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功