Getting Started

Multi-threaded matrix multiplication: matmul! and matmul

Octavian exports the functions matmul! and matmul, which provide multithreaded matrix multiplication in pure Julia.

Remember to start Julia with multiple threads with e.g. one of the following:

  • julia -t auto
  • julia -t 4
  • Set the JULIA_NUM_THREADS environment variable to 4 before starting Julia
julia> using Octavian
julia> A = [1 2 3; 4 5 6]2×3 Matrix{Int64}: 1 2 3 4 5 6
julia> B = [7 8 9 10; 11 12 13 14; 15 16 17 18]3×4 Matrix{Int64}: 7 8 9 10 11 12 13 14 15 16 17 18
julia> C = Matrix{Int}(undef, 2, 4)2×4 Matrix{Int64}: 139695872798832 139695872798960 139695872799024 139695872799152 139695872798896 139695872798728 139695872799088 139695872799216
julia> matmul!(C, A, B) # (multi-threaded) multiply A×B and store the result in C (overwriting the contents of C)2×4 Matrix{Int64}: 74 80 86 92 173 188 203 218
julia> C2×4 Matrix{Int64}: 74 80 86 92 173 188 203 218
julia> C == A * Btrue
julia> using Octavian
julia> A = [1 2 3; 4 5 6]2×3 Matrix{Int64}: 1 2 3 4 5 6
julia> B = [7 8 9 10; 11 12 13 14; 15 16 17 18]3×4 Matrix{Int64}: 7 8 9 10 11 12 13 14 15 16 17 18
julia> C = matmul(A, B) # (multi-threaded) multiply A×B and return the result2×4 Matrix{Int64}: 74 80 86 92 173 188 203 218
julia> C2×4 Matrix{Int64}: 74 80 86 92 173 188 203 218
julia> C == A * Btrue