@geastack/compiler 1.0.35 → 1.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/compiler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.36",
|
|
4
4
|
"description": "The geastack TypeScript-to-C++ compiler: one semantic spine, no source-shaped authority, no boxing of statically typed values.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -5785,6 +5785,43 @@ inline void tasks(Count count, const Body& body) {
|
|
|
5785
5785
|
detail::parallel::runRegion(total, run);
|
|
5786
5786
|
}
|
|
5787
5787
|
|
|
5788
|
+
/**
|
|
5789
|
+
* `tabulate(length, body)` of `@geastack/parallel/native`: the array whose
|
|
5790
|
+
* element `index` is `body(index)`. The result is sized once, before the
|
|
5791
|
+
* region, and every task stores its own contiguous run of elements straight
|
|
5792
|
+
* into it. A parallel `map` built on `tasks` instead filled an array per leaf
|
|
5793
|
+
* and concatenated them on the joining thread afterwards; with forty short
|
|
5794
|
+
* maps in a row that serial gap outlasted the workers' spin, so every region
|
|
5795
|
+
* paid to wake them again (spectral-norm at 20 threads: 27 ms against Rayon's
|
|
5796
|
+
* 18).
|
|
5797
|
+
*
|
|
5798
|
+
* Tasks own disjoint index ranges and the storage never grows, so no two
|
|
5799
|
+
* threads touch one cell. The compiler certified `body` exactly as it does a
|
|
5800
|
+
* `tasks` body; the stores of what it returns are the runtime's, here. The
|
|
5801
|
+
* leaf count only schedules work: every element is computed on its own, so
|
|
5802
|
+
* no result depends on it, and the exception that escapes is the lowest
|
|
5803
|
+
* index's, as in a sequential loop.
|
|
5804
|
+
*/
|
|
5805
|
+
template <typename Count, typename Body>
|
|
5806
|
+
inline auto tabulate(Count length, const Body& body) {
|
|
5807
|
+
using Element = std::decay_t<decltype(body.callStable(0LL))>;
|
|
5808
|
+
auto out = gea::makeRef<gea::ArrayObject<Element>>();
|
|
5809
|
+
const double requested = static_cast<double>(length);
|
|
5810
|
+
if (!(requested > 0)) return out;
|
|
5811
|
+
const auto total = static_cast<std::size_t>(requested);
|
|
5812
|
+
out->cells.resize(total);
|
|
5813
|
+
gea::ArrayObject<Element>& array = *out;
|
|
5814
|
+
const std::size_t leaves = total < 1024 ? total : 1024;
|
|
5815
|
+
auto run = [&array, &body, total, leaves](std::size_t leaf) -> bool {
|
|
5816
|
+
const std::size_t end = (leaf + 1) * total / leaves;
|
|
5817
|
+
for (std::size_t index = leaf * total / leaves; index < end; ++index)
|
|
5818
|
+
array.cells[index].value = body.callStable(static_cast<long long>(index));
|
|
5819
|
+
return false;
|
|
5820
|
+
};
|
|
5821
|
+
detail::parallel::runRegion(leaves, run);
|
|
5822
|
+
return out;
|
|
5823
|
+
}
|
|
5824
|
+
|
|
5788
5825
|
} // namespace parallel
|
|
5789
5826
|
#endif
|
|
5790
5827
|
|