simple microbenchmark to study locking
authoradash <adash>
Wed, 5 Aug 2009 00:49:31 +0000 (00:49 +0000)
committeradash <adash>
Wed, 5 Aug 2009 00:49:31 +0000 (00:49 +0000)
Robust/src/Benchmarks/SingleTM/MicroBenchmarks/README [new file with mode: 0644]
Robust/src/Benchmarks/SingleTM/MicroBenchmarks/SingleObjectMod.java [new file with mode: 0644]
Robust/src/Benchmarks/SingleTM/MicroBenchmarks/makefile [new file with mode: 0644]

diff --git a/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/README b/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/README
new file mode 100644 (file)
index 0000000..e246752
--- /dev/null
@@ -0,0 +1,24 @@
+SingleObjectMod.java:
+----------------------
+ Completes two transactions on single object type inside one loop iteration. The first transaction reads from the 
+ object while the second transaction randomly generates an index and writes into the object.
+ The contention is controlled by decreasing and increasing the size of the shared object array. Also
+ we get high contention by increasing the number of loop iterations to regulate the number of 
+ transactions that will commit.
+
+ Compiling and Running
+ ----------------------
+
+  To build: 
+  make stmlock
+  e.g. ~/research/Robust/src/Benchmarks/SingleTM/MicroBenchmarks$ make clean && make stmlock
+
+  To run:
+  ./STATSSingleObjectMod.bin -t <num threads>
+                             -size <array size>
+                             -l <loopsize>
+  
+  low contention:  -t 8 -size 5000 -l 100
+  high contention: -t 8 -size 5 -l 500000
+
diff --git a/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/SingleObjectMod.java b/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/SingleObjectMod.java
new file mode 100644 (file)
index 0000000..8658663
--- /dev/null
@@ -0,0 +1,106 @@
+public class SingleObjectMod extends Thread {
+  int nthreads;
+  int arrysize;
+  int loopsize;
+  int threadid;
+  intwrapper[] mainobj;
+  Random rand;
+
+  public SingleObjectMod() {
+
+  }
+
+  public SingleObjectMod(int nthreads, int arrysize, int loopsize, int threadid, intwrapper[] mainobj, Random rand) {
+    this.nthreads = nthreads;
+    this.arrysize = arrysize;
+    this.loopsize = loopsize;
+    this.threadid = threadid;
+    this.mainobj = mainobj;
+    this.rand = rand;
+  }
+
+  public static void parseCmdLine(String args[], SingleObjectMod som) {
+    int i = 0;
+    String arg;
+    while(i < args.length && args[i].startsWith("-")) {
+      arg = args[i++];
+      //check options
+      if(arg.equals("-t")) {
+        if(i < args.length) {
+          som.nthreads = new Integer(args[i++]).intValue();
+        }
+      } else if(arg.equals("-size")) {
+        if(i <  args.length) {
+          som.arrysize = new Integer(args[i++]).intValue();
+        }
+      } else if(arg.equals("-l")) {
+        if(i < args.length) {
+          som.loopsize = new Integer(args[i++]).intValue();
+        }
+      } else {
+        System.out.println("Incorrect argument");
+        System.out.println("usage: ./SingleObjectMod -t <threads> -size <array size> -l <loopsize>\n");
+      }
+    }
+  }
+
+  public void run() {
+    int index, val;
+    Random rand = new Random();
+    rand.random_alloc();
+    rand.random_seed(threadid);
+    int partitionSize = (loopsize + nthreads/2) /nthreads;
+    int start = threadid * partitionSize;
+    int stop;
+    if(threadid == (nthreads - 1))
+      stop = loopsize;
+    else
+      stop = start + partitionSize;
+    //System.out.println("Start = " + start+ " stop= " + stop + " partitionSize= " + partitionSize+ " nthreads= " + nthreads);
+    for(int i = start; i < stop; i++) {
+      // Only read values from an object
+      atomic {
+        index = (int)(rand.random_generate() % arrysize);
+        val = mainobj[index];
+      }
+
+      // Write values 
+      atomic {
+        index = (int)(rand.random_generate() % arrysize);
+        mainobj[index] = index;
+      }
+    }
+  }
+
+  public static void main(String[] args) {
+    SingleObjectMod som = new SingleObjectMod();
+    SingleObjectMod.parseCmdLine(args, som);
+    som.mainobj = new intwrapper[som.arrysize];
+
+    Random rand = new Random();
+    rand.random_alloc();
+
+    for(int i = 0; i<som.arrysize; i++) {
+      som.mainobj[i] = i;
+    }
+
+    int nthreads = som.nthreads;
+    System.out.println("Num threads= "+ nthreads);
+
+    SingleObjectMod[] mysom = new SingleObjectMod[nthreads];
+    for(int i = 0; i < nthreads; i++) {
+      mysom[i] = new SingleObjectMod(nthreads, som.arrysize, som.loopsize, i, som.mainobj, rand);
+    }
+
+    for(int i = 0; i < nthreads; i++) {
+      mysom[i].start();
+    }
+
+    for(int i = 0; i < nthreads; i++) {
+      mysom[i].join();
+    }
+
+    System.out.println("Finished......");
+    System.exit(0);
+  }
+}
diff --git a/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/makefile b/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/makefile
new file mode 100644 (file)
index 0000000..655a510
--- /dev/null
@@ -0,0 +1,13 @@
+MAINCLASS=SingleObjectMod
+SRC=${MAINCLASS}.java \
+    ../KMeans/Random.java \
+    ../../../ClassLibrary/intwrapper.java
+
+FLAGSSTATS=-mainclass ${MAINCLASS} -singleTM -optimize -debug -joptimize -64bit -abcclose -dcopts -transstats -arraypad
+
+stmlock:
+       ../../../buildscript ${FLAGSSTATS} ${SRC} -o STATS${MAINCLASS}
+
+clean:
+       rm -rf tmpbuilddirectory 
+       rm *.bin