From 32251eb3338c8f14cae725f00053011b29ced8fe Mon Sep 17 00:00:00 2001 From: yeom Date: Tue, 3 Aug 2010 18:47:33 +0000 Subject: [PATCH] polish source code + last changes. --- .../oooJava/barneshut/Barneshut.java | 47 +++++++------------ .../barneshut/OctTreeLeafNodeData.java | 11 +---- .../src/Benchmarks/oooJava/kmeans/KMeans.java | 8 +++- .../oooJava/mergesort/BMergeSort4.java | 4 +- .../oooJava/mergesort/MergeSort.java | 6 +-- .../oooJava/sor/JGFSORBenchSizeD.java | 13 ++--- .../src/Benchmarks/oooJava/sor/SORRunner.java | 2 +- 7 files changed, 36 insertions(+), 55 deletions(-) diff --git a/Robust/src/Benchmarks/oooJava/barneshut/Barneshut.java b/Robust/src/Benchmarks/oooJava/barneshut/Barneshut.java index f7623622..42b97b11 100644 --- a/Robust/src/Benchmarks/oooJava/barneshut/Barneshut.java +++ b/Robust/src/Benchmarks/oooJava/barneshut/Barneshut.java @@ -1,5 +1,3 @@ -import System; - /* Lonestar Benchmark Suite for irregular applications that exhibit amorphous data-parallelism. @@ -164,8 +162,7 @@ public void ComputeCenterOfMass(ArrayIndexedGraph octree, ArrayIndexedNode roo public static void Insert(ArrayIndexedGraph octree, ArrayIndexedNode root, OctTreeLeafNodeData b, double r) { // builds the tree double x = 0.0, y = 0.0, z = 0.0; -// OctTreeNodeData n = octree.getNodeData(root); - OctTreeNodeData n = root.data; + OctTreeNodeData n = octree.getNodeData(root); int i = 0; if (n.posx < b.posx) { i = 1; @@ -186,8 +183,7 @@ public void ComputeCenterOfMass(ArrayIndexedGraph octree, ArrayIndexedNode roo octree.setNeighbor(root, i, newnode); } else { double rh = 0.5 * r; -// OctTreeNodeData ch = octree.getNodeData(child); - OctTreeNodeData ch = child.data; + OctTreeNodeData ch = octree.getNodeData(child); if (!(ch instanceof OctTreeLeafNodeData)) { Insert(octree, child, b, rh); } else { @@ -211,11 +207,11 @@ public void ComputeCenterOfMass(ArrayIndexedGraph octree, ArrayIndexedNode roo mintime =9223372036854775807L; run = 0; - while (((run < 3) || (Math.abs(lasttime-runtime)*64 > min(lasttime, runtime))) && (run < 7)) { +// while (((run < 3) || (Math.abs(lasttime-runtime)*64 > min(lasttime, runtime))) && (run < 7)) { runtime = bh.run(args); if (runtime < mintime) mintime = runtime; run++; - } +// } System.out.println("minimum runtime: " + mintime + " ms"); System.out.println(""); } @@ -244,6 +240,7 @@ public void ComputeCenterOfMass(ArrayIndexedGraph octree, ArrayIndexedNode roo int local_nbodies=nbodies; int local_ntimesteps=ntimesteps; + long start_time = System.currentTimeMillis(); for (int step = 0; step < local_ntimesteps; step++) { // time-step the system ComputeCenterAndDiameter(); ArrayIndexedGraph octree = new ArrayIndexedGraph(8); @@ -259,44 +256,36 @@ public void ComputeCenterOfMass(ArrayIndexedGraph octree, ArrayIndexedNode roo // summarize subtree info in each internal node (plus restructure tree and sort bodies for performance reasons) ComputeCenterOfMass(octree, root); -// long id = Time.getNewTimeId(); - long start_time = System.currentTimeMillis(); for(int i=0; i < local_nbodies; i++){ -// for (OctTreeLeafNodeData n : body) { // compute the acceleration of each body (consumes most of the total runtime) -// n.ComputeForce(octree, root, diameter, itolsq, step, dthf, epssq); + // n.ComputeForce(octree, root, diameter, itolsq, step, dthf, epssq); OctTreeLeafNodeData eachbody=body[i]; double di=diameter; double it=itolsq; double dt=dthf; double ep=epssq; sese parallel{ -// body[i].ComputeForce(octree, root, diameter, itolsq, step, dthf, epssq); -// eachbody.ComputeForce(octree, root, diameter, itolsq, step, dthf, epssq); - eachbody.ComputeForce(octree, root, di, it, step, dt, ep); + eachbody.ComputeForce(octree, di, it, step, dt, ep); } } - long end_time=System.currentTimeMillis(); - runtime += (end_time-start_time); -// runtime += Time.elapsedTime(id); - for (int i = 0; i < local_nbodies; i++) { + + for (int i = 0; i < local_nbodies; i++) { body[i].Advance(dthf, dtime); // advance the position and velocity of each body } + } // end of time step + long end_time=System.currentTimeMillis(); + if (isFirstRun) { - // DecimalFormat df = new DecimalFormat("0.0000E00"); - // for (int i = 0; i < nbodies; i++) { - // System.out.println(df.format(body[i].posx) + " " + - // df.format(body[i].posy) + " " + df.format(body[i].posz)); // print - // result - // } - for (int i = 0; i < local_nbodies; i++) { -// System.out.println(body[i].posx + " " + body[i].posy + " " + body[i].posz); // print - // result - } + /* + for (int i = 0; i < local_nbodies; i++) { + System.out.println(body[i].posx + " " + body[i].posy + " " + body[i].posz); // print result + } + */ System.out.println(""); } + runtime += (end_time-start_time); System.out.println("runtime: " + runtime + " ms"); isFirstRun = false; diff --git a/Robust/src/Benchmarks/oooJava/barneshut/OctTreeLeafNodeData.java b/Robust/src/Benchmarks/oooJava/barneshut/OctTreeLeafNodeData.java index 7552a0e6..1a6dccd2 100644 --- a/Robust/src/Benchmarks/oooJava/barneshut/OctTreeLeafNodeData.java +++ b/Robust/src/Benchmarks/oooJava/barneshut/OctTreeLeafNodeData.java @@ -67,7 +67,7 @@ public class OctTreeLeafNodeData extends OctTreeNodeData { // the tree leaves ar velz = velhz + dvelz; } - void ComputeForce(ArrayIndexedGraph octree, ArrayIndexedNode root, double size, double itolsq, + void ComputeForce(ArrayIndexedGraph octree, double size, double itolsq, int step, double dthf, double epssq) { // computes the acceleration and velocity of a body double ax, ay, az; ax = accx; @@ -87,7 +87,6 @@ public class OctTreeLeafNodeData extends OctTreeNodeData { // the tree leaves ar private void RecurseForce(ArrayIndexedGraph octree, ArrayIndexedNode nn, double dsq, double epssq) { // recursively walks the tree to compute the force on a body double drx, dry, drz, drsq, nphi, scale, idr; -// OctTreeNodeData n = octree.getNodeData(nn); OctTreeNodeData n = nn.data; drx = n.posx - posx; dry = n.posy - posy; @@ -96,35 +95,27 @@ public class OctTreeLeafNodeData extends OctTreeNodeData { // the tree leaves ar if (drsq < dsq) { if (!(n instanceof OctTreeLeafNodeData)) { // n is a cell dsq *= 0.25; -// ArrayIndexedNode child = octree.getNeighbor(nn, 0); ArrayIndexedNode child =nn.neighbors[0]; if (child != null) { RecurseForce(octree, child, dsq, epssq); -// child = octree.getNeighbor(nn, 1); child =nn.neighbors[1]; if (child != null) { RecurseForce(octree, child, dsq, epssq); -// child = octree.getNeighbor(nn, 2); child =nn.neighbors[2]; if (child != null) { RecurseForce(octree, child, dsq, epssq); -// child = octree.getNeighbor(nn, 3); child =nn.neighbors[3]; if (child != null) { RecurseForce(octree, child, dsq, epssq); -// child = octree.getNeighbor(nn, 4); child =nn.neighbors[4]; if (child != null) { RecurseForce(octree, child, dsq, epssq); -// child = octree.getNeighbor(nn, 5); child =nn.neighbors[5]; if (child != null) { RecurseForce(octree, child, dsq, epssq); -// child = octree.getNeighbor(nn, 6); child =nn.neighbors[6]; if (child != null) { RecurseForce(octree, child, dsq, epssq); -// child = octree.getNeighbor(nn, 7); child =nn.neighbors[7]; if (child != null) { RecurseForce(octree, child, dsq, epssq); diff --git a/Robust/src/Benchmarks/oooJava/kmeans/KMeans.java b/Robust/src/Benchmarks/oooJava/kmeans/KMeans.java index d7e107f8..16adc36a 100644 --- a/Robust/src/Benchmarks/oooJava/kmeans/KMeans.java +++ b/Robust/src/Benchmarks/oooJava/kmeans/KMeans.java @@ -229,7 +229,7 @@ public class KMeans /*extends Thread*/ { attributes = new float[numObjects][numAttributes]; KMeans.readFromFile(inputFile, kms.filename, buf, MAX_LINE_LENGTH); System.out.println("Finished Reading from file ......"); - + long startT=System.currentTimeMillis(); /* * The core of the clustering */ @@ -271,12 +271,15 @@ public class KMeans /*extends Thread*/ { g_args); // Global arguments common to all threads } - System.out.println("TIME="+g_args.global_time); + long endT=System.currentTimeMillis(); + System.out.println("running time="+(endT-startT)); +// System.out.println("TIME="+g_args.global_time); System.out.println("Printing output......"); System.out.println("Best_nclusters= " + kms.best_nclusters); /* Output: the coordinates of the cluster centres */ + /* { for (int i = 0; i < kms.best_nclusters; i++) { System.out.print(i + " "); @@ -286,6 +289,7 @@ public class KMeans /*extends Thread*/ { System.out.println("\n"); } } + */ System.out.println("Finished......"); System.exit(0); diff --git a/Robust/src/Benchmarks/oooJava/mergesort/BMergeSort4.java b/Robust/src/Benchmarks/oooJava/mergesort/BMergeSort4.java index 254df675..899a3bbf 100644 --- a/Robust/src/Benchmarks/oooJava/mergesort/BMergeSort4.java +++ b/Robust/src/Benchmarks/oooJava/mergesort/BMergeSort4.java @@ -42,7 +42,7 @@ public class MergeSort4 extends MergeSort { int max = R.length; int j = low; for (int i = 0; i < max; i++) { - R[i] = A[j++]; + R[i] = A[j++]; } quickSort(R, 0, R.length - 1); return R; @@ -77,7 +77,7 @@ public class MergeSort4 extends MergeSort { int max = R.length; int j = low; for (int i = 0; i < max; i++) { - R[i] = A[j++]; + R[i] = A[j++]; } quickSort(R, 0, R.length-1); return R; diff --git a/Robust/src/Benchmarks/oooJava/mergesort/MergeSort.java b/Robust/src/Benchmarks/oooJava/mergesort/MergeSort.java index 8301df61..4289bf13 100644 --- a/Robust/src/Benchmarks/oooJava/mergesort/MergeSort.java +++ b/Robust/src/Benchmarks/oooJava/mergesort/MergeSort.java @@ -63,9 +63,9 @@ public class MergeSort { sese run{ sort(input); } -// sese test{ -// checkSorted(input); -// } + sese test{ + checkSorted(input); + } } public void sort(int A[]) { diff --git a/Robust/src/Benchmarks/oooJava/sor/JGFSORBenchSizeD.java b/Robust/src/Benchmarks/oooJava/sor/JGFSORBenchSizeD.java index bd1ce691..6ef9add1 100644 --- a/Robust/src/Benchmarks/oooJava/sor/JGFSORBenchSizeD.java +++ b/Robust/src/Benchmarks/oooJava/sor/JGFSORBenchSizeD.java @@ -23,21 +23,18 @@ public class JGFSORBenchSizeD{ public static void main(String argv[]){ int nthreads; + nthreads = 1; + int size = 3; if(argv.length != 0 ) { - nthreads = Integer.parseInt(argv[0]); - } else { - System.printString("The no of threads has not been specified, defaulting to 1\n"); - System.printString(" \n"); - nthreads = 1; - } + size = Integer.parseInt(argv[0]); + } JGFInstrumentor instr = new JGFInstrumentor(); - //JGFInstrumentor.printHeader(2,0,nthreads); JGFSORBench sor; sor = new JGFSORBench(nthreads); - int size = 3; + JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size, instr.timers); sor.JGFsetsize(size); diff --git a/Robust/src/Benchmarks/oooJava/sor/SORRunner.java b/Robust/src/Benchmarks/oooJava/sor/SORRunner.java index deb5bfbe..a8c8dc4c 100644 --- a/Robust/src/Benchmarks/oooJava/sor/SORRunner.java +++ b/Robust/src/Benchmarks/oooJava/sor/SORRunner.java @@ -19,7 +19,7 @@ * * **************************************************************************/ -class SORRunner { +class SORRunner { int id, num_iterations; double G[][],omega; -- 2.34.1