Skip to content

Commit 5076e82

Browse files
MarcelKochfritzgoebelthoasm
committed
review updates:
- add documentation on empty dim - fix documentation of return type - rename `is_in_box` -> `is_in_range` Co-authored-by: Fritz Goebel <[email protected]> Co-authored-by: Thomas Grützmacher <[email protected]>
1 parent d68cb37 commit 5076e82

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

benchmark/utils/generator.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ struct DefaultSystemGenerator {
2929
auto [data, size] = [&] {
3030
if (config.contains("filename")) {
3131
std::ifstream in(config["filename"].get<std::string>());
32+
// Returning an empty dim means that there is no specified local
33+
// size, which is relevant in the distributed case
3234
return std::make_pair(
3335
gko::read_generic_raw<ValueType, IndexType>(in),
3436
gko::dim<2>());
@@ -179,6 +181,8 @@ struct DistributedDefaultSystemGenerator {
179181
auto [data, local_size] = [&] {
180182
if (config.contains("filename")) {
181183
std::ifstream in(config["filename"].get<std::string>());
184+
// Returning an empty dim means that no local size is specified,
185+
// and thus the partition has to be deduced from the global size
182186
return std::make_pair(
183187
gko::read_generic_raw<value_type, index_type>(in),
184188
gko::dim<2>());
@@ -262,8 +266,6 @@ struct DistributedDefaultSystemGenerator {
262266

263267
auto dist_mat = dist_mtx<etype, itype, global_itype>::create(
264268
exec, comm, local_mat, non_local_mat);
265-
gko::matrix_data<value_type, index_type> global_data(
266-
{part->get_size(), part->get_size()});
267269
dist_mat->read_distributed(data, part);
268270

269271
if (spmv_case) {

benchmark/utils/stencil_matrix.hpp

+23-30
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ double closest_nth_root(T v, int n)
3434
* @return True if i in [0, bound).
3535
*/
3636
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)
3838
{
3939
return 0 <= i && i < bound;
4040
}
@@ -57,10 +57,11 @@ bool is_in_box(const IndexType i, const IndexType bound)
5757
* dimension.
5858
* @param target_local_size The desired size of the subdomains. The actual size
5959
* can deviate from this to accommodate the square
60-
* size of the subdomains.
60+
* size of the global domain.
6161
* @param restricted If true, a 5-pt stencil is used, else a 9-pt stencil.
6262
*
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.
6465
*/
6566
template <typename ValueType, typename IndexType>
6667
std::pair<gko::matrix_data<ValueType, IndexType>, gko::dim<2>>
@@ -101,8 +102,8 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
101102
/**
102103
* The offset of a subdomain in a single dimension. Since the first R
103104
* 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
106107
*/
107108
auto subdomain_offset_1d = [&](const IndexType dim, const IndexType i) {
108109
assert(0 <= i && i < dims[dim]);
@@ -142,7 +143,7 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
142143
*/
143144
auto target_position = [&](const IndexType dim, const IndexType i,
144145
const int position) {
145-
return is_in_box(i, discretization_points[dim])
146+
return is_in_range(i, discretization_points[dim])
146147
? position
147148
: (i < 0 ? position - 1 : position + 1);
148149
};
@@ -156,7 +157,7 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
156157
*/
157158
auto target_local_idx = [&](const IndexType dim, const IndexType pos,
158159
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))
160161
? i
161162
: (i < 0 ? i + subdomain_size_1d(dim, pos)
162163
: i - subdomain_size_1d(dim, positions[dim]));
@@ -171,7 +172,7 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
171172
auto flat_idx = [&](const IndexType iy, const IndexType ix) {
172173
auto tpx = target_position(0, ix, positions[0]);
173174
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])) {
175176
return subdomain_offset(tpy, tpx) + target_local_idx(0, tpx, ix) +
176177
target_local_idx(1, tpy, iy) * subdomain_size_1d(0, tpx);
177178
} else {
@@ -213,8 +214,8 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
213214
for (IndexType dx : {-1, 0, 1}) {
214215
if (is_valid_neighbor(dy, dx)) {
215216
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))) {
218219
if (col != row) {
219220
A_data.nonzeros.emplace_back(
220221
row, col, -gko::one<ValueType>());
@@ -237,15 +238,6 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
237238
* Generates matrix data for a 3D stencil matrix. If restricted is set to true,
238239
* creates a 7-pt stencil, if it is false creates a 27-pt stencil.
239240
*
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-
*
249241
* If `dim != [1 1 1]` then the matrix data is a subset of a larger matrix.
250242
* The total matrix is a discretization of `[0, 1]^3`, and each subdomain has
251243
* (roughly) the shape
@@ -261,10 +253,11 @@ generate_2d_stencil_subdomain(std::array<int, 2> dims,
261253
* dimension.
262254
* @param target_local_size The desired size of the subdomains. The actual size
263255
* can deviate from this to accommodate the uniform
264-
* size of the subdomains.
256+
* size of the global domain.
265257
* @param restricted If true, a 7-pt stencil is used, else a 27-pt stencil.
266258
*
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.
268261
*/
269262
template <typename ValueType, typename IndexType>
270263
std::pair<gko::matrix_data<ValueType, IndexType>, gko::dim<2>>
@@ -307,8 +300,8 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
307300
/**
308301
* The offset of a subdomain in a single dimension. Since the first R
309302
* 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
312305
*/
313306
auto subdomain_offset_1d = [&](const IndexType dim, const IndexType i) {
314307
assert(0 <= i && i < dims[dim]);
@@ -356,7 +349,7 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
356349
*/
357350
auto target_position = [&](const IndexType dim, const IndexType i,
358351
const int position) {
359-
return is_in_box(i, discretization_points[dim])
352+
return is_in_range(i, discretization_points[dim])
360353
? position
361354
: (i < 0 ? position - 1 : position + 1);
362355
};
@@ -370,7 +363,7 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
370363
*/
371364
auto target_local_idx = [&](const IndexType dim, const IndexType pos,
372365
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))
374367
? i
375368
: (i < 0 ? i + subdomain_size_1d(dim, pos)
376369
: i - subdomain_size_1d(dim, positions[dim]));
@@ -387,8 +380,8 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
387380
auto tpx = target_position(0, ix, positions[0]);
388381
auto tpy = target_position(1, iy, positions[1]);
389382
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])) {
392385
return subdomain_offset(tpz, tpy, tpx) +
393386
target_local_idx(0, tpx, ix) +
394387
target_local_idx(1, tpy, iy) * subdomain_size_1d(0, tpx) +
@@ -438,8 +431,8 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
438431
for (IndexType dx : {-1, 0, 1}) {
439432
if (is_valid_neighbor(dz, dy, dx)) {
440433
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))) {
443436
if (col != row) {
444437
A_data.nonzeros.emplace_back(
445438
row, col, -gko::one<ValueType>());
@@ -469,7 +462,7 @@ generate_3d_stencil_subdomain(std::array<int, 3> dims,
469462
* @param target_local_size The desired size of the matrix. The actual size can
470463
* deviate from this to accommodate the uniform size
471464
* of the discretization.
472-
* @return matrix data using the requested stencil.
465+
* @return pair of (matrix data, local size) using the requested stencil.
473466
*/
474467
template <typename ValueType, typename IndexType>
475468
std::pair<gko::matrix_data<ValueType, IndexType>, gko::dim<2>> generate_stencil(

0 commit comments

Comments
 (0)