| 53 | |
| 54 | template <typename Sch, typename F, typename Proj = std::identity> |
| 55 | void test(Sch &&sch, F sum, Proj proj = {}) { |
| 56 | // |
| 57 | |
| 58 | std::span<int> oops; |
| 59 | |
| 60 | // Empty cases |
| 61 | REQUIRE(lf::sync_wait(sch, lf::fold, oops, sum, proj) == std::nullopt); |
| 62 | REQUIRE(lf::sync_wait(sch, lf::fold, oops.begin(), oops.end(), sum, proj) == std::nullopt); |
| 63 | REQUIRE(lf::sync_wait(sch, lf::fold, oops, 10, sum, proj) == std::nullopt); |
| 64 | REQUIRE(lf::sync_wait(sch, lf::fold, oops.begin(), oops.end(), 10, sum, proj) == std::nullopt); |
| 65 | |
| 66 | std::vector<int> v; |
| 67 | |
| 68 | constexpr int n = 10'000; |
| 69 | |
| 70 | for (auto i = 1; i <= n; i++) { |
| 71 | v.push_back(i); |
| 72 | } |
| 73 | |
| 74 | constexpr int correct = n * (n + 1) / 2; |
| 75 | |
| 76 | // Check grain = 1 case: |
| 77 | REQUIRE(lf::sync_wait(sch, lf::fold, v, sum, proj) == correct); |
| 78 | REQUIRE(lf::sync_wait(sch, lf::fold, v.begin(), v.end(), sum, proj) == correct); |
| 79 | REQUIRE(lf::sync_wait(sch, lf::fold, v, sum, doubler(proj)) == 2 * correct); |
| 80 | REQUIRE(lf::sync_wait(sch, lf::fold, v.begin(), v.end(), sum, doubler(proj)) == 2 * correct); |
| 81 | |
| 82 | for (auto m : {100, 300, 20'000}) { |
| 83 | REQUIRE(lf::sync_wait(sch, lf::fold, v, m, sum, proj) == correct); |
| 84 | REQUIRE(lf::sync_wait(sch, lf::fold, v.begin(), v.end(), m, sum, proj) == correct); |
| 85 | REQUIRE(lf::sync_wait(sch, lf::fold, v, m, sum, doubler(proj)) == 2 * correct); |
| 86 | REQUIRE(lf::sync_wait(sch, lf::fold, v.begin(), v.end(), m, sum, doubler(proj)) == 2 * correct); |
| 87 | } |
| 88 | |
| 89 | #ifndef _MSC_VER |
| 90 | |
| 91 | // ----------- Now with small inputs ----------- // |
| 92 | |
| 93 | REQUIRE(lf::sync_wait(sch, fold, std::span(v.data(), 4), sum, proj) == 4 * (4 + 1) / 2); |
| 94 | REQUIRE(lf::sync_wait(sch, fold, std::span(v.data(), 3), sum, proj) == 3 * (3 + 1) / 2); |
| 95 | REQUIRE(lf::sync_wait(sch, fold, std::span(v.data(), 2), sum, proj) == 2 * (2 + 1) / 2); |
| 96 | REQUIRE(lf::sync_wait(sch, fold, std::span(v.data(), 1), sum, proj) == 1 * (1 + 1) / 2); |
| 97 | |
| 98 | #endif |
| 99 | } |
| 100 | |
| 101 | constexpr auto sum_reg = std::plus<>{}; |
| 102 | |