




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验三 利用预约表编程计算非线性流水线的任务调度方案一、 实验目的通过本实验帮助学生理解单功能非线性流水线基本任务调度方法。二、 实验环境开发工具使用windows平台下的vc+6.0。三、 实验内容给定某单功能非线性流水线的预约表,通过编程求出所有不冲突的任务调度方案并输出。流水线功能段数随机。四、 实验结果#include #include #include #include const int MAXJOB=50;/定义数据结构体 typedef struct node int number; int reach_time; int reach_hour; int reach_minite; int need_time; int privilege; float excellent; int start_time; int wait_time; int visited; job; job jobsMAXJOB; int quantity; /初始化函数 void initial() int i; for(i=0;iMAXJOB;i+) jobsi.number=0; jobsi.reach_time=0; jobsi.reach_hour=0; jobsi.reach_minite=0; jobsi.privilege=0; jobsi.excellent=0; jobsi.start_time=0; jobsi.wait_time=0; jobsi.visited=0; quantity=0; void reset() /重置作业数据函数 int i; for(i=0;iMAXJOB;i+) jobsi.start_time=0; jobsi.wait_time=0; jobsi.visited=0; void readData() /读入作业数据函数 FILE *fp; char fname20; int i; coutfname; if(fp=fopen(fname,r)=NULL) cout错误,文件打不开,请检查文件名:)endl; else while(!feof(fp) fscanf(fp,%d %d %d %d,&jobsquantity.number,&jobsquantity.reach_time,&jobsquantity.need_time,&jobsquantity.privilege); jobsquantity.reach_hour=jobsquantity.reach_time/100; jobsquantity.reach_minite=jobsquantity.reach_time%100; quantity+; /输出初始作业数据 cout输出初始作业数据endl; cout-endl; cout.setf(2); coutsetw(10)作业号setw(12)到达时间setw(14)所需时间(分)setw(14)1)endl; for(i=0;iquantity;i+) coutsetw(10)jobsi.numbersetw(12)jobsi.reach_timesetw(14)jobsi.need_timesetw(14)jobsi.privilegeendl; /FIFO算法 void FIFO() int i; int current_hour; int current_minute; int total_time=0; coutendl; /输出作业流coutendlFIFO算法作业流endl; cout-endl; cout.setf(2); coutsetw(10)作业号setw(12)到达时间setw(12)开始时间setw(14)周转时间(分)endl; current_hour=jobs0.reach_hour; current_minute=jobs0.reach_minite; for(i=0;iquantity;i+) jobsi.start_time=current_hour*100+current_minute; jobsi.wait_time=(current_hour-jobsi.reach_hour)*60+(current_minute-jobsi.reach_minite)+jobsi .need_time; coutsetw(10)jobsi.numbersetw(12)jobsi.reach_timesetw(12)jobsi.start_timesetw(14)jobsi.wait_timeendl; current_hour=current_hour+(jobsi.need_time+current_minute)/60; current_minute=(jobsi.need_time+current_minute)%60; total_time+=jobsi.wait_time; coutendl总周转时间:total_time 平均周转时间:total_time/quantityendl; void shorter() /运算时间短的作业优先算法 int i,j,p; int current_hour; int current_minute; int current_need_time; int total_time=0; /输出作业流 coutendl; coutendl时间短作业优先算法作业流(开始调度时刻为最后一个作业到达系统的时间)endl; cout-endl; cout.setf(2); coutsetw(10)作业号setw(12)到达时间setw(14)所需时间(分)setw(12)开始时间setw(14)周转时间(分)endl; current_hour=jobsquantity-1.reach_hour; current_minute=jobsquantity-1.reach_minite; for(i=0;iquantity;i+) current_need_time=30000; for(j=0;jquantity;j+) if(jobsj.visited=0)&(jobsj.need_timecurrent_need_time) p=j; current_need_time=jobsj.need_time; jobsp.start_time=current_hour*100+current_minute; jobsp.wait_time=(current_hour-jobsp.reach_hour)*60+(current_minute-jobsp.reach_minite)+jobsp .need_time; coutsetw(10)jobsp.numbersetw(12)jobsp.reach_timesetw(14)jobsp.need_timesetw(12)jobsp.start_timesetw(14)jobsp.wait_timeendl; current_hour=current_hour+(jobsp.need_time+current_minute)/60; current_minute=(jobsp.need_time+current_minute)%60; jobsp.visited=1; total_time+=jobsp.wait_time; coutendl总周转时间:total_time 平均周转时间:total_time/quantityendl; void privilege() /优先数调度算法 int i,j,p; int current_hour; int current_minute; int current_privilege; int total_time=0; /输出作业流 coutendl; coutendl优先数调度算法作业流(开始调度时刻为最后一个作业到达系统的时间)endl; cout-endl; cout.setf(2); coutsetw(10)作业号setw(12)到达时间setw(14)1)setw(12)开始时间setw(14)周转时间(分)endl; current_hour=jobsquantity-1.reach_hour; current_minute=jobsquantity-1.reach_minite; for(i=0;iquantity;i+) current_privilege=30000; for(j=0;jquantity;j+) if(jobsj.visited=0)&(jobsj.privilegecurrent_privilege) p=j; current_privilege=jobsj.privilege; jobsp.start_time=current_hour*100+current_minute; jobsp.wait_time=(current_hour-jobsp.reach_hour)*60+(current_minute-jobsp.reach_minite)+jobsp .need_time; coutsetw(10)jobsp.numbersetw(12)jobsp.reach_timesetw(14)jobsp.privilegesetw(12)jobsp.start_timesetw(14)jobsp.wait_timeendl; current_hour=current_hour+(jobsp.need_time+current_minute)/60; current_minute=(jobsp.need_time+current_minute)%60; jobsp.visited=1; total_time+=jobsp.wait_time; coutendl总周转时间:total_time 平均周转时间:total_time/quantityendl; /响应比最高者优先调度算法 void excellent() int i,j,p; int current_hour; int current_minute; float current_excellent; int total_time=0; /输出作业流 coutendl; coutendl响应比高者优先调度算法作业流(开始调度时刻为最后一个作业到达系统的时间)endl; cout-endl; cout.setf(2); coutsetw(10)作业号setw(12)到达时间setw(12)开始时间setw(14)周转时间(分)endl; current_hour=jobsquantity-1.reach_hour; current_minute=jobsquantity-1.reach_minite; for(i=0;iquantity;i+) current_excellent=-1; for(j=0;jquantity;j+) if(jobsj.visited=0) jobsj.wait_time=(current_hour-jobsj.reach_hour)*60+(current_minute-jobsj.reach_minite); jobsj.excellent=(float)(jobsj.wait_time/jobsj.need_time); for(j=0;jcurrent_excellent) p=j; current_excellent=jobsj.excellent; jobsp.start_time=current_hour*100+current_minute; jobsp.wait_time=(current_hour-jobsp.reach_hour)*60+(current_minute-jobsp.reach_minite)+jobsp .need_time; coutsetw(10)jobsp.numbersetw(12)jobsp.reach_timesetw(12)jobsp.start_timesetw(14)jobsp.wait_timeendl; current_hour=current_hour+(jobsp.need_time+current_minute)/60; current_minute=(jobsp.need_time+current_minute)%60; jobsp.visited=1; total_time+=jobsp.wait_time; coutendl总周转时间:total_time 平均周转时间:total_time/quantityendl; Void main() initial(); readData(); FIFO(); shorter(); reset(); privilege(); reset(); excellent(); 五、 问题以及解决方案1. 问题:什么是线性流水线和非线性流水线;解决方案:线性流水线:流水线的各段串行连接,没有反馈回路。非线性流水线:
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 医用设备试题及答案
- 整式试卷测试题及答案
- 招标采购岗试题及答案
- 高一物理期末考试题及答案
- 新沂教编考试试题及答案
- 2025年噶尔县教育系统招聘教师考试笔试试题(含答案)
- 2025年达州市农科院招聘考试笔试试题(含答案)
- 2025年医学装备相关知识培训考核题(含答案)
- 2024年民航安全隐患排查治理长效机制建设大比武指南试题及答案
- (2025)全国水利安全生产知识竞赛题库及参考答案
- 全面质量管理TQM体系概述与实践应用探讨
- 2025年云南省事业单位招聘考试教师信息技术学科专业知识试卷试题
- 借款转为租金合法合同范本
- 2025年国企融媒体考试题库
- 2025年事业单位笔试-云南-云南药剂学(医疗招聘)历年参考题库含答案解析(5卷套题【单选100题】)
- 2025年度铝合金门购销及节能技术合同
- 心源性休克的护理个案
- 2024年10月19日北京市下半年事业单位七区联考《公共基本能力测验》笔试试题(海淀-房山-西城-通州-丰台-怀柔)真题及答案
- 《中国动态血压监测基层应用指南(2024年)》解读 2
- 2025初中语文新教材培训
- 企业技术人员管理制度
评论
0/150
提交评论