@@ -34,7 +34,7 @@ double closest_nth_root(T v, int n)
34
34
* @return True if i in [0, bound).
35
35
*/
36
36
template <typename IndexType>
37
- bool is_in_box (const IndexType i, const IndexType bound)
37
+ bool is_in_range (const IndexType i, const IndexType bound)
38
38
{
39
39
return 0 <= i && i < bound;
40
40
}
@@ -57,10 +57,11 @@ bool is_in_box(const IndexType i, const IndexType bound)
57
57
* dimension.
58
58
* @param target_local_size The desired size of the subdomains. The actual size
59
59
* can deviate from this to accommodate the square
60
- * size of the subdomains .
60
+ * size of the global domain .
61
61
* @param restricted If true, a 5-pt stencil is used, else a 9-pt stencil.
62
62
*
63
- * @return matrix data of a subdomain using either 5-pt or 9-pt stencil.
63
+ * @return pair of (matrix data, local size) of a subdomain using either 5-pt
64
+ * or 9-pt stencil.
64
65
*/
65
66
template <typename ValueType, typename IndexType>
66
67
std::pair<gko::matrix_data<ValueType, IndexType>, gko::dim<2 >>
@@ -101,8 +102,8 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
101
102
/* *
102
103
* The offset of a subdomain in a single dimension. Since the first R
103
104
* processes have a subdomain size of discretization_points_min[dim]+1, the
104
- * offset adds min(subdomain-id , R) to
105
- * discretization_points_min[dim]*subdomain-id
105
+ * offset adds min(subdomain_id , R) to
106
+ * discretization_points_min[dim]*subdomain_id
106
107
*/
107
108
auto subdomain_offset_1d = [&](const IndexType dim, const IndexType i) {
108
109
assert (0 <= i && i < dims[dim]);
@@ -142,7 +143,7 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
142
143
*/
143
144
auto target_position = [&](const IndexType dim, const IndexType i,
144
145
const int position) {
145
- return is_in_box (i, discretization_points[dim])
146
+ return is_in_range (i, discretization_points[dim])
146
147
? position
147
148
: (i < 0 ? position - 1 : position + 1 );
148
149
};
@@ -156,7 +157,7 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
156
157
*/
157
158
auto target_local_idx = [&](const IndexType dim, const IndexType pos,
158
159
const IndexType i) {
159
- return is_in_box (i, subdomain_size_1d (dim, pos))
160
+ return is_in_range (i, subdomain_size_1d (dim, pos))
160
161
? i
161
162
: (i < 0 ? i + subdomain_size_1d (dim, pos)
162
163
: i - subdomain_size_1d (dim, positions[dim]));
@@ -171,7 +172,7 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
171
172
auto flat_idx = [&](const IndexType iy, const IndexType ix) {
172
173
auto tpx = target_position (0 , ix, positions[0 ]);
173
174
auto tpy = target_position (1 , iy, positions[1 ]);
174
- if (is_in_box (tpx, dims[0 ]) && is_in_box (tpy, dims[1 ])) {
175
+ if (is_in_range (tpx, dims[0 ]) && is_in_range (tpy, dims[1 ])) {
175
176
return subdomain_offset (tpy, tpx) + target_local_idx (0 , tpx, ix) +
176
177
target_local_idx (1 , tpy, iy) * subdomain_size_1d (0 , tpx);
177
178
} else {
@@ -213,8 +214,8 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
213
214
for (IndexType dx : {-1 , 0 , 1 }) {
214
215
if (is_valid_neighbor (dy, dx)) {
215
216
auto col = flat_idx (iy + dy, ix + dx);
216
- if (is_in_box (col,
217
- static_cast <IndexType>(global_size))) {
217
+ if (is_in_range (col,
218
+ static_cast <IndexType>(global_size))) {
218
219
if (col != row) {
219
220
A_data.nonzeros .emplace_back (
220
221
row, col, -gko::one<ValueType>());
@@ -237,15 +238,6 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
237
238
* Generates matrix data for a 3D stencil matrix. If restricted is set to true,
238
239
* creates a 7-pt stencil, if it is false creates a 27-pt stencil.
239
240
*
240
- *
241
- * If `dim != [1 1]` then the matrix data is a subset of a larger matrix.
242
- * The total matrix is a discretization of `[0, 1]^2`, and each subdomain has
243
- * (roughly) the shape `[global_size_1d / dims[0]; global_size_1d / dims[1]]`.
244
- * The position of the subdomain defines the subset of the matrix.
245
- * The degrees of freedom are ordered subdomain-wise and the subdomains
246
- * themselves are ordered lexicographical. This means that the indices are with
247
- * respect to the larger matrix, i.e. they might not start with 0.
248
- *
249
241
* If `dim != [1 1 1]` then the matrix data is a subset of a larger matrix.
250
242
* The total matrix is a discretization of `[0, 1]^3`, and each subdomain has
251
243
* (roughly) the shape
@@ -261,10 +253,11 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
261
253
* dimension.
262
254
* @param target_local_size The desired size of the subdomains. The actual size
263
255
* can deviate from this to accommodate the uniform
264
- * size of the subdomains .
256
+ * size of the global domain .
265
257
* @param restricted If true, a 7-pt stencil is used, else a 27-pt stencil.
266
258
*
267
- * @return matrix data of a subdomain using either 7-pt or 27-pt stencil.
259
+ * @return pair of (matrix data, local size) of a subdomain using either 7-pt
260
+ * or 27-pt stencil.
268
261
*/
269
262
template <typename ValueType, typename IndexType>
270
263
std::pair<gko::matrix_data<ValueType, IndexType>, gko::dim<2 >>
@@ -307,8 +300,8 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
307
300
/* *
308
301
* The offset of a subdomain in a single dimension. Since the first R
309
302
* processes have a subdomain size of discretization_points_min[dim]+1, the
310
- * offset adds min(subdomain-id , R) to
311
- * discretization_points_min[dim]*subdomain-id
303
+ * offset adds min(subdomain_id , R) to
304
+ * discretization_points_min[dim]*subdomain_id
312
305
*/
313
306
auto subdomain_offset_1d = [&](const IndexType dim, const IndexType i) {
314
307
assert (0 <= i && i < dims[dim]);
@@ -356,7 +349,7 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
356
349
*/
357
350
auto target_position = [&](const IndexType dim, const IndexType i,
358
351
const int position) {
359
- return is_in_box (i, discretization_points[dim])
352
+ return is_in_range (i, discretization_points[dim])
360
353
? position
361
354
: (i < 0 ? position - 1 : position + 1 );
362
355
};
@@ -370,7 +363,7 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
370
363
*/
371
364
auto target_local_idx = [&](const IndexType dim, const IndexType pos,
372
365
const IndexType i) {
373
- return is_in_box (i, subdomain_size_1d (dim, pos))
366
+ return is_in_range (i, subdomain_size_1d (dim, pos))
374
367
? i
375
368
: (i < 0 ? i + subdomain_size_1d (dim, pos)
376
369
: i - subdomain_size_1d (dim, positions[dim]));
@@ -387,8 +380,8 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
387
380
auto tpx = target_position (0 , ix, positions[0 ]);
388
381
auto tpy = target_position (1 , iy, positions[1 ]);
389
382
auto tpz = target_position (2 , iz, positions[2 ]);
390
- if (is_in_box (tpx, dims[0 ]) && is_in_box (tpy, dims[1 ]) &&
391
- is_in_box (tpz, dims[2 ])) {
383
+ if (is_in_range (tpx, dims[0 ]) && is_in_range (tpy, dims[1 ]) &&
384
+ is_in_range (tpz, dims[2 ])) {
392
385
return subdomain_offset (tpz, tpy, tpx) +
393
386
target_local_idx (0 , tpx, ix) +
394
387
target_local_idx (1 , tpy, iy) * subdomain_size_1d (0 , tpx) +
@@ -438,8 +431,8 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
438
431
for (IndexType dx : {-1 , 0 , 1 }) {
439
432
if (is_valid_neighbor (dz, dy, dx)) {
440
433
auto col = flat_idx (iz + dz, iy + dy, ix + dx);
441
- if (is_in_box (col, static_cast <IndexType>(
442
- global_size))) {
434
+ if (is_in_range (col, static_cast <IndexType>(
435
+ global_size))) {
443
436
if (col != row) {
444
437
A_data.nonzeros .emplace_back (
445
438
row, col, -gko::one<ValueType>());
@@ -469,7 +462,7 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
469
462
* @param target_local_size The desired size of the matrix. The actual size can
470
463
* deviate from this to accommodate the uniform size
471
464
* of the discretization.
472
- * @return matrix data using the requested stencil.
465
+ * @return pair of ( matrix data, local size) using the requested stencil.
473
466
*/
474
467
template <typename ValueType, typename IndexType>
475
468
std::pair<gko::matrix_data<ValueType, IndexType>, gko::dim<2 >> generate_stencil (
0 commit comments