2022年源程序-分布式系统死锁探测 .pdf
《2022年源程序-分布式系统死锁探测 .pdf》由会员分享,可在线阅读,更多相关《2022年源程序-分布式系统死锁探测 .pdf(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、/源程序-分布式系统死锁探测/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(intp
2、Size,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
3、);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,
4、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(multi
5、map 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
6、,&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,m
7、yRank,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/argcintar
8、gument 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
9、 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 thefirstpr
10、obe;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);mu
11、ltimap 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:probeRece
12、iving/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:t
13、herank 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_L
14、ITTLE_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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年源程序-分布式系统死锁探测 2022 源程序 分布式 系统 死锁 探测
限制150内