Skip to content

Commit

Permalink
Added GenmapScan to calculate NEL and start index
Browse files Browse the repository at this point in the history
  • Loading branch information
thilinarmtb committed Feb 9, 2019
1 parent 3497a62 commit 81e05d4
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 49 deletions.
31 changes: 10 additions & 21 deletions src/genmap-algo.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,9 @@ void GenmapBinSort(GenmapHandle h, int field, buffer *buf0) {


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

int maxIter = 50;
int iter = maxIter;
Expand All @@ -268,12 +265,7 @@ void GenmapRSB(GenmapHandle h) {
printf("running RSB "), fflush(stdout);

crystal_init(&(h->cr), &(h->local->gsComm));
GenmapLong out[2][1], buf[2][1];

buffer buf0 = null_buffer;
// Calculate the global Fiedler vector, local communicator
// must be initialized using the global communicator, we never
// touch global communicator

while(GenmapCommSize(GenmapGetLocalComm(h)) > 1) {
if(GenmapCommRank(GenmapGetGlobalComm(h)) == 0
Expand All @@ -295,10 +287,10 @@ void GenmapRSB(GenmapHandle h) {

GenmapBinSort(h, 0, &buf0);

GenmapLong lelt_ = (GenmapLong)GenmapGetNLocalElements(h);
comm_scan(out, &(h->local->gsComm), genmap_gs_long, gs_add, &lelt_, 1, buf);
start = out[0][0]; GenmapSetLocalStartIndex(h, start);
nel = out[1][0]; GenmapSetNGlobalElements(h, nel);
GenmapScan(h, GenmapGetLocalComm(h));
lelt = GenmapGetNLocalElements(h);
start = GenmapGetLocalStartIndex(h);
nel = GenmapGetNGlobalElements(h);
id = GenmapCommRank(GenmapGetLocalComm(h));
np = GenmapCommSize(GenmapGetLocalComm(h));
elements = GenmapGetElements(h);
Expand Down Expand Up @@ -357,15 +349,12 @@ void GenmapRSB(GenmapHandle h) {
lelt = GenmapGetNLocalElements(h);
#endif

lelt_ = (GenmapLong)lelt;
comm_scan(out, &(GenmapGetLocalComm(h)->gsComm), genmap_gs_long, gs_add, &lelt_,
1, buf);
start = out[0][0]; GenmapSetLocalStartIndex(h, start);
nel = h->nel = out[1][0];
GenmapScan(h, GenmapGetLocalComm(h));
start = GenmapGetLocalStartIndex(h);
nel = GenmapGetNGlobalElements(h);
id = GenmapCommRank(GenmapGetLocalComm(h));
np = GenmapCommSize(GenmapGetLocalComm(h));
elements = GenmapGetElements(h);

}

crystal_free(&(h->cr));
Expand Down
14 changes: 14 additions & 0 deletions src/genmap-comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,17 @@ GenmapComm GenmapGetGlobalComm(GenmapHandle h) {
void GenmapSetGlobalComm(GenmapHandle h, GenmapComm c) {
h->global = c;
}

int GenmapGop(GenmapComm c, void *v, GenmapInt size,
GenmapDataType type, GenmapInt op) {
#ifdef GENMAP_MPI
if(op == GENMAP_SUM) {
MPI_Allreduce(MPI_IN_PLACE, v, size, type, MPI_SUM, c->gsComm.c);
} else if(op == GENMAP_MAX) {
MPI_Allreduce(MPI_IN_PLACE, v, size, type, MPI_MAX, c->gsComm.c);
} else if(op == GENMAP_MIN) {
MPI_Allreduce(MPI_IN_PLACE, v, size, type, MPI_MIN, c->gsComm.c);
}
#endif
return 0;
}
9 changes: 8 additions & 1 deletion src/genmap-handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// GenmapHandle
//
int GenmapCreateHandle(GenmapHandle h) {
// Datastructures
h->global = NULL;
h->local = NULL;

Expand Down Expand Up @@ -60,3 +59,11 @@ int GenmapGetNVertices(GenmapHandle h) {
void GenmapSetNVertices(GenmapHandle h, int nVertices) {
h->nv = nVertices;
}

void GenmapScan(GenmapHandle h, GenmapComm c) {
GenmapLong out[2][1], buf[2][1];
GenmapLong lelt = GenmapGetNLocalElements(h);
comm_scan(out, &(c->gsComm), genmap_gs_long, gs_add, &lelt, 1, buf);
GenmapSetLocalStartIndex(h, out[0][0]);
GenmapSetNGlobalElements(h, out[1][0]);
}
1 change: 1 addition & 0 deletions src/genmap-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct GenmapHandle_private {

GenmapLong nel;
GenmapLong Nnodes;
GenmapLong start;
int nv;

struct array elementArray;
Expand Down
16 changes: 1 addition & 15 deletions src/genmap-laplacian.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

int GenmapInitLaplacian(GenmapHandle h, GenmapComm c, GenmapVector weights) {
GenmapInt lelt = GenmapGetNLocalElements(h);
GenmapInt nv = GenmapGetNVertices(h, nv);
GenmapInt nv = GenmapGetNVertices(h);
GenmapUInt numPoints = (GenmapUInt) nv * lelt;

GenmapLong *vertices;
Expand Down Expand Up @@ -90,17 +90,3 @@ int GenmapLaplacian(GenmapHandle h, GenmapComm c, GenmapVector u,

return 0;
}

int GenmapGop(GenmapComm c, void *v, GenmapInt size,
GenmapDataType type, GenmapInt op) {
#ifdef GENMAP_MPI
if(op == GENMAP_SUM) {
MPI_Allreduce(MPI_IN_PLACE, v, size, type, MPI_SUM, c->gsComm.c);
} else if(op == GENMAP_MAX) {
MPI_Allreduce(MPI_IN_PLACE, v, size, type, MPI_MAX, c->gsComm.c);
} else if(op == GENMAP_MIN) {
MPI_Allreduce(MPI_IN_PLACE, v, size, type, MPI_MIN, c->gsComm.c);
}
#endif
return 0;
}
2 changes: 2 additions & 0 deletions src/genmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ void GenmapSetLocalStartIndex(GenmapHandle h, GenmapLong localStart);

int GenmapGetNVertices(GenmapHandle h);
void GenmapSetNVertices(GenmapHandle, int nVertices);

void GenmapScan(GenmapHandle h, GenmapComm c);
//
// GenmapComm
//
Expand Down
15 changes: 3 additions & 12 deletions src/parRSB.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,9 @@ int parRSB_partMesh(long long *egl, long long *vl, int *negl,
}

GenmapSetNLocalElements(h, (GenmapInt)neglcon);
GenmapScan(h, GenmapGetGlobalComm(h));
GenmapSetNVertices(h, nve);

GenmapLong out[2][1], buf[2][1];
GenmapLong lelt_ = GenmapGetNLocalElements(h);
comm_scan(out, &(GenmapGetGlobalComm(h)->gsComm), genmap_gs_long, gs_add,
&lelt_, 1,
buf);
GenmapSetLocalStartIndex(h, out[0][0]);
GenmapSetNGlobalElements(h, out[1][0]);

GenmapElements e = GenmapGetElements(h);
GenmapInt i, j;

Expand All @@ -70,14 +63,12 @@ int parRSB_partMesh(long long *egl, long long *vl, int *negl,
GenmapRSB(h);

GenmapElements elements = GenmapGetElements(h);
GenmapInt nv = h->nv;

*negl = GenmapGetNLocalElements(h);

for(i = 0; i < *negl; i++) {
egl[i] = elements[i].globalId;
for(j = 0; j < nv; j++) {
vl[nv * i + j] = elements[i].vertices[j];
for(j = 0; j < nve; j++) {
vl[nve * i + j] = elements[i].vertices[j];
}
}

Expand Down

0 comments on commit 81e05d4

Please sign in to comment.