Skip to content

Matrix-vector product with StaticArrays yields different results in each iteration of an @batch loop #156

@efaulhaber

Description

@efaulhaber

MWE:

using StaticArrays: SVector, SMatrix
using Polyester: @batch

function test()
    A = SMatrix{1, 2}(-160.12486538933146, 39.88422637822968)
    x = SVector(-1.000000018394, -1.000000013424)

    result_batch = zeros(2)
    result_serial = zeros(2)

    @batch for i in 1:2
        result = A * x
        result_batch[i] = result[1]
    end

    for i in 1:2
        result = A * x
        result_serial[i] = result[1]
    end

    @info "" result_batch.-result_serial
end

Tested on different architectures with Polyester v0.7.16:

julia> versioninfo()
Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 128 × AMD Ryzen Threadripper 3990X 64-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver2)
Threads: 32 default, 0 interactive, 16 GC (on 128 virtual cores)

julia> test()
┌ Info: 
│   result_batch .- result_serial =
│    2-element Vector{Float64}:
│     -1.4210854715202004e-14
└      0.0
julia> versioninfo()
Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 10 × Apple M2 Pro
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m2)
Threads: 6 default, 0 interactive, 3 GC (on 6 virtual cores)

julia> test()
┌ Info: 
│   result_batch .- result_serial =
│    2-element Vector{Float64}:
│     -1.4210854715202004e-14
└      0.0

Happens both with --check-bounds=auto and --check-bounds=yes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions