Repository navigation
Conversation
`MPI.Buffer(data)` had a method only for `Array`, so dense arrays such as `Memory` or `FixedSizeArray` could not be used directly as buffers even though they can be converted to an `MPIPtr`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MEJYUviAUshj5fZt8LTe8A
giordano
approved these changes
Oct 13, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MPI.Buffer(data)has a method only forArray(plusRef, someSubArrays and, via extensions, GPU arrays). Since #941,Base.cconvert(MPIPtr, x)works for anyAbstractArraythroughmpi_ptr_type, so the remaining blocker for using other dense arrays directly as communication buffers isBufferitself. For example,MPI.Send(m, ...)orMPI.Allreduce!(m, +, comm)withm::Memory{Float64}or aFixedSizeArrayfrom FixedSizeArrays.jl throws aMethodError.This PR changes
Buffer(arr::Array)toBuffer(arr::DenseArray). ADenseArraystores its elements contiguously in column-major order, so sendinglength(arr)elements ofeltype(arr)is correct. Pointer conversion is unchanged and still has to be provided by the array type (mpi_ptr_typeandBase.cconvert/Base.unsafe_convert). Types that can't provide a pointer fail at theccallas before.BitArrayis aDenseArray{Bool}, but it stores packed bits, so it gets an explicitArgumentError. Before this PR,Buffer(::BitArray)was aMethodError.The existing
Buffermethods forCuArray,ROCArrayandoneArrayin the extensions are now redundant, since those areDenseArrays. I left them in place to keep this PR minimal.Motivation
Trixi.jl is replacing
unsafe_wrap(Array, pointer(v), dims)withFixedSizeArrays that wrapresize!able vectors, and some of those arrays are passed to MPI. A package extension in FixedSizeArrays.jl (JuliaArrays/FixedSizeArrays.jl#198) covers released MPI.jl v0.20.x; with this PR and #941, no extension would be needed.Tests
The new
test/test_buffer_densearray.jluses a minimalDenseArraywrapper type andMemory(on Julia ≥ 1.11). It checks theBufferfields, a ringIsend/Irecv!,Allreduce!andBcast!, and thatBitArraythrows. It runs only for the CPUArrayType.Locally (Julia 1.12.6, MPICH_jll), with
mpiexec -n 2and-n 3:MethodErrorforMPI.Buffer).test_sendrecv,test_gatherv,test_scatterv,test_allreduce,test_bcast,test_subarray,test_reduceandtest_onesidedpass.Test.detect_ambiguities(MPI)reports no ambiguities involvingBuffer.I haven't run the full suite or the GPU backends.
Opening as a draft to check whether this direction is welcome. Happy to also remove the now-redundant GPU
Buffermethods or add a NEWS/docs entry.This PR was prepared with substantial assistance from Claude Code (Anthropic's AI coding assistant). I reviewed the changes.
🤖 Generated with Claude Code
https://claude.ai/code/session_01MEJYUviAUshj5fZt8LTe8A