diff --git a/src/genmap-algo.c b/src/genmap-algo.c index 83f71442a..70545711a 100644 --- a/src/genmap-algo.c +++ b/src/genmap-algo.c @@ -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; @@ -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 @@ -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); @@ -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)); diff --git a/src/genmap-comm.c b/src/genmap-comm.c index a58e02242..bf60154ff 100644 --- a/src/genmap-comm.c +++ b/src/genmap-comm.c @@ -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; +} diff --git a/src/genmap-handle.c b/src/genmap-handle.c index 087c870fc..a58bc8174 100644 --- a/src/genmap-handle.c +++ b/src/genmap-handle.c @@ -3,7 +3,6 @@ // GenmapHandle // int GenmapCreateHandle(GenmapHandle h) { - // Datastructures h->global = NULL; h->local = NULL; @@ -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]); +} diff --git a/src/genmap-impl.h b/src/genmap-impl.h index be8feecb8..103fbc47d 100644 --- a/src/genmap-impl.h +++ b/src/genmap-impl.h @@ -44,6 +44,7 @@ struct GenmapHandle_private { GenmapLong nel; GenmapLong Nnodes; + GenmapLong start; int nv; struct array elementArray; diff --git a/src/genmap-laplacian.c b/src/genmap-laplacian.c index 720c8a5a8..96acdf93a 100644 --- a/src/genmap-laplacian.c +++ b/src/genmap-laplacian.c @@ -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; @@ -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; -} diff --git a/src/genmap.h b/src/genmap.h index fe2658c87..8d04a8f46 100644 --- a/src/genmap.h +++ b/src/genmap.h @@ -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 // diff --git a/src/parRSB.c b/src/parRSB.c index 31c09d14b..1e6e1f994 100644 --- a/src/parRSB.c +++ b/src/parRSB.c @@ -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; @@ -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]; } }