Skip to content

Commit

Permalink
Import latest changes
Browse files Browse the repository at this point in the history
* Fix memory leak
* Fix invalid read
* Add option array to interface
  • Loading branch information
stgeke committed Jan 25, 2019
1 parent 0cb4f0b commit 138c639
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
20 changes: 14 additions & 6 deletions src/genmap-algo.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,13 @@ int GenmapLanczosLegendary(GenmapHandle h, GenmapComm c, GenmapVector f,
rni = 1.0 / rnorm;

// Allocate memory for q-vectors
if(*rr == NULL)
GenmapMalloc((size_t)niter, rr);
if(*rr == NULL){
GenmapMalloc((size_t)(niter+1), rr);
GenmapInt i;
for(i = 0; i < niter+1; ++i) (*rr)[i] = NULL;
}
GenmapCreateVector(&(*rr)[0], lelt);

GenmapScaleVector((*rr)[0], r, rni);

int iter;
Expand Down Expand Up @@ -313,8 +317,11 @@ int GenmapLanczos(GenmapHandle h, GenmapComm c, GenmapVector init,
beta->data[0] = 0.;

// Allocate memory for q-vectors
if(*q == NULL)
GenmapMalloc((size_t)iter, q);
if(*q == NULL){
GenmapMalloc((size_t)(iter+1), q);
GenmapInt i;
for(i = 0; i < iter+1; ++i) (*q)[i] = NULL;
}

// Store Local Laplacian weights
GenmapVector weights;
Expand Down Expand Up @@ -496,7 +503,7 @@ int GenmapFiedler(GenmapHandle h, GenmapComm c, int maxIter,
GenmapDestroyVector(evLanczos);
GenmapDestroyVector(evTriDiag);
GenmapDestroyVector(evInit);
for(i = 0; i < iter; i++) {
for(i = 0; i < iter+1; i++) {
GenmapDestroyVector(q[i]);
}
GenmapFree(q);
Expand Down Expand Up @@ -552,6 +559,7 @@ void GenmapRSB(GenmapHandle h) {
int npass = 50, ipass = 0;

if(h->Id(h->global) == 0) printf("Running RSB ... ");
fflush(stdout);
#if defined(GENMAP_MPI)
MPI_Barrier(h->global->gsComm.c);
double t0 = MPI_Wtime();
Expand Down Expand Up @@ -675,5 +683,5 @@ void GenmapRSB(GenmapHandle h) {
time = ((double)clock() - t0) / CLOCKS_PER_SEC;
#endif
if(h->Id(h->global) == 0) printf("%lf sec\n", time);

fflush(stdout);
}
1 change: 1 addition & 0 deletions src/genmap-gmsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//
int GenmapCreateHandle_gmsh(GenmapHandle h) {
h->Read = GenmapRead_gmsh;
h->dbgLevel = 0;

return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/genmap-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ struct GenmapHandle_private {
int (*Read)(GenmapHandle h, void *data);

int (*Write)(GenmapHandle h, char *fileNameBase);

GenmapInt dbgLevel;
};

// GenmapHandle
Expand Down
1 change: 1 addition & 0 deletions src/genmap-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ int GenmapWrite(GenmapHandle h, char *fileNameBase) {

int GenmapCreateHandle_interface(GenmapHandle h) {
h->Read = NULL;
h->dbgLevel = 0;

return 0;
}
13 changes: 8 additions & 5 deletions src/parRSB.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

void fparRSB_partMesh(long long *egl, long long *vl, int *negl,
long long *eglcon, long long *vlcon, int *neglcon,
int *nve, int *comm, int *err) {
int *nve, int *options, int *comm, int *err) {
*err = 1;
setbuf(stdout, NULL);

GenmapCommExternal c;
#if defined(GENMAP_MPI)
Expand All @@ -23,15 +22,19 @@ void fparRSB_partMesh(long long *egl, long long *vl, int *negl,

*err = parRSB_partMesh(egl, vl, negl,
eglcon, vlcon, *neglcon,
*nve, c);
*nve, options, c);
}

int parRSB_partMesh(long long *egl, long long *vl, int *negl,
long long *eglcon, long long *vlcon, int neglcon,
int nve, MPI_Comm comm) {
int nve, int *options, MPI_Comm comm) {
GenmapHandle h;
GenmapInit(&h, comm, "interface");

if (options[0] != 0){
h->dbgLevel = options[1];
}

// Check if negl is large enough
GenmapLong neglcon_ = (GenmapLong) neglcon;
GenmapGop(h->global, &neglcon_, 1, GENMAP_LONG, GENMAP_SUM);
Expand Down Expand Up @@ -80,7 +83,7 @@ int parRSB_partMesh(long long *egl, long long *vl, int *negl,
}
}

GenmapPartitionQuality(h);
if(h->dbgLevel > 0) GenmapPartitionQuality(h);

GenmapFinalize(h);

Expand Down
4 changes: 2 additions & 2 deletions src/parRSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#define fparRSB_partMesh FORTRAN_UNPREFIXED(fparrsb_partmesh,FPARRSB_PARTMESH)
void fparRSB_partMesh(long long *egl, long long *vl, int *negl,
long long *eglcon, long long *vlcon, int *neglcon,
int *nve, int *comm, int *err);
int *nve, int *options, int *comm, int *err);

int parRSB_partMesh(long long *egl, long long *vl, int *negl,
long long *eglcon, long long *vlcon, int neglcon,
int nve, MPI_Comm comm);
int nve, int *options, MPI_Comm comm);
5 changes: 4 additions & 1 deletion tests/con/con-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ int main(int argc, char *argv[]) {
MPI_Comm_rank(comm, &myid);
MPI_Comm_size(comm, &np);

int options[2];

struct con c;
int ierr = conRead(argv[1], &c, comm);
if(ierr) goto quit;
Expand All @@ -25,7 +27,8 @@ int main(int argc, char *argv[]) {
long long *vl = (long long*) malloc(nel_max * c.nv * sizeof(long long));

int nelo = nel_max;
ierr = parRSB_partMesh(el, vl, &nelo, c.el, c.vl, c.nel, c.nv, comm);
options[0] = 0; // use default values
ierr = parRSB_partMesh(el, vl, &nelo, c.el, c.vl, c.nel, c.nv, options, comm);
if(ierr) goto quit;

printf("myid = %d, nel = %d\n", myid, nelo);
Expand Down

0 comments on commit 138c639

Please sign in to comment.