add multi-core version for PERT benchmark
authorjzhou <jzhou>
Tue, 15 Jul 2008 21:39:19 +0000 (21:39 +0000)
committerjzhou <jzhou>
Tue, 15 Jul 2008 21:39:19 +0000 (21:39 +0000)
Robust/src/Benchmarks/PERT/Mcore/Estimator.java [new file with mode: 0644]
Robust/src/Benchmarks/PERT/Mcore/PERT.java [new file with mode: 0644]
Robust/src/Benchmarks/PERT/Mcore/Stage.java [new file with mode: 0644]

diff --git a/Robust/src/Benchmarks/PERT/Mcore/Estimator.java b/Robust/src/Benchmarks/PERT/Mcore/Estimator.java
new file mode 100644 (file)
index 0000000..a2232dc
--- /dev/null
@@ -0,0 +1,107 @@
+public class Estimator {
+    flag estimate;
+    flag prob;
+
+    int stages;
+    int time;
+    double variance;
+    double[] probtable;
+
+    public Estimator(int stages) {
+       this.stages = stages;
+       this.time = 0;
+       this.variance = 0;
+
+       this.probtable = new double[31];
+       int i = 0;
+       this.probtable[i++] = 0.5000;
+       this.probtable[i++] = 0.5398;
+       this.probtable[i++] = 0.5793;
+       this.probtable[i++] = 0.6179;
+       this.probtable[i++] = 0.6554;
+       this.probtable[i++] = 0.6915;
+       this.probtable[i++] = 0.7257;
+       this.probtable[i++] = 0.7580;
+       this.probtable[i++] = 0.7881;
+       this.probtable[i++] = 0.8159;
+       this.probtable[i++] = 0.8413;
+       this.probtable[i++] = 0.8643;
+       this.probtable[i++] = 0.8849;
+       this.probtable[i++] = 0.9032;
+       this.probtable[i++] = 0.9192;
+       this.probtable[i++] = 0.9332;
+       this.probtable[i++] = 0.9452;
+       this.probtable[i++] = 0.9554;
+       this.probtable[i++] = 0.9641;
+       this.probtable[i++] = 0.9713;
+       this.probtable[i++] = 0.9772;
+       this.probtable[i++] = 0.9821;
+       this.probtable[i++] = 0.9861;
+       this.probtable[i++] = 0.9893;
+       this.probtable[i++] = 0.9918;
+       this.probtable[i++] = 0.9938;
+       this.probtable[i++] = 0.9953;
+       this.probtable[i++] = 0.9965;
+       this.probtable[i++] = 0.9974;
+       this.probtable[i++] = 0.9981;
+       this.probtable[i++] = 0.9987;
+    }
+
+    public boolean estimate(int time, double variance2) {
+       System.printI(0xff30);
+       this.time += time;
+       this.variance += variance2;
+       --this.stages;
+       System.printI(0xff31);
+       System.printI(this.stages);
+       System.printI(this.time);
+       System.printI((int)this.variance);
+       if(this.stages == 0) {
+               System.printI(0xff32);
+           //System.printString("variance2: " + (int)(this.variance*100) + "(/100); ");
+           this.variance = Math.sqrt(this.variance);
+           //System.printString("variance: " + (int)(this.variance*100) + "(/100)\n");
+           return true;
+       }
+       System.printI(0xff33);
+       return false;
+    }
+
+    public double getProbability(int x, int y) {
+       int l = x;
+       int r = y;
+       if(x > y) {
+           l = y;
+           r = x;
+       }
+
+       double prob = prob(r) - prob(l);
+       return prob;
+    }
+
+    private double prob(int s) {
+       int tmp = (int)((s - this.time) * 10 / this.variance);
+       //System.printString(tmp + "\n");
+       int abs = (int)Math.abs(tmp);
+       double prob = 0;
+       if(abs > this.probtable.length - 1) {
+           prob = 1;
+       } else {
+           prob = this.probtable[abs];
+       }
+       if(tmp < 0) {
+           return 1.0 - prob;
+       } else {
+           return prob;
+       }
+    }
+
+    public int getTime() {
+       return this.time;
+    }
+
+    public double getVariance() {
+       return this.variance;
+    }
+
+}
diff --git a/Robust/src/Benchmarks/PERT/Mcore/PERT.java b/Robust/src/Benchmarks/PERT/Mcore/PERT.java
new file mode 100644 (file)
index 0000000..1aa9119
--- /dev/null
@@ -0,0 +1,56 @@
+task t1(StartupObject s{initialstate}) {
+    System.printString("task t1\n");
+    int stages = 2;
+    Estimator estimator = new Estimator(stages){estimate};
+    for(int i = 0; i < stages; ++i) {
+       Stage stage = new Stage(i){sampling};
+    }
+
+    taskexit(s{!initialstate});
+}
+
+task t2(Stage s{sampling}) {
+    System.printString("task t2\n");
+
+    s.sampling();
+
+    taskexit(s{!sampling, estimate});
+}
+
+task t3(Stage s{estimate}) {
+    System.printString("task t3\n");
+
+    s.estimate();
+
+    taskexit(s{!estimate, merge});
+}
+
+task t4(Estimator e{estimate}, Stage s{merge}) {
+    System.printString("task t4\n");
+
+    boolean fake = false;
+    boolean finish = e.estimate(s.getAntTime(), s.getAntVariance2());
+
+    if(finish) {
+       System.printI(0xff40);
+       taskexit(e{!estimate, prob}, s{!merge});
+    } else {
+       System.printI(0xff41);
+       taskexit(s{!merge});
+    }
+}
+
+task t5(Estimator e{prob}) {
+    System.printString("task t5\n");
+
+    int x = 10;
+    int y = 20;
+    System.printString("x: " + x + "; y: " + y + "\n");
+    System.printString("The anticipate days need to finish this project is: " + e.getTime() + "\n");
+    System.printString("And the anticipate variance is: " + (int)(e.getVariance()*100) + "(/100)\n");
+    double prob = e.getProbability(x, y);
+
+    System.printString("The probability of this project to be finished in " + x + " to " + y + " days is: " + (int)(prob*100) + "%\n");
+       System.printI((int)(prob*100));
+    taskexit(e{!prob});
+}
diff --git a/Robust/src/Benchmarks/PERT/Mcore/Stage.java b/Robust/src/Benchmarks/PERT/Mcore/Stage.java
new file mode 100644 (file)
index 0000000..79d6857
--- /dev/null
@@ -0,0 +1,92 @@
+public class Stage {
+    flag sampling;
+    flag estimate;
+    flag merge;
+
+    int ID;
+
+    int[] samplings;
+    int optime;
+    int nortime;
+    int petime;
+    int time;
+    double variance2;
+
+    public Stage(int id) {
+       System.printI(0xff20);
+       this.ID = id;
+
+       this.samplings = new int[10];
+       System.printI(0xff21);
+       for(int i = 0; i < this.samplings.length; ++i) {
+               System.printI(0xff22);
+           this.samplings[i] = 0;
+       }
+       System.printI(0xff23);
+
+       this.optime = 0;
+       this.nortime = 0;
+       this.petime = 0;
+       this.time = 0;
+       this.variance2 = 0;
+       System.printI(0xff24);
+    }
+
+    public void sampling() {
+       System.printI(0xff00);
+       Random r = new Random(ID);
+       System.printI(0xff01);
+       int tint = 0;
+       System.printI(this.samplings.length);
+       for(int i = 0; i < this.samplings.length; ++i) {
+           do {
+               tint = r.nextInt()%50;
+           } while(tint <= 0);
+               System.printI(0xff02);
+           this.samplings[i] = tint;
+           //System.printString(tint + "; ");
+       }
+       System.printI(0xff03);
+    }
+
+    public void estimate() {
+       System.printI(0xff10);
+       int highest = this.samplings[0];
+       System.printI(0xff12);
+       int lowest = this.samplings[0];
+       int sum = this.samplings[0];
+       System.printI(0xff13);
+       System.printI(this.samplings.length);
+       for(int i = 1; i < this.samplings.length; ++i) {
+               System.printI(0xff14);
+           int temp = this.samplings[i];
+           if(temp > highest) {
+               highest = temp;
+           } else if(temp < lowest) {
+               lowest = temp;
+           }
+           sum += temp;
+       }
+       System.printI(0xff15);
+       sum  = sum - highest - lowest;
+       int ordinary = sum / (this.samplings.length - 2);
+       this.optime = lowest;;
+       this.petime = highest;
+       this.nortime = ordinary;
+       System.printI(0xff16);
+       this.time = (this.optime + 4 * this.nortime + this.petime) / 6;
+       System.printI(0xff17);
+       this.variance2 = (double)(this.optime - this.petime) * (double)(this.optime - this.petime) / 36.0;
+       System.printI(0xff18);
+       //System.printString("Op time: " + this.optime + "; Nor time: " + this.nortime + "; Pe time: " + this.petime + "; variance2: " + (int)(this.variance2*100) + "(/100)\n");
+    }
+
+    public int getAntTime() {
+       return this.time;
+    }
+
+    public double getAntVariance2() {
+       return this.variance2;
+    }
+
+}