diff --git a/Project.toml b/Project.toml index 33f56db..0871c2c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "HauntedArrays" uuid = "88ea1a40-65ed-4bf4-98f2-fb8783b28482" authors = ["bmxam "] -version = "0.1.2" +version = "0.1.3" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/Array.jl b/src/Array.jl index 9d4d200..6239575 100644 --- a/src/Array.jl +++ b/src/Array.jl @@ -98,6 +98,8 @@ Build a view of the parent array, with the elements that are owned by the curren """ @inline owned_values(A::HauntedArray) = view(parent(A), _own_to_local_ndims(A)...) +@inline set_owned_values(A::HauntedArray, B::AbstractArray) = owned_values(A) .= B + """ Transform a `Vector` index into a Vector of nd-CartesianIndices (assuming same length in all Array direction) diff --git a/src/HauntedArrays.jl b/src/HauntedArrays.jl index cb25eb4..f3f0b55 100644 --- a/src/HauntedArrays.jl +++ b/src/HauntedArrays.jl @@ -24,7 +24,8 @@ export HauntedArray, local_to_global, local_to_part, n_local_rows, - n_own_rows + n_own_rows, + set_owned_values include("./interface.jl") include("./collective.jl") diff --git a/src/algebra.jl b/src/algebra.jl index 2948adf..c7b60bd 100644 --- a/src/algebra.jl +++ b/src/algebra.jl @@ -23,6 +23,14 @@ function LinearAlgebra.mul!( C end +function LinearAlgebra.norm2(A::HauntedVector) + # MPI.Allreduce(LinearAlgebra.norm2(owned_values(A)), +, get_comm(A)) + √(mapreduce(abs2, +, A)) +end +function LinearAlgebra.dot(A::HauntedVector, B::HauntedVector) + MPI.Allreduce(LinearAlgebra.dot(owned_values(A), owned_values(B)), +, get_comm(A)) +end + for f in (:+, :-) @eval function (Base.$f)(A::HauntedArray, B::HauntedArray) _C = $f(parent(A), parent(B)) diff --git a/src/interface.jl b/src/interface.jl index fb39420..74d007b 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -88,3 +88,10 @@ function Base.view(A::HauntedVector, I::AbstractVector) return HauntedArray(array, exchanger, lid2gid, lid2part, oid2lid, cacheType) end + +# Usefull in case of wrapped sparse matrix. Maybe it would more clever to specialize +# directly Base.eachindex? +function Base.fill!(A::HauntedArray, x) + fill!(parent(A), x) + return A +end \ No newline at end of file