Update references to hapi_src to hapi_impl and revert hapiRegisterCallbacks
[charm.git] / doc / charm++ / kmeans.cpp
blob4df2006689d61d64a595bfb5fa0a3367e664f0ab
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();
10 do {
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);
16 if(d < minDistance) {
17 minDistance = d;
18 newSeed = 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;
33 curSeed = newSeed;
35 // Put the array in Read mode
36 r = a.syncToRead();
37 } while(r(0, numMetrics+1) > 0);