欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    2022年源程序-分布式系统死锁探测 .pdf

    • 资源ID:39711581       资源大小:74.32KB        全文页数:10页
    • 资源格式: PDF        下载积分:4.3金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要4.3金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    2022年源程序-分布式系统死锁探测 .pdf

    /源程序-分布式系统死锁探测/Project:Deadlock Detection./Chandy MisraHaasedge chasingdeadlockdetection-(AND方式)/-/Project:Deadlock Detection./程序语言:C+/MPI 并行程序#includempi.h#include#include#include#include#include#include#includeusingnamespace std;/level1 functions:boolcheckDebug(intargc,char*argv);voidcall_end(intpSize,intmyid);boolcheckNumprocs(i#includempi.h#include#include#include#include#include#include#includeusingnamespace std;/level1 functions:boolcheckDebug(intargc,char*argv);voidcall_end(intpSize,intmyid);boolcheckNumprocs(intpSize,intnumprocs);multimap readEdge(char*argv,int&p1,int&pSize,int&numEdge);voidprobeSending_first(int*probe,vector&Sender_Tracker,multimap&myEdge,intii,intn_total,intn_ini,intdebug,intmyid,intMY_LITTLE_TAG,MPI_Status&名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 10 页 -myStatus,MPI_Request&myRequest);voidprobeSending_rest(int*probe,vector&Sender_Tracker,multimap&myEdge,intii,intn_total,intn_ini,intdebug,intmyid,intMY_LITTLE_TAG,MPI_Status&myStatus,MPI_Request&myRequest);voidprobeReceiving(int*probe,vector&Sender_Tracker,intii,intn_total,intmyid,intMY_LITTLE_TAG,MPI_Status&myStatus,MPI_Request&myRequest,vector&deadlock,vector&isReceiving);/level2 functions:voidDeadlockDection(multimap myEdge,intmyRank,intnumprocs,intpSize,intp1,intnumEdge,MPI_Status&myStatus,MPI_Request&myRequest,intargc,char*argv);intmain(intargc,char*argv)/mpiinitialization.intmyRank,numprocs;intpSize=0,p1=0,numEdge=0;MPI_Init(&argc,&argv);MPI_Comm_size(MPI_COMM_WORLD,&numprocs);MPI_Comm_rank(MPI_COMM_WORLD,&myRank);MPI_Request myRequest;MPI_Status myStatus;/Disableoutputbufferingon STDOUT so thatoutputisshown as soon as we write/itto thedisplay.setvbuf(stdout,NULL,_IONBF,0);/usea multimaptostoretheedge listmultimap myEdge=readEdge(argv,p1,pSize,numEdge);/implementthedetection;DeadlockDection(myEdge,myRank,numprocs,pSize,p1,numEdge,myStatus,myRequest,argc,argv);MPI_Finalize();return0;/*名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 10 页 -/level1 Function:checkDebug/This functioniscalledtoseta bool value=1ifthe excecutionisindebugging mode./Return Value/-/bool/Value Parameters/-/argvcharargument vector/argcintargument count/*boolcheckDebug(intargc,char*argv)stringoption(-debug);stringoption_dummy;if(argc=3)option_dummy=argv2;if(pare(option_dummy)=0)return1;elsereturn0;/*/level1 Function:readEdge/Functionto read the Edge List/Return Value/-/multimap/Value Parameters/-/argvcharargument vector/argcintargument count名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 10 页 -/p1inttheprocess thatsends out thefirstprobe/pSizeintnumber ofprocessesfrom theinput/numEdgeintnumber ofEdges from the input/*Thefollowinggivesa sample inputedge list:070 11 22 33 43 54 55 66 0-1-1Note that:thefirstlinemeans theprocess0 sends out thefirstprobe;thesecond linemeans thereare 7 nodes;the restisan edge list.0 1 means edge from process 0 to 1,1 2 means edge from process1 to2containgthe edgep1-p2,then row 1 and columb 2 is1;-1indicatestheend ofedge list.*/*multimap readEdge(char*argv,int&p1,int&pSize,int&numEdge)inte1,e2;/anedge is(e1,e2);multimap myEdge;/usea multimaptostoretheedge listFILE*f=fopen(argv1,r);fscanf(f,%d,&p1);fscanf(f,%d,&pSize);fscanf(f,%d,&numEdge);for(inti=0;i numEdge;i+)fscanf(f,%d,&e1);fscanf(f,%d,&e2);myEdge.insert(pair(e1,e2);fclose(f);returnmyEdge;名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 10 页 -/*/level1 Function:probeReceiving/Thisfunctioniscalledtosend probesotherthanthefirstprobe./arguments/-/int*probe:theprobe fordetection;/vector&Sender_Tracker:vectorthatstoressendersinfoateach roundofsendingofa probe;/intii:thenth round ofsendingouta probe;/intn_totalthe totalnumber ofprocesses;/intdebug:outputoption;/intmyid:therank ofprocess/intMY_LITTLE_TAG:mpi message tag;/MPI_Status&myStatus/MPI_Request&myRequest/vector&deadlock:whetherthe processison the deadlockedloop/vector&isReceiving:whethertheprocessreceiveda probe at laststep/*void probeReceiving(int*probe,vector&Sender_Tracker,intii,intn_total,intmyid,intMY_LITTLE_TAG,MPI_Status&myStatus,MPI_Request&myRequest,vector&deadlock,vector&isReceiving)for(intj=0;j n_total;j+)if(Sender_Trackermyid+n_total*j=1)MPI_Irecv(probe,3,MPI_INT,j,MY_LITTLE_TAG,MPI_COMM_WORLD,&myRequest);MPI_Wait(&myRequest,&myStatus);isReceivingii=1;/coutprobe0,probe1,probe2endl;if(probe0=probe2)deadlockmyid=1;名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 10 页 -/*/level1 Function:probeSending_rest/Thisfunctioniscalledtosend probesotherthanthefirstprobe./arguments/-/int*probe:theprobefordetection;/vector&Sender_Tracker:vectorthatstoressendersinfoateach round ofsendingofa probe;/intii:thenth round ofsendingouta probe;/intpSize:thetotalnumber ofprocessesfrom the input;/multimap&myEdge:the edge list/intp1:theprobe thatsendingout thefirstprobe;/intisDebug:outputoption;/intmyRank:the rankof process/intmyTag:mpi message tag;/MPI_Status&myStatus/MPI_Request&myRequest/*voidprobeSending_rest(int*probe,vector&Sender_Tracker,multimap&myEdge,intii,intpSize,intp1,intisDebug,intmyRank,intmyTag,MPI_Status&myStatus,MPI_Request&myRequest)multimap:iteratorit;it=myEdge.find(myRank);名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 10 页 -while(it!=myEdge.end()probe0=p1;probe1=myRank;probe2=it-second;MPI_Isend(probe,3,MPI_INT,probe2,myTag,MPI_COMM_WORLD,&myRequest);MPI_Wait(&myRequest,&myStatus);Sender_Trackerprobe2+pSize*myRank=1;if(isDebug=1)coutPROCESS myRank SENDS p1,myRank,probe2 TO PROCESS probe2endl;myEdge.erase(it);it=myEdge.find(myRank);/*/level1 Function:probeSending_first/Thisfunctioniscalledtosend the firstprobe./arguments/-/int*probe:theprobe fordetection;/vector&Sender_Tracker:vectorthatstoressendersinfoateach roundofsendingofa probe;/intii:thenth round ofsendingouta probe;/intpSize:thetotalnumber ofprocessesfrom the input;/multimap&myEdge:the edge list/intp1:theprobe thatsendingout thefirstprobe;/intisDebug:outputoption;/intmyRank:the rankof process/intmyTag:mpi message tag;/MPI_Status&myStatus/MPI_Request&myRequest/*名师资料总结-精品资料欢迎下载-名师精心整理-第 7 页,共 10 页 -voidprobeSending_first(int*probe,vector&Sender_Tracker,multimap&myEdge,intii,intpSize,intp1,intisDebug,intmyRank,intmyTag,MPI_Status&myStatus,MPI_Request&myRequest)multimap:iteratorit;it=myEdge.find(myRank);while(it!=myEdge.end()probe0=p1;probe1=p1;probe2=it-second;MPI_Isend(probe,3,MPI_INT,probe2,myTag,MPI_COMM_WORLD,&myRequest);MPI_Wait(&myRequest,&myStatus);Sender_Trackerprobe2+pSize*myRank=1;if(isDebug=1)coutPROCESS myRank SENDS p1,myRank,probe2 TO PROCESS probe2endl;myEdge.erase(it);it=myEdge.find(myRank);/*/level1 Function:call_end/This functioniscalledtoexitexecutionifthe number ofprocessdoes not match theinputfile./arguments/-/intpSize:thetotalnumber ofprocessesfrom the input;/intmyid:therank ofprocess/*名师资料总结-精品资料欢迎下载-名师精心整理-第 8 页,共 10 页 -*voidcall_end(intpSize,intmyid)if(myid=0)coutYoushouldusepSizeprocessestosimulatetheproblem!endl;MPI_Finalize();exit(1);/*/level2 Function:DeadlockDection/Thisfunctioniscalledtowrap up theimplementationof DeadlockDection./arguments/-/multimap&myEdge:the edge list/intpSize:thetotalnumber ofprocessesfrom the input;/intnumEdge:the totalnumber ofedges from theinput;/intp1:theprobe thatsendingout thefirstprobe;/intnumprocs:totalnumber ofprocessesthe program called./intmyRank:the rankof process/intmyTag:mpi message tag;/MPI_Status&myStatus/MPI_Request&myRequest/charargv:argumentvector/intargc:argument count/*voidDeadlockDection(multimap myEdge,intmyRank,intnumprocs,intpSize,intp1,intnumEdge,MPI_Status&myStatus,MPI_Request&myRequest,intargc,char*argv)multimap:iteratorit;if(pSize!=numprocs)call_end(pSize,myRank);boolisDebug=checkDebug(argc,argv);intmyTag=1;intprobe3;/initializetheprobe.probe0=-1;probe1=-2;probe2=-3;/prepareforthe simulationboolisDeadlock=0;vector deadlock(numprocs,-1);名师资料总结-精品资料欢迎下载-名师精心整理-第 9 页,共 10 页 -vector Sender_Tracker(pSize*numprocs,-1);/forcollectingsendersinfovector Tracker_dummy(pSize*numprocs,-1);vector isReceiving(pSize,0);for(intii=0;iipSize;ii+)Sender_Tracker=Tracker_dummy;/p1sendingoutthe firstprobeif(ii=0)&(myRank=p1)probeSending_first(probe,Sender_Tracker,myEdge,ii,pSize,p1,isDebug,myRank,myTag,myStatus,myRequest);for(inti=0;i=1)&(isReceivingii-1=1)probeSending_rest(probe,Sender_Tracker,myEdge,ii,pSize,p1,isDebug,myRank,myTag,myStatus,myRequest);MPI_Barrier(MPI_COMM_WORLD);/updatingsendersinfofor(intk=0;knumprocs;k+)MPI_Bcast(&(Sender_Trackerk*pSize),pSize,MPI_INT,k,MPI_COMM_WORLD);MPI_Barrier(MPI_COMM_WORLD);/receivingprobes.isReceivingii=0;probeReceiving(probe,Sender_Tracker,ii,pSize,myRank,myTag,myStatus,myRequest,deadlock,isReceiving);MPI_Barrier(MPI_COMM_WORLD);/checkifthe processison a deadlockedloopfor(inti=0;inumprocs;i+)MPI_Bcast(&(deadlocki),1,MPI_INT,i,MPI_COMM_WORLD);for(inti=0;inumprocs;i+)if(deadlocki=1)isDeadlock=1;isReceivingii=0;break;if(isDeadlock=1)break;for(inti=0;i10000;i+)MPI_Barrier(MPI_COMM_WORLD);if(isDeadlock!=1&myRank=0)cout THE SYSTEM IS NOTDEADLOCKEDendl;if(isDeadlock=1&myRank=0)cout THE SYSTEM IS DEADLOCKEDendl;名师资料总结-精品资料欢迎下载-名师精心整理-第 10 页,共 10 页 -

    注意事项

    本文(2022年源程序-分布式系统死锁探测 .pdf)为本站会员(H****o)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开