int hypre_SMGRelaxSetNewMatrixStencil( void *relax_vdata, hypre_StructStencil *diff_stencil ) { hypre_SMGRelaxData *relax_data = relax_vdata; hypre_Index *stencil_shape = hypre_StructStencilShape(diff_stencil); int stencil_size = hypre_StructStencilSize(diff_stencil); int stencil_dim = hypre_StructStencilDim(diff_stencil); int i; int ierr = 0; for (i = 0; i < stencil_size; i++) { if (hypre_IndexD(stencil_shape[i], (stencil_dim - 1)) != 0) { (relax_data -> setup_a_rem) = 1; } else { (relax_data -> setup_a_sol) = 1; } } return ierr; }
hypre_BoxArray * hypre_GrowBoxByStencil( hypre_Box *box, hypre_StructStencil *stencil, int transpose ) { hypre_BoxArray *grow_box_array; hypre_BoxArray *shift_box_array; hypre_Box *shift_box; hypre_Index *stencil_shape; int s, d; stencil_shape = hypre_StructStencilShape(stencil); shift_box_array = hypre_BoxArrayCreate(hypre_StructStencilSize(stencil)); shift_box = hypre_BoxCreate(); for (s = 0; s < hypre_StructStencilSize(stencil); s++) { if (transpose) for (d = 0; d < 3; d++) { hypre_BoxIMinD(shift_box, d) = hypre_BoxIMinD(box, d) - hypre_IndexD(stencil_shape[s], d); hypre_BoxIMaxD(shift_box, d) = hypre_BoxIMaxD(box, d) - hypre_IndexD(stencil_shape[s], d); } else for (d = 0; d < 3; d++) { hypre_BoxIMinD(shift_box, d) = hypre_BoxIMinD(box, d) + hypre_IndexD(stencil_shape[s], d); hypre_BoxIMaxD(shift_box, d) = hypre_BoxIMaxD(box, d) + hypre_IndexD(stencil_shape[s], d); } hypre_CopyBox(shift_box, hypre_BoxArrayBox(shift_box_array, s)); } hypre_BoxDestroy(shift_box); hypre_UnionBoxes(shift_box_array); grow_box_array = shift_box_array; return grow_box_array; }
hypre_StructStencil * hypre_StructStencilCreate( HYPRE_Int dim, HYPRE_Int size, hypre_Index *shape ) { hypre_StructStencil *stencil; stencil = hypre_TAlloc(hypre_StructStencil, 1); hypre_StructStencilShape(stencil) = shape; hypre_StructStencilSize(stencil) = size; hypre_StructStencilDim(stencil) = dim; hypre_StructStencilRefCount(stencil) = 1; return stencil; }
HYPRE_Int hypre_StructStencilElementRank( hypre_StructStencil *stencil, hypre_Index stencil_element ) { hypre_Index *stencil_shape; HYPRE_Int rank; HYPRE_Int i; rank = -1; stencil_shape = hypre_StructStencilShape(stencil); for (i = 0; i < hypre_StructStencilSize(stencil); i++) { if ((hypre_IndexX(stencil_shape[i]) == hypre_IndexX(stencil_element)) && (hypre_IndexY(stencil_shape[i]) == hypre_IndexY(stencil_element)) && (hypre_IndexZ(stencil_shape[i]) == hypre_IndexZ(stencil_element)) ) { rank = i; break; } } return rank; }
HYPRE_Int hypre_StructStencilSymmetrize( hypre_StructStencil *stencil, hypre_StructStencil **symm_stencil_ptr, HYPRE_Int **symm_elements_ptr ) { hypre_Index *stencil_shape = hypre_StructStencilShape(stencil); HYPRE_Int stencil_size = hypre_StructStencilSize(stencil); hypre_StructStencil *symm_stencil; hypre_Index *symm_stencil_shape; HYPRE_Int symm_stencil_size; HYPRE_Int *symm_elements; HYPRE_Int no_symmetric_stencil_element; HYPRE_Int i, j, d; /*------------------------------------------------------ * Copy stencil elements into `symm_stencil_shape' *------------------------------------------------------*/ symm_stencil_shape = hypre_CTAlloc(hypre_Index, 2*stencil_size); for (i = 0; i < stencil_size; i++) { hypre_CopyIndex(stencil_shape[i], symm_stencil_shape[i]); } /*------------------------------------------------------ * Create symmetric stencil elements and `symm_elements' *------------------------------------------------------*/ symm_elements = hypre_CTAlloc(HYPRE_Int, 2*stencil_size); for (i = 0; i < 2*stencil_size; i++) symm_elements[i] = -1; symm_stencil_size = stencil_size; for (i = 0; i < stencil_size; i++) { if (symm_elements[i] < 0) { /* note: start at i to handle "center" element correctly */ no_symmetric_stencil_element = 1; for (j = i; j < stencil_size; j++) { if ( (hypre_IndexX(symm_stencil_shape[j]) == -hypre_IndexX(symm_stencil_shape[i]) ) && (hypre_IndexY(symm_stencil_shape[j]) == -hypre_IndexY(symm_stencil_shape[i]) ) && (hypre_IndexZ(symm_stencil_shape[j]) == -hypre_IndexZ(symm_stencil_shape[i]) ) ) { /* only "off-center" elements have symmetric entries */ if (i != j) symm_elements[j] = i; no_symmetric_stencil_element = 0; } } if (no_symmetric_stencil_element) { /* add symmetric stencil element to `symm_stencil' */ for (d = 0; d < 3; d++) { hypre_IndexD(symm_stencil_shape[symm_stencil_size], d) = -hypre_IndexD(symm_stencil_shape[i], d); } symm_elements[symm_stencil_size] = i; symm_stencil_size++; } } } symm_stencil = hypre_StructStencilCreate(hypre_StructStencilDim(stencil), symm_stencil_size, symm_stencil_shape); *symm_stencil_ptr = symm_stencil; *symm_elements_ptr = symm_elements; return hypre_error_flag; }
hypre_SStructPMatrix * hypre_SysPFMGCreateRAPOp( hypre_SStructPMatrix *R, hypre_SStructPMatrix *A, hypre_SStructPMatrix *P, hypre_SStructPGrid *coarse_grid, HYPRE_Int cdir ) { hypre_SStructPMatrix *RAP; HYPRE_Int ndim; HYPRE_Int nvars; hypre_SStructVariable vartype; hypre_SStructStencil **RAP_stencils; hypre_StructMatrix *RAP_s; hypre_StructMatrix *R_s; hypre_StructMatrix *A_s; hypre_StructMatrix *P_s; hypre_Index **RAP_shapes; hypre_StructStencil *sstencil; hypre_Index *shape; HYPRE_Int s; HYPRE_Int *sstencil_sizes; HYPRE_Int stencil_size; hypre_StructGrid *cgrid; HYPRE_Int vi,vj; HYPRE_Int sten_cntr; HYPRE_Int P_stored_as_transpose = 0; ndim = hypre_StructStencilDim(hypre_SStructPMatrixSStencil(A, 0, 0)); nvars = hypre_SStructPMatrixNVars(A); vartype = hypre_SStructPGridVarType(coarse_grid, 0); cgrid = hypre_SStructPGridVTSGrid(coarse_grid, vartype); RAP_stencils = hypre_CTAlloc(hypre_SStructStencil *, nvars); RAP_shapes = hypre_CTAlloc(hypre_Index *, nvars); sstencil_sizes = hypre_CTAlloc(HYPRE_Int, nvars); /*-------------------------------------------------------------------------- * Symmetry within a block is exploited, but not symmetry of the form * A_{vi,vj} = A_{vj,vi}^T. *--------------------------------------------------------------------------*/ for (vi = 0; vi < nvars; vi++) { R_s = hypre_SStructPMatrixSMatrix(R, vi, vi); stencil_size = 0; for (vj = 0; vj < nvars; vj++) { A_s = hypre_SStructPMatrixSMatrix(A, vi, vj); P_s = hypre_SStructPMatrixSMatrix(P, vj, vj); sstencil_sizes[vj] = 0; if (A_s != NULL) { RAP_s = hypre_SemiCreateRAPOp(R_s, A_s, P_s, cgrid, cdir, P_stored_as_transpose); /* Just want stencil for RAP */ hypre_StructMatrixInitializeShell(RAP_s); sstencil = hypre_StructMatrixStencil(RAP_s); shape = hypre_StructStencilShape(sstencil); sstencil_sizes[vj] = hypre_StructStencilSize(sstencil); stencil_size += sstencil_sizes[vj]; RAP_shapes[vj] = hypre_CTAlloc(hypre_Index, sstencil_sizes[vj]); for (s = 0; s < sstencil_sizes[vj]; s++) { hypre_CopyIndex(shape[s],RAP_shapes[vj][s]); } hypre_StructMatrixDestroy(RAP_s); } } HYPRE_SStructStencilCreate(ndim, stencil_size, &RAP_stencils[vi]); sten_cntr = 0; for (vj = 0; vj < nvars; vj++) { if (sstencil_sizes[vj] > 0) { for (s = 0; s < sstencil_sizes[vj]; s++) { HYPRE_SStructStencilSetEntry(RAP_stencils[vi], sten_cntr, RAP_shapes[vj][s], vj); sten_cntr++; } hypre_TFree(RAP_shapes[vj]); } } } /* create RAP Pmatrix */ hypre_SStructPMatrixCreate(hypre_SStructPMatrixComm(A), coarse_grid, RAP_stencils, &RAP); hypre_TFree(RAP_shapes); hypre_TFree(sstencil_sizes); return RAP; }
int hypre_SMGResidual( void *residual_vdata, hypre_StructMatrix *A, hypre_StructVector *x, hypre_StructVector *b, hypre_StructVector *r ) { int ierr = 0; hypre_SMGResidualData *residual_data = (hypre_SMGResidualData *)residual_vdata; hypre_IndexRef base_stride = (residual_data -> base_stride); hypre_BoxArray *base_points = (residual_data -> base_points); hypre_ComputePkg *compute_pkg = (residual_data -> compute_pkg); hypre_CommHandle *comm_handle; hypre_BoxArrayArray *compute_box_aa; hypre_BoxArray *compute_box_a; hypre_Box *compute_box; hypre_Box *A_data_box; hypre_Box *x_data_box; hypre_Box *b_data_box; hypre_Box *r_data_box; int Ai; int xi; int bi; int ri; double *Ap; double *xp; double *bp; double *rp; hypre_Index loop_size; hypre_IndexRef start; hypre_StructStencil *stencil; hypre_Index *stencil_shape; int stencil_size; int compute_i, i, j, si; int loopi, loopj, loopk; hypre_BeginTiming(residual_data -> time_index); /*----------------------------------------------------------------------- * Compute residual r = b - Ax *-----------------------------------------------------------------------*/ stencil = hypre_StructMatrixStencil(A); stencil_shape = hypre_StructStencilShape(stencil); stencil_size = hypre_StructStencilSize(stencil); for (compute_i = 0; compute_i < 2; compute_i++) { switch(compute_i) { case 0: { xp = hypre_StructVectorData(x); hypre_InitializeIndtComputations(compute_pkg, xp, &comm_handle); compute_box_aa = hypre_ComputePkgIndtBoxes(compute_pkg); /*---------------------------------------- * Copy b into r *----------------------------------------*/ compute_box_a = base_points; hypre_ForBoxI(i, compute_box_a) { compute_box = hypre_BoxArrayBox(compute_box_a, i); start = hypre_BoxIMin(compute_box); b_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(b), i); r_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(r), i); bp = hypre_StructVectorBoxData(b, i); rp = hypre_StructVectorBoxData(r, i); hypre_BoxGetStrideSize(compute_box, base_stride, loop_size); hypre_BoxLoop2Begin(loop_size, b_data_box, start, base_stride, bi, r_data_box, start, base_stride, ri); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,bi,ri #include "hypre_box_smp_forloop.h" hypre_BoxLoop2For(loopi, loopj, loopk, bi, ri) { rp[ri] = bp[bi]; } hypre_BoxLoop2End(bi, ri); } } break; case 1: { hypre_FinalizeIndtComputations(comm_handle); compute_box_aa = hypre_ComputePkgDeptBoxes(compute_pkg); } break; } /*-------------------------------------------------------------------- * Compute r -= A*x *--------------------------------------------------------------------*/ hypre_ForBoxArrayI(i, compute_box_aa) { compute_box_a = hypre_BoxArrayArrayBoxArray(compute_box_aa, i); A_data_box = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(A), i); x_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(x), i); r_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(r), i); rp = hypre_StructVectorBoxData(r, i); hypre_ForBoxI(j, compute_box_a) { compute_box = hypre_BoxArrayBox(compute_box_a, j); start = hypre_BoxIMin(compute_box); for (si = 0; si < stencil_size; si++) { Ap = hypre_StructMatrixBoxData(A, i, si); xp = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[si]); hypre_BoxGetStrideSize(compute_box, base_stride, loop_size); hypre_BoxLoop3Begin(loop_size, A_data_box, start, base_stride, Ai, x_data_box, start, base_stride, xi, r_data_box, start, base_stride, ri); #if 0 /* The following portion is preprocessed to be handled by ROSE outliner */ #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,Ai,xi,ri #include "hypre_box_smp_forloop.h" hypre_BoxLoop3For(loopi, loopj, loopk, Ai, xi, ri) { rp[ri] -= Ap[Ai] * xp[xi]; } hypre_BoxLoop3End(Ai, xi, ri); #else for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++) { loopi = 0; loopj = 0; loopk = 0; hypre__nx = hypre__mx; hypre__ny = hypre__my; hypre__nz = hypre__mz; if (hypre__num_blocks > 1) { if (hypre__dir == 0) { loopi = hypre__block * hypre__div + (((hypre__mod) < (hypre__block)) ? (hypre__mod) : (hypre__block)); hypre__nx = hypre__div + ((hypre__mod > hypre__block) ? 1 : 0); } else if (hypre__dir == 1) { loopj = hypre__block * hypre__div + (((hypre__mod) < (hypre__block)) ? (hypre__mod) : (hypre__block)); hypre__ny = hypre__div + ((hypre__mod > hypre__block) ? 1 : 0); } else if (hypre__dir == 2) { loopk = hypre__block * hypre__div + (((hypre__mod) < (hypre__block)) ? (hypre__mod) : (hypre__block)); hypre__nz = hypre__div + ((hypre__mod > hypre__block) ? 1 : 0); } }; Ai = hypre__i1start + loopi * hypre__sx1 + loopj * hypre__sy1 + loopk * hypre__sz1; xi = hypre__i2start + loopi * hypre__sx2 + loopj * hypre__sy2 + loopk * hypre__sz2; ri = hypre__i3start + loopi * hypre__sx3 + loopj * hypre__sy3 + loopk * hypre__sz3; //begin of the loop #if 0 // for (loopk = 0; loopk < hypre__nz; loopk++) { for (loopj = 0; loopj < hypre__ny; loopj++) { for (loopi = 0; loopi < hypre__nx; loopi++) { { rp[ri] -= Ap[Ai] * xp[xi]; } Ai += hypre__sx1; xi += hypre__sx2; ri += hypre__sx3; } Ai += hypre__sy1 - hypre__nx * hypre__sx1; xi += hypre__sy2 - hypre__nx * hypre__sx2; ri += hypre__sy3 - hypre__nx * hypre__sx3; } Ai += hypre__sz1 - hypre__ny * hypre__sy1; xi += hypre__sz2 - hypre__ny * hypre__sy2; ri += hypre__sz3 - hypre__ny * hypre__sy3; } // end of the loop #else #if BLCR_CHECKPOINTING // Only checkpoint it at the first occurrance. if (g_checkpoint_flag == 0) { int err; cr_checkpoint_args_t cr_args; cr_checkpoint_handle_t cr_handle; cr_initialize_checkpoint_args_t(&cr_args); cr_args.cr_scope = CR_SCOPE_PROC;// a process cr_args.cr_target = 0; //self cr_args.cr_signal = SIGKILL; // kill after checkpointing cr_args.cr_fd = open("dump.yy", O_WRONLY|O_CREAT|O_LARGEFILE, 0400); if (cr_args.cr_fd < 0) { printf("Error: cannot open file for checkpoiting context\n"); abort(); } g_checkpoint_flag ++; printf("Checkpoiting: starting here ..\n"); err = cr_request_checkpoint(&cr_args, &cr_handle); if (err < 0) { printf("cannot request checkpoining! err=%d\n",err); abort(); } // block until the request is served cr_enter_cs(cr); cr_leave_cs(cr); printf("Checkpoiting: restarting here ..\n"); } #endif OUT__1__6755__(&Ai,&xi,&ri,&Ap,&xp,&rp,&loopi,&loopj,&loopk,&hypre__sx1,&hypre__sy1,&hypre__sz1,&hypre__sx2,&hypre__sy2,&hypre__sz2,&hypre__sx3,&hypre__sy3,&hypre__sz3,&hypre__nx,&hypre__ny,&hypre__nz); #endif } };
int hypre_StructMatrixInitializeShell( hypre_StructMatrix *matrix ) { int ierr = 0; hypre_StructGrid *grid; hypre_StructStencil *user_stencil; hypre_StructStencil *stencil; hypre_Index *stencil_shape; int stencil_size; int num_values; int *symm_elements; int *num_ghost; int extra_ghost[] = {0, 0, 0, 0, 0, 0}; hypre_BoxArray *data_space; hypre_BoxArray *boxes; hypre_Box *box; hypre_Box *data_box; int **data_indices; int data_size; int data_box_volume; int i, j, d; grid = hypre_StructMatrixGrid(matrix); /*----------------------------------------------------------------------- * Set up stencil and num_values: * The stencil is a "symmetrized" version of the user's stencil * as computed by hypre_StructStencilSymmetrize. * * The `symm_elements' array is used to determine what data is * explicitely stored (symm_elements[i] < 0) and what data does is * not explicitely stored (symm_elements[i] >= 0), but is instead * stored as the transpose coefficient at a neighboring grid point. *-----------------------------------------------------------------------*/ if (hypre_StructMatrixStencil(matrix) == NULL) { user_stencil = hypre_StructMatrixUserStencil(matrix); hypre_StructStencilSymmetrize(user_stencil, &stencil, &symm_elements); stencil_shape = hypre_StructStencilShape(stencil); stencil_size = hypre_StructStencilSize(stencil); if (!hypre_StructMatrixSymmetric(matrix)) { /* store all element data */ for (i = 0; i < stencil_size; i++) symm_elements[i] = -1; num_values = stencil_size; } else { num_values = (stencil_size + 1) / 2; } hypre_StructMatrixStencil(matrix) = stencil; hypre_StructMatrixSymmElements(matrix) = symm_elements; hypre_StructMatrixNumValues(matrix) = num_values; } /*----------------------------------------------------------------------- * Set ghost-layer size for symmetric storage * - All stencil coeffs are to be available at each point in the * grid, as well as in the user-specified ghost layer. *-----------------------------------------------------------------------*/ num_ghost = hypre_StructMatrixNumGhost(matrix); stencil = hypre_StructMatrixStencil(matrix); stencil_shape = hypre_StructStencilShape(stencil); stencil_size = hypre_StructStencilSize(stencil); symm_elements = hypre_StructMatrixSymmElements(matrix); for (i = 0; i < stencil_size; i++) { if (symm_elements[i] >= 0) { for (d = 0; d < 3; d++) { extra_ghost[2*d] = hypre_max(extra_ghost[2*d], -hypre_IndexD(stencil_shape[i], d)); extra_ghost[2*d + 1] = hypre_max(extra_ghost[2*d + 1], hypre_IndexD(stencil_shape[i], d)); } } } for (d = 0; d < 3; d++) { num_ghost[2*d] += extra_ghost[2*d]; num_ghost[2*d + 1] += extra_ghost[2*d + 1]; } /*----------------------------------------------------------------------- * Set up data_space *-----------------------------------------------------------------------*/ if (hypre_StructMatrixDataSpace(matrix) == NULL) { boxes = hypre_StructGridBoxes(grid); data_space = hypre_BoxArrayCreate(hypre_BoxArraySize(boxes)); hypre_ForBoxI(i, boxes) { box = hypre_BoxArrayBox(boxes, i); data_box = hypre_BoxArrayBox(data_space, i); hypre_CopyBox(box, data_box); for (d = 0; d < 3; d++) { hypre_BoxIMinD(data_box, d) -= num_ghost[2*d]; hypre_BoxIMaxD(data_box, d) += num_ghost[2*d + 1]; } }
int hypre_SMG2BuildRAPSym( hypre_StructMatrix *A, hypre_StructMatrix *PT, hypre_StructMatrix *R, hypre_StructMatrix *RAP, hypre_Index cindex, hypre_Index cstride ) { hypre_Index index; hypre_StructStencil *fine_stencil; int fine_stencil_size; hypre_StructGrid *fgrid; int *fgrid_ids; hypre_StructGrid *cgrid; hypre_BoxArray *cgrid_boxes; int *cgrid_ids; hypre_Box *cgrid_box; hypre_IndexRef cstart; hypre_Index stridec; hypre_Index fstart; hypre_IndexRef stridef; hypre_Index loop_size; int fi, ci; int loopi, loopj, loopk; hypre_Box *A_dbox; hypre_Box *PT_dbox; hypre_Box *R_dbox; hypre_Box *RAP_dbox; double *pa, *pb; double *ra, *rb; double *a_cc, *a_cw, *a_ce, *a_cs, *a_cn; double *a_csw, *a_cse, *a_cnw; double *rap_cc, *rap_cw, *rap_cs; double *rap_csw, *rap_cse; int iA, iAm1, iAp1; int iAc; int iP, iP1; int iR; int yOffsetA; int xOffsetP; int yOffsetP; int ierr = 0; fine_stencil = hypre_StructMatrixStencil(A); fine_stencil_size = hypre_StructStencilSize(fine_stencil); stridef = cstride; hypre_SetIndex(stridec, 1, 1, 1); fgrid = hypre_StructMatrixGrid(A); fgrid_ids = hypre_StructGridIDs(fgrid); cgrid = hypre_StructMatrixGrid(RAP); cgrid_boxes = hypre_StructGridBoxes(cgrid); cgrid_ids = hypre_StructGridIDs(cgrid); fi = 0; hypre_ForBoxI(ci, cgrid_boxes) { while (fgrid_ids[fi] != cgrid_ids[ci]) { fi++; } cgrid_box = hypre_BoxArrayBox(cgrid_boxes, ci); cstart = hypre_BoxIMin(cgrid_box); hypre_StructMapCoarseToFine(cstart, cindex, cstride, fstart); A_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(A), fi); PT_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(PT), fi); R_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(R), fi); RAP_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(RAP), ci); /*----------------------------------------------------------------- * Extract pointers for interpolation operator: * pa is pointer for weight for f-point above c-point * pb is pointer for weight for f-point below c-point *-----------------------------------------------------------------*/ hypre_SetIndex(index,0,1,0); pa = hypre_StructMatrixExtractPointerByIndex(PT, fi, index); hypre_SetIndex(index,0,-1,0); pb = hypre_StructMatrixExtractPointerByIndex(PT, fi, index); /*----------------------------------------------------------------- * Extract pointers for restriction operator: * ra is pointer for weight for f-point above c-point * rb is pointer for weight for f-point below c-point *-----------------------------------------------------------------*/ hypre_SetIndex(index,0,1,0); ra = hypre_StructMatrixExtractPointerByIndex(R, fi, index); hypre_SetIndex(index,0,-1,0); rb = hypre_StructMatrixExtractPointerByIndex(R, fi, index); /*----------------------------------------------------------------- * Extract pointers for 5-point fine grid operator: * * a_cc is pointer for center coefficient * a_cw is pointer for west coefficient * a_ce is pointer for east coefficient * a_cs is pointer for south coefficient * a_cn is pointer for north coefficient *-----------------------------------------------------------------*/ hypre_SetIndex(index,0,0,0); a_cc = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index,-1,0,0); a_cw = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index,1,0,0); a_ce = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index,0,-1,0); a_cs = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index,0,1,0); a_cn = hypre_StructMatrixExtractPointerByIndex(A, fi, index); /*----------------------------------------------------------------- * Extract additional pointers for 9-point fine grid operator: * * a_csw is pointer for southwest coefficient * a_cse is pointer for southeast coefficient * a_cnw is pointer for northwest coefficient * a_cne is pointer for northeast coefficient *-----------------------------------------------------------------*/ if(fine_stencil_size > 5) { hypre_SetIndex(index,-1,-1,0); a_csw = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index,1,-1,0); a_cse = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index,-1,1,0); a_cnw = hypre_StructMatrixExtractPointerByIndex(A, fi, index); } /*----------------------------------------------------------------- * Extract pointers for coarse grid operator - always 9-point: * * We build only the lower triangular part (plus diagonal). * * rap_cc is pointer for center coefficient (etc.) *-----------------------------------------------------------------*/ hypre_SetIndex(index,0,0,0); rap_cc = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index,-1,0,0); rap_cw = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index,0,-1,0); rap_cs = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index,-1,-1,0); rap_csw = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index,1,-1,0); rap_cse = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); /*----------------------------------------------------------------- * Define offsets for fine grid stencil and interpolation * * In the BoxLoop below I assume iA and iP refer to data associated * with the point which we are building the stencil for. The below * Offsets are used in refering to data associated with other points. *-----------------------------------------------------------------*/ hypre_SetIndex(index,0,1,0); yOffsetA = hypre_BoxOffsetDistance(A_dbox,index); yOffsetP = hypre_BoxOffsetDistance(PT_dbox,index); hypre_SetIndex(index,1,0,0); xOffsetP = hypre_BoxOffsetDistance(PT_dbox,index); /*----------------------------------------------------------------- * Switch statement to direct control to apropriate BoxLoop depending * on stencil size. Default is full 9-point. *-----------------------------------------------------------------*/ switch (fine_stencil_size) { /*-------------------------------------------------------------- * Loop for symmetric 5-point fine grid operator; produces a * symmetric 9-point coarse grid operator. We calculate only the * lower triangular stencil entries: (southwest, south, southeast, * west, and center). *--------------------------------------------------------------*/ case 5: hypre_BoxGetSize(cgrid_box, loop_size); hypre_BoxLoop4Begin(loop_size, PT_dbox, cstart, stridec, iP, R_dbox, cstart, stridec, iR, A_dbox, fstart, stridef, iA, RAP_dbox, cstart, stridec, iAc); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,iP,iR,iA,iAc,iAm1,iAp1,iP1 #include "hypre_box_smp_forloop.h" hypre_BoxLoop4For(loopi, loopj, loopk, iP, iR, iA, iAc) { iAm1 = iA - yOffsetA; iAp1 = iA + yOffsetA; iP1 = iP - yOffsetP - xOffsetP; rap_csw[iAc] = rb[iR] * a_cw[iAm1] * pa[iP1]; iP1 = iP - yOffsetP; rap_cs[iAc] = rb[iR] * a_cc[iAm1] * pa[iP1] + rb[iR] * a_cs[iAm1] + a_cs[iA] * pa[iP1]; iP1 = iP - yOffsetP + xOffsetP; rap_cse[iAc] = rb[iR] * a_ce[iAm1] * pa[iP1]; iP1 = iP - xOffsetP; rap_cw[iAc] = a_cw[iA] + rb[iR] * a_cw[iAm1] * pb[iP1] + ra[iR] * a_cw[iAp1] * pa[iP1]; rap_cc[iAc] = a_cc[iA] + rb[iR] * a_cc[iAm1] * pb[iP] + ra[iR] * a_cc[iAp1] * pa[iP] + rb[iR] * a_cn[iAm1] + ra[iR] * a_cs[iAp1] + a_cs[iA] * pb[iP] + a_cn[iA] * pa[iP]; } hypre_BoxLoop4End(iP, iR, iA, iAc); break; /*-------------------------------------------------------------- * Loop for symmetric 9-point fine grid operator; produces a * symmetric 9-point coarse grid operator. We calculate only the * lower triangular stencil entries: (southwest, south, southeast, * west, and center). *--------------------------------------------------------------*/ default: hypre_BoxGetSize(cgrid_box, loop_size); hypre_BoxLoop4Begin(loop_size, PT_dbox, cstart, stridec, iP, R_dbox, cstart, stridec, iR, A_dbox, fstart, stridef, iA, RAP_dbox, cstart, stridec, iAc); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,iP,iR,iA,iAc,iAm1,iAp1,iP1 #include "hypre_box_smp_forloop.h" hypre_BoxLoop4For(loopi, loopj, loopk, iP, iR, iA, iAc) { iAm1 = iA - yOffsetA; iAp1 = iA + yOffsetA; iP1 = iP - yOffsetP - xOffsetP; rap_csw[iAc] = rb[iR] * a_cw[iAm1] * pa[iP1] + rb[iR] * a_csw[iAm1] + a_csw[iA] * pa[iP1]; iP1 = iP - yOffsetP; rap_cs[iAc] = rb[iR] * a_cc[iAm1] * pa[iP1] + rb[iR] * a_cs[iAm1] + a_cs[iA] * pa[iP1]; iP1 = iP - yOffsetP + xOffsetP; rap_cse[iAc] = rb[iR] * a_ce[iAm1] * pa[iP1] + rb[iR] * a_cse[iAm1] + a_cse[iA] * pa[iP1]; iP1 = iP - xOffsetP; rap_cw[iAc] = a_cw[iA] + rb[iR] * a_cw[iAm1] * pb[iP1] + ra[iR] * a_cw[iAp1] * pa[iP1] + rb[iR] * a_cnw[iAm1] + ra[iR] * a_csw[iAp1] + a_csw[iA] * pb[iP1] + a_cnw[iA] * pa[iP1]; rap_cc[iAc] = a_cc[iA] + rb[iR] * a_cc[iAm1] * pb[iP] + ra[iR] * a_cc[iAp1] * pa[iP] + rb[iR] * a_cn[iAm1] + ra[iR] * a_cs[iAp1] + a_cs[iA] * pb[iP] + a_cn[iA] * pa[iP]; } hypre_BoxLoop4End(iP, iR, iA, iAc); break; } /* end switch statement */
HYPRE_Int hypre_SMGResidual( void *residual_vdata, hypre_StructMatrix *A, hypre_StructVector *x, hypre_StructVector *b, hypre_StructVector *r ) { HYPRE_Int ierr; hypre_SMGResidualData *residual_data = residual_vdata; hypre_IndexRef base_stride = (residual_data -> base_stride); hypre_BoxArray *base_points = (residual_data -> base_points); hypre_ComputePkg *compute_pkg = (residual_data -> compute_pkg); hypre_CommHandle *comm_handle; hypre_BoxArrayArray *compute_box_aa; hypre_BoxArray *compute_box_a; hypre_Box *compute_box; hypre_Box *A_data_box; hypre_Box *x_data_box; hypre_Box *b_data_box; hypre_Box *r_data_box; HYPRE_Int Ai; HYPRE_Int xi; HYPRE_Int bi; HYPRE_Int ri; double *Ap0; double *xp0; double *bp; double *rp; hypre_Index loop_size; hypre_IndexRef start; hypre_StructStencil *stencil; hypre_Index *stencil_shape; HYPRE_Int stencil_size; HYPRE_Int compute_i, i, j, si; HYPRE_Int loopi, loopj, loopk; double *Ap1, *Ap2; double *Ap3, *Ap4; double *Ap5, *Ap6; double *Ap7, *Ap8, *Ap9; double *Ap10, *Ap11, *Ap12, *Ap13, *Ap14; double *Ap15, *Ap16, *Ap17, *Ap18; double *Ap19, *Ap20, *Ap21, *Ap22, *Ap23, *Ap24, *Ap25, *Ap26; double *xp1, *xp2; double *xp3, *xp4; double *xp5, *xp6; double *xp7, *xp8, *xp9; double *xp10, *xp11, *xp12, *xp13, *xp14; double *xp15, *xp16, *xp17, *xp18; double *xp19, *xp20, *xp21, *xp22, *xp23, *xp24, *xp25, *xp26; hypre_BeginTiming(residual_data -> time_index); /*----------------------------------------------------------------------- * Compute residual r = b - Ax *-----------------------------------------------------------------------*/ stencil = hypre_StructMatrixStencil(A); stencil_shape = hypre_StructStencilShape(stencil); stencil_size = hypre_StructStencilSize(stencil); for (compute_i = 0; compute_i < 2; compute_i++) { switch(compute_i) { case 0: { xp0 = hypre_StructVectorData(x); hypre_InitializeIndtComputations(compute_pkg, xp0, &comm_handle); compute_box_aa = hypre_ComputePkgIndtBoxes(compute_pkg); /*---------------------------------------- * Copy b into r *----------------------------------------*/ compute_box_a = base_points; hypre_ForBoxI(i, compute_box_a) { compute_box = hypre_BoxArrayBox(compute_box_a, i); start = hypre_BoxIMin(compute_box); b_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(b), i); r_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(r), i); bp = hypre_StructVectorBoxData(b, i); rp = hypre_StructVectorBoxData(r, i); hypre_BoxGetStrideSize(compute_box, base_stride, loop_size); hypre_BoxLoop2Begin(loop_size, b_data_box, start, base_stride, bi, r_data_box, start, base_stride, ri); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,bi,ri #include "hypre_box_smp_forloop.h" hypre_BoxLoop2For(loopi, loopj, loopk, bi, ri) { rp[ri] = bp[bi]; } hypre_BoxLoop2End(bi, ri); } } break; case 1: { hypre_FinalizeIndtComputations(comm_handle); compute_box_aa = hypre_ComputePkgDeptBoxes(compute_pkg); } break; } /*-------------------------------------------------------------------- * Compute r -= A*x *--------------------------------------------------------------------*/ hypre_ForBoxArrayI(i, compute_box_aa) { compute_box_a = hypre_BoxArrayArrayBoxArray(compute_box_aa, i); A_data_box = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(A), i); x_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(x), i); r_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(r), i); rp = hypre_StructVectorBoxData(r, i); /*-------------------------------------------------------------- * Switch statement to direct control (based on stencil size) to * code to get pointers and offsets fo A and x. *--------------------------------------------------------------*/ switch (stencil_size) { case 1: Ap0 = hypre_StructMatrixBoxData(A, i, 0); xp0 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[0]); break; case 3: Ap0 = hypre_StructMatrixBoxData(A, i, 0); Ap1 = hypre_StructMatrixBoxData(A, i, 1); Ap2 = hypre_StructMatrixBoxData(A, i, 2); xp0 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[0]); xp1 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[1]); xp2 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[2]); break; case 5: Ap0 = hypre_StructMatrixBoxData(A, i, 0); Ap1 = hypre_StructMatrixBoxData(A, i, 1); Ap2 = hypre_StructMatrixBoxData(A, i, 2); Ap3 = hypre_StructMatrixBoxData(A, i, 3); Ap4 = hypre_StructMatrixBoxData(A, i, 4); xp0 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[0]); xp1 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[1]); xp2 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[2]); xp3 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[3]); xp4 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[4]); break; case 7: Ap0 = hypre_StructMatrixBoxData(A, i, 0); Ap1 = hypre_StructMatrixBoxData(A, i, 1); Ap2 = hypre_StructMatrixBoxData(A, i, 2); Ap3 = hypre_StructMatrixBoxData(A, i, 3); Ap4 = hypre_StructMatrixBoxData(A, i, 4); Ap5 = hypre_StructMatrixBoxData(A, i, 5); Ap6 = hypre_StructMatrixBoxData(A, i, 6); xp0 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[0]); xp1 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[1]); xp2 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[2]); xp3 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[3]); xp4 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[4]); xp5 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[5]); xp6 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[6]); break; case 9: Ap0 = hypre_StructMatrixBoxData(A, i, 0); Ap1 = hypre_StructMatrixBoxData(A, i, 1); Ap2 = hypre_StructMatrixBoxData(A, i, 2); Ap3 = hypre_StructMatrixBoxData(A, i, 3); Ap4 = hypre_StructMatrixBoxData(A, i, 4); Ap5 = hypre_StructMatrixBoxData(A, i, 5); Ap6 = hypre_StructMatrixBoxData(A, i, 6); Ap7 = hypre_StructMatrixBoxData(A, i, 7); Ap8 = hypre_StructMatrixBoxData(A, i, 8); xp0 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[0]); xp1 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[1]); xp2 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[2]); xp3 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[3]); xp4 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[4]); xp5 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[5]); xp6 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[6]); xp7 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[7]); xp8 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[8]); break; case 15: Ap0 = hypre_StructMatrixBoxData(A, i, 0); Ap1 = hypre_StructMatrixBoxData(A, i, 1); Ap2 = hypre_StructMatrixBoxData(A, i, 2); Ap3 = hypre_StructMatrixBoxData(A, i, 3); Ap4 = hypre_StructMatrixBoxData(A, i, 4); Ap5 = hypre_StructMatrixBoxData(A, i, 5); Ap6 = hypre_StructMatrixBoxData(A, i, 6); Ap7 = hypre_StructMatrixBoxData(A, i, 7); Ap8 = hypre_StructMatrixBoxData(A, i, 8); Ap9 = hypre_StructMatrixBoxData(A, i, 9); Ap10 = hypre_StructMatrixBoxData(A, i, 10); Ap11 = hypre_StructMatrixBoxData(A, i, 11); Ap12 = hypre_StructMatrixBoxData(A, i, 12); Ap13 = hypre_StructMatrixBoxData(A, i, 13); Ap14 = hypre_StructMatrixBoxData(A, i, 14); xp0 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[0]); xp1 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[1]); xp2 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[2]); xp3 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[3]); xp4 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[4]); xp5 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[5]); xp6 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[6]); xp7 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[7]); xp8 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[8]); xp9 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[9]); xp10 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[10]); xp11 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[11]); xp12 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[12]); xp13 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[13]); xp14 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[14]); break; case 19: Ap0 = hypre_StructMatrixBoxData(A, i, 0); Ap1 = hypre_StructMatrixBoxData(A, i, 1); Ap2 = hypre_StructMatrixBoxData(A, i, 2); Ap3 = hypre_StructMatrixBoxData(A, i, 3); Ap4 = hypre_StructMatrixBoxData(A, i, 4); Ap5 = hypre_StructMatrixBoxData(A, i, 5); Ap6 = hypre_StructMatrixBoxData(A, i, 6); Ap7 = hypre_StructMatrixBoxData(A, i, 7); Ap8 = hypre_StructMatrixBoxData(A, i, 8); Ap9 = hypre_StructMatrixBoxData(A, i, 9); Ap10 = hypre_StructMatrixBoxData(A, i, 10); Ap11 = hypre_StructMatrixBoxData(A, i, 11); Ap12 = hypre_StructMatrixBoxData(A, i, 12); Ap13 = hypre_StructMatrixBoxData(A, i, 13); Ap14 = hypre_StructMatrixBoxData(A, i, 14); Ap15 = hypre_StructMatrixBoxData(A, i, 15); Ap16 = hypre_StructMatrixBoxData(A, i, 16); Ap17 = hypre_StructMatrixBoxData(A, i, 17); Ap18 = hypre_StructMatrixBoxData(A, i, 18); xp0 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[0]); xp1 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[1]); xp2 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[2]); xp3 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[3]); xp4 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[4]); xp5 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[5]); xp6 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[6]); xp7 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[7]); xp8 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[8]); xp9 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[9]); xp10 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[10]); xp11 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[11]); xp12 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[12]); xp13 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[13]); xp14 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[14]); xp15 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[15]); xp16 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[16]); xp17 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[17]); xp18 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[18]); break; case 27: Ap0 = hypre_StructMatrixBoxData(A, i, 0); Ap1 = hypre_StructMatrixBoxData(A, i, 1); Ap2 = hypre_StructMatrixBoxData(A, i, 2); Ap3 = hypre_StructMatrixBoxData(A, i, 3); Ap4 = hypre_StructMatrixBoxData(A, i, 4); Ap5 = hypre_StructMatrixBoxData(A, i, 5); Ap6 = hypre_StructMatrixBoxData(A, i, 6); Ap7 = hypre_StructMatrixBoxData(A, i, 7); Ap8 = hypre_StructMatrixBoxData(A, i, 8); Ap9 = hypre_StructMatrixBoxData(A, i, 9); Ap10 = hypre_StructMatrixBoxData(A, i, 10); Ap11 = hypre_StructMatrixBoxData(A, i, 11); Ap12 = hypre_StructMatrixBoxData(A, i, 12); Ap13 = hypre_StructMatrixBoxData(A, i, 13); Ap14 = hypre_StructMatrixBoxData(A, i, 14); Ap15 = hypre_StructMatrixBoxData(A, i, 15); Ap16 = hypre_StructMatrixBoxData(A, i, 16); Ap17 = hypre_StructMatrixBoxData(A, i, 17); Ap18 = hypre_StructMatrixBoxData(A, i, 18); Ap19 = hypre_StructMatrixBoxData(A, i, 19); Ap20 = hypre_StructMatrixBoxData(A, i, 20); Ap21 = hypre_StructMatrixBoxData(A, i, 21); Ap22 = hypre_StructMatrixBoxData(A, i, 22); Ap23 = hypre_StructMatrixBoxData(A, i, 23); Ap24 = hypre_StructMatrixBoxData(A, i, 24); Ap25 = hypre_StructMatrixBoxData(A, i, 25); Ap26 = hypre_StructMatrixBoxData(A, i, 26); xp0 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[0]); xp1 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[1]); xp2 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[2]); xp3 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[3]); xp4 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[4]); xp5 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[5]); xp6 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[6]); xp7 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[7]); xp8 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[8]); xp9 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[9]); xp10 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[10]); xp11 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[11]); xp12 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[12]); xp13 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[13]); xp14 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[14]); xp15 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[15]); xp16 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[16]); xp17 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[17]); xp18 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[18]); xp19 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[19]); xp20 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[20]); xp21 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[21]); xp22 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[22]); xp23 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[23]); xp24 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[24]); xp25 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[25]); xp26 = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[26]); break; default: ; } hypre_ForBoxI(j, compute_box_a) { compute_box = hypre_BoxArrayBox(compute_box_a, j); start = hypre_BoxIMin(compute_box); /*------------------------------------------------------ * Switch statement to direct control to appropriate * box loop depending on stencil size *------------------------------------------------------*/ switch (stencil_size) { case 1: hypre_BoxGetStrideSize(compute_box, base_stride, loop_size); hypre_BoxLoop3Begin(loop_size, A_data_box, start, base_stride, Ai, x_data_box, start, base_stride, xi, r_data_box, start, base_stride, ri); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,Ai,xi,ri #include "hypre_box_smp_forloop.h" hypre_BoxLoop3For(loopi, loopj, loopk, Ai, xi, ri) { rp[ri] = rp[ri] - Ap0[Ai] * xp0[xi]; } hypre_BoxLoop3End(Ai, xi, ri); break; case 3: hypre_BoxGetStrideSize(compute_box, base_stride, loop_size); hypre_BoxLoop3Begin(loop_size, A_data_box, start, base_stride, Ai, x_data_box, start, base_stride, xi, r_data_box, start, base_stride, ri); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,Ai,xi,ri #include "hypre_box_smp_forloop.h" hypre_BoxLoop3For(loopi, loopj, loopk, Ai, xi, ri) { rp[ri] = rp[ri] - Ap0[Ai] * xp0[xi] - Ap1[Ai] * xp1[xi] - Ap2[Ai] * xp2[xi]; }
HYPRE_Int hypre_FacZeroCData( void *fac_vdata, hypre_SStructMatrix *A ) { hypre_FACData *fac_data = fac_vdata; hypre_SStructGrid *grid; hypre_SStructPGrid *p_cgrid; hypre_StructGrid *cgrid; hypre_BoxArray *cgrid_boxes; hypre_Box *cgrid_box; hypre_BoxManager *fboxman; hypre_BoxManEntry **boxman_entries; HYPRE_Int nboxman_entries; hypre_Box scaled_box; hypre_Box intersect_box; hypre_SStructPMatrix *level_pmatrix; hypre_StructStencil *stencils; HYPRE_Int stencil_size; hypre_Index *refine_factors; hypre_Index temp_index; hypre_Index ilower, iupper; HYPRE_Int max_level = fac_data -> max_levels; HYPRE_Int *level_to_part = fac_data -> level_to_part; HYPRE_Int ndim = hypre_SStructMatrixNDim(A); HYPRE_Int part_crse = 0; HYPRE_Int part_fine = 1; HYPRE_Int level; HYPRE_Int nvars, var; HYPRE_Int ci, i, j, rem, intersect_size; double *values; HYPRE_Int ierr = 0; for (level= max_level; level> 0; level--) { level_pmatrix = hypre_SStructMatrixPMatrix(fac_data -> A_level[level], part_crse); grid = (fac_data -> grid_level[level]); refine_factors= &(fac_data -> refine_factors[level]); p_cgrid= hypre_SStructGridPGrid(grid, part_crse); nvars = hypre_SStructPGridNVars(p_cgrid); for (var= 0; var< nvars; var++) { stencils = hypre_SStructPMatrixSStencil(level_pmatrix, var, var); stencil_size= hypre_StructStencilSize(stencils); /*--------------------------------------------------------------------- * For each variable, find the underlying boxes for each coarse box. *---------------------------------------------------------------------*/ cgrid = hypre_SStructPGridSGrid(p_cgrid, var); cgrid_boxes = hypre_StructGridBoxes(cgrid); fboxman = hypre_SStructGridBoxManager(grid, part_fine, var); hypre_ForBoxI(ci, cgrid_boxes) { cgrid_box= hypre_BoxArrayBox(cgrid_boxes, ci); hypre_ClearIndex(temp_index); hypre_StructMapCoarseToFine(hypre_BoxIMin(cgrid_box), temp_index, *refine_factors, hypre_BoxIMin(&scaled_box)); for (i= 0; i< ndim; i++) { temp_index[i]= (*refine_factors)[i]-1; } hypre_StructMapCoarseToFine(hypre_BoxIMax(cgrid_box), temp_index, *refine_factors, hypre_BoxIMax(&scaled_box)); hypre_BoxManIntersect(fboxman, hypre_BoxIMin(&scaled_box), hypre_BoxIMax(&scaled_box), &boxman_entries, &nboxman_entries); for (i= 0; i< nboxman_entries; i++) { hypre_BoxManEntryGetExtents(boxman_entries[i], ilower, iupper); hypre_BoxSetExtents(&intersect_box, ilower, iupper); hypre_IntersectBoxes(&intersect_box, &scaled_box, &intersect_box); /* adjust the box so that it is divisible by refine_factors */ for (j= 0; j< ndim; j++) { rem= hypre_BoxIMin(&intersect_box)[j]%(*refine_factors)[j]; if (rem) { hypre_BoxIMin(&intersect_box)[j]+=(*refine_factors)[j] - rem; } } hypre_ClearIndex(temp_index); hypre_StructMapFineToCoarse(hypre_BoxIMin(&intersect_box), temp_index, *refine_factors, hypre_BoxIMin(&intersect_box)); hypre_StructMapFineToCoarse(hypre_BoxIMax(&intersect_box), temp_index, *refine_factors, hypre_BoxIMax(&intersect_box)); intersect_size= hypre_BoxVolume(&intersect_box); if (intersect_size > 0) { /*------------------------------------------------------------ * Coarse underlying box found. Now zero off. *------------------------------------------------------------*/ values= hypre_CTAlloc(double, intersect_size); for (j= 0; j< stencil_size; j++) { HYPRE_SStructMatrixSetBoxValues(fac_data -> A_level[level], part_crse, hypre_BoxIMin(&intersect_box), hypre_BoxIMax(&intersect_box), var, 1, &j, values); HYPRE_SStructMatrixSetBoxValues(A, level_to_part[level-1], hypre_BoxIMin(&intersect_box), hypre_BoxIMax(&intersect_box), var, 1, &j, values); } hypre_TFree(values); } /* if (intersect_size > 0) */ } /* for (i= 0; i< nboxman_entries; i++) */ hypre_TFree(boxman_entries); } /* hypre_ForBoxI(ci, cgrid_boxes) */ } /* for (var= 0; var< nvars; var++) */
int hypre_SMGRelaxSetupASol( void *relax_vdata, hypre_StructMatrix *A, hypre_StructVector *b, hypre_StructVector *x ) { hypre_SMGRelaxData *relax_data = relax_vdata; int num_spaces = (relax_data -> num_spaces); int *space_indices = (relax_data -> space_indices); int *space_strides = (relax_data -> space_strides); hypre_StructVector *temp_vec = (relax_data -> temp_vec); int num_pre_relax = (relax_data -> num_pre_relax); int num_post_relax = (relax_data -> num_post_relax); hypre_StructStencil *stencil = hypre_StructMatrixStencil(A); hypre_Index *stencil_shape = hypre_StructStencilShape(stencil); int stencil_size = hypre_StructStencilSize(stencil); int stencil_dim = hypre_StructStencilDim(stencil); hypre_StructMatrix *A_sol; void **solve_data; hypre_Index base_index; hypre_Index base_stride; int num_stencil_indices; int *stencil_indices; int i; int ierr = 0; /*---------------------------------------------------------- * Free up old data before putting new data into structure *----------------------------------------------------------*/ hypre_SMGRelaxDestroyASol(relax_vdata); /*---------------------------------------------------------- * Set up data *----------------------------------------------------------*/ hypre_CopyIndex((relax_data -> base_index), base_index); hypre_CopyIndex((relax_data -> base_stride), base_stride); stencil_indices = hypre_TAlloc(int, stencil_size); num_stencil_indices = 0; for (i = 0; i < stencil_size; i++) { if (hypre_IndexD(stencil_shape[i], (stencil_dim - 1)) == 0) { stencil_indices[num_stencil_indices] = i; num_stencil_indices++; } } A_sol = hypre_StructMatrixCreateMask(A, num_stencil_indices, stencil_indices); hypre_StructStencilDim(hypre_StructMatrixStencil(A_sol)) = stencil_dim - 1; hypre_TFree(stencil_indices); /* Set up solve_data */ solve_data = hypre_TAlloc(void *, num_spaces); for (i = 0; i < num_spaces; i++) { hypre_IndexD(base_index, (stencil_dim - 1)) = space_indices[i]; hypre_IndexD(base_stride, (stencil_dim - 1)) = space_strides[i]; if (stencil_dim > 2) { solve_data[i] = hypre_SMGCreate(relax_data -> comm); hypre_SMGSetNumPreRelax( solve_data[i], num_pre_relax); hypre_SMGSetNumPostRelax( solve_data[i], num_post_relax); hypre_SMGSetBase(solve_data[i], base_index, base_stride); hypre_SMGSetMemoryUse(solve_data[i], (relax_data -> memory_use)); hypre_SMGSetTol(solve_data[i], 0.0); hypre_SMGSetMaxIter(solve_data[i], 1); hypre_SMGSetup(solve_data[i], A_sol, temp_vec, x); } else { solve_data[i] = hypre_CyclicReductionCreate(relax_data -> comm); hypre_CyclicReductionSetBase(solve_data[i], base_index, base_stride); hypre_CyclicReductionSetup(solve_data[i], A_sol, temp_vec, x); } } (relax_data -> A_sol) = A_sol; (relax_data -> solve_data) = solve_data; (relax_data -> setup_a_sol) = 0; return ierr; }
int hypre_SMGRelaxSetupARem( void *relax_vdata, hypre_StructMatrix *A, hypre_StructVector *b, hypre_StructVector *x ) { hypre_SMGRelaxData *relax_data = relax_vdata; int num_spaces = (relax_data -> num_spaces); int *space_indices = (relax_data -> space_indices); int *space_strides = (relax_data -> space_strides); hypre_StructVector *temp_vec = (relax_data -> temp_vec); hypre_StructStencil *stencil = hypre_StructMatrixStencil(A); hypre_Index *stencil_shape = hypre_StructStencilShape(stencil); int stencil_size = hypre_StructStencilSize(stencil); int stencil_dim = hypre_StructStencilDim(stencil); hypre_StructMatrix *A_rem; void **residual_data; hypre_Index base_index; hypre_Index base_stride; int num_stencil_indices; int *stencil_indices; int i; int ierr = 0; /*---------------------------------------------------------- * Free up old data before putting new data into structure *----------------------------------------------------------*/ hypre_SMGRelaxDestroyARem(relax_vdata); /*---------------------------------------------------------- * Set up data *----------------------------------------------------------*/ hypre_CopyIndex((relax_data -> base_index), base_index); hypre_CopyIndex((relax_data -> base_stride), base_stride); stencil_indices = hypre_TAlloc(int, stencil_size); num_stencil_indices = 0; for (i = 0; i < stencil_size; i++) { if (hypre_IndexD(stencil_shape[i], (stencil_dim - 1)) != 0) { stencil_indices[num_stencil_indices] = i; num_stencil_indices++; } } A_rem = hypre_StructMatrixCreateMask(A, num_stencil_indices, stencil_indices); hypre_TFree(stencil_indices); /* Set up residual_data */ residual_data = hypre_TAlloc(void *, num_spaces); for (i = 0; i < num_spaces; i++) { hypre_IndexD(base_index, (stencil_dim - 1)) = space_indices[i]; hypre_IndexD(base_stride, (stencil_dim - 1)) = space_strides[i]; residual_data[i] = hypre_SMGResidualCreate(); hypre_SMGResidualSetBase(residual_data[i], base_index, base_stride); hypre_SMGResidualSetup(residual_data[i], A_rem, x, b, temp_vec); } (relax_data -> A_rem) = A_rem; (relax_data -> residual_data) = residual_data; (relax_data -> setup_a_rem) = 0; return ierr; }
/*-------------------------------------------------------------------------- * hypre_CFInterfaceExtents: Given a cgrid_box, a fgrid_box, and stencils, * find the extents of the C/F interface (interface nodes in the C box). * Boxes corresponding to stencil shifts are stored in the first stencil_size * boxes, and the union of these are appended to the end of the returned * box_array. *--------------------------------------------------------------------------*/ hypre_BoxArray * hypre_CFInterfaceExtents( hypre_Box *fgrid_box, hypre_Box *cgrid_box, hypre_StructStencil *stencils, hypre_Index rfactors ) { hypre_BoxArray *stencil_box_extents; hypre_BoxArray *union_boxes; hypre_Box *cfine_box; hypre_Box *box; hypre_Index stencil_shape, cstart, zero_index, neg_index; HYPRE_Int stencil_size; HYPRE_Int abs_stencil; HYPRE_Int ndim= hypre_StructStencilDim(stencils); HYPRE_Int i, j; hypre_ClearIndex(zero_index); hypre_ClearIndex(neg_index); for (i= 0; i< ndim; i++) { neg_index[i]= -1; } hypre_CopyIndex(hypre_BoxIMin(cgrid_box), cstart); stencil_size = hypre_StructStencilSize(stencils); stencil_box_extents= hypre_BoxArrayCreate(stencil_size); union_boxes = hypre_BoxArrayCreate(0); for (i= 0; i< stencil_size; i++) { hypre_CopyIndex(hypre_StructStencilElement(stencils, i), stencil_shape); AbsStencilShape(stencil_shape, abs_stencil); if (abs_stencil) /* only do if not the centre stencil */ { cfine_box= hypre_CF_StenBox(fgrid_box, cgrid_box, stencil_shape, rfactors, ndim); if ( hypre_BoxVolume(cfine_box) ) { hypre_AppendBox(cfine_box, union_boxes); hypre_CopyBox(cfine_box, hypre_BoxArrayBox(stencil_box_extents, i)); for (j= 0; j< ndim; j++) { hypre_BoxIMin(cfine_box)[j]-= cstart[j]; hypre_BoxIMax(cfine_box)[j]-= cstart[j]; } hypre_CopyBox(cfine_box, hypre_BoxArrayBox(stencil_box_extents, i)); } else { hypre_BoxSetExtents(hypre_BoxArrayBox(stencil_box_extents, i), zero_index, neg_index); } hypre_BoxDestroy(cfine_box); } else /* centre */ { hypre_BoxSetExtents(hypre_BoxArrayBox(stencil_box_extents, i), zero_index, neg_index); } } /*-------------------------------------------------------------------------- * Union the stencil_box_extents to get the full CF extents and append to * the end of the stencil_box_extents BoxArray. Then shift the unioned boxes * by cstart. *--------------------------------------------------------------------------*/ if (hypre_BoxArraySize(union_boxes) > 1) { hypre_UnionBoxes(union_boxes); } hypre_ForBoxI(i, union_boxes) { hypre_AppendBox(hypre_BoxArrayBox(union_boxes, i), stencil_box_extents); }
HYPRE_Int hypre_CreateCommInfoFromStencil( hypre_StructGrid *grid, hypre_StructStencil *stencil, hypre_CommInfo **comm_info_ptr ) { HYPRE_Int i,j,k, d, m, s; hypre_BoxArrayArray *send_boxes; hypre_BoxArrayArray *recv_boxes; HYPRE_Int **send_procs; HYPRE_Int **recv_procs; HYPRE_Int **send_rboxnums; HYPRE_Int **recv_rboxnums; hypre_BoxArrayArray *send_rboxes; hypre_BoxArrayArray *recv_rboxes; hypre_BoxArray *local_boxes; HYPRE_Int num_boxes; HYPRE_Int *local_ids; hypre_BoxManager *boxman; hypre_Index *stencil_shape; hypre_IndexRef stencil_offset; hypre_IndexRef pshift; hypre_Box *box; hypre_Box *hood_box; hypre_Box *grow_box; hypre_Box *extend_box; hypre_Box *int_box; hypre_Box *periodic_box; HYPRE_Int stencil_grid[3][3][3]; HYPRE_Int grow[3][2]; hypre_BoxManEntry **entries; hypre_BoxManEntry *entry; HYPRE_Int num_entries; hypre_BoxArray *neighbor_boxes = NULL; HYPRE_Int *neighbor_procs = NULL; HYPRE_Int *neighbor_ids = NULL; HYPRE_Int *neighbor_shifts = NULL; HYPRE_Int neighbor_count; HYPRE_Int neighbor_alloc; hypre_Index ilower, iupper; hypre_BoxArray *send_box_array; hypre_BoxArray *recv_box_array; hypre_BoxArray *send_rbox_array; hypre_BoxArray *recv_rbox_array; hypre_Box **cboxes; hypre_Box *cboxes_mem; HYPRE_Int *cboxes_neighbor_location; HYPRE_Int num_cboxes, cbox_alloc; HYPRE_Int istart[3], istop[3]; HYPRE_Int sgindex[3]; HYPRE_Int num_periods, loc, box_id, id, proc_id; HYPRE_Int myid; MPI_Comm comm; /*------------------------------------------------------ * Initializations *------------------------------------------------------*/ local_boxes = hypre_StructGridBoxes(grid); local_ids = hypre_StructGridIDs(grid); num_boxes = hypre_BoxArraySize(local_boxes); num_periods = hypre_StructGridNumPeriods(grid); boxman = hypre_StructGridBoxMan(grid); comm = hypre_StructGridComm(grid); hypre_MPI_Comm_rank(comm, &myid); for (k = 0; k < 3; k++) { for (j = 0; j < 3; j++) { for (i = 0; i < 3; i++) { stencil_grid[i][j][k] = 0; } } } /*------------------------------------------------------ * Compute the "grow" information from the stencil *------------------------------------------------------*/ stencil_shape = hypre_StructStencilShape(stencil); for (d = 0; d < 3; d++) { grow[d][0] = 0; grow[d][1] = 0; } for (s = 0; s < hypre_StructStencilSize(stencil); s++) { stencil_offset = stencil_shape[s]; for (d = 0; d < 3; d++) { m = stencil_offset[d]; istart[d] = 1; istop[d] = 1; if (m < 0) { istart[d] = 0; grow[d][0] = hypre_max(grow[d][0], -m); } else if (m > 0) { istop[d] = 2; grow[d][1] = hypre_max(grow[d][1], m); } } /* update stencil grid from the grow_stencil */ for (k = istart[2]; k <= istop[2]; k++) { for (j = istart[1]; j <= istop[1]; j++) { for (i = istart[0]; i <= istop[0]; i++) { stencil_grid[i][j][k] = 1; } } } } /*------------------------------------------------------ * Compute send/recv boxes and procs for each local box *------------------------------------------------------*/ /* initialize: for each local box, we create an array of send/recv info */ send_boxes = hypre_BoxArrayArrayCreate(num_boxes); recv_boxes = hypre_BoxArrayArrayCreate(num_boxes); send_procs = hypre_CTAlloc(HYPRE_Int *, num_boxes); recv_procs = hypre_CTAlloc(HYPRE_Int *, num_boxes); /* Remote boxnums and boxes describe data on the opposing processor, so some shifting of boxes is needed below for periodic neighbor boxes. Remote box info is also needed for receives to allow for reverse communication. */ send_rboxnums = hypre_CTAlloc(HYPRE_Int *, num_boxes); send_rboxes = hypre_BoxArrayArrayCreate(num_boxes); recv_rboxnums = hypre_CTAlloc(HYPRE_Int *, num_boxes); recv_rboxes = hypre_BoxArrayArrayCreate(num_boxes); grow_box = hypre_BoxCreate(); extend_box = hypre_BoxCreate(); int_box = hypre_BoxCreate(); periodic_box = hypre_BoxCreate(); /* storage we will use and keep track of the neighbors */ neighbor_alloc = 30; /* initial guess at max size */ neighbor_boxes = hypre_BoxArrayCreate(neighbor_alloc); neighbor_procs = hypre_CTAlloc(HYPRE_Int, neighbor_alloc); neighbor_ids = hypre_CTAlloc(HYPRE_Int, neighbor_alloc); neighbor_shifts = hypre_CTAlloc(HYPRE_Int, neighbor_alloc); /* storage we will use to collect all of the intersected boxes (the send and recv regions for box i (this may not be enough in the case of periodic boxes, so we will have to check) */ cbox_alloc = hypre_BoxManNEntries(boxman); cboxes_neighbor_location = hypre_CTAlloc(HYPRE_Int, cbox_alloc); cboxes = hypre_CTAlloc(hypre_Box *, cbox_alloc); cboxes_mem = hypre_CTAlloc(hypre_Box, cbox_alloc); /******* loop through each local box **************/ for (i = 0; i < num_boxes; i++) { /* get the box */ box = hypre_BoxArrayBox(local_boxes, i); /* box_id = local_ids[i]; the box id in the Box Manager is the box number, * and we use this to find out if a box has intersected with itself */ box_id = i; /* grow box local i according to the stencil*/ hypre_CopyBox(box, grow_box); for (d = 0; d < 3; d++) { hypre_BoxIMinD(grow_box, d) -= grow[d][0]; hypre_BoxIMaxD(grow_box, d) += grow[d][1]; } /* extend_box - to find the list of potential neighbors, we need to grow the local box a bit differently in case, for example, the stencil grows in one dimension [0] and not the other [1] */ hypre_CopyBox(box, extend_box); for (d = 0; d < 3; d++) { hypre_BoxIMinD(extend_box, d) -= hypre_max(grow[d][0],grow[d][1]); hypre_BoxIMaxD(extend_box, d) += hypre_max(grow[d][0],grow[d][1]); } /*------------------------------------------------ * Determine the neighbors of box i *------------------------------------------------*/ /* Do this by intersecting the extend box with the BoxManager. We must also check for periodic neighbors. */ neighbor_count = 0; hypre_BoxArraySetSize(neighbor_boxes, 0); /* shift the box by each period (k=0 is original box) */ for (k = 0; k < num_periods; k++) { hypre_CopyBox(extend_box, periodic_box); pshift = hypre_StructGridPShift(grid, k); hypre_BoxShiftPos(periodic_box, pshift); /* get the intersections */ hypre_BoxManIntersect(boxman, hypre_BoxIMin(periodic_box) , hypre_BoxIMax(periodic_box) , &entries , &num_entries); /* note: do we need to remove the intersection with our original box? no if periodic, yes if non-periodic (k=0) */ /* unpack entries (first check storage) */ if (neighbor_count + num_entries > neighbor_alloc) { neighbor_alloc = neighbor_count + num_entries + 5; neighbor_procs = hypre_TReAlloc(neighbor_procs, HYPRE_Int, neighbor_alloc); neighbor_ids = hypre_TReAlloc(neighbor_ids, HYPRE_Int, neighbor_alloc); neighbor_shifts = hypre_TReAlloc(neighbor_shifts, HYPRE_Int, neighbor_alloc); } /* check storage for the array */ hypre_BoxArraySetSize(neighbor_boxes, neighbor_count + num_entries); /* now unpack */ for (j = 0; j < num_entries; j++) { entry = entries[j]; proc_id = hypre_BoxManEntryProc(entry); id = hypre_BoxManEntryId(entry); /* don't keep box i in the non-periodic case*/ if (!k) { if((myid == proc_id) && (box_id == id)) { continue; } } hypre_BoxManEntryGetExtents(entry, ilower, iupper); hypre_BoxSetExtents(hypre_BoxArrayBox(neighbor_boxes, neighbor_count), ilower, iupper); /* shift the periodic boxes (needs to be the opposite of above) */ if (k) { hypre_BoxShiftNeg( hypre_BoxArrayBox(neighbor_boxes, neighbor_count), pshift); } neighbor_procs[neighbor_count] = proc_id; neighbor_ids[neighbor_count] = id; neighbor_shifts[neighbor_count] = k; neighbor_count++; } hypre_BoxArraySetSize(neighbor_boxes, neighbor_count); hypre_TFree(entries); } /* end of loop through periods k */ /* Now we have a list of all of the neighbors for box i! */ /* note: we don't want/need to remove duplicates - they should have different intersections (TO DO: put more thought into if there are ever any exceptions to this? - the intersection routine already eliminates duplicates - so what i mean is eliminating duplicates from multiple intersection calls in periodic case) */ /*------------------------------------------------ * Compute recv_box_array for box i *------------------------------------------------*/ /* check size of storage for cboxes */ /* let's make sure that we have enough storage in case each neighbor produces a send/recv region */ if (neighbor_count > cbox_alloc) { cbox_alloc = neighbor_count; cboxes_neighbor_location = hypre_TReAlloc(cboxes_neighbor_location, HYPRE_Int, cbox_alloc); cboxes = hypre_TReAlloc(cboxes, hypre_Box *, cbox_alloc); cboxes_mem = hypre_TReAlloc(cboxes_mem, hypre_Box, cbox_alloc); } /* Loop through each neighbor box. If the neighbor box intersects the grown box i (grown according to our stencil), then the intersection is a recv region. If the neighbor box was shifted to handle periodicity, we need to (positive) shift it back. */ num_cboxes = 0; for (k = 0; k < neighbor_count; k++) { hood_box = hypre_BoxArrayBox(neighbor_boxes, k); /* check the stencil grid to see if it makes sense to intersect */ for (d = 0; d < 3; d++) { sgindex[d] = 1; s = hypre_BoxIMinD(hood_box, d) - hypre_BoxIMaxD(box, d); if (s > 0) { sgindex[d] = 2; } s = hypre_BoxIMinD(box, d) - hypre_BoxIMaxD(hood_box, d); if (s > 0) { sgindex[d] = 0; } } /* it makes sense only if we have at least one non-zero entry */ if (stencil_grid[sgindex[0]][sgindex[1]][sgindex[2]]) { /* intersect - result is int_box */ hypre_IntersectBoxes(grow_box, hood_box, int_box); /* if we have a positive volume box, this is a recv region */ if (hypre_BoxVolume(int_box)) { /* keep track of which neighbor: k... */ cboxes_neighbor_location[num_cboxes] = k; cboxes[num_cboxes] = &cboxes_mem[num_cboxes]; /* keep the intersected box */ hypre_CopyBox(int_box, cboxes[num_cboxes]); num_cboxes++; } } } /* end of loop through each neighbor */ /* create recv_box_array and recv_procs for box i */ recv_box_array = hypre_BoxArrayArrayBoxArray(recv_boxes, i); hypre_BoxArraySetSize(recv_box_array, num_cboxes); recv_procs[i] = hypre_CTAlloc(HYPRE_Int, num_cboxes); recv_rboxnums[i] = hypre_CTAlloc(HYPRE_Int, num_cboxes); recv_rbox_array = hypre_BoxArrayArrayBoxArray(recv_rboxes, i); hypre_BoxArraySetSize(recv_rbox_array, num_cboxes); for (m = 0; m < num_cboxes; m++) { loc = cboxes_neighbor_location[m]; recv_procs[i][m] = neighbor_procs[loc]; recv_rboxnums[i][m] = neighbor_ids[loc]; hypre_CopyBox(cboxes[m], hypre_BoxArrayBox(recv_box_array, m)); /* if periodic, positive shift before copying to the rbox_array */ if (neighbor_shifts[loc]) /* periodic if shift != 0 */ { pshift = hypre_StructGridPShift(grid, neighbor_shifts[loc]); hypre_BoxShiftPos(cboxes[m], pshift); } hypre_CopyBox(cboxes[m], hypre_BoxArrayBox(recv_rbox_array, m)); cboxes[m] = NULL; } /*------------------------------------------------ * Compute send_box_array for box i *------------------------------------------------*/ /* Loop through each neighbor box. If the grown neighbor box intersects box i, then the intersection is a send region. If the neighbor box was shifted to handle periodicity, we need to (positive) shift it back. */ num_cboxes = 0; for (k = 0; k < neighbor_count; k++) { hood_box = hypre_BoxArrayBox(neighbor_boxes, k); /* check the stencil grid to see if it makes sense to intersect */ for (d = 0; d < 3; d++) { sgindex[d] = 1; s = hypre_BoxIMinD(box, d) - hypre_BoxIMaxD(hood_box, d); if (s > 0) { sgindex[d] = 2; } s = hypre_BoxIMinD(hood_box, d) - hypre_BoxIMaxD(box, d); if (s > 0) { sgindex[d] = 0; } } /* it makes sense only if we have at least one non-zero entry */ if (stencil_grid[sgindex[0]][sgindex[1]][sgindex[2]]) { /* grow the neighbor box and intersect */ hypre_CopyBox(hood_box, grow_box); for (d = 0; d < 3; d++) { hypre_BoxIMinD(grow_box, d) -= grow[d][0]; hypre_BoxIMaxD(grow_box, d) += grow[d][1]; } hypre_IntersectBoxes(box, grow_box, int_box); /* if we have a positive volume box, this is a send region */ if (hypre_BoxVolume(int_box)) { /* keep track of which neighbor: k... */ cboxes_neighbor_location[num_cboxes] = k; cboxes[num_cboxes] = &cboxes_mem[num_cboxes]; /* keep the intersected box */ hypre_CopyBox(int_box, cboxes[num_cboxes]); num_cboxes++; } } }/* end of loop through neighbors */ /* create send_box_array and send_procs for box i */ send_box_array = hypre_BoxArrayArrayBoxArray(send_boxes, i); hypre_BoxArraySetSize(send_box_array, num_cboxes); send_procs[i] = hypre_CTAlloc(HYPRE_Int, num_cboxes); send_rboxnums[i] = hypre_CTAlloc(HYPRE_Int, num_cboxes); send_rbox_array = hypre_BoxArrayArrayBoxArray(send_rboxes, i); hypre_BoxArraySetSize(send_rbox_array, num_cboxes); for (m = 0; m < num_cboxes; m++) { loc = cboxes_neighbor_location[m]; send_procs[i][m] = neighbor_procs[loc]; send_rboxnums[i][m] = neighbor_ids[loc]; hypre_CopyBox(cboxes[m], hypre_BoxArrayBox(send_box_array, m)); /* if periodic, positive shift before copying to the rbox_array */ if (neighbor_shifts[loc]) /* periodic if shift != 0 */ { pshift = hypre_StructGridPShift(grid, neighbor_shifts[loc]); hypre_BoxShiftPos(cboxes[m], pshift); } hypre_CopyBox(cboxes[m], hypre_BoxArrayBox(send_rbox_array, m)); cboxes[m] = NULL; } } /* end of loop through each local box */
int hypre_PointRelax( void *relax_vdata, hypre_StructMatrix *A, hypre_StructVector *b, hypre_StructVector *x ) { hypre_PointRelaxData *relax_data = (hypre_PointRelaxData *)relax_vdata; int max_iter = (relax_data -> max_iter); int zero_guess = (relax_data -> zero_guess); double weight = (relax_data -> weight); int num_pointsets = (relax_data -> num_pointsets); int *pointset_ranks = (relax_data -> pointset_ranks); hypre_Index *pointset_strides = (relax_data -> pointset_strides); hypre_StructVector *t = (relax_data -> t); int diag_rank = (relax_data -> diag_rank); hypre_ComputePkg **compute_pkgs = (relax_data -> compute_pkgs); hypre_ComputePkg *compute_pkg; hypre_CommHandle *comm_handle; hypre_BoxArrayArray *compute_box_aa; hypre_BoxArray *compute_box_a; hypre_Box *compute_box; hypre_Box *A_data_box; hypre_Box *b_data_box; hypre_Box *x_data_box; hypre_Box *t_data_box; int Ai; int bi; int xi; int ti; double *Ap; double *bp; double *xp; double *tp; hypre_IndexRef stride; hypre_IndexRef start; hypre_Index loop_size; hypre_StructStencil *stencil; hypre_Index *stencil_shape; int stencil_size; int iter, p, compute_i, i, j, si; int loopi, loopj, loopk; int pointset; int ierr = 0; /*---------------------------------------------------------- * Initialize some things and deal with special cases *----------------------------------------------------------*/ hypre_BeginTiming(relax_data -> time_index); hypre_StructMatrixDestroy(relax_data -> A); hypre_StructVectorDestroy(relax_data -> b); hypre_StructVectorDestroy(relax_data -> x); (relax_data -> A) = hypre_StructMatrixRef(A); (relax_data -> x) = hypre_StructVectorRef(x); (relax_data -> b) = hypre_StructVectorRef(b); (relax_data -> num_iterations) = 0; /* if max_iter is zero, return */ if (max_iter == 0) { /* if using a zero initial guess, return zero */ if (zero_guess) { hypre_StructVectorSetConstantValues(x, 0.0); } hypre_EndTiming(relax_data -> time_index); return ierr; } stencil = hypre_StructMatrixStencil(A); stencil_shape = hypre_StructStencilShape(stencil); stencil_size = hypre_StructStencilSize(stencil); /*---------------------------------------------------------- * Do zero_guess iteration *----------------------------------------------------------*/ p = 0; iter = 0; if (zero_guess) { pointset = pointset_ranks[p]; compute_pkg = compute_pkgs[pointset]; stride = pointset_strides[pointset]; for (compute_i = 0; compute_i < 2; compute_i++) { switch(compute_i) { case 0: { compute_box_aa = hypre_ComputePkgIndtBoxes(compute_pkg); } break; case 1: { compute_box_aa = hypre_ComputePkgDeptBoxes(compute_pkg); } break; } hypre_ForBoxArrayI(i, compute_box_aa) { compute_box_a = hypre_BoxArrayArrayBoxArray(compute_box_aa, i); A_data_box = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(A), i); b_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(b), i); x_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(x), i); Ap = hypre_StructMatrixBoxData(A, i, diag_rank); bp = hypre_StructVectorBoxData(b, i); xp = hypre_StructVectorBoxData(x, i); hypre_ForBoxI(j, compute_box_a) { compute_box = hypre_BoxArrayBox(compute_box_a, j); start = hypre_BoxIMin(compute_box); hypre_BoxGetStrideSize(compute_box, stride, loop_size); hypre_BoxLoop3Begin(loop_size, A_data_box, start, stride, Ai, b_data_box, start, stride, bi, x_data_box, start, stride, xi); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,Ai,bi,xi #include "hypre_box_smp_forloop.h" hypre_BoxLoop3For(loopi, loopj, loopk, Ai, bi, xi) { xp[xi] = bp[bi] / Ap[Ai]; } hypre_BoxLoop3End(Ai, bi, xi); } } }
/*-------------------------------------------------------------------------- * hypre_FacZeroCFSten: Zeroes the coarse stencil coefficients that reach * into an underlying coarsened refinement box. * Algo: For each cbox * { * 1) refine cbox and expand by one in each direction * 2) boxman_intersect with the fboxman * 3) loop over intersection boxes to see if stencil * reaches over. * } *--------------------------------------------------------------------------*/ HYPRE_Int hypre_FacZeroCFSten( hypre_SStructPMatrix *Af, hypre_SStructPMatrix *Ac, hypre_SStructGrid *grid, HYPRE_Int fine_part, hypre_Index rfactors ) { hypre_BoxManager *fboxman; hypre_BoxManEntry **boxman_entries; HYPRE_Int nboxman_entries; hypre_SStructPGrid *p_cgrid; hypre_Box fgrid_box; hypre_StructGrid *cgrid; hypre_BoxArray *cgrid_boxes; hypre_Box *cgrid_box; hypre_Box scaled_box; hypre_Box *shift_ibox; hypre_StructMatrix *smatrix; hypre_StructStencil *stencils; HYPRE_Int stencil_size; hypre_Index refine_factors, upper_shift; hypre_Index stride; hypre_Index stencil_shape; hypre_Index zero_index, ilower, iupper; HYPRE_Int nvars, var1, var2; HYPRE_Int ndim; hypre_Box *ac_dbox; HYPRE_Real *ac_ptr; hypre_Index loop_size; HYPRE_Int iac; HYPRE_Int ci, i, j; HYPRE_Int abs_shape; HYPRE_Int ierr = 0; p_cgrid = hypre_SStructPMatrixPGrid(Ac); nvars = hypre_SStructPMatrixNVars(Ac); ndim = hypre_SStructPGridNDim(p_cgrid); hypre_BoxInit(&fgrid_box, ndim); hypre_BoxInit(&scaled_box, ndim); hypre_ClearIndex(zero_index); hypre_ClearIndex(stride); hypre_ClearIndex(upper_shift); for (i= 0; i< ndim; i++) { stride[i]= 1; upper_shift[i]= rfactors[i]-1; } hypre_CopyIndex(rfactors, refine_factors); if (ndim < 3) { for (i= ndim; i< 3; i++) { refine_factors[i]= 1; } } for (var1= 0; var1< nvars; var1++) { cgrid= hypre_SStructPGridSGrid(hypre_SStructPMatrixPGrid(Ac), var1); cgrid_boxes= hypre_StructGridBoxes(cgrid); fboxman= hypre_SStructGridBoxManager(grid, fine_part, var1); /*------------------------------------------------------------------ * For each parent coarse box find all fboxes that may be connected * through a stencil entry- refine this box, expand it by one * in each direction, and boxman_intersect with fboxman *------------------------------------------------------------------*/ hypre_ForBoxI(ci, cgrid_boxes) { cgrid_box= hypre_BoxArrayBox(cgrid_boxes, ci); hypre_StructMapCoarseToFine(hypre_BoxIMin(cgrid_box), zero_index, refine_factors, hypre_BoxIMin(&scaled_box)); hypre_StructMapCoarseToFine(hypre_BoxIMax(cgrid_box), upper_shift, refine_factors, hypre_BoxIMax(&scaled_box)); hypre_SubtractIndexes(hypre_BoxIMin(&scaled_box), stride, 3, hypre_BoxIMin(&scaled_box)); hypre_AddIndexes(hypre_BoxIMax(&scaled_box), stride, 3, hypre_BoxIMax(&scaled_box)); hypre_BoxManIntersect(fboxman, hypre_BoxIMin(&scaled_box), hypre_BoxIMax(&scaled_box), &boxman_entries, &nboxman_entries); for (var2= 0; var2< nvars; var2++) { stencils= hypre_SStructPMatrixSStencil(Ac, var1, var2); if (stencils != NULL) { stencil_size= hypre_StructStencilSize(stencils); smatrix = hypre_SStructPMatrixSMatrix(Ac, var1, var2); ac_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(smatrix), ci); /*--------------------------------------------------------- * Find the stencil coefficients that must be zeroed off. * Loop over all possible boxes. *---------------------------------------------------------*/ for (i= 0; i< stencil_size; i++) { hypre_CopyIndex(hypre_StructStencilElement(stencils, i), stencil_shape); AbsStencilShape(stencil_shape, abs_shape); if (abs_shape) /* non-centre stencils are zeroed */ { /* look for connecting fboxes that must be zeroed. */ for (j= 0; j< nboxman_entries; j++) { hypre_BoxManEntryGetExtents(boxman_entries[j], ilower, iupper); hypre_BoxSetExtents(&fgrid_box, ilower, iupper); shift_ibox= hypre_CF_StenBox(&fgrid_box, cgrid_box, stencil_shape, refine_factors, ndim); if ( hypre_BoxVolume(shift_ibox) ) { ac_ptr= hypre_StructMatrixExtractPointerByIndex(smatrix, ci, stencil_shape); hypre_BoxGetSize(shift_ibox, loop_size); hypre_BoxLoop1Begin(ndim, loop_size, ac_dbox, hypre_BoxIMin(shift_ibox), stride, iac); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(HYPRE_BOX_PRIVATE,iac) HYPRE_SMP_SCHEDULE #endif hypre_BoxLoop1For(iac) { ac_ptr[iac] = 0.0; } hypre_BoxLoop1End(iac); } /* if ( hypre_BoxVolume(shift_ibox) ) */ hypre_BoxDestroy(shift_ibox); } /* for (j= 0; j< nboxman_entries; j++) */ } /* if (abs_shape) */ } /* for (i= 0; i< stencil_size; i++) */ } /* if (stencils != NULL) */ } /* for (var2= 0; var2< nvars; var2++) */ hypre_TFree(boxman_entries); } /* hypre_ForBoxI ci */
int hypre_SMGResidual( void *residual_vdata, hypre_StructMatrix *A, hypre_StructVector *x, hypre_StructVector *b, hypre_StructVector *r ) { int ierr = 0; hypre_SMGResidualData *residual_data = residual_vdata; hypre_IndexRef base_stride = (residual_data -> base_stride); hypre_BoxArray *base_points = (residual_data -> base_points); hypre_ComputePkg *compute_pkg = (residual_data -> compute_pkg); hypre_CommHandle *comm_handle; hypre_BoxArrayArray *compute_box_aa; hypre_BoxArray *compute_box_a; hypre_Box *compute_box; hypre_Box *A_data_box; hypre_Box *x_data_box; hypre_Box *b_data_box; hypre_Box *r_data_box; int Ai; int xi; int bi; int ri; double *Ap; double *xp; double *bp; double *rp; hypre_Index loop_size; hypre_IndexRef start; hypre_StructStencil *stencil; hypre_Index *stencil_shape; int stencil_size; int compute_i, i, j, si; int loopi, loopj, loopk; hypre_BeginTiming(residual_data -> time_index); /*----------------------------------------------------------------------- * Compute residual r = b - Ax *-----------------------------------------------------------------------*/ stencil = hypre_StructMatrixStencil(A); stencil_shape = hypre_StructStencilShape(stencil); stencil_size = hypre_StructStencilSize(stencil); for (compute_i = 0; compute_i < 2; compute_i++) { switch(compute_i) { case 0: { xp = hypre_StructVectorData(x); hypre_InitializeIndtComputations(compute_pkg, xp, &comm_handle); compute_box_aa = hypre_ComputePkgIndtBoxes(compute_pkg); /*---------------------------------------- * Copy b into r *----------------------------------------*/ compute_box_a = base_points; hypre_ForBoxI(i, compute_box_a) { compute_box = hypre_BoxArrayBox(compute_box_a, i); start = hypre_BoxIMin(compute_box); b_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(b), i); r_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(r), i); bp = hypre_StructVectorBoxData(b, i); rp = hypre_StructVectorBoxData(r, i); hypre_BoxGetStrideSize(compute_box, base_stride, loop_size); hypre_BoxLoop2Begin(loop_size, b_data_box, start, base_stride, bi, r_data_box, start, base_stride, ri); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,bi,ri #include "hypre_box_smp_forloop.h" hypre_BoxLoop2For(loopi, loopj, loopk, bi, ri) { rp[ri] = bp[bi]; } hypre_BoxLoop2End(bi, ri); } } break; case 1: { hypre_FinalizeIndtComputations(comm_handle); compute_box_aa = hypre_ComputePkgDeptBoxes(compute_pkg); } break; } /*-------------------------------------------------------------------- * Compute r -= A*x *--------------------------------------------------------------------*/ hypre_ForBoxArrayI(i, compute_box_aa) { compute_box_a = hypre_BoxArrayArrayBoxArray(compute_box_aa, i); A_data_box = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(A), i); x_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(x), i); r_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(r), i); rp = hypre_StructVectorBoxData(r, i); hypre_ForBoxI(j, compute_box_a) { compute_box = hypre_BoxArrayBox(compute_box_a, j); start = hypre_BoxIMin(compute_box); for (si = 0; si < stencil_size; si++) { Ap = hypre_StructMatrixBoxData(A, i, si); xp = hypre_StructVectorBoxData(x, i) + hypre_BoxOffsetDistance(x_data_box, stencil_shape[si]); hypre_BoxGetStrideSize(compute_box, base_stride, loop_size); hypre_BoxLoop3Begin(loop_size, A_data_box, start, base_stride, Ai, x_data_box, start, base_stride, xi, r_data_box, start, base_stride, ri); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,Ai,xi,ri #include "hypre_box_smp_forloop.h" hypre_BoxLoop3For(loopi, loopj, loopk, Ai, xi, ri) { rp[ri] -= Ap[Ai] * xp[xi]; } hypre_BoxLoop3End(Ai, xi, ri); }
int hypre_SStructPMatrixCreate( MPI_Comm comm, hypre_SStructPGrid *pgrid, hypre_SStructStencil **stencils, hypre_SStructPMatrix **pmatrix_ptr ) { hypre_SStructPMatrix *pmatrix; int nvars; int **smaps; hypre_StructStencil ***sstencils; hypre_StructMatrix ***smatrices; int **symmetric; hypre_StructStencil *sstencil; int *vars; hypre_Index *sstencil_shape; int sstencil_size; int new_dim; int *new_sizes; hypre_Index **new_shapes; int size; hypre_StructGrid *sgrid; int vi, vj; int i, j, k; pmatrix = hypre_TAlloc(hypre_SStructPMatrix, 1); hypre_SStructPMatrixComm(pmatrix) = comm; hypre_SStructPMatrixPGrid(pmatrix) = pgrid; hypre_SStructPMatrixStencils(pmatrix) = stencils; nvars = hypre_SStructPGridNVars(pgrid); hypre_SStructPMatrixNVars(pmatrix) = nvars; /* create sstencils */ smaps = hypre_TAlloc(int *, nvars); sstencils = hypre_TAlloc(hypre_StructStencil **, nvars); new_sizes = hypre_TAlloc(int, nvars); new_shapes = hypre_TAlloc(hypre_Index *, nvars); size = 0; for (vi = 0; vi < nvars; vi++) { sstencils[vi] = hypre_TAlloc(hypre_StructStencil *, nvars); for (vj = 0; vj < nvars; vj++) { sstencils[vi][vj] = NULL; new_sizes[vj] = 0; } sstencil = hypre_SStructStencilSStencil(stencils[vi]); vars = hypre_SStructStencilVars(stencils[vi]); sstencil_shape = hypre_StructStencilShape(sstencil); sstencil_size = hypre_StructStencilSize(sstencil); smaps[vi] = hypre_TAlloc(int, sstencil_size); for (i = 0; i < sstencil_size; i++) { j = vars[i]; new_sizes[j]++; } for (vj = 0; vj < nvars; vj++) { if (new_sizes[vj]) { new_shapes[vj] = hypre_TAlloc(hypre_Index, new_sizes[vj]); new_sizes[vj] = 0; } } for (i = 0; i < sstencil_size; i++) { j = vars[i]; k = new_sizes[j]; hypre_CopyIndex(sstencil_shape[i], new_shapes[j][k]); smaps[vi][i] = k; new_sizes[j]++; } new_dim = hypre_StructStencilDim(sstencil); for (vj = 0; vj < nvars; vj++) { if (new_sizes[vj]) { sstencils[vi][vj] = hypre_StructStencilCreate(new_dim, new_sizes[vj], new_shapes[vj]); } size = hypre_max(size, new_sizes[vj]); } } hypre_SStructPMatrixSMaps(pmatrix) = smaps; hypre_SStructPMatrixSStencils(pmatrix) = sstencils; hypre_TFree(new_sizes); hypre_TFree(new_shapes); /* create smatrices */ smatrices = hypre_TAlloc(hypre_StructMatrix **, nvars); for (vi = 0; vi < nvars; vi++) { smatrices[vi] = hypre_TAlloc(hypre_StructMatrix *, nvars); for (vj = 0; vj < nvars; vj++) { smatrices[vi][vj] = NULL; if (sstencils[vi][vj] != NULL) { sgrid = hypre_SStructPGridSGrid(pgrid, vi); smatrices[vi][vj] = hypre_StructMatrixCreate(comm, sgrid, sstencils[vi][vj]); } } } hypre_SStructPMatrixSMatrices(pmatrix) = smatrices; /* create symmetric */ symmetric = hypre_TAlloc(int *, nvars); for (vi = 0; vi < nvars; vi++) { symmetric[vi] = hypre_TAlloc(int, nvars); for (vj = 0; vj < nvars; vj++) { symmetric[vi][vj] = 0; } } hypre_SStructPMatrixSymmetric(pmatrix) = symmetric; hypre_SStructPMatrixSEntriesSize(pmatrix) = size; hypre_SStructPMatrixSEntries(pmatrix) = hypre_TAlloc(int, size); hypre_SStructPMatrixRefCount(pmatrix) = 1; *pmatrix_ptr = pmatrix; return hypre_error_flag; }
int hypre_CreateComputeInfo( hypre_StructGrid *grid, hypre_StructStencil *stencil, hypre_ComputeInfo **compute_info_ptr ) { int ierr = 0; hypre_CommInfo *comm_info; hypre_BoxArrayArray *indt_boxes; hypre_BoxArrayArray *dept_boxes; hypre_BoxArray *boxes; hypre_BoxArray *cbox_array; hypre_Box *cbox; int i; #ifdef HYPRE_OVERLAP_COMM_COMP hypre_Box *rembox; hypre_Index *stencil_shape; int border[3][2] = {{0, 0}, {0, 0}, {0, 0}}; int cbox_array_size; int s, d; #endif /*------------------------------------------------------ * Extract needed grid info *------------------------------------------------------*/ boxes = hypre_StructGridBoxes(grid); /*------------------------------------------------------ * Get communication info *------------------------------------------------------*/ hypre_CreateCommInfoFromStencil(grid, stencil, &comm_info); #ifdef HYPRE_OVERLAP_COMM_COMP /*------------------------------------------------------ * Compute border info *------------------------------------------------------*/ stencil_shape = hypre_StructStencilShape(stencil); for (s = 0; s < hypre_StructStencilSize(stencil); s++) { for (d = 0; d < 3; d++) { i = hypre_IndexD(stencil_shape[s], d); if (i < 0) { border[d][0] = hypre_max(border[d][0], -i); } else if (i > 0) { border[d][1] = hypre_max(border[d][1], i); } } } /*------------------------------------------------------ * Set up the dependent boxes *------------------------------------------------------*/ dept_boxes = hypre_BoxArrayArrayCreate(hypre_BoxArraySize(boxes)); rembox = hypre_BoxCreate(); hypre_ForBoxI(i, boxes) { cbox_array = hypre_BoxArrayArrayBoxArray(dept_boxes, i); hypre_BoxArraySetSize(cbox_array, 6); hypre_CopyBox(hypre_BoxArrayBox(boxes, i), rembox); cbox_array_size = 0; for (d = 0; d < 3; d++) { if ( (hypre_BoxVolume(rembox)) && (border[d][0]) ) { cbox = hypre_BoxArrayBox(cbox_array, cbox_array_size); hypre_CopyBox(rembox, cbox); hypre_BoxIMaxD(cbox, d) = hypre_BoxIMinD(cbox, d) + border[d][0] - 1; hypre_BoxIMinD(rembox, d) = hypre_BoxIMinD(cbox, d) + border[d][0]; cbox_array_size++; } if ( (hypre_BoxVolume(rembox)) && (border[d][1]) ) { cbox = hypre_BoxArrayBox(cbox_array, cbox_array_size); hypre_CopyBox(rembox, cbox); hypre_BoxIMinD(cbox, d) = hypre_BoxIMaxD(cbox, d) - border[d][1] + 1; hypre_BoxIMaxD(rembox, d) = hypre_BoxIMaxD(cbox, d) - border[d][1]; cbox_array_size++; } } hypre_BoxArraySetSize(cbox_array, cbox_array_size); }
hypre_StructMatrix * hypre_StructMatrixCreateMask( hypre_StructMatrix *matrix, int num_stencil_indices, int *stencil_indices ) { hypre_StructMatrix *mask; hypre_StructStencil *stencil; hypre_Index *stencil_shape; int stencil_size; hypre_Index *mask_stencil_shape; int mask_stencil_size; hypre_BoxArray *data_space; int **data_indices; int **mask_data_indices; int i, j; stencil = hypre_StructMatrixStencil(matrix); stencil_shape = hypre_StructStencilShape(stencil); stencil_size = hypre_StructStencilSize(stencil); mask = hypre_CTAlloc(hypre_StructMatrix, 1); hypre_StructMatrixComm(mask) = hypre_StructMatrixComm(matrix); hypre_StructGridRef(hypre_StructMatrixGrid(matrix), &hypre_StructMatrixGrid(mask)); hypre_StructMatrixUserStencil(mask) = hypre_StructStencilRef(hypre_StructMatrixUserStencil(matrix)); mask_stencil_size = num_stencil_indices; mask_stencil_shape = hypre_CTAlloc(hypre_Index, num_stencil_indices); for (i = 0; i < num_stencil_indices; i++) { hypre_CopyIndex(stencil_shape[stencil_indices[i]], mask_stencil_shape[i]); } hypre_StructMatrixStencil(mask) = hypre_StructStencilCreate(hypre_StructStencilDim(stencil), mask_stencil_size, mask_stencil_shape); hypre_StructMatrixNumValues(mask) = hypre_StructMatrixNumValues(matrix); hypre_StructMatrixDataSpace(mask) = hypre_BoxArrayDuplicate(hypre_StructMatrixDataSpace(matrix)); hypre_StructMatrixData(mask) = hypre_StructMatrixData(matrix); hypre_StructMatrixDataAlloced(mask) = 0; hypre_StructMatrixDataSize(mask) = hypre_StructMatrixDataSize(matrix); data_space = hypre_StructMatrixDataSpace(matrix); data_indices = hypre_StructMatrixDataIndices(matrix); mask_data_indices = hypre_CTAlloc(int *, hypre_BoxArraySize(data_space)); hypre_ForBoxI(i, data_space) { mask_data_indices[i] = hypre_TAlloc(int, num_stencil_indices); for (j = 0; j < num_stencil_indices; j++) { mask_data_indices[i][j] = data_indices[i][stencil_indices[j]]; } }