From c66e1464add1c05acfd71d019b3f5c6c32c2460f Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 18 Sep 2022 10:16:43 -0700 Subject: [PATCH] topfish findGlobalIndexesOfActiveNeighbors: use cgraph wrappers for allocation The lib/cgraph/alloc.h wrappers are similar to the older lib/common/memory.h wrappers except (1) they are header-only and (2) they live in a directory (cgraph) that is at the root of the dependency tree. The long term plan is to replace all use of lib/common/memory.h with lib/cgraph/alloc.h. --- lib/topfish/hierarchy.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/topfish/hierarchy.c b/lib/topfish/hierarchy.c index 0e196ad7a..0e729c079 100644 --- a/lib/topfish/hierarchy.c +++ b/lib/topfish/hierarchy.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -1197,7 +1196,6 @@ findGlobalIndexesOfActiveNeighbors(Hierarchy * hierarchy, int index, int **np) { int numNeighbors = 0; - int *neighbors; int i, j; int level, node,active_level,found; v_data neighborsInLevel; @@ -1215,9 +1213,9 @@ findGlobalIndexesOfActiveNeighbors(Hierarchy * hierarchy, int index, neighborsInLevel = hierarchy->graphs[level][node]; nAllocNeighbors = 2 * neighborsInLevel.nedges; - neighbors = N_NEW(nAllocNeighbors, int); + int *neighbors = gv_calloc(nAllocNeighbors, sizeof(int)); - stack = N_NEW(5 * hierarchy->nlevels + 1, int); + stack = gv_calloc(5 * hierarchy->nlevels + 1, sizeof(int)); for (i = 1; i < neighborsInLevel.nedges; i++) { neighbor = neighborsInLevel.edges[i]; @@ -1226,8 +1224,9 @@ findGlobalIndexesOfActiveNeighbors(Hierarchy * hierarchy, int index, if (active_level == level) { // neighbor is active - add it if (numNeighbors >= nAllocNeighbors) { + neighbors = gv_recalloc(neighbors, nAllocNeighbors, 2 * nAllocNeighbors + 1, + sizeof(int)); nAllocNeighbors = 2 * nAllocNeighbors + 1; - neighbors = RALLOC(nAllocNeighbors, neighbors, int); } neighbors[numNeighbors] = hierarchy->geom_graphs[level][neighbor].globalIndex; @@ -1250,8 +1249,9 @@ findGlobalIndexesOfActiveNeighbors(Hierarchy * hierarchy, int index, } if (!found) { if (numNeighbors >= nAllocNeighbors) { + neighbors = gv_recalloc(neighbors, nAllocNeighbors, + 2 * nAllocNeighbors + 1, sizeof(int)); nAllocNeighbors = 2 * nAllocNeighbors + 1; - neighbors = RALLOC(nAllocNeighbors, neighbors, int); } neighbors[numNeighbors] = hierarchy->geom_graphs[neighborLevel][neighbor]. @@ -1272,9 +1272,9 @@ findGlobalIndexesOfActiveNeighbors(Hierarchy * hierarchy, int index, if (hierarchy->geom_graphs[neighborLevel][neighbor]. active_level == neighborLevel) { if (numNeighbors >= nAllocNeighbors) { + neighbors = gv_recalloc(neighbors, nAllocNeighbors, + 2 * nAllocNeighbors + 1, sizeof(int)); nAllocNeighbors = 2 * nAllocNeighbors + 1; - neighbors = - RALLOC(nAllocNeighbors, neighbors, int); } neighbors[numNeighbors] = hierarchy->geom_graphs[neighborLevel][neighbor]. -- 2.40.0