HYPRE_Int hypre_PFMGRelaxSetType( void *pfmg_relax_vdata, HYPRE_Int relax_type ) { hypre_PFMGRelaxData *pfmg_relax_data = pfmg_relax_vdata; void *relax_data = (pfmg_relax_data -> relax_data); (pfmg_relax_data -> relax_type) = relax_type; switch(relax_type) { case 0: /* Jacobi */ { hypre_Index stride; hypre_Index indices[1]; hypre_PointRelaxSetWeight(relax_data, 1.0); hypre_PointRelaxSetNumPointsets(relax_data, 1); hypre_SetIndex(stride, 1, 1, 1); hypre_SetIndex(indices[0], 0, 0, 0); hypre_PointRelaxSetPointset(relax_data, 0, 1, stride, indices); } break; case 2: /* Red-Black Gauss-Seidel */ case 3: /* Red-Black Gauss-Seidel (non-symmetric) */ break; } return hypre_error_flag; }
int hypre_CommInfoCreate( hypre_BoxArrayArray *send_boxes, hypre_BoxArrayArray *recv_boxes, int **send_procs, int **recv_procs, int **send_rboxnums, int **recv_rboxnums, hypre_BoxArrayArray *send_rboxes, hypre_CommInfo **comm_info_ptr ) { int ierr = 0; hypre_CommInfo *comm_info; comm_info = hypre_TAlloc(hypre_CommInfo, 1); hypre_CommInfoSendBoxes(comm_info) = send_boxes; hypre_CommInfoRecvBoxes(comm_info) = recv_boxes; hypre_CommInfoSendProcesses(comm_info) = send_procs; hypre_CommInfoRecvProcesses(comm_info) = recv_procs; hypre_CommInfoSendRBoxnums(comm_info) = send_rboxnums; hypre_CommInfoRecvRBoxnums(comm_info) = recv_rboxnums; hypre_CommInfoSendRBoxes(comm_info) = send_rboxes; hypre_SetIndex(hypre_CommInfoSendStride(comm_info), 1, 1, 1); hypre_SetIndex(hypre_CommInfoRecvStride(comm_info), 1, 1, 1); *comm_info_ptr = comm_info; return ierr; }
void * hypre_SMGCreate( MPI_Comm comm ) { hypre_SMGData *smg_data; smg_data = hypre_CTAlloc(hypre_SMGData, 1); (smg_data -> comm) = comm; (smg_data -> time_index) = hypre_InitializeTiming("SMG"); /* set defaults */ (smg_data -> memory_use) = 0; (smg_data -> tol) = 1.0e-06; (smg_data -> max_iter) = 200; (smg_data -> rel_change) = 0; (smg_data -> zero_guess) = 0; (smg_data -> max_levels) = 0; (smg_data -> num_pre_relax) = 1; (smg_data -> num_post_relax) = 1; (smg_data -> cdir) = 2; hypre_SetIndex((smg_data -> base_index), 0, 0, 0); hypre_SetIndex((smg_data -> base_stride), 1, 1, 1); (smg_data -> logging) = 0; /* initialize */ (smg_data -> num_levels) = -1; return (void *) smg_data; }
void * hypre_PointRelaxCreate( MPI_Comm comm ) { hypre_PointRelaxData *relax_data; hypre_Index stride; hypre_Index indices[1]; relax_data = hypre_CTAlloc(hypre_PointRelaxData, 1); (relax_data -> comm) = comm; (relax_data -> time_index) = hypre_InitializeTiming("PointRelax"); /* set defaults */ (relax_data -> tol) = 1.0e-06; (relax_data -> max_iter) = 1000; (relax_data -> rel_change) = 0; (relax_data -> zero_guess) = 0; (relax_data -> weight) = 1.0; (relax_data -> num_pointsets) = 0; (relax_data -> pointset_sizes) = NULL; (relax_data -> pointset_ranks) = NULL; (relax_data -> pointset_strides) = NULL; (relax_data -> pointset_indices) = NULL; (relax_data -> t) = NULL; hypre_SetIndex(stride, 1, 1, 1); hypre_SetIndex(indices[0], 0, 0, 0); hypre_PointRelaxSetNumPointsets((void *) relax_data, 1); hypre_PointRelaxSetPointset((void *) relax_data, 0, 1, stride, indices); return (void *) relax_data; }
void * hypre_SMGResidualCreate( ) { hypre_SMGResidualData *residual_data; residual_data = hypre_CTAlloc(hypre_SMGResidualData, 1); (residual_data -> time_index) = hypre_InitializeTiming("SMGResidual"); /* set defaults */ hypre_SetIndex((residual_data -> base_index), 0, 0, 0); hypre_SetIndex((residual_data -> base_stride), 1, 1, 1); return (void *) residual_data; }
int hypre_PrintBoxArrayData( FILE *file, hypre_BoxArray *box_array, hypre_BoxArray *data_space, int num_values, double *data ) { int ierr = 0; hypre_Box *box; hypre_Box *data_box; int data_box_volume; int datai; hypre_Index loop_size; hypre_IndexRef start; hypre_Index stride; int i, j; int loopi, loopj, loopk; /*---------------------------------------- * Print data *----------------------------------------*/ hypre_SetIndex(stride, 1, 1, 1); hypre_ForBoxI(i, box_array) { box = hypre_BoxArrayBox(box_array, i); data_box = hypre_BoxArrayBox(data_space, i); start = hypre_BoxIMin(box); data_box_volume = hypre_BoxVolume(data_box); hypre_BoxGetSize(box, loop_size); hypre_BoxLoop1Begin(loop_size, data_box, start, stride, datai); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,datai #include "hypre_box_smp_forloop.h" hypre_BoxLoop1For(loopi, loopj, loopk, datai) { for (j = 0; j < num_values; j++) { fprintf(file, "%d: (%d, %d, %d; %d) %e\n", i, hypre_IndexX(start) + loopi, hypre_IndexY(start) + loopj, hypre_IndexZ(start) + loopk, j, data[datai + j*data_box_volume]); } } hypre_BoxLoop1End(datai); data += num_values*data_box_volume; }
HYPRE_Int HYPRE_StructGridSetExtents( HYPRE_StructGrid grid, HYPRE_Int *ilower, HYPRE_Int *iupper ) { hypre_Index new_ilower; hypre_Index new_iupper; HYPRE_Int d; hypre_SetIndex(new_ilower, 0); hypre_SetIndex(new_iupper, 0); for (d = 0; d < hypre_StructGridNDim((hypre_StructGrid *) grid); d++) { hypre_IndexD(new_ilower, d) = ilower[d]; hypre_IndexD(new_iupper, d) = iupper[d]; } return ( hypre_StructGridSetExtents(grid, new_ilower, new_iupper) ); }
int hypre_StructMatvecSetup( void *matvec_vdata, hypre_StructMatrix *A, hypre_StructVector *x ) { int ierr = 0; hypre_StructMatvecData *matvec_data = matvec_vdata; hypre_StructGrid *grid; hypre_StructStencil *stencil; hypre_BoxArrayArray *send_boxes; hypre_BoxArrayArray *recv_boxes; int **send_processes; int **recv_processes; hypre_BoxArrayArray *indt_boxes; hypre_BoxArrayArray *dept_boxes; hypre_Index unit_stride; hypre_ComputePkg *compute_pkg; /*---------------------------------------------------------- * Set up the compute package *----------------------------------------------------------*/ grid = hypre_StructMatrixGrid(A); stencil = hypre_StructMatrixStencil(A); hypre_CreateComputeInfo(grid, stencil, &send_boxes, &recv_boxes, &send_processes, &recv_processes, &indt_boxes, &dept_boxes); hypre_SetIndex(unit_stride, 1, 1, 1); hypre_ComputePkgCreate(send_boxes, recv_boxes, unit_stride, unit_stride, send_processes, recv_processes, indt_boxes, dept_boxes, unit_stride, grid, hypre_StructVectorDataSpace(x), 1, &compute_pkg); /*---------------------------------------------------------- * Set up the matvec data structure *----------------------------------------------------------*/ (matvec_data -> A) = hypre_StructMatrixRef(A); (matvec_data -> x) = hypre_StructVectorRef(x); (matvec_data -> compute_pkg) = compute_pkg; return ierr; }
HYPRE_Int hypre_CommInfoCreate( 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_Int boxes_match, hypre_CommInfo **comm_info_ptr ) { hypre_CommInfo *comm_info; comm_info = hypre_TAlloc(hypre_CommInfo, 1); hypre_CommInfoNDim(comm_info) = hypre_BoxArrayArrayNDim(send_boxes); hypre_CommInfoSendBoxes(comm_info) = send_boxes; hypre_CommInfoRecvBoxes(comm_info) = recv_boxes; hypre_CommInfoSendProcesses(comm_info) = send_procs; hypre_CommInfoRecvProcesses(comm_info) = recv_procs; hypre_CommInfoSendRBoxnums(comm_info) = send_rboxnums; hypre_CommInfoRecvRBoxnums(comm_info) = recv_rboxnums; hypre_CommInfoSendRBoxes(comm_info) = send_rboxes; hypre_CommInfoRecvRBoxes(comm_info) = recv_rboxes; hypre_CommInfoNumTransforms(comm_info) = 0; hypre_CommInfoCoords(comm_info) = NULL; hypre_CommInfoDirs(comm_info) = NULL; hypre_CommInfoSendTransforms(comm_info) = NULL; hypre_CommInfoRecvTransforms(comm_info) = NULL; hypre_CommInfoBoxesMatch(comm_info) = boxes_match; hypre_SetIndex(hypre_CommInfoSendStride(comm_info), 1); hypre_SetIndex(hypre_CommInfoRecvStride(comm_info), 1); *comm_info_ptr = comm_info; return hypre_error_flag; }
void * hypre_SMGRelaxCreate( MPI_Comm comm ) { hypre_SMGRelaxData *relax_data; relax_data = hypre_CTAlloc(hypre_SMGRelaxData, 1); (relax_data -> setup_temp_vec) = 1; (relax_data -> setup_a_rem) = 1; (relax_data -> setup_a_sol) = 1; (relax_data -> comm) = comm; (relax_data -> base_box_array) = NULL; (relax_data -> time_index) = hypre_InitializeTiming("SMGRelax"); /* set defaults */ (relax_data -> memory_use) = 0; (relax_data -> tol) = 1.0e-06; (relax_data -> max_iter) = 1000; (relax_data -> zero_guess) = 0; (relax_data -> num_spaces) = 1; (relax_data -> space_indices) = hypre_TAlloc(int, 1); (relax_data -> space_strides) = hypre_TAlloc(int, 1); (relax_data -> space_indices[0]) = 0; (relax_data -> space_strides[0]) = 1; (relax_data -> num_pre_spaces) = 0; (relax_data -> num_reg_spaces) = 1; (relax_data -> pre_space_ranks) = NULL; (relax_data -> reg_space_ranks) = hypre_TAlloc(int, 1); (relax_data -> reg_space_ranks[0]) = 0; hypre_SetIndex((relax_data -> base_index), 0, 0, 0); hypre_SetIndex((relax_data -> base_stride), 1, 1, 1); (relax_data -> A) = NULL; (relax_data -> b) = NULL; (relax_data -> x) = NULL; (relax_data -> temp_vec) = NULL; (relax_data -> num_pre_relax) = 1; (relax_data -> num_post_relax) = 1; return (void *) relax_data; }
int hypre_StructCopy( hypre_StructVector *x, hypre_StructVector *y ) { int ierr = 0; hypre_Box *x_data_box; hypre_Box *y_data_box; int xi; int yi; double *xp; double *yp; hypre_BoxArray *boxes; hypre_Box *box; hypre_Index loop_size; hypre_IndexRef start; hypre_Index unit_stride; int i; int loopi, loopj, loopk; hypre_SetIndex(unit_stride, 1, 1, 1); boxes = hypre_StructGridBoxes(hypre_StructVectorGrid(y)); hypre_ForBoxI(i, boxes) { box = hypre_BoxArrayBox(boxes, i); start = hypre_BoxIMin(box); x_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(x), i); y_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(y), i); xp = hypre_StructVectorBoxData(x, i); yp = hypre_StructVectorBoxData(y, i); hypre_BoxGetSize(box, loop_size); hypre_BoxLoop2Begin(loop_size, x_data_box, start, unit_stride, xi, y_data_box, start, unit_stride, yi); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,xi,yi #include "hypre_box_smp_forloop.h" hypre_BoxLoop2For(loopi, loopj, loopk, xi, yi) { yp[yi] = xp[xi]; } hypre_BoxLoop2End(xi, yi); }
HYPRE_Int hypre_StructVectorSetRandomValues( hypre_StructVector *vector, HYPRE_Int seed ) { hypre_Box *v_data_box; HYPRE_Int vi; double *vp; hypre_BoxArray *boxes; hypre_Box *box; hypre_Index loop_size; hypre_IndexRef start; hypre_Index unit_stride; HYPRE_Int i; /*----------------------------------------------------------------------- * Set the vector coefficients *-----------------------------------------------------------------------*/ srand( seed ); hypre_SetIndex(unit_stride, 1, 1, 1); boxes = hypre_StructGridBoxes(hypre_StructVectorGrid(vector)); hypre_ForBoxI(i, boxes) { box = hypre_BoxArrayBox(boxes, i); start = hypre_BoxIMin(box); v_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(vector), i); vp = hypre_StructVectorBoxData(vector, i); hypre_BoxGetSize(box, loop_size); hypre_BoxLoop1Begin(hypre_StructVectorDim(vector), loop_size, v_data_box, start, unit_stride, vi); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(HYPRE_BOX_PRIVATE,vi ) HYPRE_SMP_SCHEDULE #endif hypre_BoxLoop1For(vi) { vp[vi] = 2.0*rand()/RAND_MAX - 1.0; } hypre_BoxLoop1End(vi); }
HYPRE_Int HYPRE_StructGridSetPeriodic( HYPRE_StructGrid grid, HYPRE_Int *periodic ) { hypre_Index new_periodic; HYPRE_Int d; hypre_SetIndex(new_periodic, 0); for (d = 0; d < hypre_StructGridNDim(grid); d++) { hypre_IndexD(new_periodic, d) = periodic[d]; } return ( hypre_StructGridSetPeriodic(grid, new_periodic) ); }
int hypre_StructScale( double alpha, hypre_StructVector *y ) { int ierr = 0; hypre_Box *y_data_box; int yi; double *yp; hypre_BoxArray *boxes; hypre_Box *box; hypre_Index loop_size; hypre_IndexRef start; hypre_Index unit_stride; int i; int loopi, loopj, loopk; hypre_SetIndex(unit_stride, 1, 1, 1); boxes = hypre_StructGridBoxes(hypre_StructVectorGrid(y)); hypre_ForBoxI(i, boxes) { box = hypre_BoxArrayBox(boxes, i); start = hypre_BoxIMin(box); y_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(y), i); yp = hypre_StructVectorBoxData(y, i); hypre_BoxGetSize(box, loop_size); hypre_BoxLoop1Begin(loop_size, y_data_box, start, unit_stride, yi); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,yi #include "hypre_box_smp_forloop.h" hypre_BoxLoop1For(loopi, loopj, loopk, yi) { yp[yi] *= alpha; } hypre_BoxLoop1End(yi); }
HYPRE_Int hypre_StructScale( double alpha, hypre_StructVector *y ) { hypre_Box *y_data_box; HYPRE_Int yi; double *yp; hypre_BoxArray *boxes; hypre_Box *box; hypre_Index loop_size; hypre_IndexRef start; hypre_Index unit_stride; HYPRE_Int i; hypre_SetIndex(unit_stride, 1, 1, 1); boxes = hypre_StructGridBoxes(hypre_StructVectorGrid(y)); hypre_ForBoxI(i, boxes) { box = hypre_BoxArrayBox(boxes, i); start = hypre_BoxIMin(box); y_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(y), i); yp = hypre_StructVectorBoxData(y, i); hypre_BoxGetSize(box, loop_size); hypre_BoxLoop1Begin(hypre_StructVectorDim(y), loop_size, y_data_box, start, unit_stride, yi); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(HYPRE_BOX_PRIVATE,yi) HYPRE_SMP_SCHEDULE #endif hypre_BoxLoop1For(yi) { yp[yi] *= alpha; } hypre_BoxLoop1End(yi); }
int hypre_ComputeInfoCreate( hypre_CommInfo *comm_info, hypre_BoxArrayArray *indt_boxes, hypre_BoxArrayArray *dept_boxes, hypre_ComputeInfo **compute_info_ptr ) { int ierr = 0; hypre_ComputeInfo *compute_info; compute_info = hypre_TAlloc(hypre_ComputeInfo, 1); hypre_ComputeInfoCommInfo(compute_info) = comm_info; hypre_ComputeInfoIndtBoxes(compute_info) = indt_boxes; hypre_ComputeInfoDeptBoxes(compute_info) = dept_boxes; hypre_SetIndex(hypre_ComputeInfoStride(compute_info), 1, 1, 1); *compute_info_ptr = compute_info; return ierr; }
HYPRE_Int hypre_SparseMSGInterp( void *interp_vdata, hypre_StructMatrix *P, hypre_StructVector *xc, hypre_StructVector *e ) { HYPRE_Int ierr = 0; hypre_SparseMSGInterpData *interp_data = interp_vdata; hypre_ComputePkg *compute_pkg; hypre_IndexRef cindex; hypre_IndexRef findex; hypre_IndexRef stride; hypre_IndexRef strideP; hypre_StructGrid *fgrid; HYPRE_Int *fgrid_ids; hypre_StructGrid *cgrid; hypre_BoxArray *cgrid_boxes; HYPRE_Int *cgrid_ids; hypre_CommHandle *comm_handle; hypre_BoxArrayArray *compute_box_aa; hypre_BoxArray *compute_box_a; hypre_Box *compute_box; hypre_Box *P_dbox; hypre_Box *xc_dbox; hypre_Box *e_dbox; HYPRE_Int Pi; HYPRE_Int xci; HYPRE_Int ei; double *Pp0, *Pp1; double *xcp; double *ep, *ep0, *ep1; hypre_Index loop_size; hypre_Index start; hypre_Index startc; hypre_Index startP; hypre_Index stridec; hypre_StructStencil *stencil; hypre_Index *stencil_shape; HYPRE_Int compute_i, fi, ci, j; HYPRE_Int loopi, loopj, loopk; /*----------------------------------------------------------------------- * Initialize some things *-----------------------------------------------------------------------*/ hypre_BeginTiming(interp_data -> time_index); compute_pkg = (interp_data -> compute_pkg); cindex = (interp_data -> cindex); findex = (interp_data -> findex); stride = (interp_data -> stride); strideP = (interp_data -> strideP); stencil = hypre_StructMatrixStencil(P); stencil_shape = hypre_StructStencilShape(stencil); hypre_SetIndex(stridec, 1, 1, 1); /*----------------------------------------------------------------------- * Compute e at coarse points (injection) *-----------------------------------------------------------------------*/ fgrid = hypre_StructVectorGrid(e); fgrid_ids = hypre_StructGridIDs(fgrid); cgrid = hypre_StructVectorGrid(xc); 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++; } compute_box = hypre_BoxArrayBox(cgrid_boxes, ci); hypre_CopyIndex(hypre_BoxIMin(compute_box), startc); hypre_StructMapCoarseToFine(startc, cindex, stride, start); e_dbox = hypre_BoxArrayBox(hypre_StructVectorDataSpace(e), fi); xc_dbox = hypre_BoxArrayBox(hypre_StructVectorDataSpace(xc), ci); ep = hypre_StructVectorBoxData(e, fi); xcp = hypre_StructVectorBoxData(xc, ci); hypre_BoxGetSize(compute_box, loop_size); hypre_BoxLoop2Begin(loop_size, e_dbox, start, stride, ei, xc_dbox, startc, stridec, xci); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,ei,xci #include "hypre_box_smp_forloop.h" hypre_BoxLoop2For(loopi, loopj, loopk, ei, xci) { ep[ei] = xcp[xci]; } hypre_BoxLoop2End(ei, xci); } /*----------------------------------------------------------------------- * Compute e at fine points *-----------------------------------------------------------------------*/ for (compute_i = 0; compute_i < 2; compute_i++) { switch(compute_i) { case 0: { ep = hypre_StructVectorData(e); hypre_InitializeIndtComputations(compute_pkg, ep, &comm_handle); compute_box_aa = hypre_ComputePkgIndtBoxes(compute_pkg); } break; case 1: { hypre_FinalizeIndtComputations(comm_handle); compute_box_aa = hypre_ComputePkgDeptBoxes(compute_pkg); } break; } hypre_ForBoxArrayI(fi, compute_box_aa) { compute_box_a = hypre_BoxArrayArrayBoxArray(compute_box_aa, fi); P_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(P), fi); e_dbox = hypre_BoxArrayBox(hypre_StructVectorDataSpace(e), fi); Pp0 = hypre_StructMatrixBoxData(P, fi, 0); Pp1 = hypre_StructMatrixBoxData(P, fi, 1); ep = hypre_StructVectorBoxData(e, fi); ep0 = ep + hypre_BoxOffsetDistance(e_dbox, stencil_shape[0]); ep1 = ep + hypre_BoxOffsetDistance(e_dbox, stencil_shape[1]); hypre_ForBoxI(j, compute_box_a) { compute_box = hypre_BoxArrayBox(compute_box_a, j); hypre_CopyIndex(hypre_BoxIMin(compute_box), start); hypre_StructMapFineToCoarse(start, findex, stride, startc); hypre_StructMapCoarseToFine(startc, cindex, strideP, startP); hypre_BoxGetStrideSize(compute_box, stride, loop_size); hypre_BoxLoop2Begin(loop_size, P_dbox, startP, strideP, Pi, e_dbox, start, stride, ei); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,Pi,ei #include "hypre_box_smp_forloop.h" hypre_BoxLoop2For(loopi, loopj, loopk, Pi, ei) { ep[ei] = (Pp0[Pi] * ep0[ei] + Pp1[Pi] * ep1[ei]); } hypre_BoxLoop2End(Pi, ei); } }
HYPRE_Int hypre_PFMGBuildCoarseOp5( hypre_StructMatrix *A, hypre_StructMatrix *P, hypre_StructMatrix *R, HYPRE_Int cdir, hypre_Index cindex, hypre_Index cstride, hypre_StructMatrix *RAP ) { hypre_Index index; hypre_Index index_temp; hypre_StructGrid *fgrid; hypre_BoxArray *fgrid_boxes; hypre_Box *fgrid_box; HYPRE_Int *fgrid_ids; hypre_StructGrid *cgrid; hypre_BoxArray *cgrid_boxes; hypre_Box *cgrid_box; HYPRE_Int *cgrid_ids; hypre_IndexRef cstart, bfstart, stridef; hypre_Index fstart, bcstart, stridec; hypre_Index loop_size; HYPRE_Int constant_coefficient; HYPRE_Int fi, ci, fbi; HYPRE_Int loopi, loopj, loopk; hypre_Box *A_dbox; hypre_Box *P_dbox; hypre_Box *RAP_dbox; hypre_BoxArray *bdy_boxes, *tmp_boxes; hypre_Box *bdy_box, *fcbox; double *pb, *pa; double *a_cc, *a_cw, *a_ce, *a_cb, *a_ca; double *rap_cc, *rap_cw, *rap_ce; double *rap_cb, *rap_ca; double west, east; double center_int, center_bdy; HYPRE_Int iA, iAm1, iAp1; HYPRE_Int iAc; HYPRE_Int iP, iPm1, iPp1; HYPRE_Int OffsetA; HYPRE_Int OffsetP; stridef = cstride; hypre_SetIndex(stridec, 1, 1, 1); fgrid = hypre_StructMatrixGrid(A); fgrid_boxes = hypre_StructGridBoxes(fgrid); fgrid_ids = hypre_StructGridIDs(fgrid); cgrid = hypre_StructMatrixGrid(RAP); cgrid_boxes = hypre_StructGridBoxes(cgrid); cgrid_ids = hypre_StructGridIDs(cgrid); constant_coefficient = hypre_StructMatrixConstantCoefficient(RAP); hypre_assert( hypre_StructMatrixConstantCoefficient(A) == constant_coefficient ); if ( constant_coefficient==0 ) { hypre_assert( hypre_StructMatrixConstantCoefficient(R) == 0 ); hypre_assert( hypre_StructMatrixConstantCoefficient(P) == 0 ); } else /* 1 or 2 */ { hypre_assert( hypre_StructMatrixConstantCoefficient(R) == 1 ); hypre_assert( hypre_StructMatrixConstantCoefficient(P) == 1 ); } fcbox = hypre_BoxCreate(); bdy_boxes = hypre_BoxArrayCreate(0); tmp_boxes = hypre_BoxArrayCreate(0); fi = 0; hypre_ForBoxI(ci, cgrid_boxes) { while (fgrid_ids[fi] != cgrid_ids[ci]) { fi++; } cgrid_box = hypre_BoxArrayBox(cgrid_boxes, ci); fgrid_box = hypre_BoxArrayBox(fgrid_boxes, fi); cstart = hypre_BoxIMin(cgrid_box); hypre_StructMapCoarseToFine(cstart, cindex, cstride, fstart); A_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(A), fi); P_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(P), fi); RAP_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(RAP), ci); /*----------------------------------------------------------------- * Extract pointers for interpolation operator: * pb is pointer for weight for f-point below c-point * pa is pointer for weight for f-point above c-point *-----------------------------------------------------------------*/ hypre_SetIndex(index_temp,0,-1,0); MapIndex(index_temp, cdir, index); pa = hypre_StructMatrixExtractPointerByIndex(P, fi, index); hypre_SetIndex(index_temp,0,1,0); MapIndex(index_temp, cdir, index); pb = hypre_StructMatrixExtractPointerByIndex(P, fi, index) - hypre_BoxOffsetDistance(P_dbox, 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_cb is pointer for below coefficient * a_ca is pointer for above coefficient *-----------------------------------------------------------------*/ hypre_SetIndex(index_temp,0,0,0); MapIndex(index_temp, cdir, index); a_cc = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index_temp,-1,0,0); MapIndex(index_temp, cdir, index); a_cw = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index_temp,1,0,0); MapIndex(index_temp, cdir, index); a_ce = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index_temp,0,-1,0); MapIndex(index_temp, cdir, index); a_cb = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index_temp,0,1,0); MapIndex(index_temp, cdir, index); a_ca = hypre_StructMatrixExtractPointerByIndex(A, fi, index); /*----------------------------------------------------------------- * Extract pointers for coarse grid operator * rap_cc is pointer for center coefficient (etc.) *-----------------------------------------------------------------*/ hypre_SetIndex(index_temp,0,0,0); MapIndex(index_temp, cdir, index); rap_cc = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index_temp,-1,0,0); MapIndex(index_temp, cdir, index); rap_cw = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index_temp,1,0,0); MapIndex(index_temp, cdir, index); rap_ce = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index_temp,0,-1,0); MapIndex(index_temp, cdir, index); rap_cb = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index_temp,0,1,0); MapIndex(index_temp, cdir, index); rap_ca = 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_temp,0,1,0); MapIndex(index_temp, cdir, index); OffsetP = hypre_BoxOffsetDistance(P_dbox,index); OffsetA = hypre_BoxOffsetDistance(A_dbox,index); /*-------------------------------------------------------------- * Loop for symmetric 5-point fine grid operator; produces a * symmetric 5-point coarse grid operator. *--------------------------------------------------------------*/ if ( constant_coefficient==0 ) { hypre_BoxGetSize(cgrid_box, loop_size); hypre_BoxLoop3Begin(loop_size, P_dbox, cstart, stridec, iP, A_dbox, fstart, stridef, iA, RAP_dbox, cstart, stridec, iAc); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,iP,iA,iAc,iAm1,iAp1,iPm1,iPp1,west,east #include "hypre_box_smp_forloop.h" hypre_BoxLoop3For(loopi, loopj, loopk, iP, iA, iAc) { iAm1 = iA - OffsetA; iAp1 = iA + OffsetA; iPm1 = iP - OffsetP; iPp1 = iP + OffsetP; rap_cb[iAc] = a_cb[iA] * pa[iPm1]; rap_ca[iAc] = a_ca[iA] * pb[iPp1]; west = a_cw[iA] + 0.5 * a_cw[iAm1] + 0.5 * a_cw[iAp1]; east = a_ce[iA] + 0.5 * a_ce[iAm1] + 0.5 * a_ce[iAp1]; /*----------------------------------------------------- * Prevent non-zero entries reaching off grid *-----------------------------------------------------*/ if(a_cw[iA] == 0.0) west = 0.0; if(a_ce[iA] == 0.0) east = 0.0; rap_cw[iAc] = west; rap_ce[iAc] = east; rap_cc[iAc] = a_cc[iA] + a_cw[iA] + a_ce[iA] + a_cb[iA] * pb[iP] + a_ca[iA] * pa[iP] - west - east; } hypre_BoxLoop3End(iP, iA, iAc); }
hypre_StructMatrix * hypre_PFMGCreateCoarseOp5( hypre_StructMatrix *R, hypre_StructMatrix *A, hypre_StructMatrix *P, hypre_StructGrid *coarse_grid, HYPRE_Int cdir ) { hypre_StructMatrix *RAP; hypre_Index *RAP_stencil_shape; hypre_StructStencil *RAP_stencil; HYPRE_Int RAP_stencil_size; HYPRE_Int RAP_stencil_dim; HYPRE_Int RAP_num_ghost[] = {1, 1, 1, 1, 1, 1}; hypre_Index index_temp; HYPRE_Int j, i; HYPRE_Int stencil_rank; RAP_stencil_dim = 2; /*----------------------------------------------------------------------- * Define RAP_stencil *-----------------------------------------------------------------------*/ stencil_rank = 0; /*----------------------------------------------------------------------- * non-symmetric case *-----------------------------------------------------------------------*/ if (!hypre_StructMatrixSymmetric(A)) { /*-------------------------------------------------------------------- * 5 point coarse grid stencil *--------------------------------------------------------------------*/ RAP_stencil_size = 5; RAP_stencil_shape = hypre_CTAlloc(hypre_Index, RAP_stencil_size); for (j = -1; j < 2; j++) { for (i = -1; i < 2; i++) { /*-------------------------------------------------------------- * Storage for 5 elements (c,w,e,n,s) *--------------------------------------------------------------*/ if (i*j == 0) { hypre_SetIndex(index_temp,i,j,0); MapIndex(index_temp, cdir, RAP_stencil_shape[stencil_rank]); stencil_rank++; } } } } /*----------------------------------------------------------------------- * symmetric case *-----------------------------------------------------------------------*/ else { /*-------------------------------------------------------------------- * 5 point coarse grid stencil * Only store the lower triangular part + diagonal = 3 entries, * lower triangular means the lower triangular part on the matrix * in the standard lexicographic ordering. *--------------------------------------------------------------------*/ RAP_stencil_size = 3; RAP_stencil_shape = hypre_CTAlloc(hypre_Index, RAP_stencil_size); for (j = -1; j < 1; j++) { for (i = -1; i < 1; i++) { /*-------------------------------------------------------------- * Store 3 elements in (c,w,s) *--------------------------------------------------------------*/ if( i*j == 0 ) { hypre_SetIndex(index_temp,i,j,0); MapIndex(index_temp, cdir, RAP_stencil_shape[stencil_rank]); stencil_rank++; } } } } RAP_stencil = hypre_StructStencilCreate(RAP_stencil_dim, RAP_stencil_size, RAP_stencil_shape); RAP = hypre_StructMatrixCreate(hypre_StructMatrixComm(A), coarse_grid, RAP_stencil); hypre_StructStencilDestroy(RAP_stencil); /*----------------------------------------------------------------------- * Coarse operator in symmetric iff fine operator is *-----------------------------------------------------------------------*/ hypre_StructMatrixSymmetric(RAP) = hypre_StructMatrixSymmetric(A); /*----------------------------------------------------------------------- * Set number of ghost points - one one each boundary *-----------------------------------------------------------------------*/ hypre_StructMatrixSetNumGhost(RAP, RAP_num_ghost); return RAP; }
HYPRE_Int hypre_AMR_CFCoarsen( hypre_SStructMatrix * A, hypre_SStructMatrix * fac_A, hypre_Index refine_factors, HYPRE_Int level ) { MPI_Comm comm = hypre_SStructMatrixComm(A); hypre_SStructGraph *graph = hypre_SStructMatrixGraph(A); HYPRE_Int graph_type = hypre_SStructGraphObjectType(graph); hypre_SStructGrid *grid = hypre_SStructGraphGrid(graph); HYPRE_Int nUventries = hypre_SStructGraphNUVEntries(graph); HYPRE_IJMatrix ij_A = hypre_SStructMatrixIJMatrix(A); HYPRE_Int matrix_type= hypre_SStructMatrixObjectType(A); HYPRE_Int ndim = hypre_SStructMatrixNDim(A); hypre_SStructPMatrix *A_pmatrix; hypre_StructMatrix *smatrix_var; hypre_StructStencil *stencils; HYPRE_Int stencil_size; hypre_Index stencil_shape_i; hypre_Index loop_size; hypre_Box refined_box; double **a_ptrs; hypre_Box *A_dbox; HYPRE_Int part_crse= level-1; HYPRE_Int part_fine= level; hypre_BoxManager *fboxman; hypre_BoxManEntry **boxman_entries, *boxman_entry; HYPRE_Int nboxman_entries; hypre_Box boxman_entry_box; hypre_BoxArrayArray ***fgrid_cinterface_extents; hypre_StructGrid *cgrid; hypre_BoxArray *cgrid_boxes; hypre_Box *cgrid_box; hypre_Index node_extents; hypre_Index stridec, stridef; hypre_BoxArrayArray *cinterface_arrays; hypre_BoxArray *cinterface_array; hypre_Box *fgrid_cinterface; HYPRE_Int centre; HYPRE_Int ci, fi, boxi; HYPRE_Int max_stencil_size= 27; HYPRE_Int false= 0; HYPRE_Int true = 1; HYPRE_Int found; HYPRE_Int *stencil_ranks, *rank_stencils; HYPRE_Int rank, startrank; double *vals; HYPRE_Int i, j, iA; HYPRE_Int nvars, var1; hypre_Index lindex, zero_index; hypre_Index index1, index2; hypre_Index index_temp; hypre_SStructUVEntry *Uventry; HYPRE_Int nUentries, cnt1; HYPRE_Int box_array_size; HYPRE_Int *ncols, *rows, *cols; HYPRE_Int *temp1, *temp2; HYPRE_Int myid; hypre_MPI_Comm_rank(comm, &myid); hypre_SetIndex(zero_index, 0, 0, 0); /*-------------------------------------------------------------------------- * Task: Coarsen the CF interface connections of A into fac_A so that * fac_A will have the stencil coefficients extending into a coarsened * fbox. The centre coefficient is constructed to preserve the row sum. *--------------------------------------------------------------------------*/ if (graph_type == HYPRE_SSTRUCT) { startrank = hypre_SStructGridGhstartRank(grid); } if (graph_type == HYPRE_PARCSR) { startrank = hypre_SStructGridStartRank(grid); } /*-------------------------------------------------------------------------- * Fine grid strides by the refinement factors. *--------------------------------------------------------------------------*/ hypre_SetIndex(stridec, 1, 1, 1); for (i= 0; i< ndim; i++) { stridef[i]= refine_factors[i]; } for (i= ndim; i< 3; i++) { stridef[i]= 1; } /*-------------------------------------------------------------------------- * Determine the c/f interface index boxes: fgrid_cinterface_extents. * These are between fpart= level and cpart= (level-1). The * fgrid_cinterface_extents are indexed by cboxes, but fboxes that * abutt a given cbox must be considered. Moreover, for each fbox, * we can have a c/f interface from a number of different stencil * directions- i.e., we have a boxarrayarray for each cbox, each * fbox leading to a boxarray. * * Algo.: For each cbox: * 1) refine & stretch by a unit in each dimension. * 2) boxman_intersect with the fgrid boxman to get all fboxes contained * or abutting this cbox. * 3) get the fgrid_cinterface_extents for each of these fboxes. * * fgrid_cinterface_extents[var1][ci] *--------------------------------------------------------------------------*/ A_pmatrix= hypre_SStructMatrixPMatrix(fac_A, part_crse); nvars = hypre_SStructPMatrixNVars(A_pmatrix); fgrid_cinterface_extents= hypre_TAlloc(hypre_BoxArrayArray **, nvars); for (var1= 0; var1< nvars; var1++) { fboxman= hypre_SStructGridBoxManager(grid, part_fine, var1); stencils= hypre_SStructPMatrixSStencil(A_pmatrix, var1, var1); cgrid= hypre_SStructPGridSGrid(hypre_SStructPMatrixPGrid(A_pmatrix), var1); cgrid_boxes= hypre_StructGridBoxes(cgrid); fgrid_cinterface_extents[var1]= hypre_TAlloc(hypre_BoxArrayArray *, hypre_BoxArraySize(cgrid_boxes)); hypre_ForBoxI(ci, cgrid_boxes) { cgrid_box= hypre_BoxArrayBox(cgrid_boxes, ci); hypre_StructMapCoarseToFine(hypre_BoxIMin(cgrid_box), zero_index, refine_factors, hypre_BoxIMin(&refined_box)); hypre_SetIndex(index1, refine_factors[0]-1, refine_factors[1]-1, refine_factors[2]-1); hypre_StructMapCoarseToFine(hypre_BoxIMax(cgrid_box), index1, refine_factors, hypre_BoxIMax(&refined_box)); /*------------------------------------------------------------------------ * Stretch the refined_box so that a BoxManIntersect will get abutting * fboxes. *------------------------------------------------------------------------*/ for (i= 0; i< ndim; i++) { hypre_BoxIMin(&refined_box)[i]-= 1; hypre_BoxIMax(&refined_box)[i]+= 1; } hypre_BoxManIntersect(fboxman, hypre_BoxIMin(&refined_box), hypre_BoxIMax(&refined_box), &boxman_entries, &nboxman_entries); fgrid_cinterface_extents[var1][ci]= hypre_BoxArrayArrayCreate(nboxman_entries); /*------------------------------------------------------------------------ * Get the fgrid_cinterface_extents using var1-var1 stencil (only like- * variables couple). *------------------------------------------------------------------------*/ if (stencils != NULL) { for (i= 0; i< nboxman_entries; i++) { hypre_BoxManEntryGetExtents(boxman_entries[i], hypre_BoxIMin(&boxman_entry_box), hypre_BoxIMax(&boxman_entry_box)); hypre_CFInterfaceExtents2(&boxman_entry_box, cgrid_box, stencils, refine_factors, hypre_BoxArrayArrayBoxArray(fgrid_cinterface_extents[var1][ci], i) ); } } hypre_TFree(boxman_entries); } /* hypre_ForBoxI(ci, cgrid_boxes) */ } /* for (var1= 0; var1< nvars; var1++) */
HYPRE_Int hypre_StructCoarsen( hypre_StructGrid *fgrid, hypre_Index index, hypre_Index stride, HYPRE_Int prune, hypre_StructGrid **cgrid_ptr ) { hypre_StructGrid *cgrid; MPI_Comm comm; HYPRE_Int ndim; hypre_BoxArray *my_boxes; hypre_Index periodic; hypre_Index ilower, iupper; hypre_Box *box; hypre_Box *new_box; hypre_Box *bounding_box; HYPRE_Int i, j, myid, count; HYPRE_Int info_size, max_nentries; HYPRE_Int num_entries; HYPRE_Int *fids, *cids; hypre_Index new_dist; hypre_IndexRef max_distance; HYPRE_Int proc, id; HYPRE_Int coarsen_factor, known; HYPRE_Int num, last_proc; #if 0 hypre_StructAssumedPart *fap = NULL, *cap = NULL; #endif hypre_BoxManager *fboxman, *cboxman; hypre_BoxManEntry *entries; hypre_BoxManEntry *entry; void *entry_info = NULL; #if TIME_DEBUG HYPRE_Int tindex; char new_title[80]; hypre_sprintf(new_title,"Coarsen.%d",s_coarsen_num); tindex = hypre_InitializeTiming(new_title); s_coarsen_num++; hypre_BeginTiming(tindex); #endif hypre_SetIndex(ilower, 0); hypre_SetIndex(iupper, 0); /* get relevant information from the fine grid */ fids = hypre_StructGridIDs(fgrid); fboxman = hypre_StructGridBoxMan(fgrid); comm = hypre_StructGridComm(fgrid); ndim = hypre_StructGridNDim(fgrid); max_distance = hypre_StructGridMaxDistance(fgrid); /* initial */ hypre_MPI_Comm_rank(comm, &myid ); /* create new coarse grid */ hypre_StructGridCreate(comm, ndim, &cgrid); /* coarsen my boxes and create the coarse grid ids (same as fgrid) */ my_boxes = hypre_BoxArrayDuplicate(hypre_StructGridBoxes(fgrid)); cids = hypre_TAlloc(HYPRE_Int, hypre_BoxArraySize(my_boxes)); for (i = 0; i < hypre_BoxArraySize(my_boxes); i++) { box = hypre_BoxArrayBox(my_boxes, i); hypre_StructCoarsenBox(box, index, stride); cids[i] = fids[i]; } /* prune? */ /* zero volume boxes are needed when forming P and P^T */ if (prune) { count = 0; hypre_ForBoxI(i, my_boxes) { box = hypre_BoxArrayBox(my_boxes, i); if (hypre_BoxVolume(box)) { hypre_CopyBox(box, hypre_BoxArrayBox(my_boxes, count)); cids[count] = cids[i]; count++; } } hypre_BoxArraySetSize(my_boxes, count); }
int hypre_SMGResidualSetup( 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_index = (residual_data -> base_index); hypre_IndexRef base_stride = (residual_data -> base_stride); hypre_Index unit_stride; hypre_StructGrid *grid; hypre_StructStencil *stencil; hypre_BoxArrayArray *send_boxes; hypre_BoxArrayArray *recv_boxes; int **send_processes; int **recv_processes; hypre_BoxArrayArray *indt_boxes; hypre_BoxArrayArray *dept_boxes; hypre_BoxArray *base_points; hypre_ComputePkg *compute_pkg; /*---------------------------------------------------------- * Set up base points and the compute package *----------------------------------------------------------*/ grid = hypre_StructMatrixGrid(A); stencil = hypre_StructMatrixStencil(A); hypre_SetIndex(unit_stride, 1, 1, 1); base_points = hypre_BoxArrayDuplicate(hypre_StructGridBoxes(grid)); hypre_ProjectBoxArray(base_points, base_index, base_stride); hypre_CreateComputeInfo(grid, stencil, &send_boxes, &recv_boxes, &send_processes, &recv_processes, &indt_boxes, &dept_boxes); hypre_ProjectBoxArrayArray(indt_boxes, base_index, base_stride); hypre_ProjectBoxArrayArray(dept_boxes, base_index, base_stride); hypre_ComputePkgCreate(send_boxes, recv_boxes, unit_stride, unit_stride, send_processes, recv_processes, indt_boxes, dept_boxes, base_stride, grid, hypre_StructVectorDataSpace(x), 1, &compute_pkg); /*---------------------------------------------------------- * Set up the residual data structure *----------------------------------------------------------*/ (residual_data -> A) = hypre_StructMatrixRef(A); (residual_data -> x) = hypre_StructVectorRef(x); (residual_data -> b) = hypre_StructVectorRef(b); (residual_data -> r) = hypre_StructVectorRef(r); (residual_data -> base_points) = base_points; (residual_data -> compute_pkg) = compute_pkg; /*----------------------------------------------------- * Compute flops *-----------------------------------------------------*/ (residual_data -> flops) = (hypre_StructMatrixGlobalSize(A) + hypre_StructVectorGlobalSize(x)) / (hypre_IndexX(base_stride) * hypre_IndexY(base_stride) * hypre_IndexZ(base_stride) ); return ierr; }
int HYPRE_StructDiagScale( HYPRE_StructSolver solver, HYPRE_StructMatrix HA, HYPRE_StructVector Hy, HYPRE_StructVector Hx ) { hypre_StructMatrix *A = (hypre_StructMatrix *) HA; hypre_StructVector *y = (hypre_StructVector *) Hy; hypre_StructVector *x = (hypre_StructVector *) Hx; hypre_BoxArray *boxes; hypre_Box *box; hypre_Box *A_data_box; hypre_Box *y_data_box; hypre_Box *x_data_box; double *Ap; double *yp; double *xp; int Ai; int yi; int xi; hypre_Index index; hypre_IndexRef start; hypre_Index stride; hypre_Index loop_size; int i; int loopi, loopj, loopk; int ierr = 0; /* x = D^{-1} y */ hypre_SetIndex(stride, 1, 1, 1); boxes = hypre_StructGridBoxes(hypre_StructMatrixGrid(A)); hypre_ForBoxI(i, boxes) { box = hypre_BoxArrayBox(boxes, i); A_data_box = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(A), i); x_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(x), i); y_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(y), i); hypre_SetIndex(index, 0, 0, 0); Ap = hypre_StructMatrixExtractPointerByIndex(A, i, index); xp = hypre_StructVectorBoxData(x, i); yp = hypre_StructVectorBoxData(y, i); start = hypre_BoxIMin(box); hypre_BoxGetSize(box, loop_size); hypre_BoxLoop3Begin(loop_size, A_data_box, start, stride, Ai, x_data_box, start, stride, xi, y_data_box, start, stride, yi); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,yi,xi,Ai #include "hypre_box_smp_forloop.h" hypre_BoxLoop3For(loopi, loopj, loopk, Ai, xi, yi) { xp[xi] = yp[yi] / Ap[Ai]; } hypre_BoxLoop3End(Ai, xi, yi); }
hypre_StructMatrix * hypre_SMG2CreateRAPOp( hypre_StructMatrix *R, hypre_StructMatrix *A, hypre_StructMatrix *PT, hypre_StructGrid *coarse_grid ) { hypre_StructMatrix *RAP; hypre_Index *RAP_stencil_shape; hypre_StructStencil *RAP_stencil; int RAP_stencil_size; int RAP_stencil_dim; int RAP_num_ghost[] = {1, 1, 1, 1, 0, 0}; int j, i; int stencil_rank; RAP_stencil_dim = 2; /*----------------------------------------------------------------------- * Define RAP_stencil *-----------------------------------------------------------------------*/ stencil_rank = 0; /*----------------------------------------------------------------------- * non-symmetric case *-----------------------------------------------------------------------*/ if (!hypre_StructMatrixSymmetric(A)) { /*-------------------------------------------------------------------- * 5 or 9 point fine grid stencil produces 9 point RAP *--------------------------------------------------------------------*/ RAP_stencil_size = 9; RAP_stencil_shape = hypre_CTAlloc(hypre_Index, RAP_stencil_size); for (j = -1; j < 2; j++) { for (i = -1; i < 2; i++) { /*-------------------------------------------------------------- * Storage for 9 elements (c,w,e,n,s,sw,se,nw,se) *--------------------------------------------------------------*/ hypre_SetIndex(RAP_stencil_shape[stencil_rank],i,j,0); stencil_rank++; } } } /*----------------------------------------------------------------------- * symmetric case *-----------------------------------------------------------------------*/ else { /*-------------------------------------------------------------------- * 5 or 9 point fine grid stencil produces 9 point RAP * Only store the lower triangular part + diagonal = 5 entries, * lower triangular means the lower triangular part on the matrix * in the standard lexicalgraphic ordering. *--------------------------------------------------------------------*/ RAP_stencil_size = 5; RAP_stencil_shape = hypre_CTAlloc(hypre_Index, RAP_stencil_size); for (j = -1; j < 1; j++) { for (i = -1; i < 2; i++) { /*-------------------------------------------------------------- * Store 5 elements in (c,w,s,sw,se) *--------------------------------------------------------------*/ if( i+j <=0 ) { hypre_SetIndex(RAP_stencil_shape[stencil_rank],i,j,0); stencil_rank++; } } } } RAP_stencil = hypre_StructStencilCreate(RAP_stencil_dim, RAP_stencil_size, RAP_stencil_shape); RAP = hypre_StructMatrixCreate(hypre_StructMatrixComm(A), coarse_grid, RAP_stencil); hypre_StructStencilDestroy(RAP_stencil); /*----------------------------------------------------------------------- * Coarse operator in symmetric iff fine operator is *-----------------------------------------------------------------------*/ hypre_StructMatrixSymmetric(RAP) = hypre_StructMatrixSymmetric(A); /*----------------------------------------------------------------------- * Set number of ghost points *-----------------------------------------------------------------------*/ if (hypre_StructMatrixSymmetric(A)) { RAP_num_ghost[1] = 0; RAP_num_ghost[3] = 0; } hypre_StructMatrixSetNumGhost(RAP, RAP_num_ghost); return RAP; }
HYPRE_Int HYPRE_StructDiagScale( HYPRE_StructSolver solver, HYPRE_StructMatrix HA, HYPRE_StructVector Hy, HYPRE_StructVector Hx ) { hypre_StructMatrix *A = (hypre_StructMatrix *) HA; hypre_StructVector *y = (hypre_StructVector *) Hy; hypre_StructVector *x = (hypre_StructVector *) Hx; hypre_BoxArray *boxes; hypre_Box *box; hypre_Box *A_data_box; hypre_Box *y_data_box; hypre_Box *x_data_box; double *Ap; double *yp; double *xp; HYPRE_Int Ai; HYPRE_Int yi; HYPRE_Int xi; hypre_Index index; hypre_IndexRef start; hypre_Index stride; hypre_Index loop_size; HYPRE_Int i; /* x = D^{-1} y */ hypre_SetIndex(stride, 1, 1, 1); boxes = hypre_StructGridBoxes(hypre_StructMatrixGrid(A)); hypre_ForBoxI(i, boxes) { box = hypre_BoxArrayBox(boxes, i); A_data_box = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(A), i); x_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(x), i); y_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(y), i); hypre_SetIndex(index, 0, 0, 0); Ap = hypre_StructMatrixExtractPointerByIndex(A, i, index); xp = hypre_StructVectorBoxData(x, i); yp = hypre_StructVectorBoxData(y, i); start = hypre_BoxIMin(box); hypre_BoxGetSize(box, loop_size); hypre_BoxLoop3Begin(hypre_StructVectorDim(Hx), loop_size, A_data_box, start, stride, Ai, x_data_box, start, stride, xi, y_data_box, start, stride, yi); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(HYPRE_BOX_PRIVATE,yi,xi,Ai) HYPRE_SMP_SCHEDULE #endif hypre_BoxLoop3For(Ai, xi, yi) { xp[xi] = yp[yi] / Ap[Ai]; } hypre_BoxLoop3End(Ai, xi, yi); }
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_SStructSharedDOF_ParcsrMatRowsComm * Given a sstruct_grid & parcsr matrix with rows corresponding to the * sstruct_grid, determine and extract the rows that must be communicated. * These rows are for shared dof that geometrically lie on processor * boundaries but internally are stored on one processor. * Algo: * for each cellbox * RECVs: * i) stretch the cellbox to the variable box * ii) in the appropriate (dof-dependent) direction, take the * boundary and boxman_intersect to extract boxmanentries * that contain these boundary edges. * iii)loop over the boxmanentries and see if they belong * on this proc or another proc * a) if belong on another proc, these are the recvs: * count and prepare the communication buffers and * values. * * SENDs: * i) form layer of cells that is one layer off cellbox * (stretches in the appropriate direction) * ii) boxman_intersect with the cellgrid boxman * iii)loop over the boxmanentries and see if they belong * on this proc or another proc * a) if belong on another proc, these are the sends: * count and prepare the communication buffers and * values. * * Note: For the recv data, the dof can come from only one processor. * For the send data, the dof can go to more than one processor * (the same dof is on the boundary of several cells). *--------------------------------------------------------------------------*/ HYPRE_Int hypre_SStructSharedDOF_ParcsrMatRowsComm( hypre_SStructGrid *grid, hypre_ParCSRMatrix *A, HYPRE_Int *num_offprocrows_ptr, hypre_MaxwellOffProcRow ***OffProcRows_ptr) { MPI_Comm A_comm= hypre_ParCSRMatrixComm(A); MPI_Comm grid_comm= hypre_SStructGridComm(grid); HYPRE_Int matrix_type= HYPRE_PARCSR; HYPRE_Int nparts= hypre_SStructGridNParts(grid); HYPRE_Int ndim = hypre_SStructGridNDim(grid); hypre_SStructGrid *cell_ssgrid; hypre_SStructPGrid *pgrid; hypre_StructGrid *cellgrid; hypre_BoxArray *cellboxes; hypre_Box *box, *cellbox, vbox, boxman_entry_box; hypre_Index loop_size, start; HYPRE_Int loopi, loopj, loopk; HYPRE_Int start_rank, end_rank, rank; HYPRE_Int i, j, k, m, n, t, part, var, nvars; HYPRE_SStructVariable *vartypes; HYPRE_Int nbdry_slabs; hypre_BoxArray *recv_slabs, *send_slabs; hypre_Index varoffset; hypre_BoxManager **boxmans, *cell_boxman; hypre_BoxManEntry **boxman_entries, *entry; HYPRE_Int nboxman_entries; hypre_Index ishift, jshift, kshift, zero_index; hypre_Index ilower, iupper, index; HYPRE_Int proc, nprocs, myproc; HYPRE_Int *SendToProcs, *RecvFromProcs; HYPRE_Int **send_RowsNcols; /* buffer for rows & ncols */ HYPRE_Int *send_RowsNcols_alloc; HYPRE_Int *send_ColsData_alloc; HYPRE_Int *tot_nsendRowsNcols, *tot_sendColsData; double **vals; /* buffer for cols & data */ HYPRE_Int *col_inds; double *values; hypre_MPI_Request *requests; hypre_MPI_Status *status; HYPRE_Int **rbuffer_RowsNcols; double **rbuffer_ColsData; HYPRE_Int num_sends, num_recvs; hypre_MaxwellOffProcRow **OffProcRows; HYPRE_Int *starts; HYPRE_Int ierr= 0; hypre_MPI_Comm_rank(A_comm, &myproc); hypre_MPI_Comm_size(grid_comm, &nprocs); start_rank= hypre_ParCSRMatrixFirstRowIndex(A); end_rank = hypre_ParCSRMatrixLastRowIndex(A); hypre_SetIndex(ishift, 1, 0, 0); hypre_SetIndex(jshift, 0, 1, 0); hypre_SetIndex(kshift, 0, 0, 1); hypre_SetIndex(zero_index, 0, 0, 0); /* need a cellgrid boxman to determine the send boxes -> only the cell dofs are unique so a boxman intersect can be used to get the edges that must be sent. */ HYPRE_SStructGridCreate(grid_comm, ndim, nparts, &cell_ssgrid); vartypes= hypre_CTAlloc(HYPRE_SStructVariable, 1); vartypes[0]= HYPRE_SSTRUCT_VARIABLE_CELL; for (i= 0; i< nparts; i++) { pgrid= hypre_SStructGridPGrid(grid, i); cellgrid= hypre_SStructPGridCellSGrid(pgrid); cellboxes= hypre_StructGridBoxes(cellgrid); hypre_ForBoxI(j, cellboxes) { box= hypre_BoxArrayBox(cellboxes, j); HYPRE_SStructGridSetExtents(cell_ssgrid, i, hypre_BoxIMin(box), hypre_BoxIMax(box)); } HYPRE_SStructGridSetVariables(cell_ssgrid, i, 1, vartypes); }
double hypre_StructOverlapInnerProd( hypre_StructVector *x, hypre_StructVector *y ) { double final_innerprod_result; double local_result, overlap_result; double process_result; hypre_Box *x_data_box; hypre_Box *y_data_box; hypre_BoxArray *overlap_boxes; HYPRE_Int xi; HYPRE_Int yi; double *xp; double *yp; hypre_BoxArray *boxes; hypre_Box *boxi, *boxj, intersect_box; hypre_StructGrid *grid= hypre_StructVectorGrid(y); hypre_BoxManager *boxman = hypre_StructGridBoxMan(grid); hypre_BoxArray *neighbor_boxes; HYPRE_Int *neighbors_procs= NULL; hypre_BoxArray *selected_nboxes; hypre_BoxArray *tmp_box_array, *tmp2_box_array; hypre_Index loop_size; hypre_IndexRef start; hypre_Index unit_stride; HYPRE_Int i, j; HYPRE_Int myid; HYPRE_Int boxarray_size; HYPRE_Int loopi, loopj, loopk; #ifdef HYPRE_USE_PTHREADS HYPRE_Int threadid = hypre_GetThreadID(); #endif local_result = 0.0; process_result = 0.0; hypre_SetIndex(unit_stride, 1, 1, 1); hypre_MPI_Comm_rank(hypre_StructVectorComm(y), &myid); /*----------------------------------------------------------------------- * Determine the overlapped boxes on this local processor. *-----------------------------------------------------------------------*/ boxes = hypre_StructGridBoxes(hypre_StructVectorGrid(y)); boxarray_size= hypre_BoxArraySize(boxes); /*----------------------------------------------------------------------- * To compute the inner product over this local processor, given a box, * the inner product between x & y is computed over the whole box and * over any overlapping between this box and overlap_boxes. The latter * result is subtracted from the former. Overlapping between more than * two boxes are handled. *-----------------------------------------------------------------------*/ hypre_ForBoxI(i, boxes) { boxi = hypre_BoxArrayBox(boxes, i); start = hypre_BoxIMin(boxi); x_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(x), i); y_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(y), i); xp = hypre_StructVectorBoxData(x, i); yp = hypre_StructVectorBoxData(y, i); hypre_BoxGetSize(boxi, loop_size); #ifdef HYPRE_USE_PTHREADS local_result_ref[threadid] = &local_result; #endif hypre_BoxLoop2Begin(loop_size, x_data_box, start, unit_stride, xi, y_data_box, start, unit_stride, yi); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,xi,yi #define HYPRE_SMP_REDUCTION_OP + #define HYPRE_SMP_REDUCTION_VARS local_result #include "hypre_box_smp_forloop.h" hypre_BoxLoop2For(loopi, loopj, loopk, xi, yi) { local_result += xp[xi] * yp[yi]; }
HYPRE_Int hypre_PrintBoxArrayData( FILE *file, hypre_BoxArray *box_array, hypre_BoxArray *data_space, HYPRE_Int num_values, HYPRE_Int dim, HYPRE_Complex *data ) { hypre_Box *box; hypre_Box *data_box; HYPRE_Int data_box_volume; HYPRE_Int datai; hypre_Index loop_size; hypre_IndexRef start; hypre_Index stride; hypre_Index index; HYPRE_Int i, j, d; HYPRE_Complex value; /*---------------------------------------- * Print data *----------------------------------------*/ hypre_SetIndex(stride, 1); hypre_ForBoxI(i, box_array) { box = hypre_BoxArrayBox(box_array, i); data_box = hypre_BoxArrayBox(data_space, i); start = hypre_BoxIMin(box); data_box_volume = hypre_BoxVolume(data_box); hypre_BoxGetSize(box, loop_size); hypre_BoxLoop1Begin(dim, loop_size, data_box, start, stride, datai); hypre_BoxLoop1For(datai) { /* Print lines of the form: "%d: (%d, %d, %d; %d) %.14e\n" */ hypre_BoxLoopGetIndex(index); for (j = 0; j < num_values; j++) { hypre_fprintf(file, "%d: (%d", i, hypre_IndexD(start, 0) + hypre_IndexD(index, 0)); for (d = 1; d < dim; d++) { hypre_fprintf(file, ", %d", hypre_IndexD(start, d) + hypre_IndexD(index, d)); } value = data[datai + j*data_box_volume]; #ifdef HYPRE_COMPLEX hypre_fprintf(file, "; %d) %.14e , %.14e\n", j, hypre_creal(value), hypre_cimag(value)); #else hypre_fprintf(file, "; %d) %.14e\n", j, value); #endif } } hypre_BoxLoop1End(datai); data += num_values*data_box_volume; }
int hypre_PointRelaxSetup( void *relax_vdata, hypre_StructMatrix *A, hypre_StructVector *b, hypre_StructVector *x ) { hypre_PointRelaxData *relax_data = (hypre_PointRelaxData *)relax_vdata; int num_pointsets = (relax_data -> num_pointsets); int *pointset_sizes = (relax_data -> pointset_sizes); hypre_Index *pointset_strides = (relax_data -> pointset_strides); hypre_Index **pointset_indices = (relax_data -> pointset_indices); hypre_StructVector *t; int diag_rank; hypre_ComputePkg **compute_pkgs; hypre_Index unit_stride; hypre_Index diag_index; hypre_IndexRef stride; hypre_IndexRef index; hypre_StructGrid *grid; hypre_StructStencil *stencil; hypre_BoxArrayArray *send_boxes; hypre_BoxArrayArray *recv_boxes; int **send_processes; int **recv_processes; hypre_BoxArrayArray *indt_boxes; hypre_BoxArrayArray *dept_boxes; hypre_BoxArrayArray *orig_indt_boxes; hypre_BoxArrayArray *orig_dept_boxes; hypre_BoxArrayArray *box_aa; hypre_BoxArray *box_a; hypre_Box *box; int box_aa_size; int box_a_size; hypre_BoxArrayArray *new_box_aa; hypre_BoxArray *new_box_a; hypre_Box *new_box; double scale; int frac; int i, j, k, p, m, compute_i; int ierr = 0; /*---------------------------------------------------------- * Set up the temp vector *----------------------------------------------------------*/ if ((relax_data -> t) == NULL) { t = hypre_StructVectorCreate(hypre_StructVectorComm(b), hypre_StructVectorGrid(b)); hypre_StructVectorSetNumGhost(t, hypre_StructVectorNumGhost(b)); hypre_StructVectorInitialize(t); hypre_StructVectorAssemble(t); (relax_data -> t) = t; } /*---------------------------------------------------------- * Find the matrix diagonal *----------------------------------------------------------*/ grid = hypre_StructMatrixGrid(A); stencil = hypre_StructMatrixStencil(A); hypre_SetIndex(diag_index, 0, 0, 0); diag_rank = hypre_StructStencilElementRank(stencil, diag_index); /*---------------------------------------------------------- * Set up the compute packages *----------------------------------------------------------*/ hypre_SetIndex(unit_stride, 1, 1, 1); compute_pkgs = hypre_CTAlloc(hypre_ComputePkg *, num_pointsets); for (p = 0; p < num_pointsets; p++) { hypre_CreateComputeInfo(grid, stencil, &send_boxes, &recv_boxes, &send_processes, &recv_processes, &orig_indt_boxes, &orig_dept_boxes); stride = pointset_strides[p]; for (compute_i = 0; compute_i < 2; compute_i++) { switch(compute_i) { case 0: box_aa = orig_indt_boxes; break; case 1: box_aa = orig_dept_boxes; break; } box_aa_size = hypre_BoxArrayArraySize(box_aa); new_box_aa = hypre_BoxArrayArrayCreate(box_aa_size); for (i = 0; i < box_aa_size; i++) { box_a = hypre_BoxArrayArrayBoxArray(box_aa, i); box_a_size = hypre_BoxArraySize(box_a); new_box_a = hypre_BoxArrayArrayBoxArray(new_box_aa, i); hypre_BoxArraySetSize(new_box_a, box_a_size * pointset_sizes[p]); k = 0; for (m = 0; m < pointset_sizes[p]; m++) { index = pointset_indices[p][m]; for (j = 0; j < box_a_size; j++) { box = hypre_BoxArrayBox(box_a, j); new_box = hypre_BoxArrayBox(new_box_a, k); hypre_CopyBox(box, new_box); hypre_ProjectBox(new_box, index, stride); k++; } } } switch(compute_i) { case 0: indt_boxes = new_box_aa; break; case 1: dept_boxes = new_box_aa; break; } } hypre_ComputePkgCreate(send_boxes, recv_boxes, unit_stride, unit_stride, send_processes, recv_processes, indt_boxes, dept_boxes, stride, grid, hypre_StructVectorDataSpace(x), 1, &compute_pkgs[p]); hypre_BoxArrayArrayDestroy(orig_indt_boxes); hypre_BoxArrayArrayDestroy(orig_dept_boxes); } /*---------------------------------------------------------- * Set up the relax data structure *----------------------------------------------------------*/ (relax_data -> A) = hypre_StructMatrixRef(A); (relax_data -> x) = hypre_StructVectorRef(x); (relax_data -> b) = hypre_StructVectorRef(b); (relax_data -> diag_rank) = diag_rank; (relax_data -> compute_pkgs) = compute_pkgs; /*----------------------------------------------------- * Compute flops *-----------------------------------------------------*/ scale = 0.0; for (p = 0; p < num_pointsets; p++) { stride = pointset_strides[p]; frac = hypre_IndexX(stride); frac *= hypre_IndexY(stride); frac *= hypre_IndexZ(stride); scale += (pointset_sizes[p] / frac); } (relax_data -> flops) = scale * (hypre_StructMatrixGlobalSize(A) + hypre_StructVectorGlobalSize(x)); return ierr; }