verified functionality and correctness with C versions
authoradash <adash>
Tue, 21 Apr 2009 19:29:40 +0000 (19:29 +0000)
committeradash <adash>
Tue, 21 Apr 2009 19:29:40 +0000 (19:29 +0000)
Robust/src/Benchmarks/SingleTM/KMeans/Cluster.java
Robust/src/Benchmarks/SingleTM/KMeans/KMeans.java
Robust/src/Benchmarks/SingleTM/KMeans/Normal.java
Robust/src/Benchmarks/SingleTM/KMeans/README

index fb16765ecd365abab4f1374a7877458ccceff554..4b694240080c05bdc07a582fa9c263dd8da603fb 100644 (file)
@@ -138,14 +138,8 @@ public class Cluster {
         int      numObjects,             /* number of input objects */
         int      numAttributes,          /* size of attribute of each object */
         double[][]  attributes,           /* [numObjects][numAttributes] */
-        int      use_zscore_transform,
-        int      min_nclusters,          /* testing k range from min to max */
-        int      max_nclusters,
-        double    threshold,              /* in:   */
-        int     best_nclusters,          /* out: number between min and max */
-        double[][] cluster_centres,       /* out: [best_nclusters][numAttributes] */
-        int[]     cluster_assign,        /* out: [numObjects] */
-        GlobalArgs args                 /* Thread arguments */
+        KMeans kms,                       /* KMeans class hold the inputs and outputs */
+        GlobalArgs args                 /* Global thread arguments */
         )
     {
       int itime;
@@ -157,7 +151,7 @@ public class Cluster {
       Random randomPtr = new Random();
       randomPtr = randomPtr.random_alloc(randomPtr);
 
-      if (use_zscore_transform == 1) {
+      if (kms.use_zscore_transform == 1) {
         zscoreTransform(attributes, numObjects, numAttributes);
       }
 
@@ -166,8 +160,7 @@ public class Cluster {
       /*
        * From min_nclusters to max_nclusters, find best_nclusters
        */
-      for (nclusters = min_nclusters; nclusters <= max_nclusters; nclusters++) {
-        //System.out.println("ncluster= " + nclusters);
+      for (nclusters = kms.min_nclusters; nclusters <= kms.max_nclusters; nclusters++) {
 
         randomPtr.random_seed(randomPtr, 7);
         args.nclusters = nclusters;
@@ -179,14 +172,14 @@ public class Cluster {
             numAttributes,
             numObjects,
             nclusters,
-            threshold,
+            kms.threshold,
             membership,
             randomPtr,
             args);
 
         {
-          cluster_centres = tmp_cluster_centres;
-          best_nclusters = nclusters;
+          kms.cluster_centres = tmp_cluster_centres;
+          kms.best_nclusters = nclusters;
         }
 
         itime++;
@@ -196,7 +189,6 @@ public class Cluster {
     }
 }
 
-
 /* =============================================================================
  *
  * End of cluster.java
index 50156284e578963ccc7e4d741d2def864b68f51f..e8fdd63a684e760d19cef762df3f9ceb28aae70e 100644 (file)
@@ -184,7 +184,6 @@ public class KMeans extends Thread {
     buf = new double[numObjects][numAttributes];
     attributes = new double[numObjects][numAttributes];
     KMeans.readFromFile(inputFile, kms.filename, buf);
-    System.out.println("Finished Reading from file ......");
 
     /*
      * The core of the clustering
@@ -207,7 +206,7 @@ public class KMeans extends Thread {
       km[i].start();
     }
 
-    System.out.println("Finished starting threads......");
+    System.out.println("Finished Starting threads......");
 
     for (int i = 0; i < nloops; i++) {
       /*
@@ -225,23 +224,19 @@ public class KMeans extends Thread {
           numObjects,
           numAttributes,
           attributes,             // [numObjects][numAttributes] 
-          kms.use_zscore_transform, // 0 or 1 
-          kms.min_nclusters,      // pre-define range from min to max 
-          kms.max_nclusters,
-          kms.threshold,
-          kms.best_nclusters,     // return: number between min and max
-          kms.cluster_centres,    // return: [best_nclusters][numAttributes]
-          cluster_assign,         // return: [numObjects] cluster id for each object
+          kms,                    //main class that holds users inputs from command prompt and output arrays that need to be filled
           g_args);                // Global arguments common to all threads
     }
 
-    System.out.println("Start printing output......\n");
+    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.println(i);
+        System.out.print(i + " ");
         for (int j = 0; j < numAttributes; j++) {
-          System.out.println(kms.cluster_centres[i][j]);
+          System.out.print(kms.cluster_centres[i][j] + " ");
         }
         System.out.println("\n");
       }
index 3426f61e48b95472181a8c0105c1358cae1e498e..c845fcfe1cd47af3f449538d971d97c789a54f27 100644 (file)
@@ -111,6 +111,7 @@ public class Normal {
 
     start = myId * CHUNK;
 
+    //System.out.println("myId= " + myId + " start= " + start + " npoints= " + npoints);
     while (start < npoints) {
       stop = (((start + CHUNK) < npoints) ? (start + CHUNK) : npoints);
       for (int i = start; i < stop; i++) {
@@ -211,7 +212,7 @@ public class Normal {
       args.global_i = nthreads * CHUNK;
       args.global_delta = delta;
 
-      //Sequential thread doing work in parallel with other threads
+      //Work in parallel with other threads
       thread_work(args);
 
       delta = args.global_delta;
@@ -229,6 +230,8 @@ public class Normal {
 
       delta /= npoints;
 
+      //System.out.println("delta= " + delta + " loop= " + loop + " threshold= " + threshold);
+
     } while ((delta > threshold) && (loop++ < 500));
 
     return clusters;
@@ -239,7 +242,7 @@ public class Normal {
    **/
   thread_work(GlobalArgs args) {
    Barrier.enterBarrier();
-   work(0, args); //threadId = 0 because primary thread
+   Normal.work(0, args); //threadId = 0 because primary thread
    Barrier.enterBarrier();
   }
 }
index 5c6e16dd2f110829cddc3233bc1c09f403cfca54..7b051e2fa786cd412a21f412639614ba727ca0ee 100644 (file)
@@ -37,14 +37,14 @@ run in the following manner:
 
 To produce the data in [1], the following values were used:
 
-    low contention:  -m40 -n40 -t0.05 -i inputs/random-n2048-d16-c16.txt
-    high contention: -m15 -n15 -t0.05 -i inputs/random-n2048-d16-c16.txt
+    low contention:  -m 40 -n 40 -t 0.05 -i inputs/random-n2048-d16-c16.txt
+    high contention: -m 15 -n 15 -t 0.05 -i inputs/random-n2048-d16-c16.txt
 
 For runs without a simulator, a larger input file, (more info below) can be used
 instead:
 
-    low contention:  -m40 -n40 -t0.00001 -i inputs/random-n65536-d32-c16.txt
-    high contention: -m15 -n15 -t0.00001 -i inputs/random-n65536-d32-c16.txt   
+    low contention:  -m 40 -n 40 -t 0.00001 -i inputs/random-n65536-d32-c16.txt
+    high contention: -m 15 -n 15 -t 0.00001 -i inputs/random-n65536-d32-c16.txt   
 
 
 Input Files