Skip to content

Commit 885f83c

Browse files
committed
Change sparse threshold in block_assign_threshold_mismatch via the serial_invoke idiom
The global (static) SparseShape<float>::threshold() must be changed consistently on all ranks -- see the note on SparseShape::threshold and the world.gop.serial_invoke pattern used in conversions/truncate.h. The test changed it with bare setter calls and restored it on the happy path only. Route every change (including the restore) through a local set_threshold helper that gop.serial_invoke's the setter, matching the documented idiom.
1 parent 06d29d0 commit 885f83c

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

tests/expressions_sparse.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,22 @@ BOOST_AUTO_TEST_CASE(block_assign_threshold_mismatch) {
4747
auto& world = *GlobalFixture::world;
4848
const float saved_threshold = Shape::threshold();
4949

50+
// The global (static) sparse threshold must be changed consistently on all
51+
// ranks; use the documented gop.serial_invoke idiom (see
52+
// SparseShape::threshold and conversions/truncate.h) rather than a bare
53+
// setter call.
54+
auto set_threshold = [&world](float t) {
55+
world.gop.serial_invoke([t] { Shape::threshold(t); });
56+
};
57+
5058
// dest: 4x2 tiles; the assigned sub-block is tiles [2,4) x [0,2).
5159
TiledRange dest_tr{{0, 2, 4, 6, 8}, {0, 3, 6}};
5260
TiledRange blk_tr{{4, 6, 8}, {0, 3, 6}}; // sub-block, lobounds preserved
5361

5462
// src (built under a LOW threshold) keeps two tiles: a small-norm one that
5563
// the destination's higher threshold will screen, and a large-norm one it
5664
// will not.
57-
Shape::threshold(1.0e-8f);
65+
set_threshold(1.0e-8f);
5866
Tensor<float> src_norms(blk_tr.tiles_range(), 0.0f);
5967
src_norms(0, 0) = 1.0e-3f; // below dest threshold -> must be dropped
6068
src_norms(1, 1) = 1.0f; // above dest threshold -> must be kept
@@ -65,7 +73,7 @@ BOOST_AUTO_TEST_CASE(block_assign_threshold_mismatch) {
6573
world.gop.fence();
6674

6775
// dest: all-ones sparse array pre-sized under a HIGHER threshold.
68-
Shape::threshold(1.0e-2f);
76+
set_threshold(1.0e-2f);
6977
TSpArrayD dest(world, dest_tr); // SparseShape(1, trange): every tile nonzero
7078
dest.fill(0.0);
7179
world.gop.fence();
@@ -81,7 +89,7 @@ BOOST_AUTO_TEST_CASE(block_assign_threshold_mismatch) {
8189
BOOST_CHECK(dest.is_zero({2, 0})); // 1e-3 < 1e-2 -> screened out
8290
BOOST_CHECK(!dest.is_zero({3, 1})); // 1.0 >= 1e-2 -> kept
8391

84-
Shape::threshold(saved_threshold); // restore global (static) threshold
92+
set_threshold(saved_threshold); // restore global (static) threshold
8593
}
8694

8795
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)