Basic RainForest benchmark that compiles...needs more work
authoradash <adash>
Fri, 27 Feb 2009 21:01:01 +0000 (21:01 +0000)
committeradash <adash>
Fri, 27 Feb 2009 21:01:01 +0000 (21:01 +0000)
Robust/src/Benchmarks/Distributed/RainForest/dsm/Barrier.java [new file with mode: 0644]
Robust/src/Benchmarks/Distributed/RainForest/dsm/GameMap.java [new file with mode: 0644]
Robust/src/Benchmarks/Distributed/RainForest/dsm/Player.java [new file with mode: 0644]
Robust/src/Benchmarks/Distributed/RainForest/dsm/RainForest.java [new file with mode: 0644]
Robust/src/Benchmarks/Distributed/RainForest/dsm/RockType.java [new file with mode: 0644]
Robust/src/Benchmarks/Distributed/RainForest/dsm/TreeType.java [new file with mode: 0644]
Robust/src/Benchmarks/Distributed/RainForest/dsm/extractLines [new file with mode: 0755]
Robust/src/Benchmarks/Distributed/RainForest/dsm/makefile [new file with mode: 0644]

diff --git a/Robust/src/Benchmarks/Distributed/RainForest/dsm/Barrier.java b/Robust/src/Benchmarks/Distributed/RainForest/dsm/Barrier.java
new file mode 100644 (file)
index 0000000..f8389c4
--- /dev/null
@@ -0,0 +1,52 @@
+public class BarrierServer extends Thread {
+  int numthreads;
+  boolean done;
+
+  public BarrierServer(int n) {
+    numthreads=n;
+    done=false;
+  }
+
+  public void run() {
+    int n;
+    ServerSocket ss=new ServerSocket(2000);
+    atomic {
+      n=numthreads;
+      done=true;
+    }
+    Socket ar[]=new Socket[n];
+    for(int i=0; i<n; i++) {
+      ar[i]=ss.accept();
+    }
+
+    while(true) {
+      for(int j=0; j<n; j++) {
+       Socket s=ar[j];
+       byte b[]=new byte[1];
+       while(s.read(b)!=1) {
+         ;
+       }
+      }
+      byte b[]=new byte[1];
+      b[0]= (byte) 'A';
+      for(int j=0; j<n; j++)
+       ar[j].write(b);
+    }
+  }
+}
+
+public class Barrier {
+  Socket s;
+  public Barrier(String name) {
+    s=new Socket(name, 2000);
+  }
+
+  public static void enterBarrier(Barrier barr) {
+    byte b[]=new byte[1];
+    b[0]=(byte)'A';
+    barr.s.write(b);
+    while(barr.s.read(b)!=1) {
+      ;
+    }
+  }
+}
diff --git a/Robust/src/Benchmarks/Distributed/RainForest/dsm/GameMap.java b/Robust/src/Benchmarks/Distributed/RainForest/dsm/GameMap.java
new file mode 100644 (file)
index 0000000..5e35b65
--- /dev/null
@@ -0,0 +1,38 @@
+public class GameMap {
+  private TreeType tree;
+  private RockType rock;
+
+  public GameMap() {
+    tree = null;
+    rock = null;
+  }
+
+  public boolean hasTree() {
+    if (tree != null) {
+      return true;
+    }
+    return false;
+  }
+
+  public boolean hasRock() {
+    if (rock != null) {
+      return true;
+    } 
+    return false;
+  }
+
+  public void putTree(TreeType t) {
+    tree = t;
+  }
+
+  public void putRock(RockType r) {
+    rock = r;
+  }
+
+  public boolean isEmpty() {
+    if (tree == null && rock == null) {
+      return true;
+    }
+    return false;
+  }
+}
diff --git a/Robust/src/Benchmarks/Distributed/RainForest/dsm/Player.java b/Robust/src/Benchmarks/Distributed/RainForest/dsm/Player.java
new file mode 100644 (file)
index 0000000..080e332
--- /dev/null
@@ -0,0 +1,66 @@
+public class Player {
+  private int type;
+  private int x;
+  private int y;
+  private int id;
+  private int lowx, highx;
+  private int lowy, highy;
+
+  public Player(int type) {
+    this.type = type;
+    x = -1;
+    y = -1;
+    id = -1;
+  }
+
+  public Player(int type, int x, int y) {
+    this.type = type;
+    this.x = x;
+    this.y = y;
+    id = -1;
+  }
+
+  public Player(int type, int x, int y, int id, int rows, int cols, int bounds) {
+    this.type = type;
+    this.x = x;
+    this.y = y;
+    this.id = id;
+    lowx = x - bounds;
+    highx = x + bounds;
+    lowy = y - bounds;
+    highy = y + bounds;
+    // define new boundaries
+    if (lowx <= 0) 
+      lowx = 1;
+    if (lowy <= 0) 
+      lowy = 1;
+    if (highx >= rows) 
+      highx = rows-1;
+    if (highy >= cols) 
+      highx = cols-1;
+  }
+
+  public int kind() {
+    return type;
+  }
+
+  public void setPosition(int x, int y) {
+    this.x = x;
+    this.y = y;
+    return;
+  }
+
+  public int getX() {
+    return x;
+  } 
+  
+  public int getY() { 
+    return y; 
+  }
+
+  public int getId() {
+    return id;
+  }
+
+}
+
diff --git a/Robust/src/Benchmarks/Distributed/RainForest/dsm/RainForest.java b/Robust/src/Benchmarks/Distributed/RainForest/dsm/RainForest.java
new file mode 100644 (file)
index 0000000..061a414
--- /dev/null
@@ -0,0 +1,130 @@
+#define ROW       10     /* columns in the map */
+#define COLUMN    10    /* rows of in the map */
+#define ROUNDS    100   /* Number of moves by each player */
+#define PLAYERS   20    /* Number of Players when num Players != num of client machines */
+#define RATI0     0.5   /* Number of lumberjacks to number of planters */
+#define BLOCK     3     /* Area around the gamer to consider */
+#define TREE_ZONE 0.4   /* Max percentage of trees in a zone */
+
+#define LUMBERJACK 0
+#define PLANTER    1
+
+public class RainForest extends Thread {
+  GameMap land;
+  Player gamer;
+
+  public RainForest(GameMap land, Player gamer) {
+    this.land = land;
+    this.gamer = gamer;
+  }
+
+  public void run() {
+    // For N interations do one move and synchronise
+    return;
+  }
+
+  public static void main(String[] args) {
+    int numThreads= 1;
+    BarrierServer mybarr;
+
+    int[] mid = new int[8];
+    mid[0] = (128<<24)|(195<<16)|(136<<8)|162;//dc-1
+    mid[1] = (128<<24)|(195<<16)|(136<<8)|163;//dc-2
+    mid[2] = (128<<24)|(195<<16)|(136<<8)|164;//dc-3
+    mid[3] = (128<<24)|(195<<16)|(136<<8)|165;//dc-4
+    mid[4] = (128<<24)|(195<<16)|(136<<8)|166;//dc-5
+    mid[5] = (128<<24)|(195<<16)|(136<<8)|167;//dc-6
+    mid[6] = (128<<24)|(195<<16)|(136<<8)|168;//dc-7
+    mid[7] = (128<<24)|(195<<16)|(136<<8)|169;//dc-8
+
+    // Init land and place rocks in boundaries
+    GameMap[][] world;
+    atomic {
+      mybarr = global new BarrierServer(numThreads);
+      world = global new GameMap[ROW][COLUMN];
+      int i, j;
+      for (i = 0; i < ROW; i++) {
+        for (j = 0; j < COLUMN; j++) {
+          world[i][j] = global new GameMap();
+          if (j == 0 || j == COLUMN-1) {
+            RockType r = global new RockType();
+            world[i][j].putRock(r);
+          }
+        }
+        if (i == 0 || i == ROW-1) {
+          RockType r = global new RockType();
+          world[i][j].putRock(r);
+        }
+      }
+    }
+
+    mybarr.start(mid[0]);
+
+    // Create P players
+    // Parse args get number of threads
+    // For each thread, init either a lumberjack/planter
+    Player[] players;
+    atomic {
+      players = global new Player[numThreads];
+      for (int i = 0; i < numThreads; i++) {
+        Random rand = new Random(i);
+        int row = rand.nextInt(ROW-1);
+        int col = rand.nextInt(COLUMN-1);
+        int type = rand.nextInt(1);
+        int person;
+        if (type == 0) {
+          person = LUMBERJACK;
+        } else {
+          person = PLANTER;
+        }
+        players[i] = global new Player(person, row, col, i, ROW, COLUMN, BLOCK);
+      }
+    }
+
+    // Set up threads 
+    RainForest[] rf;
+    atomic {
+      rf = global new RainForest[numThreads];
+      for(int i=0; i<numThreads; i++) {
+        Random rand = new Random(i);
+        int row = rand.nextInt(ROW-1);
+        int col = rand.nextInt(COLUMN-1);
+        rf[i] = global new RainForest(world[row][col], players[i]);
+      }
+    }
+
+    boolean waitforthreaddone = true;
+    while(waitforthreaddone) {
+      atomic {
+        if(mybarr.done)
+          waitforthreaddone = false;
+      }
+    }
+
+    RainForest tmp;
+    /* Start threads */
+    for(int i = 0; i<numThreads; i++) {
+      atomic {
+        tmp = rf[i];
+      }
+      tmp.start(mid[i]);
+    }
+
+    /* Join threads */
+    for(int i = 0; i<numThreads; i++) {
+      atomic {
+        tmp = rf[i];
+      }
+      tmp.join();
+    }
+
+    System.printString("Finished\n");
+
+  }
+
+  //TODO
+  public void doOneMove() {
+
+
+  }
+}
diff --git a/Robust/src/Benchmarks/Distributed/RainForest/dsm/RockType.java b/Robust/src/Benchmarks/Distributed/RainForest/dsm/RockType.java
new file mode 100644 (file)
index 0000000..315677b
--- /dev/null
@@ -0,0 +1,15 @@
+public class RockType {
+  private char color;
+
+  public RockType() {
+    color = (char)0;
+  }
+
+  public RockType(char color) {
+    this.color = color;
+  }
+
+  public char getColor() {
+      return color;
+  }
+}
diff --git a/Robust/src/Benchmarks/Distributed/RainForest/dsm/TreeType.java b/Robust/src/Benchmarks/Distributed/RainForest/dsm/TreeType.java
new file mode 100644 (file)
index 0000000..a4718cc
--- /dev/null
@@ -0,0 +1,15 @@
+public class TreeType {
+  private int age;
+
+  public TreeType() {
+    age = 0;
+  }
+
+  public int getage() {
+    return age;
+  }
+
+  public void incrementAge() {
+    age++;
+  }
+}
diff --git a/Robust/src/Benchmarks/Distributed/RainForest/dsm/extractLines b/Robust/src/Benchmarks/Distributed/RainForest/dsm/extractLines
new file mode 100755 (executable)
index 0000000..c2953ed
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh -x
+lines=$(grep -n "#" tmp1RainForest.java | cut -d: -f1 | sed '1q')
+sed '/#/d' tmp1RainForest.java > tmpRainForest.java
diff --git a/Robust/src/Benchmarks/Distributed/RainForest/dsm/makefile b/Robust/src/Benchmarks/Distributed/RainForest/dsm/makefile
new file mode 100644 (file)
index 0000000..6ce4c58
--- /dev/null
@@ -0,0 +1,21 @@
+MAINCLASS=RainForest
+SRC=tmp${MAINCLASS}.java \
+       Player.java \
+       TreeType.java \
+       GameMap.java \
+       RockType.java \
+       Barrier.java
+
+FLAGS1=-dsm -optimize -mainclass ${MAINCLASS}
+FLAGS2=-dsm -dsmcaching -optimize -mainclass ${MAINCLASS}
+FLAGS3=-dsm -dsmcaching -prefetch -optimize -mainclass ${MAINCLASS} -trueprob 0.90
+FLAGS4=-dsm -dsmcaching -rangeprefetch -optimize -mainclass ${MAINCLASS} -trueprob 0.90
+
+default:
+       cpp ${MAINCLASS}.java > tmp1${MAINCLASS}.java
+       ./extractLines
+       ../../../../buildscript ${FLAGS1} -o ${MAINCLASS}NPNC ${SRC}
+
+clean:
+       rm -rf tmpbuilddirectory
+       rm *.bin