diff --git a/docs/src/Changelog.md b/docs/src/Changelog.md index 63d293e9b..0216f9b33 100644 --- a/docs/src/Changelog.md +++ b/docs/src/Changelog.md @@ -41,6 +41,7 @@ When releasing a new version, move the "Unreleased" changes to a new version sec - `twist!` and `twist` on a `TensorMap`, a `DiagonalTensorMap` or their adjoints use a cached tree transformer and the index manipulation kernel instead of a loop over all fusion trees, which removes the per-subblock bookkeeping and turns a twist of a GPU tensor, diagonal or not, into a single kernel launch ([#595](https://github.com/QuantumKitHub/TensorKit.jl/issues/595)) - `foreachblock` with several tensors is type stable, which removes the dynamic dispatch on every call to it and to the factorizations that go through it +- `taskforeach` with a single worker is a plain loop without an atomic counter, which lowers the cost per subblock of single-threaded index manipulations and planar traces ## [0.17.3](https://github.com/QuantumKitHub/TensorKit.jl/compare/v0.17.2...v0.17.3) - 2026-10-30 diff --git a/src/auxiliary/auxiliary.jl b/src/auxiliary/auxiliary.jl index b46800a50..df327dc55 100644 --- a/src/auxiliary/auxiliary.jl +++ b/src/auxiliary/auxiliary.jl @@ -102,6 +102,7 @@ Apply `f(item)` (respectively `f(item, resource)`) to all elements of `items`, d The calling thread acts as the first of the workers, so at most `ntasks - 1` tasks are spawned, and none at all for a single worker. """ function taskforeach(f, items, ntasks::Integer) + ntasks == 1 && return foreach(f, items) items′ = items isa AbstractArray ? items : collect(items) n = length(items′) nworkers = min(ntasks, n) @@ -116,6 +117,7 @@ function taskforeach(f, items, ntasks::Integer) return nothing end function taskforeach(f, items, resources) + length(resources) == 1 && return foreach(Base.Fix2(f, only(resources)), items) items′ = items isa AbstractArray ? items : collect(items) n = length(items′) nworkers = min(length(resources), n)