Skip to content

Commit

Permalink
Fixed issues identified by valgrind
Browse files Browse the repository at this point in the history
  • Loading branch information
karypis committed Jan 16, 2022
1 parent 2ecef80 commit 5a82977
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
3 changes: 2 additions & 1 deletion conf/gkbuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ endif(CYGWIN)
if(CMAKE_COMPILER_IS_GNUCC)
# GCC opts.
set(GK_COPTIONS "${GK_COPTIONS} -std=c99 -fno-strict-aliasing")
set(GK_COPTIONS "${GK_COPTIONS} -march=native")
# set(GK_COPTIONS "${GK_COPTIONS} -march=native")
set(GK_COPTIONS "${GK_COPTIONS} -march=x86-64 -mtune=generic")
if(NOT MINGW)
set(GK_COPTIONS "${GK_COPTIONS} -fPIC")
endif(NOT MINGW)
Expand Down
35 changes: 21 additions & 14 deletions libmetis/coarsen.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ idx_t Match_JC(ctrl_t *ctrl, graph_t *graph)
idx_t *xadj, *vwgt, *adjncy, *adjwgt, *maxvwgt;
idx_t *match, *cmap, *degrees, *perm, *tperm, *vec, *marker;
idx_t mytwgt, xtwgt, ctwgt;
float bscore, score;
real_t bscore, score;

WCOREPUSH;

Expand Down Expand Up @@ -834,7 +834,7 @@ void CreateCoarseGraph(ctrl_t *ctrl, graph_t *graph, idx_t cnvtxs,
idx_t *cxadj, *cvwgt, *cvsize, *cadjncy, *cadjwgt;
graph_t *cgraph;
int dovsize, dropedges;
idx_t cv, nkeep, droppedewgt;
idx_t cv, nkeys, droppedewgt;
idx_t *keys=NULL, *medianewgts=NULL, *noise=NULL;

WCOREPUSH;
Expand All @@ -857,12 +857,13 @@ void CreateCoarseGraph(ctrl_t *ctrl, graph_t *graph, idx_t cnvtxs,

/* Setup structures for dropedges */
if (dropedges) {
for (nkeep=-1, v=0; v<nvtxs; v++)
nkeep = gk_max(nkeep, xadj[v+1]-xadj[v]);
for (nkeys=0, v=0; v<nvtxs; v++)
nkeys = gk_max(nkeys, xadj[v+1]-xadj[v]);
nkeys = 2*nkeys+1;

medianewgts = iwspacemalloc(ctrl, cnvtxs);
keys = iwspacemalloc(ctrl, nkeys);
noise = iwspacemalloc(ctrl, cnvtxs);
keys = iwspacemalloc(ctrl, 2*(nkeep+1));
medianewgts = iset(cnvtxs, -1, iwspacemalloc(ctrl, cnvtxs));

for (v=0; v<cnvtxs; v++)
noise[v] = irandInRange(128);
Expand Down Expand Up @@ -947,8 +948,9 @@ void CreateCoarseGraph(ctrl_t *ctrl, graph_t *graph, idx_t cnvtxs,
}
}

/* zero out the htable */
for (j=0; j<nedges; j++) {
/* reset the htable -- reverse order (LIFO) is critical to prevent cadjncy[-1]
* indexing due to a remove of an earlier entry */
for (j=nedges-1; j>=0; j--) {
k = cadjncy[j];
for (kk=k&mask; cadjncy[htable[kk]]!=k; kk=((kk+1)&mask));
htable[kk] = -1;
Expand Down Expand Up @@ -1007,10 +1009,14 @@ void CreateCoarseGraph(ctrl_t *ctrl, graph_t *graph, idx_t cnvtxs,
/* Determine the median weight of the incident edges, which will be used
to keep an edge (u, v) iff wgt(u, v) >= min(medianewgts[u], medianewgts[v]) */
if (dropedges) {
for (j=0; j<nedges; j++)
keys[j] = (cadjwgt[j]<<8) + noise[cnvtxs] + noise[cadjncy[j]];
isortd(nedges, keys);
medianewgts[cnvtxs] = keys[((xadj[v+1]-xadj[v] + xadj[u+1]-xadj[u])>>1)];
ASSERTP(nedges < nkeys, ("%"PRIDX", %"PRIDX"\n", nkeys, nedges));
medianewgts[cnvtxs] = 8; /* default for island nodes */
if (nedges > 0) {
for (j=0; j<nedges; j++)
keys[j] = (cadjwgt[j]<<8) + noise[cnvtxs] + noise[cadjncy[j]];
isortd(nedges, keys);
medianewgts[cnvtxs] = keys[gk_min(nedges-1, ((xadj[v+1]-xadj[v] + xadj[u+1]-xadj[u])>>1))];
}
}

cadjncy += nedges;
Expand All @@ -1019,6 +1025,7 @@ void CreateCoarseGraph(ctrl_t *ctrl, graph_t *graph, idx_t cnvtxs,
cxadj[++cnvtxs] = cnedges;
}


/* compact the adjacency structure of the coarser graph to keep only +ve edges */
if (dropedges) {
droppedewgt = 0;
Expand All @@ -1032,6 +1039,8 @@ void CreateCoarseGraph(ctrl_t *ctrl, graph_t *graph, idx_t cnvtxs,
iend = cxadj[u+1];
for (j=istart; j<iend; j++) {
v = cadjncy[j];
ASSERTP(medianewgts[u] >= 0, ("%"PRIDX" %"PRIDX"\n", u, medianewgts[u]));
ASSERTP(medianewgts[v] >= 0, ("%"PRIDX" %"PRIDX" %"PRIDX"\n", v, medianewgts[v], cnvtxs));
if ((cadjwgt[j]<<8) + noise[u] + noise[v] >= gk_min(medianewgts[u], medianewgts[v])) {
cadjncy[cnedges] = cadjncy[j];
cadjwgt[cnedges++] = cadjwgt[j];
Expand All @@ -1043,8 +1052,6 @@ void CreateCoarseGraph(ctrl_t *ctrl, graph_t *graph, idx_t cnvtxs,
}
SHIFTCSR(j, cnvtxs, cxadj);

//printf("droppedewgt: %d\n", (int)droppedewgt);

cgraph->droppedewgt = droppedewgt;
}

Expand Down

0 comments on commit 5a82977

Please sign in to comment.