A nice example of using OoOJava to parallelize an algorithm that is much clearer...
authorjjenista <jjenista>
Tue, 25 May 2010 23:18:54 +0000 (23:18 +0000)
committerjjenista <jjenista>
Tue, 25 May 2010 23:18:54 +0000 (23:18 +0000)
Robust/src/Benchmarks/Java-Single/mergeSort/MergeSort.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/mergeSort/makefile [new file with mode: 0644]

diff --git a/Robust/src/Benchmarks/Java-Single/mergeSort/MergeSort.java b/Robust/src/Benchmarks/Java-Single/mergeSort/MergeSort.java
new file mode 100644 (file)
index 0000000..19b6a41
--- /dev/null
@@ -0,0 +1,82 @@
+public class Record {
+  int key;
+  char[] data;
+  public Record( int k ) {
+    key = k;
+    data = new char[250];
+  }
+}
+
+public class MergeSort {
+
+  static public void main( String[] args ) {
+    
+    int problemSize = 20000;
+    int numProblems = 100;
+    
+    for( int p = 0; p < numProblems; ++p ) {
+
+      rblock doAProblem {      
+
+        Record[] records = new Record[problemSize];    
+        
+        Random random = new Random( p );
+        
+        for( int i = 0; i < problemSize; ++i ) {
+          int k = random.nextInt();
+          if( k < 0 ) { k *= -1; }
+          k = k % 1000;
+          records[i] = new Record( k );
+        }
+
+        mergeSort( records );                
+      }
+    }
+  }
+
+
+  static public void mergeSort( Record[] a ) {
+    if( a.length <= 1 ) {
+      //insertionSort( a );, but for len < 10, 14 ish
+      return;
+    }
+
+    int middle = a.length / 2;
+
+    rblock sortLeft {
+      Record[] l = new Record[middle];
+      for( int i = 0; i < middle; ++i ) {
+        l[i] = a[i];
+      }
+      mergeSort( l );
+    }
+
+    rblock sortRight {
+      Record[] r = new Record[a.length - middle];
+      for( int i = middle; i < a.length; ++i ) {
+        r[i - middle] = a[i];
+      }
+      mergeSort( r );
+    }
+    
+    int lpos = 0;
+    int rpos = 0;
+    for( int i = 0; i < a.length; ++i ) {
+
+      if( rpos == r.length ) {
+        a[i] = l[lpos]; ++lpos;
+
+      } else if( lpos == l.length ) {
+        a[i] = r[rpos]; ++rpos;
+
+      } else if( l[lpos].key < r[rpos].key ) {
+        a[i] = l[lpos]; ++lpos;
+        
+      } else {
+        a[i] = r[rpos]; ++rpos;
+      }
+
+    }    
+  }
+
+}
diff --git a/Robust/src/Benchmarks/Java-Single/mergeSort/makefile b/Robust/src/Benchmarks/Java-Single/mergeSort/makefile
new file mode 100644 (file)
index 0000000..cf8984c
--- /dev/null
@@ -0,0 +1,47 @@
+PROGRAM=MergeSort
+
+PROGRAM1=msSingle
+PROGRAM2=msMulti
+
+SOURCE_FILES=MergeSort.java
+
+BUILDSCRIPT=../../../buildscript
+
+USE64BIT= -64bit
+USEMLP=  -mlp 8 2 -mlpdebug  # use to turn mlp on and off and make sure rest of build not broken
+BSFLAGS= -nooptimize -debug -garbagestats -mainclass $(PROGRAM)
+OWNERSHIP= -ownership -ownallocdepth 1 -enable-assertions  -methodeffects -flatirusermethods -ownwritedots final -ownaliasfile aliases.txt 
+
+default: single
+#      ../../../buildscript -nojava $(USEMLP) $(USE64BIT) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM) $(SOURCE_FILES)
+
+single:
+       ../../../buildscript $(USE64BIT) $(BSFLAGS) -o $(PROGRAM) $(SOURCE_FILES)
+
+java:
+       ../../../buildscript $(USEMLP) $(USE64BIT) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM) $(SOURCE_FILES)
+
+both32bit: $(PROGRAM1).bin $(PROGRAM2).bin
+
+
+$(PROGRAM1).bin: $(SOURCE_FILES)
+       $(BUILDSCRIPT)           $(BSFLAGS) -o $(PROGRAM1) $(SOURCE_FILES)
+       rm -fr tmpbuilddirectory
+
+$(PROGRAM2).bin: $(SOURCE_FILES)
+       $(BUILDSCRIPT) $(USEMLP) $(BSFLAGS) -o $(PROGRAM2) $(SOURCE_FILES)
+
+
+
+clean:
+       rm -f  $(PROGRAM).bin
+       rm -f  $(PROGRAM1).bin
+       rm -f  $(PROGRAM2).bin
+       rm -fr tmpbuilddirectory
+       rm -f  *~
+       rm -f  *.dot
+       rm -f  *.png
+       rm -f  *.txt
+       rm -f  aliases.txt
+       rm -f  mlpReport*txt
+       rm -f  results*txt