| 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 | * Header info for the Box structures
|
|---|
| 17 | *
|
|---|
| 18 | *****************************************************************************/
|
|---|
| 19 |
|
|---|
| 20 | #ifndef hypre_BOX_HEADER
|
|---|
| 21 | #define hypre_BOX_HEADER
|
|---|
| 22 |
|
|---|
| 23 | /*--------------------------------------------------------------------------
|
|---|
| 24 | * hypre_Index:
|
|---|
| 25 | * This is used to define indices in index space, or dimension
|
|---|
| 26 | * sizes of boxes.
|
|---|
| 27 | *
|
|---|
| 28 | * The spatial dimensions x, y, and z may be specified by the
|
|---|
| 29 | * integers 0, 1, and 2, respectively (see the hypre_IndexD macro below).
|
|---|
| 30 | * This simplifies the code in the hypre_Box class by reducing code
|
|---|
| 31 | * replication.
|
|---|
| 32 | *--------------------------------------------------------------------------*/
|
|---|
| 33 |
|
|---|
| 34 | typedef int hypre_Index[3];
|
|---|
| 35 | typedef int *hypre_IndexRef;
|
|---|
| 36 |
|
|---|
| 37 | /*--------------------------------------------------------------------------
|
|---|
| 38 | * hypre_Box:
|
|---|
| 39 | *--------------------------------------------------------------------------*/
|
|---|
| 40 |
|
|---|
| 41 | typedef struct hypre_Box_struct
|
|---|
| 42 | {
|
|---|
| 43 | hypre_Index imin; /* min bounding indices */
|
|---|
| 44 | hypre_Index imax; /* max bounding indices */
|
|---|
| 45 |
|
|---|
| 46 | } hypre_Box;
|
|---|
| 47 |
|
|---|
| 48 | /*--------------------------------------------------------------------------
|
|---|
| 49 | * hypre_BoxArray:
|
|---|
| 50 | * An array of boxes.
|
|---|
| 51 | *--------------------------------------------------------------------------*/
|
|---|
| 52 |
|
|---|
| 53 | typedef struct hypre_BoxArray_struct
|
|---|
| 54 | {
|
|---|
| 55 | hypre_Box *boxes; /* Array of boxes */
|
|---|
| 56 | int size; /* Size of box array */
|
|---|
| 57 | int alloc_size; /* Size of currently alloced space */
|
|---|
| 58 |
|
|---|
| 59 | } hypre_BoxArray;
|
|---|
| 60 |
|
|---|
| 61 | #define hypre_BoxArrayExcess 10
|
|---|
| 62 |
|
|---|
| 63 | /*--------------------------------------------------------------------------
|
|---|
| 64 | * hypre_BoxArrayArray:
|
|---|
| 65 | * An array of box arrays.
|
|---|
| 66 | *--------------------------------------------------------------------------*/
|
|---|
| 67 |
|
|---|
| 68 | typedef struct hypre_BoxArrayArray_struct
|
|---|
| 69 | {
|
|---|
| 70 | hypre_BoxArray **box_arrays; /* Array of pointers to box arrays */
|
|---|
| 71 | int size; /* Size of box array array */
|
|---|
| 72 |
|
|---|
| 73 | } hypre_BoxArrayArray;
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | /*--------------------------------------------------------------------------
|
|---|
| 77 | * Accessor macros: hypre_Index
|
|---|
| 78 | *--------------------------------------------------------------------------*/
|
|---|
| 79 |
|
|---|
| 80 | #define hypre_IndexD(index, d) (index[d])
|
|---|
| 81 |
|
|---|
| 82 | #define hypre_IndexX(index) hypre_IndexD(index, 0)
|
|---|
| 83 | #define hypre_IndexY(index) hypre_IndexD(index, 1)
|
|---|
| 84 | #define hypre_IndexZ(index) hypre_IndexD(index, 2)
|
|---|
| 85 |
|
|---|
| 86 | /*--------------------------------------------------------------------------
|
|---|
| 87 | * Member functions: hypre_Index
|
|---|
| 88 | *--------------------------------------------------------------------------*/
|
|---|
| 89 |
|
|---|
| 90 | #define hypre_SetIndex(index, ix, iy, iz) \
|
|---|
| 91 | ( hypre_IndexX(index) = ix,\
|
|---|
| 92 | hypre_IndexY(index) = iy,\
|
|---|
| 93 | hypre_IndexZ(index) = iz )
|
|---|
| 94 |
|
|---|
| 95 | #define hypre_ClearIndex(index) hypre_SetIndex(index, 0, 0, 0)
|
|---|
| 96 |
|
|---|
| 97 | #define hypre_CopyIndex(index1, index2) \
|
|---|
| 98 | ( hypre_IndexX(index2) = hypre_IndexX(index1),\
|
|---|
| 99 | hypre_IndexY(index2) = hypre_IndexY(index1),\
|
|---|
| 100 | hypre_IndexZ(index2) = hypre_IndexZ(index1) )
|
|---|
| 101 |
|
|---|
| 102 | #define hypre_CopyToCleanIndex(in_index, ndim, out_index) \
|
|---|
| 103 | {\
|
|---|
| 104 | int d;\
|
|---|
| 105 | for (d = 0; d < ndim; d++)\
|
|---|
| 106 | {\
|
|---|
| 107 | hypre_IndexD(out_index, d) = hypre_IndexD(in_index, d);\
|
|---|
| 108 | }\
|
|---|
| 109 | for (d = ndim; d < 3; d++)\
|
|---|
| 110 | {\
|
|---|
| 111 | hypre_IndexD(out_index, d) = 0;\
|
|---|
| 112 | }\
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | /*--------------------------------------------------------------------------
|
|---|
| 116 | * Accessor macros: hypre_Box
|
|---|
| 117 | *--------------------------------------------------------------------------*/
|
|---|
| 118 |
|
|---|
| 119 | #define hypre_BoxIMin(box) ((box) -> imin)
|
|---|
| 120 | #define hypre_BoxIMax(box) ((box) -> imax)
|
|---|
| 121 |
|
|---|
| 122 | #define hypre_AddIndex(index1, index2, index3) \
|
|---|
| 123 | ( hypre_IndexX(index3) = hypre_IndexX(index2) + hypre_IndexX(index1),\
|
|---|
| 124 | hypre_IndexY(index3) = hypre_IndexY(index2) + hypre_IndexY(index1),\
|
|---|
| 125 | hypre_IndexZ(index3) = hypre_IndexZ(index2) + hypre_IndexZ(index1) )
|
|---|
| 126 |
|
|---|
| 127 | #define hypre_SubtractIndex(index1, index2, index3) \
|
|---|
| 128 | ( hypre_IndexX(index3) = hypre_IndexX(index1) - hypre_IndexX(index2),\
|
|---|
| 129 | hypre_IndexY(index3) = hypre_IndexY(index1) - hypre_IndexY(index2),\
|
|---|
| 130 | hypre_IndexZ(index3) = hypre_IndexZ(index1) - hypre_IndexZ(index2) )
|
|---|
| 131 |
|
|---|
| 132 | #define hypre_BoxIMinD(box, d) (hypre_IndexD(hypre_BoxIMin(box), d))
|
|---|
| 133 | #define hypre_BoxIMaxD(box, d) (hypre_IndexD(hypre_BoxIMax(box), d))
|
|---|
| 134 | #define hypre_BoxSizeD(box, d) \
|
|---|
| 135 | hypre_max(0, (hypre_BoxIMaxD(box, d) - hypre_BoxIMinD(box, d) + 1))
|
|---|
| 136 |
|
|---|
| 137 | #define hypre_BoxIMinX(box) hypre_BoxIMinD(box, 0)
|
|---|
| 138 | #define hypre_BoxIMinY(box) hypre_BoxIMinD(box, 1)
|
|---|
| 139 | #define hypre_BoxIMinZ(box) hypre_BoxIMinD(box, 2)
|
|---|
| 140 |
|
|---|
| 141 | #define hypre_BoxIMaxX(box) hypre_BoxIMaxD(box, 0)
|
|---|
| 142 | #define hypre_BoxIMaxY(box) hypre_BoxIMaxD(box, 1)
|
|---|
| 143 | #define hypre_BoxIMaxZ(box) hypre_BoxIMaxD(box, 2)
|
|---|
| 144 |
|
|---|
| 145 | #define hypre_BoxSizeX(box) hypre_BoxSizeD(box, 0)
|
|---|
| 146 | #define hypre_BoxSizeY(box) hypre_BoxSizeD(box, 1)
|
|---|
| 147 | #define hypre_BoxSizeZ(box) hypre_BoxSizeD(box, 2)
|
|---|
| 148 |
|
|---|
| 149 | #define hypre_BoxEqualP( box1, box2 ) (\
|
|---|
| 150 | hypre_BoxIMinX(box1)==hypre_BoxIMinX(box2) &&\
|
|---|
| 151 | hypre_BoxIMaxX(box1)==hypre_BoxIMaxX(box2) &&\
|
|---|
| 152 | hypre_BoxIMinY(box1)==hypre_BoxIMinY(box2) &&\
|
|---|
| 153 | hypre_BoxIMaxY(box1)==hypre_BoxIMaxY(box2) &&\
|
|---|
| 154 | hypre_BoxIMinZ(box1)==hypre_BoxIMinZ(box2) &&\
|
|---|
| 155 | hypre_BoxIMaxZ(box1)==hypre_BoxIMaxZ(box2) )
|
|---|
| 156 |
|
|---|
| 157 | #define hypre_IndexInBoxP( index, box ) (\
|
|---|
| 158 | hypre_IndexX(index)>=hypre_BoxIMinX(box) &&\
|
|---|
| 159 | hypre_IndexX(index)<=hypre_BoxIMaxX(box) &&\
|
|---|
| 160 | hypre_IndexY(index)>=hypre_BoxIMinY(box) &&\
|
|---|
| 161 | hypre_IndexY(index)<=hypre_BoxIMaxY(box) &&\
|
|---|
| 162 | hypre_IndexZ(index)>=hypre_BoxIMinZ(box) &&\
|
|---|
| 163 | hypre_IndexZ(index)<=hypre_BoxIMaxZ(box) )
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 | #define hypre_IndexDInBoxP( index, d, box ) (\
|
|---|
| 167 | hypre_IndexD(index, d)>=hypre_BoxIMinD(box, d) &&\
|
|---|
| 168 | hypre_IndexD(index, d)<=hypre_BoxIMaxD(box, d) )
|
|---|
| 169 |
|
|---|
| 170 | #define hypre_CopyBox(box1, box2) \
|
|---|
| 171 | ( hypre_CopyIndex(hypre_BoxIMin(box1), hypre_BoxIMin(box2)),\
|
|---|
| 172 | hypre_CopyIndex(hypre_BoxIMax(box1), hypre_BoxIMax(box2)) )
|
|---|
| 173 |
|
|---|
| 174 | #define hypre_BoxVolume(box) \
|
|---|
| 175 | (hypre_BoxSizeX(box) * hypre_BoxSizeY(box) * hypre_BoxSizeZ(box))
|
|---|
| 176 |
|
|---|
| 177 | #define hypre_BoxShiftPos(box, shift) \
|
|---|
| 178 | {\
|
|---|
| 179 | hypre_BoxIMinX(box) += hypre_IndexX(shift);\
|
|---|
| 180 | hypre_BoxIMinY(box) += hypre_IndexY(shift);\
|
|---|
| 181 | hypre_BoxIMinZ(box) += hypre_IndexZ(shift);\
|
|---|
| 182 | hypre_BoxIMaxX(box) += hypre_IndexX(shift);\
|
|---|
| 183 | hypre_BoxIMaxY(box) += hypre_IndexY(shift);\
|
|---|
| 184 | hypre_BoxIMaxZ(box) += hypre_IndexZ(shift);\
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | #define hypre_BoxShiftNeg(box, shift) \
|
|---|
| 188 | {\
|
|---|
| 189 | hypre_BoxIMinX(box) -= hypre_IndexX(shift);\
|
|---|
| 190 | hypre_BoxIMinY(box) -= hypre_IndexY(shift);\
|
|---|
| 191 | hypre_BoxIMinZ(box) -= hypre_IndexZ(shift);\
|
|---|
| 192 | hypre_BoxIMaxX(box) -= hypre_IndexX(shift);\
|
|---|
| 193 | hypre_BoxIMaxY(box) -= hypre_IndexY(shift);\
|
|---|
| 194 | hypre_BoxIMaxZ(box) -= hypre_IndexZ(shift);\
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | #define hypre_BoxIndexRank(box, index) \
|
|---|
| 198 | ((hypre_IndexX(index) - hypre_BoxIMinX(box)) + \
|
|---|
| 199 | ((hypre_IndexY(index) - hypre_BoxIMinY(box)) + \
|
|---|
| 200 | ((hypre_IndexZ(index) - hypre_BoxIMinZ(box)) * \
|
|---|
| 201 | hypre_BoxSizeY(box))) * \
|
|---|
| 202 | hypre_BoxSizeX(box))
|
|---|
| 203 |
|
|---|
| 204 | /* The first hypre_CCBoxIndexRank is better style because it keeps
|
|---|
| 205 | its similarity to the variable coefficient hypre_BoxIndexRank.
|
|---|
| 206 | The second one sometimes avoids compiler warnings...*/
|
|---|
| 207 | #define hypre_CCBoxIndexRank(box, index) 0
|
|---|
| 208 | #define hypre_CCBoxIndexRank_noargs() 0
|
|---|
| 209 |
|
|---|
| 210 | #define hypre_BoxOffsetDistance(box, index) \
|
|---|
| 211 | (hypre_IndexX(index) + \
|
|---|
| 212 | (hypre_IndexY(index) + \
|
|---|
| 213 | (hypre_IndexZ(index) * \
|
|---|
| 214 | hypre_BoxSizeY(box))) * \
|
|---|
| 215 | hypre_BoxSizeX(box))
|
|---|
| 216 |
|
|---|
| 217 | #define hypre_CCBoxOffsetDistance(box, index) 0
|
|---|
| 218 |
|
|---|
| 219 | /*--------------------------------------------------------------------------
|
|---|
| 220 | * Accessor macros: hypre_BoxArray
|
|---|
| 221 | *--------------------------------------------------------------------------*/
|
|---|
| 222 |
|
|---|
| 223 | #define hypre_BoxArrayBoxes(box_array) ((box_array) -> boxes)
|
|---|
| 224 | #define hypre_BoxArrayBox(box_array, i) &((box_array) -> boxes[(i)])
|
|---|
| 225 | #define hypre_BoxArraySize(box_array) ((box_array) -> size)
|
|---|
| 226 | #define hypre_BoxArrayAllocSize(box_array) ((box_array) -> alloc_size)
|
|---|
| 227 |
|
|---|
| 228 | /*--------------------------------------------------------------------------
|
|---|
| 229 | * Accessor macros: hypre_BoxArrayArray
|
|---|
| 230 | *--------------------------------------------------------------------------*/
|
|---|
| 231 |
|
|---|
| 232 | #define hypre_BoxArrayArrayBoxArrays(box_array_array) \
|
|---|
| 233 | ((box_array_array) -> box_arrays)
|
|---|
| 234 | #define hypre_BoxArrayArrayBoxArray(box_array_array, i) \
|
|---|
| 235 | ((box_array_array) -> box_arrays[(i)])
|
|---|
| 236 | #define hypre_BoxArrayArraySize(box_array_array) \
|
|---|
| 237 | ((box_array_array) -> size)
|
|---|
| 238 |
|
|---|
| 239 | /*--------------------------------------------------------------------------
|
|---|
| 240 | * Looping macros:
|
|---|
| 241 | *--------------------------------------------------------------------------*/
|
|---|
| 242 |
|
|---|
| 243 | #define hypre_ForBoxI(i, box_array) \
|
|---|
| 244 | for (i = 0; i < hypre_BoxArraySize(box_array); i++)
|
|---|
| 245 |
|
|---|
| 246 | #define hypre_ForBoxArrayI(i, box_array_array) \
|
|---|
| 247 | for (i = 0; i < hypre_BoxArrayArraySize(box_array_array); i++)
|
|---|
| 248 |
|
|---|
| 249 | /*--------------------------------------------------------------------------
|
|---|
| 250 | * BoxLoop macros:
|
|---|
| 251 | *
|
|---|
| 252 | * NOTE: PThreads version of BoxLoop looping macros are in `box_pthreads.h'.
|
|---|
| 253 | *
|
|---|
| 254 | *--------------------------------------------------------------------------*/
|
|---|
| 255 |
|
|---|
| 256 | #ifndef HYPRE_USE_PTHREADS
|
|---|
| 257 |
|
|---|
| 258 | #define hypre_BoxLoopDeclareS(dbox, stride, sx, sy, sz) \
|
|---|
| 259 | int sx = (hypre_IndexX(stride));\
|
|---|
| 260 | int sy = (hypre_IndexY(stride)*hypre_BoxSizeX(dbox));\
|
|---|
| 261 | int sz = (hypre_IndexZ(stride)*\
|
|---|
| 262 | hypre_BoxSizeX(dbox)*hypre_BoxSizeY(dbox))
|
|---|
| 263 |
|
|---|
| 264 | #define hypre_BoxLoopDeclareN(loop_size) \
|
|---|
| 265 | int hypre__nx = hypre_IndexX(loop_size);\
|
|---|
| 266 | int hypre__ny = hypre_IndexY(loop_size);\
|
|---|
| 267 | int hypre__nz = hypre_IndexZ(loop_size);\
|
|---|
| 268 | int hypre__mx = hypre__nx;\
|
|---|
| 269 | int hypre__my = hypre__ny;\
|
|---|
| 270 | int hypre__mz = hypre__nz;\
|
|---|
| 271 | int hypre__dir, hypre__max;\
|
|---|
| 272 | int hypre__div, hypre__mod;\
|
|---|
| 273 | int hypre__block, hypre__num_blocks;\
|
|---|
| 274 | hypre__dir = 0;\
|
|---|
| 275 | hypre__max = hypre__nx;\
|
|---|
| 276 | if (hypre__ny > hypre__max)\
|
|---|
| 277 | {\
|
|---|
| 278 | hypre__dir = 1;\
|
|---|
| 279 | hypre__max = hypre__ny;\
|
|---|
| 280 | }\
|
|---|
| 281 | if (hypre__nz > hypre__max)\
|
|---|
| 282 | {\
|
|---|
| 283 | hypre__dir = 2;\
|
|---|
| 284 | hypre__max = hypre__nz;\
|
|---|
| 285 | }\
|
|---|
| 286 | hypre__num_blocks = hypre_NumThreads();\
|
|---|
| 287 | if (hypre__max < hypre__num_blocks)\
|
|---|
| 288 | {\
|
|---|
| 289 | hypre__num_blocks = hypre__max;\
|
|---|
| 290 | }\
|
|---|
| 291 | if (hypre__num_blocks > 0)\
|
|---|
| 292 | {\
|
|---|
| 293 | hypre__div = hypre__max / hypre__num_blocks;\
|
|---|
| 294 | hypre__mod = hypre__max % hypre__num_blocks;\
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | #define hypre_BoxLoopSet(i, j, k) \
|
|---|
| 298 | i = 0;\
|
|---|
| 299 | j = 0;\
|
|---|
| 300 | k = 0;\
|
|---|
| 301 | hypre__nx = hypre__mx;\
|
|---|
| 302 | hypre__ny = hypre__my;\
|
|---|
| 303 | hypre__nz = hypre__mz;\
|
|---|
| 304 | if (hypre__num_blocks > 1)\
|
|---|
| 305 | {\
|
|---|
| 306 | if (hypre__dir == 0)\
|
|---|
| 307 | {\
|
|---|
| 308 | i = hypre__block * hypre__div + hypre_min(hypre__mod, hypre__block);\
|
|---|
| 309 | hypre__nx = hypre__div + ((hypre__mod > hypre__block) ? 1 : 0);\
|
|---|
| 310 | }\
|
|---|
| 311 | else if (hypre__dir == 1)\
|
|---|
| 312 | {\
|
|---|
| 313 | j = hypre__block * hypre__div + hypre_min(hypre__mod, hypre__block);\
|
|---|
| 314 | hypre__ny = hypre__div + ((hypre__mod > hypre__block) ? 1 : 0);\
|
|---|
| 315 | }\
|
|---|
| 316 | else if (hypre__dir == 2)\
|
|---|
| 317 | {\
|
|---|
| 318 | k = hypre__block * hypre__div + hypre_min(hypre__mod, hypre__block);\
|
|---|
| 319 | hypre__nz = hypre__div + ((hypre__mod > hypre__block) ? 1 : 0);\
|
|---|
| 320 | }\
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | #define hypre_BoxLoopGetIndex( index, base, i, j, k )\
|
|---|
| 324 | hypre_SetIndex( index, i+hypre_IndexX(base),\
|
|---|
| 325 | j+hypre_IndexY(base), k+hypre_IndexZ(base) )
|
|---|
| 326 |
|
|---|
| 327 | /*-----------------------------------*/
|
|---|
| 328 |
|
|---|
| 329 | #define hypre_BoxLoop0Begin(loop_size)\
|
|---|
| 330 | {\
|
|---|
| 331 | hypre_BoxLoopDeclareN(loop_size);
|
|---|
| 332 |
|
|---|
| 333 | #define hypre_BoxLoop0For(i, j, k)\
|
|---|
| 334 | for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\
|
|---|
| 335 | {\
|
|---|
| 336 | hypre_BoxLoopSet(i, j, k);\
|
|---|
| 337 | for (k = 0; k < hypre__nz; k++)\
|
|---|
| 338 | {\
|
|---|
| 339 | for (j = 0; j < hypre__ny; j++)\
|
|---|
| 340 | {\
|
|---|
| 341 | for (i = 0; i < hypre__nx; i++)\
|
|---|
| 342 | {
|
|---|
| 343 |
|
|---|
| 344 | #define hypre_BoxLoop0End()\
|
|---|
| 345 | }\
|
|---|
| 346 | }\
|
|---|
| 347 | }\
|
|---|
| 348 | }\
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | /*-----------------------------------*/
|
|---|
| 352 |
|
|---|
| 353 | #define hypre_BoxLoop1Begin(loop_size,\
|
|---|
| 354 | dbox1, start1, stride1, i1)\
|
|---|
| 355 | {\
|
|---|
| 356 | int hypre__i1start = hypre_BoxIndexRank(dbox1, start1);\
|
|---|
| 357 | hypre_BoxLoopDeclareS(dbox1, stride1, hypre__sx1, hypre__sy1, hypre__sz1);\
|
|---|
| 358 | hypre_BoxLoopDeclareN(loop_size);
|
|---|
| 359 |
|
|---|
| 360 | #define hypre_BoxLoop1For(i, j, k, i1)\
|
|---|
| 361 | for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\
|
|---|
| 362 | {\
|
|---|
| 363 | hypre_BoxLoopSet(i, j, k);\
|
|---|
| 364 | i1 = hypre__i1start + i*hypre__sx1 + j*hypre__sy1 + k*hypre__sz1;\
|
|---|
| 365 | for (k = 0; k < hypre__nz; k++)\
|
|---|
| 366 | {\
|
|---|
| 367 | for (j = 0; j < hypre__ny; j++)\
|
|---|
| 368 | {\
|
|---|
| 369 | for (i = 0; i < hypre__nx; i++)\
|
|---|
| 370 | {
|
|---|
| 371 |
|
|---|
| 372 | #define hypre_BoxLoop1End(i1)\
|
|---|
| 373 | i1 += hypre__sx1;\
|
|---|
| 374 | }\
|
|---|
| 375 | i1 += hypre__sy1 - hypre__nx*hypre__sx1;\
|
|---|
| 376 | }\
|
|---|
| 377 | i1 += hypre__sz1 - hypre__ny*hypre__sy1;\
|
|---|
| 378 | }\
|
|---|
| 379 | }\
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | /*-----------------------------------*/
|
|---|
| 383 |
|
|---|
| 384 | #define hypre_BoxLoop2Begin(loop_size,\
|
|---|
| 385 | dbox1, start1, stride1, i1,\
|
|---|
| 386 | dbox2, start2, stride2, i2)\
|
|---|
| 387 | {\
|
|---|
| 388 | int hypre__i1start = hypre_BoxIndexRank(dbox1, start1);\
|
|---|
| 389 | int hypre__i2start = hypre_BoxIndexRank(dbox2, start2);\
|
|---|
| 390 | hypre_BoxLoopDeclareS(dbox1, stride1, hypre__sx1, hypre__sy1, hypre__sz1);\
|
|---|
| 391 | hypre_BoxLoopDeclareS(dbox2, stride2, hypre__sx2, hypre__sy2, hypre__sz2);\
|
|---|
| 392 | hypre_BoxLoopDeclareN(loop_size);
|
|---|
| 393 |
|
|---|
| 394 | #define hypre_BoxLoop2For(i, j, k, i1, i2)\
|
|---|
| 395 | for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\
|
|---|
| 396 | {\
|
|---|
| 397 | hypre_BoxLoopSet(i, j, k);\
|
|---|
| 398 | i1 = hypre__i1start + i*hypre__sx1 + j*hypre__sy1 + k*hypre__sz1;\
|
|---|
| 399 | i2 = hypre__i2start + i*hypre__sx2 + j*hypre__sy2 + k*hypre__sz2;\
|
|---|
| 400 | for (k = 0; k < hypre__nz; k++)\
|
|---|
| 401 | {\
|
|---|
| 402 | for (j = 0; j < hypre__ny; j++)\
|
|---|
| 403 | {\
|
|---|
| 404 | for (i = 0; i < hypre__nx; i++)\
|
|---|
| 405 | {
|
|---|
| 406 |
|
|---|
| 407 | #define hypre_BoxLoop2End(i1, i2)\
|
|---|
| 408 | i1 += hypre__sx1;\
|
|---|
| 409 | i2 += hypre__sx2;\
|
|---|
| 410 | }\
|
|---|
| 411 | i1 += hypre__sy1 - hypre__nx*hypre__sx1;\
|
|---|
| 412 | i2 += hypre__sy2 - hypre__nx*hypre__sx2;\
|
|---|
| 413 | }\
|
|---|
| 414 | i1 += hypre__sz1 - hypre__ny*hypre__sy1;\
|
|---|
| 415 | i2 += hypre__sz2 - hypre__ny*hypre__sy2;\
|
|---|
| 416 | }\
|
|---|
| 417 | }\
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 | /* incomplete BoxLoop2 macros leave out the inner loop so it can be hand-coded */
|
|---|
| 421 | #define hypre_BoxLoop2For_INC(i, j, k, i1, i2)\
|
|---|
| 422 | for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\
|
|---|
| 423 | {\
|
|---|
| 424 | hypre_BoxLoopSet(i, j, k);\
|
|---|
| 425 | i1 = hypre__i1start + i*hypre__sx1 + j*hypre__sy1 + k*hypre__sz1;\
|
|---|
| 426 | i2 = hypre__i2start + i*hypre__sx2 + j*hypre__sy2 + k*hypre__sz2;\
|
|---|
| 427 | for (k = 0; k < hypre__nz; k++)\
|
|---|
| 428 | {\
|
|---|
| 429 | for (j = 0; j < hypre__ny; j++)\
|
|---|
| 430 | {
|
|---|
| 431 |
|
|---|
| 432 | #define hypre_BoxLoop2End_INC(i1, i2)\
|
|---|
| 433 | i1 += hypre__sy1 - hypre__nx*hypre__sx1;\
|
|---|
| 434 | i2 += hypre__sy2 - hypre__nx*hypre__sx2;\
|
|---|
| 435 | }\
|
|---|
| 436 | i1 += hypre__sz1 - hypre__ny*hypre__sy1;\
|
|---|
| 437 | i2 += hypre__sz2 - hypre__ny*hypre__sy2;\
|
|---|
| 438 | }\
|
|---|
| 439 | }\
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | /* BoxLoop2 macros, but only for when all strides are equal. To improve
|
|---|
| 443 | runtime, only one index is computed in the innermost loop, the internal
|
|---|
| 444 | index i.
|
|---|
| 445 | Since only the internal index, i, is updated in the innermost loop, you
|
|---|
| 446 | can't reference i1, i2 inside the innermost loop. To get the effect of i1, i2
|
|---|
| 447 | you have to use a macro (see below) to do pointer aliasing. It works because
|
|---|
| 448 | you know that i has the same stride as i1, i2.
|
|---|
| 449 | This macro set invokes the user-defined macro hypre_UserOutsideInnerLoop inside
|
|---|
| 450 | the outer loops, just before the innermost loop. The user can define this macro
|
|---|
| 451 | for pointer aliasing.
|
|---|
| 452 | It's safer to redefine hypre_UserOutsideInnerLoop to do nothing afterwards.
|
|---|
| 453 | The Begin_OneStride macro isn't really needed, the Begin macro does the same
|
|---|
| 454 | thing, but without ensuring that the strides are the same.
|
|---|
| 455 | */
|
|---|
| 456 |
|
|---|
| 457 | #define hypre_UserOutsideInnerLoop
|
|---|
| 458 |
|
|---|
| 459 | #define hypre_BoxLoop2Begin_OneStride(loop_size, stride1,\
|
|---|
| 460 | dbox1, start1, i1,\
|
|---|
| 461 | dbox2, start2, i2)\
|
|---|
| 462 | {\
|
|---|
| 463 | int hypre__i1start = hypre_BoxIndexRank(dbox1, start1);\
|
|---|
| 464 | int hypre__i2start = hypre_BoxIndexRank(dbox2, start2);\
|
|---|
| 465 | hypre_BoxLoopDeclareS(dbox1, stride1, hypre__sx1, hypre__sy1, hypre__sz1);\
|
|---|
| 466 | hypre_BoxLoopDeclareS(dbox2, stride1, hypre__sx2, hypre__sy2, hypre__sz2);\
|
|---|
| 467 | hypre_BoxLoopDeclareN(loop_size);
|
|---|
| 468 |
|
|---|
| 469 | #define hypre_BoxLoop2For_OneStride(i, j, k, i1, i2)\
|
|---|
| 470 | for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\
|
|---|
| 471 | {\
|
|---|
| 472 | hypre_BoxLoopSet(i, j, k);\
|
|---|
| 473 | i1 = hypre__i1start + i*hypre__sx1 + j*hypre__sy1 + k*hypre__sz1;\
|
|---|
| 474 | i2 = hypre__i2start + i*hypre__sx2 + j*hypre__sy2 + k*hypre__sz2;\
|
|---|
| 475 | for (k = 0; k < hypre__nz; k++)\
|
|---|
| 476 | {\
|
|---|
| 477 | for (j = 0; j < hypre__ny; j++)\
|
|---|
| 478 | {\
|
|---|
| 479 | hypre_UserOutsideInnerLoop;\
|
|---|
| 480 | for ( i=0; i<hypre__nx*hypre__sx1; i+=hypre__sx1 )\
|
|---|
| 481 | {
|
|---|
| 482 |
|
|---|
| 483 | #define hypre_BoxLoop2End_OneStride(i1, i2)\
|
|---|
| 484 | }\
|
|---|
| 485 | i1 += hypre__sy1;\
|
|---|
| 486 | i2 += hypre__sy2;\
|
|---|
| 487 | }\
|
|---|
| 488 | i1 += hypre__sz1 - hypre__ny*hypre__sy1;\
|
|---|
| 489 | i2 += hypre__sz2 - hypre__ny*hypre__sy2;\
|
|---|
| 490 | }\
|
|---|
| 491 | }\
|
|---|
| 492 | }
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 | /*-----------------------------------*/
|
|---|
| 498 |
|
|---|
| 499 | #define hypre_BoxLoop3Begin(loop_size,\
|
|---|
| 500 | dbox1, start1, stride1, i1,\
|
|---|
| 501 | dbox2, start2, stride2, i2,\
|
|---|
| 502 | dbox3, start3, stride3, i3)\
|
|---|
| 503 | {\
|
|---|
| 504 | int hypre__i1start = hypre_BoxIndexRank(dbox1, start1);\
|
|---|
| 505 | int hypre__i2start = hypre_BoxIndexRank(dbox2, start2);\
|
|---|
| 506 | int hypre__i3start = hypre_BoxIndexRank(dbox3, start3);\
|
|---|
| 507 | hypre_BoxLoopDeclareS(dbox1, stride1, hypre__sx1, hypre__sy1, hypre__sz1);\
|
|---|
| 508 | hypre_BoxLoopDeclareS(dbox2, stride2, hypre__sx2, hypre__sy2, hypre__sz2);\
|
|---|
| 509 | hypre_BoxLoopDeclareS(dbox3, stride3, hypre__sx3, hypre__sy3, hypre__sz3);\
|
|---|
| 510 | hypre_BoxLoopDeclareN(loop_size);
|
|---|
| 511 |
|
|---|
| 512 | #define hypre_BoxLoop3For(i, j, k, i1, i2, i3)\
|
|---|
| 513 | for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\
|
|---|
| 514 | {\
|
|---|
| 515 | hypre_BoxLoopSet(i, j, k);\
|
|---|
| 516 | i1 = hypre__i1start + i*hypre__sx1 + j*hypre__sy1 + k*hypre__sz1;\
|
|---|
| 517 | i2 = hypre__i2start + i*hypre__sx2 + j*hypre__sy2 + k*hypre__sz2;\
|
|---|
| 518 | i3 = hypre__i3start + i*hypre__sx3 + j*hypre__sy3 + k*hypre__sz3;\
|
|---|
| 519 | for (k = 0; k < hypre__nz; k++)\
|
|---|
| 520 | {\
|
|---|
| 521 | for (j = 0; j < hypre__ny; j++)\
|
|---|
| 522 | {\
|
|---|
| 523 | for (i = 0; i < hypre__nx; i++)\
|
|---|
| 524 | {
|
|---|
| 525 |
|
|---|
| 526 | #define hypre_BoxLoop3End(i1, i2, i3)\
|
|---|
| 527 | i1 += hypre__sx1;\
|
|---|
| 528 | i2 += hypre__sx2;\
|
|---|
| 529 | i3 += hypre__sx3;\
|
|---|
| 530 | }\
|
|---|
| 531 | i1 += hypre__sy1 - hypre__nx*hypre__sx1;\
|
|---|
| 532 | i2 += hypre__sy2 - hypre__nx*hypre__sx2;\
|
|---|
| 533 | i3 += hypre__sy3 - hypre__nx*hypre__sx3;\
|
|---|
| 534 | }\
|
|---|
| 535 | i1 += hypre__sz1 - hypre__ny*hypre__sy1;\
|
|---|
| 536 | i2 += hypre__sz2 - hypre__ny*hypre__sy2;\
|
|---|
| 537 | i3 += hypre__sz3 - hypre__ny*hypre__sy3;\
|
|---|
| 538 | }\
|
|---|
| 539 | }\
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 | /*-----------------------------------*/
|
|---|
| 543 |
|
|---|
| 544 | #define hypre_BoxLoop4Begin(loop_size,\
|
|---|
| 545 | dbox1, start1, stride1, i1,\
|
|---|
| 546 | dbox2, start2, stride2, i2,\
|
|---|
| 547 | dbox3, start3, stride3, i3,\
|
|---|
| 548 | dbox4, start4, stride4, i4)\
|
|---|
| 549 | {\
|
|---|
| 550 | int hypre__i1start = hypre_BoxIndexRank(dbox1, start1);\
|
|---|
| 551 | int hypre__i2start = hypre_BoxIndexRank(dbox2, start2);\
|
|---|
| 552 | int hypre__i3start = hypre_BoxIndexRank(dbox3, start3);\
|
|---|
| 553 | int hypre__i4start = hypre_BoxIndexRank(dbox4, start4);\
|
|---|
| 554 | hypre_BoxLoopDeclareS(dbox1, stride1, hypre__sx1, hypre__sy1, hypre__sz1);\
|
|---|
| 555 | hypre_BoxLoopDeclareS(dbox2, stride2, hypre__sx2, hypre__sy2, hypre__sz2);\
|
|---|
| 556 | hypre_BoxLoopDeclareS(dbox3, stride3, hypre__sx3, hypre__sy3, hypre__sz3);\
|
|---|
| 557 | hypre_BoxLoopDeclareS(dbox4, stride4, hypre__sx4, hypre__sy4, hypre__sz4);\
|
|---|
| 558 | hypre_BoxLoopDeclareN(loop_size);
|
|---|
| 559 |
|
|---|
| 560 | #define hypre_BoxLoop4For(i, j, k, i1, i2, i3, i4)\
|
|---|
| 561 | for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\
|
|---|
| 562 | {\
|
|---|
| 563 | hypre_BoxLoopSet(i, j, k);\
|
|---|
| 564 | i1 = hypre__i1start + i*hypre__sx1 + j*hypre__sy1 + k*hypre__sz1;\
|
|---|
| 565 | i2 = hypre__i2start + i*hypre__sx2 + j*hypre__sy2 + k*hypre__sz2;\
|
|---|
| 566 | i3 = hypre__i3start + i*hypre__sx3 + j*hypre__sy3 + k*hypre__sz3;\
|
|---|
| 567 | i4 = hypre__i4start + i*hypre__sx4 + j*hypre__sy4 + k*hypre__sz4;\
|
|---|
| 568 | for (k = 0; k < hypre__nz; k++)\
|
|---|
| 569 | {\
|
|---|
| 570 | for (j = 0; j < hypre__ny; j++)\
|
|---|
| 571 | {\
|
|---|
| 572 | for (i = 0; i < hypre__nx; i++)\
|
|---|
| 573 | {
|
|---|
| 574 |
|
|---|
| 575 | #define hypre_BoxLoop4End(i1, i2, i3, i4)\
|
|---|
| 576 | i1 += hypre__sx1;\
|
|---|
| 577 | i2 += hypre__sx2;\
|
|---|
| 578 | i3 += hypre__sx3;\
|
|---|
| 579 | i4 += hypre__sx4;\
|
|---|
| 580 | }\
|
|---|
| 581 | i1 += hypre__sy1 - hypre__nx*hypre__sx1;\
|
|---|
| 582 | i2 += hypre__sy2 - hypre__nx*hypre__sx2;\
|
|---|
| 583 | i3 += hypre__sy3 - hypre__nx*hypre__sx3;\
|
|---|
| 584 | i4 += hypre__sy4 - hypre__nx*hypre__sx4;\
|
|---|
| 585 | }\
|
|---|
| 586 | i1 += hypre__sz1 - hypre__ny*hypre__sy1;\
|
|---|
| 587 | i2 += hypre__sz2 - hypre__ny*hypre__sy2;\
|
|---|
| 588 | i3 += hypre__sz3 - hypre__ny*hypre__sy3;\
|
|---|
| 589 | i4 += hypre__sz4 - hypre__ny*hypre__sy4;\
|
|---|
| 590 | }\
|
|---|
| 591 | }\
|
|---|
| 592 | }
|
|---|
| 593 |
|
|---|
| 594 | /*-----------------------------------*/
|
|---|
| 595 |
|
|---|
| 596 | #endif /* ifndef HYPRE_USE_PTHREADS */
|
|---|
| 597 |
|
|---|
| 598 | #endif
|
|---|