소스 검색

permuteindex and permutetarget execute in parallel now

Boyoung- 9 년 전
부모
커밋
700b59ccdb
3개의 변경된 파일97개의 추가작업 그리고 8개의 파일을 삭제
  1. 58 4
      src/protocols/Eviction.java
  2. 36 1
      src/protocols/PermuteTarget.java
  3. 3 3
      src/protocols/Pipeline.java

+ 58 - 4
src/protocols/Eviction.java

@@ -9,6 +9,7 @@ import communication.Communication;
 import gc.GCUtil;
 import oram.Bucket;
 import oram.Forest;
+import oram.Global;
 import oram.Metadata;
 import oram.Tree;
 import oram.Tuple;
@@ -23,10 +24,17 @@ public class Eviction extends Protocol {
 
 	private int pid = P.EVI;
 
+	private Communication[] cons;
+
 	public Eviction(Communication con1, Communication con2) {
 		super(con1, con2);
 	}
 
+	public Eviction(Communication[] cons) {
+		super(cons[0], cons[1]);
+		this.cons = cons;
+	}
+
 	private int[] prepareEviction(int target[], int[] ti, int W) {
 		int d = ti.length;
 		int[] evict = new int[W * d];
@@ -155,12 +163,33 @@ public class Eviction extends Protocol {
 					(logW + 7) / 8);
 		}
 
-		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
-		int[] target_pp = permutetarget.runD(predata, firstTree, outKeys[0], timer);
+		PermuteTarget permutetarget = null;
+		int[] target_pp = null;
+		Timer t = null;
+		Thread thread = null;
+		if (!Global.pipeline) {
+			permutetarget = new PermuteTarget(con1, con2);
+			target_pp = permutetarget.runD(predata, firstTree, outKeys[0], timer);
+		} else {
+			permutetarget = new PermuteTarget(cons[2], cons[3]);
+			t = new Timer();
+			permutetarget.setArgs(Party.Debbie, predata, firstTree, outKeys[0], t);
+			thread = new Thread(permutetarget);
+			thread.start();
+		}
 
 		PermuteIndex permuteindex = new PermuteIndex(con1, con2);
 		int[] ti_pp = permuteindex.runD(predata, firstTree, ti_p, w, timer);
 
+		if (Global.pipeline) {
+			try {
+				thread.join();
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			target_pp = permutetarget.getReturn();
+		}
+
 		int W = (int) Math.pow(2, logW);
 		int[] evict = prepareEviction(target_pp, ti_pp, W);
 
@@ -174,6 +203,9 @@ public class Eviction extends Protocol {
 		OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), pathBuckets);
 
 		timer.stop(pid, M.online_comp);
+
+		if (Global.pipeline)
+			timer.add(t);
 	}
 
 	public void runC(PreData predata, boolean firstTree, Tuple[] originalPath, int d, int sw, int w, Timer timer) {
@@ -204,12 +236,31 @@ public class Eviction extends Protocol {
 		con2.write(pid, C_labelInputKeys);
 		timer.stop(pid, M.online_write);
 
-		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
-		permutetarget.runC(predata, firstTree, timer);
+		PermuteTarget permutetarget = null;
+		Timer t = null;
+		Thread thread = null;
+		if (!Global.pipeline) {
+			permutetarget = new PermuteTarget(con1, con2);
+			permutetarget.runC(predata, firstTree, timer);
+		} else {
+			permutetarget = new PermuteTarget(cons[2], cons[3]);
+			t = new Timer();
+			permutetarget.setArgs(Party.Charlie, predata, firstTree, null, t);
+			thread = new Thread(permutetarget);
+			thread.start();
+		}
 
 		PermuteIndex permuteindex = new PermuteIndex(con1, con2);
 		permuteindex.runC(predata, firstTree, timer);
 
+		if (Global.pipeline) {
+			try {
+				thread.join();
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+
 		int logW = (int) Math.ceil(Math.log(w + 1) / Math.log(2));
 		int W = (int) Math.pow(2, logW);
 		for (int i = 0; i < d; i++) {
@@ -245,6 +296,9 @@ public class Eviction extends Protocol {
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);
+
+		if (Global.pipeline)
+			timer.add(t);
 	}
 
 	// for testing correctness

+ 36 - 1
src/protocols/PermuteTarget.java

@@ -18,14 +18,33 @@ import util.P;
 import util.Timer;
 import util.Util;
 
-public class PermuteTarget extends Protocol {
+public class PermuteTarget extends Protocol implements Runnable {
 
 	private int pid = P.PT;
 
+	private Party party;
+	private PreData predata;
+	private boolean firstTree;
+	private GCSignal[][] targetOutKeys;
+	private Timer timer;
+	private int[] target;
+
 	public PermuteTarget(Communication con1, Communication con2) {
 		super(con1, con2);
 	}
 
+	public void setArgs(Party party, PreData predata, boolean firstTree, GCSignal[][] targetOutKeys, Timer timer) {
+		this.party = party;
+		this.predata = predata;
+		this.firstTree = firstTree;
+		this.targetOutKeys = targetOutKeys;
+		this.timer = timer;
+	}
+
+	public int[] getReturn() {
+		return target;
+	}
+
 	public void runE() {
 	}
 
@@ -100,6 +119,22 @@ public class PermuteTarget extends Protocol {
 		timer.stop(pid, M.online_comp);
 	}
 
+	@Override
+	public void run() {
+		if (party == Party.Eddie) {
+			runE();
+
+		} else if (party == Party.Debbie) {
+			target = runD(predata, firstTree, targetOutKeys, timer);
+
+		} else if (party == Party.Charlie) {
+			runC(predata, firstTree, timer);
+
+		} else {
+			throw new NoSuchPartyException(party + "");
+		}
+	}
+
 	// for testing correctness
 	@Override
 	public void run(Party party, Metadata md, Forest forest) {

+ 3 - 3
src/protocols/Pipeline.java

@@ -47,7 +47,7 @@ public class Pipeline extends Thread {
 		Reshuffle reshuffle = new Reshuffle(cons[2], cons[3]);
 		PostProcessT postprocesst = new PostProcessT(cons[0], cons[1]);
 		UpdateRoot updateroot = new UpdateRoot(cons[0], cons[1]);
-		Eviction eviction = new Eviction(cons[0], cons[1]);
+		Eviction eviction = new Eviction(cons);
 
 		Timer t = new Timer();
 		reshuffle.setArgs(Party.Eddie, predata[0], outaccess.E_P, OTi.getTreeIndex() == 0, t);
@@ -85,7 +85,7 @@ public class Pipeline extends Thread {
 		Reshuffle reshuffle = new Reshuffle(cons[2], cons[3]);
 		PostProcessT postprocesst = new PostProcessT(cons[0], cons[1]);
 		UpdateRoot updateroot = new UpdateRoot(cons[0], cons[1]);
-		Eviction eviction = new Eviction(cons[0], cons[1]);
+		Eviction eviction = new Eviction(cons);
 
 		// no extra thread for D's reshuffle and postprocesst
 		// because D does nothing online in these two protocols
@@ -107,7 +107,7 @@ public class Pipeline extends Thread {
 		Reshuffle reshuffle = new Reshuffle(cons[2], cons[3]);
 		PostProcessT postprocesst = new PostProcessT(cons[0], cons[1]);
 		UpdateRoot updateroot = new UpdateRoot(cons[0], cons[1]);
-		Eviction eviction = new Eviction(cons[0], cons[1]);
+		Eviction eviction = new Eviction(cons);
 
 		Timer t = new Timer();
 		reshuffle.setArgs(Party.Charlie, predata[0], outaccess.C_P, ti == 0, t);