From 014cb4b3db982cc6ad5311ca182a409354bded3c Mon Sep 17 00:00:00 2001 From: adash Date: Tue, 21 Apr 2009 19:29:40 +0000 Subject: [PATCH] verified functionality and correctness with C versions --- .../Benchmarks/SingleTM/KMeans/Cluster.java | 22 ++++++------------- .../Benchmarks/SingleTM/KMeans/KMeans.java | 19 ++++++---------- .../Benchmarks/SingleTM/KMeans/Normal.java | 7 ++++-- Robust/src/Benchmarks/SingleTM/KMeans/README | 8 +++---- 4 files changed, 23 insertions(+), 33 deletions(-) diff --git a/Robust/src/Benchmarks/SingleTM/KMeans/Cluster.java b/Robust/src/Benchmarks/SingleTM/KMeans/Cluster.java index fb16765e..4b694240 100644 --- a/Robust/src/Benchmarks/SingleTM/KMeans/Cluster.java +++ b/Robust/src/Benchmarks/SingleTM/KMeans/Cluster.java @@ -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 diff --git a/Robust/src/Benchmarks/SingleTM/KMeans/KMeans.java b/Robust/src/Benchmarks/SingleTM/KMeans/KMeans.java index 50156284..e8fdd63a 100644 --- a/Robust/src/Benchmarks/SingleTM/KMeans/KMeans.java +++ b/Robust/src/Benchmarks/SingleTM/KMeans/KMeans.java @@ -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"); } diff --git a/Robust/src/Benchmarks/SingleTM/KMeans/Normal.java b/Robust/src/Benchmarks/SingleTM/KMeans/Normal.java index 3426f61e..c845fcfe 100644 --- a/Robust/src/Benchmarks/SingleTM/KMeans/Normal.java +++ b/Robust/src/Benchmarks/SingleTM/KMeans/Normal.java @@ -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(); } } diff --git a/Robust/src/Benchmarks/SingleTM/KMeans/README b/Robust/src/Benchmarks/SingleTM/KMeans/README index 5c6e16dd..7b051e2f 100644 --- a/Robust/src/Benchmarks/SingleTM/KMeans/README +++ b/Robust/src/Benchmarks/SingleTM/KMeans/README @@ -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 -- 2.34.1