1 // One instance is created and called on each PE
2 void KMeansGroup::cluster()
4 CLUSTERS::Write w
= clusters
.getInitialWrite();
5 if (initSeed
!= -1) writePosition(w
, initSeed
);
7 // Put the array in Read mode
8 CLUSTERS::Read r
= w
.syncToRead();
11 // Each PE finds the seed closest to itself
12 double minDistance
= distance(r
, curSeed
);
14 for (int i
= 0; i
< numClusters
; ++i
) {
15 double d
= distance(r
, i
);
22 // Put the array in Accumulate mode,
23 // excluding the current value
24 CLUSTERS::Accum a
= r
.syncToExcAccum();
25 // Each PE adds itself to its new seed
26 for (int i
= 0; i
< numMetrics
; ++i
)
27 a(newSeed
, i
) += metrics
[i
];
29 // Update membership and change count
30 a(newSeed
, numMetrics
) += 1;
31 if (curSeed
!= newSeed
)
32 a(0, numMetrics
+1) += 1;
35 // Put the array in Read mode
37 } while(r(0, numMetrics
+1) > 0);