+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

vijaygarg1init99f4f39

master
978 B39 linesraw
1package clocks;
2public class MatrixClock {
3    int[][] M;
4    int myId;
5    int N;
6    public MatrixClock(int numProc, int id) {
7        myId = id;
8        N = numProc;
9        M = new int[N][N];
10        for (int i = 0; i < N; i++) 
11           for (int j = 0; j < N; j++) 
12		M[i][j] = 0;
13        M[myId][myId] = 1;
14    }
15    public void tick() {
16        M[myId][myId]++;
17    }
18    public void sendAction() {
19        //include the matrix in the message
20        M[myId][myId]++;
21    }
22    public void receiveAction(int[][] W, int srcId) {
23	// component-wise maximum of matrices
24        for (int i = 0; i < N; i++)
25	   if (i != myId) {
26           	for (int j = 0; j < N; j++) 
27              	     M[i][j] = Math.max(M[i][j], W[i][j]);
28	   }
29
30	// update the vector for this process
31        for (int j = 0; j < N; j++) 
32           M[myId][j] = Math.max(M[myId][j], W[srcId][j]);
33
34        M[myId][myId]++;
35    }
36    public int getValue(int i, int j) {
37        return M[i][j];
38    }
39}