Você está na página 1de 2

/*program to implement lamports logical clock*/

#include

#include #include void main() { int n,i,a[100],m,j,c[100][100],d[100],temp,s[100][100],g,r[100][100]; clrscr(); printf("\nenter the no. of process in the distributed system="); scanf("%d",&n); for(i=0;i printf("\nenter the no. of events in each process="); scanf("%d",&a[i]); } for(i=0;i printf("\nenter the drift velocity of each process"); scanf("%d",&d[i]); } printf("\the overall configuration of the distributed system is"); for(i=0;i { printf("\nthe process P[%d] has %d events in it and its drift rate is %d",i,a[i],d[i]); } //for each process, entering happened before relationship of events within that process for(j=0;j { for(i=0;i { printf("\nenter the timestamp of %d event of process P[%d]",i+1,j); scanf("%d",&c[j][i]); } } //computing happened before reln. among the events of single process for(j=0;j { for(i=0;i { if(c[j][i]>c[j][i+1]) {

temp=c[j][i]; c[j][i]=c[j][i+1]; c[j][i+1]=temp; } } } for(j=0;j { printf("\nthe non-decreasing order of events of a process P[%d] are",j); for(i=0;i { printf("\nthe c[%d][%d] event with timestamp value %d is %d in the process",j,i,c[j][i],i); } } //considering the inter-process communication messages printf("\nenter the no. of sending events="); scanf("%d",&m); for(g=0;g { printf("\nenter the timestamp index of send message event="); scanf("%d\t%d",&s[j][i]); s[j][i]=c[j][i]; } for(g=0;g { printf("\nthe sending events in the distributed system are s[%d][%d] with timestamp values %d",j,i,s[j][i]); } //establishing happened before relationship among the events of the processes //using the implementation rule 1 and 2 c[j][i]=c[j][i]+d[j];//incrementing the values //for IPC c[j][i]=max(c[j][i] getch(); }

Você também pode gostar