Skip to content

Commit

Permalink
Update the bin sort routine to balance elements
Browse files Browse the repository at this point in the history
  • Loading branch information
thilinarmtb committed Feb 11, 2019
1 parent 929fa2f commit 786e18c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TESTDIR =$(SRCROOT)/tests

TARGET=parRSB
TESTS=$(TESTDIR)/con/con-test
LIB=src/lib$(TARGET).so
LIB=src/lib$(TARGET).a

INCFLAGS=-I$(SRCDIR) -I$(GSLIBDIR)/include

Expand Down
33 changes: 19 additions & 14 deletions src/genmap-rsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <time.h>
#include <limits.h>

#define GENMAP_FIEDLER 0
#define GENMAP_GLOBALID 1

void GenmapFiedlerMinMax(GenmapHandle h, GenmapScalar *min, GenmapScalar *max) {
*min = 1; *max = -1;

Expand Down Expand Up @@ -247,19 +250,14 @@ void GenmapSplitByGlobalId(GenmapHandle h) {
} while(downLimit - start < lelt);
}

void GenmapSplitByMedian(GenmapHandle h, int *bin) {
void GenmapSplitByMedian(GenmapHandle h) {
GenmapLong start = GenmapGetLocalStartIndex(h);
GenmapLong nel = GenmapGetNGlobalElements(h);
GenmapLong id = GenmapCommRank(GenmapGetLocalComm(h));
GenmapLong np = GenmapCommSize(GenmapGetLocalComm(h));
GenmapInt lelt = GenmapGetNLocalElements(h);
GenmapElements elements = GenmapGetElements(h);

if(id < (np + 1) / 2)
*bin = 0;
else
*bin = 1;

GenmapInt pNel = (GenmapInt)(nel / np);
GenmapInt nrem = (GenmapInt)(nel - pNel * np);
GenmapInt idCount = 0;
Expand All @@ -283,13 +281,13 @@ void GenmapAssignBins(GenmapHandle h, int field, buffer *buf0) {
GenmapElements elements = GenmapGetElements(h);
GenmapInt lelt = GenmapGetNLocalElements(h);

if(field == 0) { // Fiedler
if(field == GENMAP_FIEDLER) { // Fiedler
// sort locally according to Fiedler vector
sarray_sort_2(struct GenmapElement_private, elements, (GenmapUInt)lelt, fiedler,
TYPE_DOUBLE, globalId, TYPE_LONG, buf0);
// set the bin based on Fiedler vector
GenmapSetFiedlerBin(h);
} else {
} else if(GENMAP_GLOBALID) {
// sort locally according to globalId
sarray_sort_2(struct GenmapElement_private, elements, (GenmapUInt)lelt,
globalId, TYPE_LONG, globalId, TYPE_LONG, buf0);
Expand All @@ -302,14 +300,14 @@ void GenmapTransferToBins(GenmapHandle h, int field, buffer *buf0) {
GenmapElements elements = GenmapGetElements(h);
GenmapInt lelt = GenmapGetNLocalElements(h);

if(field == 0) { // Fiedler
if(field == GENMAP_FIEDLER) { // Fiedler
sarray_transfer(struct GenmapElement_private, &(h->elementArray), proc, 0,
&(h->cr));
elements = GenmapGetElements(h);
lelt = GenmapGetNLocalElements(h);
sarray_sort_2(struct GenmapElement_private, elements, (GenmapUInt)lelt, fiedler,
TYPE_DOUBLE, globalId, TYPE_LONG, buf0);
} else {
} else if(field == GENMAP_GLOBALID) {
sarray_transfer(struct GenmapElement_private, &(h->elementArray), proc, 0,
&(h->cr));
elements = GenmapGetElements(h);
Expand All @@ -326,6 +324,13 @@ void GenmapBinSort(GenmapHandle h, int field, buffer *buf0) {
GenmapAssignBins(h, field, buf0);
GenmapTransferToBins(h, field, buf0);
GenmapScan(h, GenmapGetLocalComm(h));
if(field == GENMAP_FIEDLER) {
GenmapSplitByMedian(h);
GenmapTransferToBins(h, 0, buf0);
} else if(field == GENMAP_GLOBALID) {
GenmapSplitByGlobalId(h);
GenmapTransferToBins(h, 1, buf0);
}
}

void GenmapRSB(GenmapHandle h) {
Expand Down Expand Up @@ -359,17 +364,17 @@ void GenmapRSB(GenmapHandle h) {

GenmapBinSort(h, 0, &buf0);
int bin;
GenmapSplitByMedian(h, &bin);
GenmapTransferToBins(h, 0, &buf0);
GenmapLong np = GenmapCommSize(GenmapGetLocalComm(h));
GenmapLong id = GenmapCommRank(GenmapGetLocalComm(h));
if(id < (np + 1) / 2) bin = 0;
else bin = 1;

GenmapComm c = GenmapGetLocalComm(h);
GenmapSplitComm(h, &c, bin);
GenmapSetLocalComm(h, c);

#if defined(GENMAP_PAUL)
GenmapBinSort(h, 1, &buf0);
GenmapSplitByGlobalId(h);
GenmapTransferToBins(h, 1, &buf0);
#endif
}

Expand Down

0 comments on commit 786e18c

Please sign in to comment.