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;
Random randomPtr = new Random();
randomPtr = randomPtr.random_alloc(randomPtr);
- if (use_zscore_transform == 1) {
+ if (kms.use_zscore_transform == 1) {
zscoreTransform(attributes, numObjects, numAttributes);
}
/*
* 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;
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++;
}
}
-
/* =============================================================================
*
* End of cluster.java
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
km[i].start();
}
- System.out.println("Finished starting threads......");
+ System.out.println("Finished Starting threads......");
for (int i = 0; i < nloops; i++) {
/*
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");
}
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++) {
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;
delta /= npoints;
+ //System.out.println("delta= " + delta + " loop= " + loop + " threshold= " + threshold);
+
} while ((delta > threshold) && (loop++ < 500));
return clusters;
**/
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();
}
}
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