-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathBlockPartitionedArraysTests.jl
More file actions
112 lines (88 loc) · 2.34 KB
/
BlockPartitionedArraysTests.jl
File metadata and controls
112 lines (88 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using Test
using Gridap
using PartitionedArrays
using GridapDistributed
using BlockArrays
using SparseArrays
using LinearAlgebra
using GridapDistributed: BlockPArray, BlockPVector, BlockPMatrix, BlockPRange
ranks = with_debug() do distribute
distribute(LinearIndices((2,)))
end
indices = map(ranks) do r
if r == 1
own_gids = [1,2,3,4,5]
ghost_gids = [6,7]
ghost_owners = [2,2]
else
own_gids = [6,7,8,9,10]
ghost_gids = [5]
ghost_owners = [1]
end
own_idx = OwnIndices(10,r,own_gids)
ghost_idx = GhostIndices(10,ghost_gids,ghost_owners)
OwnAndGhostIndices(own_idx,ghost_idx)
end
block_range = BlockPRange([PRange(indices),PRange(indices)])
_v = PVector{OwnAndGhostVectors{Vector{Float64}}}(undef,indices)
v = BlockPArray([_v,_v],(block_range,))
fill!(v,1.0)
_m = map(CartesianIndices((2,2))) do I
i,j = I[1],I[2]
local_mats = map(ranks,indices) do r, ind
n = local_length(ind)
if i==j && r == 1
SparseMatrixCSC(n,n,Int[1,3,5,7,9,10,11,13],Int[1,2,2,3,3,4,4,5,5,6,6,7],fill(1.0,12))
elseif i==j && r == 2
SparseMatrixCSC(n,n,Int[1,2,4,6,8,10,11],Int[1,1,2,2,3,3,4,4,5,6],fill(1.0,10))
else
SparseMatrixCSC(n,n,fill(Int(1),n+1),Int[],Float64.([]))
end
end
PSparseMatrix(local_mats,indices,indices)
end;
m = BlockPArray(_m,(block_range,block_range))
x = similar(_v)
mul!(x,_m[1,1],_v)
# BlockPRange
@test blocklength(block_range) == 2
@test blocksize(block_range) == (2,)
# AbstractArray API
__v = similar(v,block_range)
__m = similar(m,(block_range,block_range))
fill!(__v,1.0)
__v = __v .+ 1.0
__v = __v .- 1.0
__v = __v .* 1.0
__v = __v ./ 1.0
# PartitionedArrays API
consistent!(__v) |> wait
t = assemble!(__v)
assemble!(__m) |> wait
fetch(t);
PartitionedArrays.to_trivial_partition(m)
partition(v)
partition(m)
local_values(v)
own_values(v)
ghost_values(v)
own_ghost_values(m)
ghost_own_values(m)
# LinearAlgebra API
fill!(v,1.0)
x = similar(v)
mul!(x,m,v)
consistent!(x) |> wait
@test dot(v,x) ≈ 36
norm(v)
copy!(x,v)
LinearAlgebra.fillstored!(__m,1.0)
__v = BlockPVector{Vector{Float64}}(undef,block_range)
#__m = BlockPMatrix{SparseMatrixCSC{Float64,Int}}(undef,block_range,block_range)
maximum(abs,v)
minimum(abs,v)
# GridapDistributed API
v_parts = local_views(v)
m_parts = local_views(m)
v_parts = local_views(v,block_range)
m_parts = local_views(m,block_range,block_range)