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; }
HYPRE_Int hypre_CommInfoProjectSend( hypre_CommInfo *comm_info, hypre_Index index, hypre_Index stride ) { hypre_ProjectBoxArrayArray(hypre_CommInfoSendBoxes(comm_info), index, stride); hypre_ProjectBoxArrayArray(hypre_CommInfoSendRBoxes(comm_info), index, stride); hypre_CopyIndex(stride, hypre_CommInfoSendStride(comm_info)); return hypre_error_flag; }
int hypre_CommInfoProjectSend( hypre_CommInfo *comm_info, hypre_Index index, hypre_Index stride ) { int ierr = 0; hypre_ProjectBoxArrayArray(hypre_CommInfoSendBoxes(comm_info), index, stride); hypre_ProjectBoxArrayArray(hypre_CommInfoSendRBoxes(comm_info), index, stride); hypre_CopyIndex(stride, hypre_CommInfoSendStride(comm_info)); return ierr; }
int hypre_CommInfoDestroy( hypre_CommInfo *comm_info ) { int ierr = 0; hypre_BoxArrayArray *boxes; int **procs; int **boxnums; hypre_BoxArrayArray *rboxes; int i; boxes = hypre_CommInfoSendBoxes(comm_info); procs = hypre_CommInfoSendProcesses(comm_info); boxnums = hypre_CommInfoSendRBoxnums(comm_info); rboxes = hypre_CommInfoSendRBoxes(comm_info); hypre_ForBoxArrayI(i, boxes) { hypre_TFree(procs[i]); hypre_TFree(boxnums[i]); }
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; }
HYPRE_Int hypre_CommInfoDestroy( hypre_CommInfo *comm_info ) { HYPRE_Int **processes; HYPRE_Int **rboxnums; HYPRE_Int **transforms; HYPRE_Int i, size; size = hypre_BoxArrayArraySize(hypre_CommInfoSendBoxes(comm_info)); hypre_BoxArrayArrayDestroy(hypre_CommInfoSendBoxes(comm_info)); processes = hypre_CommInfoSendProcesses(comm_info); for (i = 0; i < size; i++) { hypre_TFree(processes[i]); } hypre_TFree(processes); rboxnums = hypre_CommInfoSendRBoxnums(comm_info); if (rboxnums != NULL) { for (i = 0; i < size; i++) { hypre_TFree(rboxnums[i]); } hypre_TFree(rboxnums); } hypre_BoxArrayArrayDestroy(hypre_CommInfoSendRBoxes(comm_info)); transforms = hypre_CommInfoSendTransforms(comm_info); if (transforms != NULL) { for (i = 0; i < size; i++) { hypre_TFree(transforms[i]); } hypre_TFree(transforms); } size = hypre_BoxArrayArraySize(hypre_CommInfoRecvBoxes(comm_info)); hypre_BoxArrayArrayDestroy(hypre_CommInfoRecvBoxes(comm_info)); processes = hypre_CommInfoRecvProcesses(comm_info); for (i = 0; i < size; i++) { hypre_TFree(processes[i]); } hypre_TFree(processes); rboxnums = hypre_CommInfoRecvRBoxnums(comm_info); if (rboxnums != NULL) { for (i = 0; i < size; i++) { hypre_TFree(rboxnums[i]); } hypre_TFree(rboxnums); } hypre_BoxArrayArrayDestroy(hypre_CommInfoRecvRBoxes(comm_info)); transforms = hypre_CommInfoRecvTransforms(comm_info); if (transforms != NULL) { for (i = 0; i < size; i++) { hypre_TFree(transforms[i]); } hypre_TFree(transforms); } hypre_TFree(hypre_CommInfoCoords(comm_info)); hypre_TFree(hypre_CommInfoDirs(comm_info)); hypre_TFree(comm_info); return hypre_error_flag; }
HYPRE_Int hypre_StructInterpAssemble( hypre_StructMatrix *A, hypre_StructMatrix *P, HYPRE_Int P_stored_as_transpose, HYPRE_Int cdir, hypre_Index index, hypre_Index stride ) { hypre_StructGrid *grid = hypre_StructMatrixGrid(A); hypre_BoxArrayArray *box_aa; hypre_BoxArray *box_a; hypre_Box *box; hypre_CommInfo *comm_info; hypre_CommPkg *comm_pkg; hypre_CommHandle *comm_handle; HYPRE_Int num_ghost[] = {0, 0, 0, 0, 0, 0}; HYPRE_Int i, j, s, dim; if (hypre_StructMatrixConstantCoefficient(P) != 0) { return hypre_error_flag; } /* set num_ghost */ dim = hypre_StructGridDim(grid); for (j = 0; j < dim; j++) { num_ghost[2*j] = 1; num_ghost[2*j+1] = 1; } if (P_stored_as_transpose) { num_ghost[2*cdir] = 2; num_ghost[2*cdir+1] = 2; } /* comm_info <-- From fine grid grown by num_ghost */ hypre_CreateCommInfoFromNumGhost(grid, num_ghost, &comm_info); /* Project and map comm_info onto coarsened index space */ hypre_CommInfoProjectSend(comm_info, index, stride); hypre_CommInfoProjectRecv(comm_info, index, stride); for (s = 0; s < 3; s++) { switch(s) { case 0: box_aa = hypre_CommInfoSendBoxes(comm_info); hypre_SetIndex(hypre_CommInfoSendStride(comm_info), 1, 1, 1); break; case 1: box_aa = hypre_CommInfoRecvBoxes(comm_info); hypre_SetIndex(hypre_CommInfoRecvStride(comm_info), 1, 1, 1); break; case 2: box_aa = hypre_CommInfoSendRBoxes(comm_info); break; } hypre_ForBoxArrayI(j, box_aa) { box_a = hypre_BoxArrayArrayBoxArray(box_aa, j); hypre_ForBoxI(i, box_a) { box = hypre_BoxArrayBox(box_a, i); hypre_StructMapFineToCoarse(hypre_BoxIMin(box), index, stride, hypre_BoxIMin(box)); hypre_StructMapFineToCoarse(hypre_BoxIMax(box), index, stride, hypre_BoxIMax(box)); } }
int hypre_CommPkgCreate( hypre_CommInfo *comm_info, hypre_BoxArray *send_data_space, hypre_BoxArray *recv_data_space, int num_values, MPI_Comm comm, hypre_CommPkg **comm_pkg_ptr ) { int ierr = 0; hypre_BoxArrayArray *send_boxes; hypre_BoxArrayArray *recv_boxes; hypre_IndexRef send_stride; hypre_IndexRef recv_stride; int **send_processes; int **recv_processes; int **send_rboxnums; hypre_BoxArrayArray *send_rboxes; hypre_CommPkg *comm_pkg; hypre_CommType *comm_types; hypre_CommType *comm_type; hypre_CommEntryType *ct_entries; int *ct_loc_boxnums; int *ct_rem_boxnums; hypre_Box *ct_loc_boxes; hypre_Box *ct_rem_boxes; int *p_comm_types; int num_comms, num_entries, comm_bufsize; hypre_BoxArray *box_array; hypre_Box *box; hypre_BoxArray *rbox_array; hypre_Box *rbox; hypre_Box *data_box; int *data_offsets; int data_offset; int i, j, k, p, m, size; int num_procs, my_proc; /*------------------------------------------------------ *------------------------------------------------------*/ send_boxes = hypre_CommInfoSendBoxes(comm_info); recv_boxes = hypre_CommInfoRecvBoxes(comm_info); send_stride = hypre_CommInfoSendStride(comm_info); recv_stride = hypre_CommInfoRecvStride(comm_info); send_processes = hypre_CommInfoSendProcesses(comm_info); recv_processes = hypre_CommInfoRecvProcesses(comm_info); send_rboxnums = hypre_CommInfoSendRBoxnums(comm_info); send_rboxes = hypre_CommInfoSendRBoxes(comm_info); MPI_Comm_size(comm, &num_procs ); MPI_Comm_rank(comm, &my_proc ); /*------------------------------------------------------ * Set up various entries in CommPkg *------------------------------------------------------*/ comm_pkg = hypre_CTAlloc(hypre_CommPkg, 1); hypre_CommPkgComm(comm_pkg) = comm; hypre_CommPkgFirstSend(comm_pkg) = 1; hypre_CommPkgFirstRecv(comm_pkg) = 1; hypre_CommPkgNumValues(comm_pkg) = num_values; hypre_CopyIndex(send_stride, hypre_CommPkgSendStride(comm_pkg)); hypre_CopyIndex(recv_stride, hypre_CommPkgRecvStride(comm_pkg)); /*------------------------------------------------------ * Set up send CommType information *------------------------------------------------------*/ p_comm_types = hypre_CTAlloc(int, num_procs); /* set send_data_offsets and send_data_space */ data_offsets = hypre_TAlloc(int, hypre_BoxArraySize(send_data_space)); data_offset = 0; hypre_ForBoxI(i, send_data_space) { data_offsets[i] = data_offset; data_box = hypre_BoxArrayBox(send_data_space, i); data_offset += hypre_BoxVolume(data_box) * num_values; }