Skip to content

Fix threaded FastBroadcast for VectorOfArray#565

Merged
ChrisRackauckas merged 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:fix-threaded-voa-broadcast
Apr 4, 2026
Merged

Fix threaded FastBroadcast for VectorOfArray#565
ChrisRackauckas merged 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:fix-threaded-voa-broadcast

Conversation

@ChrisRackauckas-Claude
Copy link
Copy Markdown
Contributor

Summary

  • Fixes Multithreading with RecursiveArrayTools.VectorOfArray is broken #564: @.. thread=true on VectorOfArray{SArray} was applying the operation once per thread (each thread iterated the full array) instead of partitioning work
  • Adds Threaded dispatch for AbstractVectorOfSArray using Threads.@threads to correctly parallelize over inner arrays
  • Adds Threaded fallback for general AbstractVectorOfArray that delegates to Serial (the generic view-based splitting doesn't work for VectorOfArray)
  • Adds regression test

Root cause

FastBroadcast's generic fast_materialize_threaded! (from the Polyester extension) splits work along the last axis using view, then calls fast_materialize!(Serial(), view(dst, ...), view(bc, ...)) per chunk. For VectorOfArray, these views don't correctly partition the underlying u storage, so each thread ends up broadcasting over the entire array.

Test plan

  • Verified the exact MRE from the issue now produces [2.0, 2.0] instead of [3.0, 3.0] with 2 threads
  • Tested with 4 threads on larger arrays
  • Verified serial path still works
  • Verified non-SArray VectorOfArray fallback works correctly
  • Full Pkg.test() passes (131→133 in interface tests)

🤖 Generated with Claude Code

The generic threaded path in FastBroadcast splits work along the last
axis via views, which does not correctly partition VectorOfArray —
each thread ended up operating on the full array. Add Threaded dispatch
methods that iterate over inner arrays directly using Threads.@threads
for SArray VectorOfArrays, and fall back to Serial for other types.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ChrisRackauckas ChrisRackauckas merged commit 3b56aa8 into SciML:master Apr 4, 2026
33 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multithreading with RecursiveArrayTools.VectorOfArray is broken

2 participants