int hypre_SStructGraphFindUVEntry( hypre_SStructGraph *graph, int part, hypre_Index index, int var, hypre_SStructUVEntry **Uventry_ptr ) { int ierr = 0; hypre_SStructUVEntry **Uventries = hypre_SStructGraphUVEntries(graph); hypre_SStructGrid *grid = hypre_SStructGraphGrid(graph); int type = hypre_SStructGraphObjectType(graph); hypre_BoxMapEntry *map_entry; HYPRE_BigInt big_rank; int rank; hypre_SStructGridFindMapEntry(grid, part, index, var, &map_entry); hypre_SStructMapEntryGetGlobalRank(map_entry, index, &big_rank, type); if (type == HYPRE_SSTRUCT || type == HYPRE_STRUCT) { rank = (int)(big_rank - hypre_SStructGridGhstartRank(grid)); } if (type == HYPRE_PARCSR) { rank = (int)(big_rank - hypre_SStructGridStartRank(grid)); } *Uventry_ptr = Uventries[rank]; return ierr; }
int HYPRE_SStructGraphDestroy( HYPRE_SStructGraph graph ) { int ierr = 0; int nparts; hypre_SStructPGrid **pgrids; hypre_SStructStencil ***stencils; int nUventries; int *iUventries; hypre_SStructUVEntry **Uventries; hypre_SStructUVEntry *Uventry; int nvars; int part, var, i; if (graph) { hypre_SStructGraphRefCount(graph) --; if (hypre_SStructGraphRefCount(graph) == 0) { nparts = hypre_SStructGraphNParts(graph); pgrids = hypre_SStructGraphPGrids(graph); stencils = hypre_SStructGraphStencils(graph); nUventries = hypre_SStructGraphNUVEntries(graph); iUventries = hypre_SStructGraphIUVEntries(graph); Uventries = hypre_SStructGraphUVEntries(graph); for (part = 0; part < nparts; part++) { nvars = hypre_SStructPGridNVars(pgrids[part]); for (var = 0; var < nvars; var++) { HYPRE_SStructStencilDestroy(stencils[part][var]); } hypre_TFree(stencils[part]); } HYPRE_SStructGridDestroy(hypre_SStructGraphGrid(graph)); hypre_TFree(stencils); for (i = 0; i < nUventries; i++) { Uventry = Uventries[iUventries[i]]; if (Uventry) { hypre_TFree(hypre_SStructUVEntryUEntries(Uventry)); hypre_TFree(Uventry); } Uventries[iUventries[i]] = NULL; } hypre_TFree(iUventries); hypre_TFree(Uventries); hypre_TFree(graph); } } return ierr; }
int HYPRE_SStructGraphAddEntries( HYPRE_SStructGraph graph, int part, int *index, int var, int to_part, int *to_index, int to_var ) { int ierr = 0; hypre_SStructGrid *grid = hypre_SStructGraphGrid(graph); int ndim = hypre_SStructGridNDim(grid); int nUventries = hypre_SStructGraphNUVEntries(graph); int aUventries = hypre_SStructGraphAUVEntries(graph); int *iUventries = hypre_SStructGraphIUVEntries(graph); int type = hypre_SStructGraphObjectType(graph); hypre_SStructUVEntry **Uventries = hypre_SStructGraphUVEntries(graph); hypre_SStructUVEntry *Uventry; int nUentries; hypre_SStructUEntry *Uentries; hypre_BoxMapEntry *map_entry; hypre_Index cindex; HYPRE_BigInt big_rank, startrank; int rank, i; int box, to_box, to_proc; if (!nUventries) { /* allocate space for non-stencil entries GEC1102 * the size equal to the ghost local size of grid */ aUventries = hypre_SStructGridGhlocalSize(grid); iUventries = hypre_TAlloc(int, aUventries); Uventries = hypre_CTAlloc(hypre_SStructUVEntry *, aUventries); hypre_SStructGraphAUVEntries(graph) = aUventries; hypre_SStructGraphIUVEntries(graph) = iUventries; hypre_SStructGraphUVEntries(graph) = Uventries; }
int HYPRE_SStructGraphCreate( MPI_Comm comm, HYPRE_SStructGrid grid, HYPRE_SStructGraph *graph_ptr ) { int ierr = 0; hypre_SStructGraph *graph; int nparts; hypre_SStructStencil ***stencils; hypre_SStructPGrid **pgrids; int nvars; int part, var; graph = hypre_TAlloc(hypre_SStructGraph, 1); hypre_SStructGraphComm(graph) = comm; hypre_SStructGraphNDim(graph) = hypre_SStructGridNDim(grid); hypre_SStructGridRef(grid, &hypre_SStructGraphGrid(graph)); nparts = hypre_SStructGridNParts(grid); hypre_SStructGraphNParts(graph) = nparts; pgrids = hypre_SStructGridPGrids(grid); hypre_SStructGraphPGrids(graph) = pgrids; stencils = hypre_TAlloc(hypre_SStructStencil **, nparts); for (part = 0; part < nparts; part++) { nvars = hypre_SStructPGridNVars(pgrids[part]); stencils[part] = hypre_TAlloc(hypre_SStructStencil *, nvars); for (var = 0; var < nvars; var++) { stencils[part][var] = NULL; } } hypre_SStructGraphStencils(graph) = stencils; hypre_SStructGraphNUVEntries(graph) = 0; hypre_SStructGraphAUVEntries(graph) = 0; hypre_SStructGraphIUVEntries(graph) = NULL; hypre_SStructGraphUVEntries(graph) = NULL; hypre_SStructGraphTotUEntries(graph) = 0; hypre_SStructGraphRefCount(graph) = 1; hypre_SStructGraphObjectType(graph) = HYPRE_SSTRUCT; *graph_ptr = graph; return ierr; }
int hypre_SStructUMatrixInitialize( hypre_SStructMatrix *matrix ) { HYPRE_IJMatrix ijmatrix = hypre_SStructMatrixIJMatrix(matrix); hypre_SStructGraph *graph = hypre_SStructMatrixGraph(matrix); hypre_SStructGrid *grid = hypre_SStructGraphGrid(graph); int nparts = hypre_SStructGraphNParts(graph); hypre_SStructPGrid **pgrids = hypre_SStructGraphPGrids(graph); hypre_SStructStencil ***stencils = hypre_SStructGraphStencils(graph); int nUventries = hypre_SStructGraphNUVEntries(graph); int *iUventries = hypre_SStructGraphIUVEntries(graph); hypre_SStructUVEntry **Uventries = hypre_SStructGraphUVEntries(graph); int **nvneighbors = hypre_SStructGridNVNeighbors(grid); hypre_StructGrid *sgrid; hypre_SStructStencil *stencil; int *split; int nvars; int nrows, nnzs ; int part, var, entry, i, j, k,m,b; int *row_sizes; int max_row_size; int matrix_type = hypre_SStructMatrixObjectType(matrix); hypre_Box *gridbox; hypre_Box *loopbox; hypre_Box *ghostbox; hypre_BoxArray *boxes; int *num_ghost; HYPRE_IJMatrixSetObjectType(ijmatrix, HYPRE_PARCSR); /* GEC1002 the ghlocalsize is used to set the number of rows */ if (matrix_type == HYPRE_PARCSR) { nrows = hypre_SStructGridLocalSize(grid); } if (matrix_type == HYPRE_SSTRUCT || matrix_type == HYPRE_STRUCT) { nrows = hypre_SStructGridGhlocalSize(grid) ; } /* set row sizes */ m = 0; row_sizes = hypre_CTAlloc(int, nrows); max_row_size = 0; for (part = 0; part < nparts; part++) { nvars = hypre_SStructPGridNVars(pgrids[part]); for (var = 0; var < nvars; var++) { sgrid = hypre_SStructPGridSGrid(pgrids[part], var); stencil = stencils[part][var]; split = hypre_SStructMatrixSplit(matrix, part, var); nnzs = 0; for (entry = 0; entry < hypre_SStructStencilSize(stencil); entry++) { if (split[entry] == -1) { nnzs++; } } #if 0 /* TODO: For now, assume stencil is full/complete */ if (hypre_SStructMatrixSymmetric(matrix)) { nnzs = 2*nnzs - 1; } #endif /**************/ boxes = hypre_StructGridBoxes(sgrid) ; num_ghost = hypre_StructGridNumGhost(sgrid); for (b = 0; b < hypre_BoxArraySize(boxes); b++) { gridbox = hypre_BoxArrayBox(boxes, b); ghostbox = hypre_BoxCreate(); loopbox = hypre_BoxCreate(); hypre_CopyBox(gridbox,ghostbox); hypre_BoxExpand(ghostbox,num_ghost); if (matrix_type == HYPRE_SSTRUCT || matrix_type == HYPRE_STRUCT) { hypre_CopyBox(ghostbox,loopbox); } if (matrix_type == HYPRE_PARCSR) { hypre_CopyBox(gridbox,loopbox); } for (k = hypre_BoxIMinZ(loopbox); k <= hypre_BoxIMaxZ(loopbox); k++) { for (j = hypre_BoxIMinY(loopbox); j <= hypre_BoxIMaxY(loopbox); j++) { for (i = hypre_BoxIMinX(loopbox); i <= hypre_BoxIMaxX(loopbox); i++) { if ( ( ( i>=hypre_BoxIMinX(gridbox) ) && ( j>=hypre_BoxIMinY(gridbox) ) ) && ( k>=hypre_BoxIMinZ(gridbox) ) ) { if ( ( ( i<=hypre_BoxIMaxX(gridbox) ) && ( j<=hypre_BoxIMaxY(gridbox) ) ) && ( k<=hypre_BoxIMaxZ(gridbox) ) ) { row_sizes[m] = nnzs; max_row_size = hypre_max(max_row_size, row_sizes[m]); } } m++; } } } hypre_BoxDestroy(ghostbox); hypre_BoxDestroy(loopbox); } if (nvneighbors[part][var]) { max_row_size = hypre_max(max_row_size, hypre_SStructStencilSize(stencil)); } /*********************/ } } /* GEC0902 essentially for each UVentry we figure out how many extra columns * we need to add to the rowsizes */ for (entry = 0; entry < nUventries; entry++) { i = iUventries[entry]; row_sizes[i] += hypre_SStructUVEntryNUEntries(Uventries[i]); max_row_size = hypre_max(max_row_size, row_sizes[i]); } /* ZTODO: Update row_sizes based on neighbor off-part couplings */ HYPRE_IJMatrixSetRowSizes (ijmatrix, (const int *) row_sizes); hypre_TFree(row_sizes); hypre_SStructMatrixTmpColCoords(matrix) = hypre_CTAlloc(HYPRE_BigInt, max_row_size); hypre_SStructMatrixTmpCoeffs(matrix) = hypre_CTAlloc(double, max_row_size); /* GEC1002 at this point the processor has the partitioning (creation of ij) */ HYPRE_IJMatrixInitialize(ijmatrix); return hypre_error_flag; }
HYPRE_Int HYPRE_SStructGraphDestroy( HYPRE_SStructGraph graph ) { HYPRE_Int nparts; hypre_SStructPGrid **pgrids; hypre_SStructStencil ***stencils; HYPRE_Int *fem_nsparse; HYPRE_Int **fem_sparse_i; HYPRE_Int **fem_sparse_j; HYPRE_Int **fem_entries; HYPRE_Int nUventries; HYPRE_Int *iUventries; hypre_SStructUVEntry **Uventries; hypre_SStructUVEntry *Uventry; HYPRE_Int nvars; HYPRE_Int part, var, i; if (graph) { hypre_SStructGraphRefCount(graph) --; if (hypre_SStructGraphRefCount(graph) == 0) { nparts = hypre_SStructGraphNParts(graph); pgrids = hypre_SStructGraphPGrids(graph); stencils = hypre_SStructGraphStencils(graph); fem_nsparse = hypre_SStructGraphFEMNSparse(graph); fem_sparse_i = hypre_SStructGraphFEMSparseJ(graph); fem_sparse_j = hypre_SStructGraphFEMSparseI(graph); fem_entries = hypre_SStructGraphFEMEntries(graph); nUventries = hypre_SStructGraphNUVEntries(graph); iUventries = hypre_SStructGraphIUVEntries(graph); Uventries = hypre_SStructGraphUVEntries(graph); for (part = 0; part < nparts; part++) { nvars = hypre_SStructPGridNVars(pgrids[part]); for (var = 0; var < nvars; var++) { HYPRE_SStructStencilDestroy(stencils[part][var]); } hypre_TFree(stencils[part]); hypre_TFree(fem_sparse_i[part]); hypre_TFree(fem_sparse_j[part]); hypre_TFree(fem_entries[part]); } HYPRE_SStructGridDestroy(hypre_SStructGraphGrid(graph)); HYPRE_SStructGridDestroy(hypre_SStructGraphDomainGrid(graph)); hypre_TFree(stencils); hypre_TFree(fem_nsparse); hypre_TFree(fem_sparse_i); hypre_TFree(fem_sparse_j); hypre_TFree(fem_entries); /* RDF: THREAD? */ for (i = 0; i < nUventries; i++) { Uventry = Uventries[iUventries[i]]; if (Uventry) { hypre_TFree(hypre_SStructUVEntryUEntries(Uventry)); hypre_TFree(Uventry); } Uventries[iUventries[i]] = NULL; } hypre_TFree(iUventries); hypre_TFree(Uventries); hypre_TFree(graph); } } return hypre_error_flag; }
HYPRE_Int HYPRE_SStructGraphCreate( MPI_Comm comm, HYPRE_SStructGrid grid, HYPRE_SStructGraph *graph_ptr ) { hypre_SStructGraph *graph; HYPRE_Int nparts; hypre_SStructStencil ***stencils; hypre_SStructPGrid **pgrids; HYPRE_Int *fem_nsparse; HYPRE_Int **fem_sparse_i; HYPRE_Int **fem_sparse_j; HYPRE_Int **fem_entries; HYPRE_Int nvars; HYPRE_Int part, var; graph = hypre_TAlloc(hypre_SStructGraph, 1); hypre_SStructGraphComm(graph) = comm; hypre_SStructGraphNDim(graph) = hypre_SStructGridNDim(grid); hypre_SStructGridRef(grid, &hypre_SStructGraphGrid(graph)); hypre_SStructGridRef(grid, &hypre_SStructGraphDomainGrid(graph)); nparts = hypre_SStructGridNParts(grid); hypre_SStructGraphNParts(graph) = nparts; pgrids = hypre_SStructGridPGrids(grid); stencils = hypre_TAlloc(hypre_SStructStencil **, nparts); fem_nsparse = hypre_TAlloc(HYPRE_Int, nparts); fem_sparse_i = hypre_TAlloc(HYPRE_Int *, nparts); fem_sparse_j = hypre_TAlloc(HYPRE_Int *, nparts); fem_entries = hypre_TAlloc(HYPRE_Int *, nparts); for (part = 0; part < nparts; part++) { nvars = hypre_SStructPGridNVars(pgrids[part]); stencils[part] = hypre_TAlloc(hypre_SStructStencil *, nvars); fem_nsparse[part] = 0; fem_sparse_i[part] = NULL; fem_sparse_j[part] = NULL; fem_entries[part] = NULL; for (var = 0; var < nvars; var++) { stencils[part][var] = NULL; } } hypre_SStructGraphStencils(graph) = stencils; hypre_SStructGraphFEMNSparse(graph) = fem_nsparse; hypre_SStructGraphFEMSparseJ(graph) = fem_sparse_i; hypre_SStructGraphFEMSparseI(graph) = fem_sparse_j; hypre_SStructGraphFEMEntries(graph) = fem_entries; hypre_SStructGraphNUVEntries(graph) = 0; hypre_SStructGraphAUVEntries(graph) = 0; hypre_SStructGraphIUVEntries(graph) = NULL; hypre_SStructGraphUVEntries(graph) = NULL; hypre_SStructGraphTotUEntries(graph) = 0; hypre_SStructGraphRefCount(graph) = 1; hypre_SStructGraphObjectType(graph) = HYPRE_SSTRUCT; hypre_SStructGraphEntries(graph) = NULL; hypre_SStructNGraphEntries(graph) = 0; hypre_SStructAGraphEntries(graph) = 0; *graph_ptr = graph; return hypre_error_flag; }