您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 【PPT精品课件】北京邮电大学讲义-计算机通信基础7-2-大
计算机通信基础北京邮电大学计算机科学与技术学院通信技术中心魏更宇2第四编II计算机仿真2一、smpl定义系统二、功能描述三、模型初始化四、装置定义和控制五、事件调度和产生六、随机变量生成七、排队网络的仿真模型3smpl八、调试九、数据采集和报告十、输出控制十一、小结4一、smpl定义系统1、三个smpl的实体2、facilities3、tokens4、events5二、功能描述1、smplfunctions2、two-linesynopsisFunctionandformalparametersTypesofparameters3、include“smpl.h”6三、模型初始化1、smpl(m,s)intm;chars;2、reset;7四、装置定义和控制1、f=facility(s,n)char*s;intn;2、r=request(f,tkn,pri)intf,tkn,pri;3、r=preempt(f,tkn,pri)intf,tkn,pri;8四、装置定义和控制(续)4、release(f,tkn)intf,tkn;5、n=inq(f)r=status(f)u=realU(f)b=realB(f)l=realLq(f)intf;9五、事件调度和产生1、schedule(ev,te,tkn)intev,tkn;realte;2、cause(ev,tkn)int*ev,*tkn;3、tkn=cancel(ev)intev;4、t=realtime();10六、随机变量生成1、r=realranf();2、i=stream(n);intn;3、r=realexpntl(x);r=realerlang(x,s);r=hyperx(x,s);intx,s;11六、随机变量生成(续)4、r=realuniform(a,b)reala,b;5、k=random(i,j)inti,j;r=realnormal(x,s)intx,s;12七、排队网络的仿真模型1、openandclosedsystem2、仿真程序13仿真程序Includesmpl.h#definen06/*no.clase0tasks*/#definen13/*no.clase1tasks*/#definentn0+n1/*totalno.oftasks*/#definend4/*no.ofdiskunits*/#defineqd1/*queuedreq.return*/structtoken{intcls;/*task’sclass(&priority)*/intun;/*unitforcurrentIOreq.*/realts;/*tourstarttimestamp*/}task[nt+1];14仿真程序intdisk[nd+1],/*diskfacilitydescriptors*/cpu,/*cpufacilitydescriptor*/nts=10000;/*no.oftourstosimulate*/realtc[2]={10.0,5.0},/*class0,1meancputime*/td=30.0,sd=7.5;/*disktimemean,std.Dev*/main(){inti,j,event,n[2];realt,s[2];structtoken*p;n[0]=n[1]=0,s[0]=s[1]=0.0;for(i=1;i=nt;i++)taks[i].cls=(in0)?1:015仿真程序smpl(0,“centralservermodel”);cpu=facility(“CPU”,1);for(i=1;i=nd;i++)disk[i]=facility(“disk”,1);for(I=1;i=nt;i++)schedule(1,0.0,i);while(nts){casuse(&event,&i);p=&task[i];switch(event){case1:/*begintour*/p-ts=time();schedule(2,0.0,i)break;16仿真程序case2:/*requestcpu*/j=p-cls;if(preempt(cpu,i,j)!=qd)thenschedule(3,expntl(tc[j]),i);break;case3:/*releasecpu,selectdisk*/release(cpu,i);p-un=random(1,nd);schedule(4,0.0,i);break;case4:/*requestdisk*/if(request(disk[p-un],i,0)!=qd)thenschedule(5,erlang(td,sd),i);break;17仿真程序case5:/*releasedisk,endtour*/release(disk[p-un],i);j=p-cls;t=time();s[j]+=t-p-ts;p-ts=t;n[j]++;schedule(1,0.0,i);nts--;break;}}printf(“class0tourtime=%.2f\n”,s[0]/n[0]);printf(“class1tourtime=%.2f\n”,s[1]/n[1]);}18八、调试1、错误信息error-messageEmptyelementpoolEmptynamespaceFacilitydefinedafterqueue/scheduleNegativeeventtimeEmptyeventlistPreemptedtokennotineventlist19调试Releaseofidle/unownedfacilityStreamargumenterrorUniformargumenterror:abRandomargumenterror:ijErlangargumenterror:sxHyperxargumenterror:snotx20调试2、跟踪trace3、调试手段21九、数据采集和报告1、report();2、smpl报告手段;3、自定义报告;22十、输出控制1、标准输出2、p=FILE*sendto(dest)FILE*dest;23十一、小结SmplfunctionsSimulationDebuggingReporting24十一、小结(续)Smplfuctionsummary
本文标题:【PPT精品课件】北京邮电大学讲义-计算机通信基础7-2-大
链接地址:https://www.777doc.com/doc-311201 .html