Skip to content

Commit

Permalink
Merge pull request #139 from gridap/allocate-vectors
Browse files Browse the repository at this point in the history
allocate_in_range/domain for distributed types
  • Loading branch information
JordiManyer authored Dec 4, 2023
2 parents b1cdfb6 + f70e642 commit a98598e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Added missing methods `allocate_in_range` and `allocate_in_domain` for distributed types. Since PR [#139](https://github.com/gridap/GridapDistributed.jl/pull/139).

## [0.3.4] - 2023-11-24

### Added
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"
[compat]
BlockArrays = "0.16.38"
FillArrays = "0.8.4,1"
Gridap = "0.17.18"
Gridap = "0.17.21"
LinearAlgebra = "1.3"
MPI = "0.16, 0.17, 0.18, 0.19, 0.20"
PartitionedArrays = "0.3.3"
SparseArrays = "1.3"
SparseMatricesCSR = "0.6.6"
WriteVTK = "1.12.0"
julia = "1.3"
SparseArrays = "1.3"
LinearAlgebra = "1.3"

[extras]
MPIPreferences = "3da0fdf6-3ccc-4f1b-acd9-58baa6c99267"
Expand Down
20 changes: 20 additions & 0 deletions src/Algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ function Algebra.allocate_vector(::Type{<:BlockPVector{V}},ids::BlockPRange) whe
BlockPVector{V}(undef,ids)
end

function Algebra.allocate_in_range(matrix::PSparseMatrix)
V = Vector{eltype(matrix)}
allocate_in_range(PVector{V},matrix)
end

function Algebra.allocate_in_domain(matrix::PSparseMatrix)
V = Vector{eltype(matrix)}
allocate_in_domain(PVector{V},matrix)
end

function Algebra.allocate_in_range(matrix::BlockPMatrix)
V = Vector{eltype(matrix)}
allocate_in_range(BlockPVector{V},matrix)
end

function Algebra.allocate_in_domain(matrix::BlockPMatrix)
V = Vector{eltype(matrix)}
allocate_in_domain(BlockPVector{V},matrix)
end

# This might go to Gridap in the future. We keep it here for the moment.
function change_axes(a::Algebra.ArrayCounter,axes)
@notimplemented
Expand Down
10 changes: 5 additions & 5 deletions test/BlockSparseMatrixAssemblersTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module BlockSparseMatrixAssemblersTests
using Test, LinearAlgebra, BlockArrays, SparseArrays

using Gridap
using Gridap.FESpaces, Gridap.ReferenceFEs, Gridap.MultiField
using Gridap.FESpaces, Gridap.ReferenceFEs, Gridap.MultiField, Gridap.Algebra

using GridapDistributed
using PartitionedArrays
Expand All @@ -22,12 +22,12 @@ function is_same_vector(x::BlockPVector,y::PVector,Ub,U)
end

function is_same_matrix(Ab::BlockPMatrix,A::PSparseMatrix,Xb,X)
yb = mortar(map(Aii->pfill(0.0,partition(axes(Aii,1))),diag(blocks(Ab))));
xb = mortar(map(Aii->pfill(1.0,partition(axes(Aii,2))),diag(blocks(Ab))));
yb = allocate_in_range(Ab)
xb = allocate_in_domain(Ab); fill!(xb,1.0)
mul!(yb,Ab,xb)

y = pfill(0.0,partition(axes(A,1)))
x = pfill(1.0,partition(axes(A,2)))
y = allocate_in_range(A)
x = allocate_in_domain(A); fill!(x,1.0)
mul!(y,A,x)

return is_same_vector(yb,y,Xb,X)
Expand Down

0 comments on commit a98598e

Please sign in to comment.