Revision 4185a5162d656d0bdb87a2599198e29c516d6470 authored by Harshitha on 10 May 2014, 01:33:10 UTC, committed by Harshitha on 25 July 2014, 19:22:59 UTC
commit 6a10d6aa7d83ecb6323aa033ef82d69fec0392ff
Author: Harshitha <gplkrsh2@illinois.edu>
Date:   Fri May 2 14:17:23 2014 -0500

    Call TPWorkDone before finishWalk

    Change-Id: Ib118d156cb01f0b93a55176a98d8164c26933290

commit 3f599bb98488be2a1c73d28e799ba196a927d586
Author: Harshitha <gplkrsh2@illinois.edu>
Date:   Mon Apr 28 20:49:58 2014 -0500

    Intra node load balancing using CkLoop

commit 760de0f3b7d294712e11cdec74b30311a7bf540e
Author: Harshitha <gplkrsh2@illinois.edu>
Date:   Mon Apr 28 19:48:42 2014 -0500

    Intra node load balancing using CkLoop

    Change-Id: Ib21eb0a0d2a37e765ee3064ce420b1b310621185

Change-Id: Id1b94c1aef9257161f65ccddd27b1c756dc9d323
1 parent b462e34
Raw File
clustering.cpp
#include "SFC.h"

class KeySorted {
public:
  SFC::Key key;
  int index;
  inline bool operator<(const KeySorted& k) const {
    return key < k.key;
  }
};

void clustering(int n, double *weights, CkVec<TaggedVector3D> &centers, int procs, int *to) {
  int saved_peanoKey = peanoKey;
  peanoKey = 1;

  // create the SFC keys
  KeySorted *keys = new KeySorted[n];
  for (int i=0; i<n; ++i) {
    float centerArray[3];
    centers[i].vec.array_form(centerArray);
    
    keys[i].key = SFC::makeKey(centerArray);
    keys[i].index = centers[i].tag;
  }
  sort(keys, keys+n);

  // divide the keys in equal weighted segments
  double sum = 0;
  for (int i=0; i<n; ++i) sum += weights[i];
  CkAssert(sum > 0.0);
  double increment = sum / procs;
  CkPrintf("sum: %f, increment: %f\n", sum, increment);
  double target = increment;
  double partial = 0;
  int cluster = 0;
  for (int i=0; i<n; ++i) {
    partial += weights[keys[i].index];
    to[keys[i].index] = cluster;
    if (partial >= target) {
      if (2*(partial-target) > weights[keys[i].index]) to[keys[i].index] ++;
      cluster ++;
      target += increment;
    }
    CkAssert(to[keys[i].index] < procs);
  }

  peanoKey = saved_peanoKey;
  delete [] keys;
}
back to top