| 1 | /*BHEADER**********************************************************************
|
|---|
| 2 | * Copyright (c) 2008, Lawrence Livermore National Security, LLC.
|
|---|
| 3 | * Produced at the Lawrence Livermore National Laboratory.
|
|---|
| 4 | * This file is part of HYPRE. See file COPYRIGHT for details.
|
|---|
| 5 | *
|
|---|
| 6 | * HYPRE is free software; you can redistribute it and/or modify it under the
|
|---|
| 7 | * terms of the GNU Lesser General Public License (as published by the Free
|
|---|
| 8 | * Software Foundation) version 2.1 dated February 1999.
|
|---|
| 9 | *
|
|---|
| 10 | * $Revision: 2.4 $
|
|---|
| 11 | ***********************************************************************EHEADER*/
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | /******************************************************************************
|
|---|
| 15 | *
|
|---|
| 16 | *****************************************************************************/
|
|---|
| 17 |
|
|---|
| 18 | #include "headers.h"
|
|---|
| 19 |
|
|---|
| 20 | /*--------------------------------------------------------------------------
|
|---|
| 21 | *--------------------------------------------------------------------------*/
|
|---|
| 22 |
|
|---|
| 23 | int
|
|---|
| 24 | hypre_ComputeInfoCreate( hypre_CommInfo *comm_info,
|
|---|
| 25 | hypre_BoxArrayArray *indt_boxes,
|
|---|
| 26 | hypre_BoxArrayArray *dept_boxes,
|
|---|
| 27 | hypre_ComputeInfo **compute_info_ptr )
|
|---|
| 28 | {
|
|---|
| 29 | int ierr = 0;
|
|---|
| 30 | hypre_ComputeInfo *compute_info;
|
|---|
| 31 |
|
|---|
| 32 | compute_info = hypre_TAlloc(hypre_ComputeInfo, 1);
|
|---|
| 33 |
|
|---|
| 34 | hypre_ComputeInfoCommInfo(compute_info) = comm_info;
|
|---|
| 35 | hypre_ComputeInfoIndtBoxes(compute_info) = indt_boxes;
|
|---|
| 36 | hypre_ComputeInfoDeptBoxes(compute_info) = dept_boxes;
|
|---|
| 37 |
|
|---|
| 38 | hypre_SetIndex(hypre_ComputeInfoStride(compute_info), 1, 1, 1);
|
|---|
| 39 |
|
|---|
| 40 | *compute_info_ptr = compute_info;
|
|---|
| 41 |
|
|---|
| 42 | return ierr;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | /*--------------------------------------------------------------------------
|
|---|
| 46 | *--------------------------------------------------------------------------*/
|
|---|
| 47 |
|
|---|
| 48 | int
|
|---|
| 49 | hypre_ComputeInfoProjectSend( hypre_ComputeInfo *compute_info,
|
|---|
| 50 | hypre_Index index,
|
|---|
| 51 | hypre_Index stride )
|
|---|
| 52 | {
|
|---|
| 53 | int ierr = 0;
|
|---|
| 54 |
|
|---|
| 55 | hypre_CommInfoProjectSend(hypre_ComputeInfoCommInfo(compute_info),
|
|---|
| 56 | index, stride);
|
|---|
| 57 |
|
|---|
| 58 | return ierr;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | /*--------------------------------------------------------------------------
|
|---|
| 62 | *--------------------------------------------------------------------------*/
|
|---|
| 63 |
|
|---|
| 64 | int
|
|---|
| 65 | hypre_ComputeInfoProjectRecv( hypre_ComputeInfo *compute_info,
|
|---|
| 66 | hypre_Index index,
|
|---|
| 67 | hypre_Index stride )
|
|---|
| 68 | {
|
|---|
| 69 | int ierr = 0;
|
|---|
| 70 |
|
|---|
| 71 | hypre_CommInfoProjectRecv(hypre_ComputeInfoCommInfo(compute_info),
|
|---|
| 72 | index, stride);
|
|---|
| 73 |
|
|---|
| 74 | return ierr;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | /*--------------------------------------------------------------------------
|
|---|
| 78 | *--------------------------------------------------------------------------*/
|
|---|
| 79 |
|
|---|
| 80 | int
|
|---|
| 81 | hypre_ComputeInfoProjectComp( hypre_ComputeInfo *compute_info,
|
|---|
| 82 | hypre_Index index,
|
|---|
| 83 | hypre_Index stride )
|
|---|
| 84 | {
|
|---|
| 85 | int ierr = 0;
|
|---|
| 86 |
|
|---|
| 87 | hypre_ProjectBoxArrayArray(hypre_ComputeInfoIndtBoxes(compute_info),
|
|---|
| 88 | index, stride);
|
|---|
| 89 | hypre_ProjectBoxArrayArray(hypre_ComputeInfoDeptBoxes(compute_info),
|
|---|
| 90 | index, stride);
|
|---|
| 91 | hypre_CopyIndex(stride, hypre_ComputeInfoStride(compute_info));
|
|---|
| 92 |
|
|---|
| 93 | return ierr;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | /*--------------------------------------------------------------------------
|
|---|
| 97 | *--------------------------------------------------------------------------*/
|
|---|
| 98 |
|
|---|
| 99 | int
|
|---|
| 100 | hypre_ComputeInfoDestroy( hypre_ComputeInfo *compute_info )
|
|---|
| 101 | {
|
|---|
| 102 | int ierr = 0;
|
|---|
| 103 |
|
|---|
| 104 | hypre_TFree(compute_info);
|
|---|
| 105 |
|
|---|
| 106 | return ierr;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | /*--------------------------------------------------------------------------
|
|---|
| 110 | * Return descriptions of communications and computations patterns for
|
|---|
| 111 | * a given grid-stencil computation. If HYPRE\_OVERLAP\_COMM\_COMP is
|
|---|
| 112 | * defined, then the patterns are computed to allow for overlapping
|
|---|
| 113 | * communications and computations. The default is no overlap.
|
|---|
| 114 | *
|
|---|
| 115 | * Note: This routine assumes that the grid boxes do not overlap.
|
|---|
| 116 | *--------------------------------------------------------------------------*/
|
|---|
| 117 |
|
|---|
| 118 | int
|
|---|
| 119 | hypre_CreateComputeInfo( hypre_StructGrid *grid,
|
|---|
| 120 | hypre_StructStencil *stencil,
|
|---|
| 121 | hypre_ComputeInfo **compute_info_ptr )
|
|---|
| 122 | {
|
|---|
| 123 | int ierr = 0;
|
|---|
| 124 |
|
|---|
| 125 | hypre_CommInfo *comm_info;
|
|---|
| 126 | hypre_BoxArrayArray *indt_boxes;
|
|---|
| 127 | hypre_BoxArrayArray *dept_boxes;
|
|---|
| 128 |
|
|---|
| 129 | hypre_BoxArray *boxes;
|
|---|
| 130 |
|
|---|
| 131 | hypre_BoxArray *cbox_array;
|
|---|
| 132 | hypre_Box *cbox;
|
|---|
| 133 |
|
|---|
| 134 | int i;
|
|---|
| 135 |
|
|---|
| 136 | #ifdef HYPRE_OVERLAP_COMM_COMP
|
|---|
| 137 | hypre_Box *rembox;
|
|---|
| 138 | hypre_Index *stencil_shape;
|
|---|
| 139 | int border[3][2] = {{0, 0}, {0, 0}, {0, 0}};
|
|---|
| 140 | int cbox_array_size;
|
|---|
| 141 | int s, d;
|
|---|
| 142 | #endif
|
|---|
| 143 |
|
|---|
| 144 | /*------------------------------------------------------
|
|---|
| 145 | * Extract needed grid info
|
|---|
| 146 | *------------------------------------------------------*/
|
|---|
| 147 |
|
|---|
| 148 | boxes = hypre_StructGridBoxes(grid);
|
|---|
| 149 |
|
|---|
| 150 | /*------------------------------------------------------
|
|---|
| 151 | * Get communication info
|
|---|
| 152 | *------------------------------------------------------*/
|
|---|
| 153 |
|
|---|
| 154 | hypre_CreateCommInfoFromStencil(grid, stencil, &comm_info);
|
|---|
| 155 |
|
|---|
| 156 | #ifdef HYPRE_OVERLAP_COMM_COMP
|
|---|
| 157 |
|
|---|
| 158 | /*------------------------------------------------------
|
|---|
| 159 | * Compute border info
|
|---|
| 160 | *------------------------------------------------------*/
|
|---|
| 161 |
|
|---|
| 162 | stencil_shape = hypre_StructStencilShape(stencil);
|
|---|
| 163 | for (s = 0; s < hypre_StructStencilSize(stencil); s++)
|
|---|
| 164 | {
|
|---|
| 165 | for (d = 0; d < 3; d++)
|
|---|
| 166 | {
|
|---|
| 167 | i = hypre_IndexD(stencil_shape[s], d);
|
|---|
| 168 | if (i < 0)
|
|---|
| 169 | {
|
|---|
| 170 | border[d][0] = hypre_max(border[d][0], -i);
|
|---|
| 171 | }
|
|---|
| 172 | else if (i > 0)
|
|---|
| 173 | {
|
|---|
| 174 | border[d][1] = hypre_max(border[d][1], i);
|
|---|
| 175 | }
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | /*------------------------------------------------------
|
|---|
| 180 | * Set up the dependent boxes
|
|---|
| 181 | *------------------------------------------------------*/
|
|---|
| 182 |
|
|---|
| 183 | dept_boxes = hypre_BoxArrayArrayCreate(hypre_BoxArraySize(boxes));
|
|---|
| 184 |
|
|---|
| 185 | rembox = hypre_BoxCreate();
|
|---|
| 186 | hypre_ForBoxI(i, boxes)
|
|---|
| 187 | {
|
|---|
| 188 | cbox_array = hypre_BoxArrayArrayBoxArray(dept_boxes, i);
|
|---|
| 189 | hypre_BoxArraySetSize(cbox_array, 6);
|
|---|
| 190 |
|
|---|
| 191 | hypre_CopyBox(hypre_BoxArrayBox(boxes, i), rembox);
|
|---|
| 192 | cbox_array_size = 0;
|
|---|
| 193 | for (d = 0; d < 3; d++)
|
|---|
| 194 | {
|
|---|
| 195 | if ( (hypre_BoxVolume(rembox)) && (border[d][0]) )
|
|---|
| 196 | {
|
|---|
| 197 | cbox = hypre_BoxArrayBox(cbox_array, cbox_array_size);
|
|---|
| 198 | hypre_CopyBox(rembox, cbox);
|
|---|
| 199 | hypre_BoxIMaxD(cbox, d) =
|
|---|
| 200 | hypre_BoxIMinD(cbox, d) + border[d][0] - 1;
|
|---|
| 201 | hypre_BoxIMinD(rembox, d) =
|
|---|
| 202 | hypre_BoxIMinD(cbox, d) + border[d][0];
|
|---|
| 203 | cbox_array_size++;
|
|---|
| 204 | }
|
|---|
| 205 | if ( (hypre_BoxVolume(rembox)) && (border[d][1]) )
|
|---|
| 206 | {
|
|---|
| 207 | cbox = hypre_BoxArrayBox(cbox_array, cbox_array_size);
|
|---|
| 208 | hypre_CopyBox(rembox, cbox);
|
|---|
| 209 | hypre_BoxIMinD(cbox, d) =
|
|---|
| 210 | hypre_BoxIMaxD(cbox, d) - border[d][1] + 1;
|
|---|
| 211 | hypre_BoxIMaxD(rembox, d) =
|
|---|
| 212 | hypre_BoxIMaxD(cbox, d) - border[d][1];
|
|---|
| 213 | cbox_array_size++;
|
|---|
| 214 | }
|
|---|
| 215 | }
|
|---|
| 216 | hypre_BoxArraySetSize(cbox_array, cbox_array_size);
|
|---|
| 217 | }
|
|---|
| 218 | hypre_BoxDestroy(rembox);
|
|---|
| 219 |
|
|---|
| 220 | /*------------------------------------------------------
|
|---|
| 221 | * Set up the independent boxes
|
|---|
| 222 | *------------------------------------------------------*/
|
|---|
| 223 |
|
|---|
| 224 | indt_boxes = hypre_BoxArrayArrayCreate(hypre_BoxArraySize(boxes));
|
|---|
| 225 |
|
|---|
| 226 | hypre_ForBoxI(i, boxes)
|
|---|
| 227 | {
|
|---|
| 228 | cbox_array = hypre_BoxArrayArrayBoxArray(indt_boxes, i);
|
|---|
| 229 | hypre_BoxArraySetSize(cbox_array, 1);
|
|---|
| 230 | cbox = hypre_BoxArrayBox(cbox_array, 0);
|
|---|
| 231 | hypre_CopyBox(hypre_BoxArrayBox(boxes, i), cbox);
|
|---|
| 232 |
|
|---|
| 233 | for (d = 0; d < 3; d++)
|
|---|
| 234 | {
|
|---|
| 235 | if ( (border[d][0]) )
|
|---|
| 236 | {
|
|---|
| 237 | hypre_BoxIMinD(cbox, d) += border[d][0];
|
|---|
| 238 | }
|
|---|
| 239 | if ( (border[d][1]) )
|
|---|
| 240 | {
|
|---|
| 241 | hypre_BoxIMaxD(cbox, d) -= border[d][1];
|
|---|
| 242 | }
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | #else
|
|---|
| 247 |
|
|---|
| 248 | /*------------------------------------------------------
|
|---|
| 249 | * Set up the independent boxes
|
|---|
| 250 | *------------------------------------------------------*/
|
|---|
| 251 |
|
|---|
| 252 | indt_boxes = hypre_BoxArrayArrayCreate(hypre_BoxArraySize(boxes));
|
|---|
| 253 |
|
|---|
| 254 | /*------------------------------------------------------
|
|---|
| 255 | * Set up the dependent boxes
|
|---|
| 256 | *------------------------------------------------------*/
|
|---|
| 257 |
|
|---|
| 258 | dept_boxes = hypre_BoxArrayArrayCreate(hypre_BoxArraySize(boxes));
|
|---|
| 259 |
|
|---|
| 260 | hypre_ForBoxI(i, boxes)
|
|---|
| 261 | {
|
|---|
| 262 | cbox_array = hypre_BoxArrayArrayBoxArray(dept_boxes, i);
|
|---|
| 263 | hypre_BoxArraySetSize(cbox_array, 1);
|
|---|
| 264 | cbox = hypre_BoxArrayBox(cbox_array, 0);
|
|---|
| 265 | hypre_CopyBox(hypre_BoxArrayBox(boxes, i), cbox);
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | #endif
|
|---|
| 269 |
|
|---|
| 270 | /*------------------------------------------------------
|
|---|
| 271 | * Return
|
|---|
| 272 | *------------------------------------------------------*/
|
|---|
| 273 |
|
|---|
| 274 | hypre_ComputeInfoCreate(comm_info, indt_boxes, dept_boxes,
|
|---|
| 275 | compute_info_ptr);
|
|---|
| 276 |
|
|---|
| 277 | return ierr;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | /*--------------------------------------------------------------------------
|
|---|
| 281 | * Create a computation package from a grid-based description of a
|
|---|
| 282 | * communication-computation pattern.
|
|---|
| 283 | *
|
|---|
| 284 | * Note: The input boxes and processes are destroyed.
|
|---|
| 285 | *--------------------------------------------------------------------------*/
|
|---|
| 286 |
|
|---|
| 287 | int
|
|---|
| 288 | hypre_ComputePkgCreate( hypre_ComputeInfo *compute_info,
|
|---|
| 289 | hypre_BoxArray *data_space,
|
|---|
| 290 | int num_values,
|
|---|
| 291 | hypre_StructGrid *grid,
|
|---|
| 292 | hypre_ComputePkg **compute_pkg_ptr )
|
|---|
| 293 | {
|
|---|
| 294 | int ierr = 0;
|
|---|
| 295 | hypre_ComputePkg *compute_pkg;
|
|---|
| 296 | hypre_CommPkg *comm_pkg;
|
|---|
| 297 |
|
|---|
| 298 | compute_pkg = hypre_CTAlloc(hypre_ComputePkg, 1);
|
|---|
| 299 |
|
|---|
| 300 | hypre_CommPkgCreate(hypre_ComputeInfoCommInfo(compute_info),
|
|---|
| 301 | data_space, data_space, num_values,
|
|---|
| 302 | hypre_StructGridComm(grid), &comm_pkg);
|
|---|
| 303 | hypre_ComputePkgCommPkg(compute_pkg) = comm_pkg;
|
|---|
| 304 |
|
|---|
| 305 | hypre_ComputePkgIndtBoxes(compute_pkg) =
|
|---|
| 306 | hypre_ComputeInfoIndtBoxes(compute_info);
|
|---|
| 307 | hypre_ComputePkgDeptBoxes(compute_pkg) =
|
|---|
| 308 | hypre_ComputeInfoDeptBoxes(compute_info);
|
|---|
| 309 | hypre_CopyIndex(hypre_ComputeInfoStride(compute_info),
|
|---|
| 310 | hypre_ComputePkgStride(compute_pkg));
|
|---|
| 311 |
|
|---|
| 312 | hypre_StructGridRef(grid, &hypre_ComputePkgGrid(compute_pkg));
|
|---|
| 313 | hypre_ComputePkgDataSpace(compute_pkg) = data_space;
|
|---|
| 314 | hypre_ComputePkgNumValues(compute_pkg) = num_values;
|
|---|
| 315 |
|
|---|
| 316 | hypre_ComputeInfoDestroy(compute_info);
|
|---|
| 317 |
|
|---|
| 318 | *compute_pkg_ptr = compute_pkg;
|
|---|
| 319 |
|
|---|
| 320 | return ierr;
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | /*--------------------------------------------------------------------------
|
|---|
| 324 | * Destroy a computation package.
|
|---|
| 325 | *--------------------------------------------------------------------------*/
|
|---|
| 326 |
|
|---|
| 327 | int
|
|---|
| 328 | hypre_ComputePkgDestroy( hypre_ComputePkg *compute_pkg )
|
|---|
| 329 | {
|
|---|
| 330 | int ierr = 0;
|
|---|
| 331 |
|
|---|
| 332 | if (compute_pkg)
|
|---|
| 333 | {
|
|---|
| 334 | hypre_CommPkgDestroy(hypre_ComputePkgCommPkg(compute_pkg));
|
|---|
| 335 |
|
|---|
| 336 | hypre_BoxArrayArrayDestroy(hypre_ComputePkgIndtBoxes(compute_pkg));
|
|---|
| 337 | hypre_BoxArrayArrayDestroy(hypre_ComputePkgDeptBoxes(compute_pkg));
|
|---|
| 338 |
|
|---|
| 339 | hypre_StructGridDestroy(hypre_ComputePkgGrid(compute_pkg));
|
|---|
| 340 |
|
|---|
| 341 | hypre_TFree(compute_pkg);
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | return ierr;
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | /*--------------------------------------------------------------------------
|
|---|
| 348 | * Initialize a non-blocking communication exchange. The independent
|
|---|
| 349 | * computations may be done after a call to this routine, to allow for
|
|---|
| 350 | * overlap of communications and computations.
|
|---|
| 351 | *--------------------------------------------------------------------------*/
|
|---|
| 352 |
|
|---|
| 353 | int
|
|---|
| 354 | hypre_InitializeIndtComputations( hypre_ComputePkg *compute_pkg,
|
|---|
| 355 | double *data,
|
|---|
| 356 | hypre_CommHandle **comm_handle_ptr )
|
|---|
| 357 | {
|
|---|
| 358 | int ierr = 0;
|
|---|
| 359 | hypre_CommPkg *comm_pkg = hypre_ComputePkgCommPkg(compute_pkg);
|
|---|
| 360 |
|
|---|
| 361 | ierr = hypre_InitializeCommunication(comm_pkg, data, data, comm_handle_ptr);
|
|---|
| 362 |
|
|---|
| 363 | return ierr;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | /*--------------------------------------------------------------------------
|
|---|
| 367 | * Finalize a communication exchange. The dependent computations may
|
|---|
| 368 | * be done after a call to this routine.
|
|---|
| 369 | *--------------------------------------------------------------------------*/
|
|---|
| 370 |
|
|---|
| 371 | int
|
|---|
| 372 | hypre_FinalizeIndtComputations( hypre_CommHandle *comm_handle )
|
|---|
| 373 | {
|
|---|
| 374 | int ierr = 0;
|
|---|
| 375 |
|
|---|
| 376 | ierr = hypre_FinalizeCommunication(comm_handle );
|
|---|
| 377 |
|
|---|
| 378 | return ierr;
|
|---|
| 379 | }
|
|---|