Skip to content

Commit 285223d

Browse files
authored
Merge pull request #158 from fverdugo/experimental
Major performance improvements
2 parents 6974826 + c53663d commit 285223d

18 files changed

+1580
-982
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.5.0] - 2024-07-26
9+
10+
### Changed
11+
12+
- `MPIArray` and `DebugArray` are now inmutable for performance reasons.
13+
14+
### Fixed
15+
16+
- Many type instabilities.
17+
- `mul!` (and also `consistent!`, `exchange!` ) allocation free for `MPIArray` (with `check-bounds=no`)
18+
19+
### Removed
20+
21+
- `OldPSparseMatrix` and related functionality.
22+
23+
### Added
24+
25+
- New method for `psparse` that accepts a sparse matrix type as first argument.
826

927
## [0.4.7] - 2024-07-18
1028

PartitionedSolvers/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9-
## [0.2.0] - Unreleased
9+
## [0.2.0] - 2025-07-26
10+
11+
### Added
12+
- Support for PartitionedArrays v0.5.
1013

1114
### Changed
1215

PartitionedSolvers/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1313
[compat]
1414

1515
IterativeSolvers = "0.9"
16-
PartitionedArrays = "0.4.4"
16+
PartitionedArrays = "0.4.4, 0.5"
1717
SparseArrays = "1"
1818
julia = "1.6"
1919

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PartitionedArrays"
22
uuid = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
33
authors = ["Francesc Verdugo <f.verdugo.rojano@vu.nl> and contributors"]
4-
version = "0.4.7"
4+
version = "0.5.0"
55

66
[deps]
77
CircularArrays = "7a955b69-7140-5f4e-a0ed-f168c5e2e749"

docs/src/reference/primitives.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ allocate_multicast
2828

2929
```@docs
3030
scan
31-
scan!
3231
```
3332

3433
## Reduction
3534

3635
```@docs
3736
reduction
38-
reduction!
3937
```
4038

4139
## Exchange

src/PartitionedArrays.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,12 @@ export assemble
132132
export consistent
133133
export repartition
134134
export repartition!
135+
export renumber
135136
export find_local_indices
136137
include("p_vector.jl")
137138

138-
export OldPSparseMatrix
139139
export SplitMatrix
140140
export PSparseMatrix
141-
export old_psparse
142141
export psparse
143142
export psparse!
144143
export split_format

src/debug_array.jl

Lines changed: 141 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ function Base.getindex(a::DebugArray,i::Int)
5858
a.items[i]
5959
end
6060
function Base.setindex!(a::DebugArray,v,i::Int)
61-
scalar_indexing_action(a)
62-
a.items[i] = v
63-
v
61+
error("DebugArray is inmutable for performance reasons")
62+
#scalar_indexing_action(a)
63+
#a.items[i] = v
64+
#v
6465
end
6566
linear_indices(a::DebugArray) = DebugArray(collect(LinearIndices(a)))
6667
cartesian_indices(a::DebugArray) = DebugArray(collect(CartesianIndices(a)))
@@ -96,21 +97,29 @@ end
9697
getany(a::DebugArray) = getany(a.items)
9798

9899
function Base.similar(a::DebugArray,::Type{T},dims::Dims) where T
99-
DebugArray(similar(a.items,T,dims))
100+
error("DebugArray is inmutable for performance reasons")
101+
#DebugArray(similar(a.items,T,dims))
100102
end
101103

102104
function Base.copyto!(b::DebugArray,a::DebugArray)
103-
copyto!(b.items,a.items)
104-
b
105+
error("DebugArray is inmutable for performance reasons")
106+
#copyto!(b.items,a.items)
107+
#b
105108
end
106109

107110
function Base.map(f,args::DebugArray...)
108111
DebugArray(map(f,map(i->i.items,args)...))
109112
end
110113

114+
function Base.foreach(f,args::DebugArray...)
115+
foreach(f,map(i->i.items,args)...)
116+
nothing
117+
end
118+
111119
function Base.map!(f,r::DebugArray,args::DebugArray...)
112-
map!(f,r.items,map(i->i.items,args)...)
113-
r
120+
error("DebugArray is inmutable for performance reasons")
121+
#map!(f,r.items,map(i->i.items,args)...)
122+
#r
114123
end
115124

116125
function Base.all(a::DebugArray)
@@ -121,42 +130,101 @@ function Base.all(p::Function,a::DebugArray)
121130
all(b)
122131
end
123132

133+
#function allocate_gather_impl(snd::DebugArray,destination)
134+
# rcv = allocate_gather_impl(snd.items,destination)
135+
# DebugArray(rcv)
136+
#end
137+
124138
function gather_impl!(
125139
rcv::DebugArray, snd::DebugArray,
126-
destination, ::Type{T}) where T
127-
gather_impl!(rcv.items,snd.items,destination,T)
140+
destination)
141+
gather_impl!(rcv.items,snd.items,destination)
128142
end
129143

130-
function gather_impl!(
131-
rcv::DebugArray, snd::DebugArray,
132-
destination, ::Type{T}) where T <: AbstractVector
133-
gather_impl!(rcv.items,snd.items,destination,T)
144+
#function setup_scatter_impl(snd::DebugArray,source)
145+
# setup_scatter_impl(snd.items,source)
146+
#end
147+
148+
function scatter_impl(snd::DebugArray,source)
149+
rcv = scatter_impl(snd.items,source)
150+
DebugArray(rcv)
151+
end
152+
153+
function scatter_impl!(rcv::DebugArray,snd::DebugArray,source,::Type{T}) where T
154+
error("In place scatter only for vectors")
155+
end
156+
157+
function scatter_impl!(rcv::DebugArray,snd::DebugArray,source,::Type{T}) where T<:AbstractVector
158+
scatter_impl!(rcv.items,snd.items,source)
159+
rcv
160+
end
161+
162+
#function setup_multicast_impl(snd::DebugArray,source)
163+
# setup_multicast_impl(snd.items,source)
164+
#end
165+
166+
function multicast_impl(snd::DebugArray,source)
167+
rcv = multicast_impl(snd.items,source)
168+
DebugArray(rcv)
134169
end
135170

136-
function scatter_impl!(
137-
rcv::DebugArray,snd::DebugArray,
138-
source,::Type{T}) where T
139-
scatter_impl!(rcv.items,snd.items,source,T)
171+
function multicast_impl!(rcv::DebugArray,snd::DebugArray,source,::Type{T}) where T
172+
error("In place multicast only for vectors")
140173
end
141174

142-
function scatter_impl!(
143-
rcv::DebugArray,snd::DebugArray,
144-
source,::Type{T}) where T<:AbstractVector
145-
scatter_impl!(rcv.items,snd.items,source,T)
175+
function multicast_impl!(rcv::DebugArray,snd::DebugArray,source,::Type{T}) where T<:AbstractVector
176+
multicast_impl!(rcv.items,snd.items,source)
177+
rcv
146178
end
147179

148-
function multicast_impl!(
149-
rcv::DebugArray,snd::DebugArray,
150-
source,::Type{T}) where T
151-
multicast_impl!(rcv.items,snd.items,source,T)
180+
#function setup_scatter_impl(op,a::DebugArray,init,type)
181+
# setup_scatter_impl(op,a.items,init,type)
182+
#end
183+
184+
function scan_impl(op,a::DebugArray,init,type)
185+
b = scan_impl(op,a.items,init,type)
186+
DebugArray(b)
152187
end
153188

154-
function multicast_impl!(
155-
rcv::DebugArray,snd::DebugArray,
156-
source,::Type{T}) where T<:AbstractVector
157-
multicast_impl!(rcv.items,snd.items,source,T)
189+
#function setup_reduction_impl(op,a::DebugArray,destination)
190+
# setup_reduction_impl(op,a.items,destination)
191+
#end
192+
193+
function reduction_impl(op,a::DebugArray,destination;kwargs...)
194+
b = reduction_impl(op,a.items,destination;kwargs...)
195+
DebugArray(b)
158196
end
159197

198+
#function gather_impl!(
199+
# rcv::DebugArray, snd::DebugArray,
200+
# destination, ::Type{T}) where T <: AbstractVector
201+
# gather_impl!(rcv.items,snd.items,destination,T)
202+
#end
203+
204+
#function scatter_impl!(
205+
# rcv::DebugArray,snd::DebugArray,
206+
# source,::Type{T}) where T
207+
# scatter_impl!(rcv.items,snd.items,source,T)
208+
#end
209+
#
210+
#function scatter_impl!(
211+
# rcv::DebugArray,snd::DebugArray,
212+
# source,::Type{T}) where T<:AbstractVector
213+
# scatter_impl!(rcv.items,snd.items,source,T)
214+
#end
215+
#
216+
#function multicast_impl!(
217+
# rcv::DebugArray,snd::DebugArray,
218+
# source,::Type{T}) where T
219+
# multicast_impl!(rcv.items,snd.items,source,T)
220+
#end
221+
#
222+
#function multicast_impl!(
223+
# rcv::DebugArray,snd::DebugArray,
224+
# source,::Type{T}) where T<:AbstractVector
225+
# multicast_impl!(rcv.items,snd.items,source,T)
226+
#end
227+
160228
Base.reduce(op,a::DebugArray;kwargs...) = reduce(op,a.items;kwargs...)
161229
Base.sum(a::DebugArray) = reduce(+,a)
162230
Base.collect(a::DebugArray) = collect(a.items)
@@ -166,29 +234,51 @@ function is_consistent(graph::ExchangeGraph{<:DebugArray})
166234
is_consistent(g)
167235
end
168236

169-
function exchange_impl!(
170-
rcv::DebugArray,
171-
snd::DebugArray,
172-
graph::ExchangeGraph{<:DebugArray},
173-
::Type{T}) where T
174-
g = ExchangeGraph(graph.snd.items,graph.rcv.items)
175-
@async begin
176-
yield() # This is to make more likely to have errors if we don't wait
177-
exchange_impl!(rcv.items,snd.items,g,T) |> wait
178-
rcv
179-
end
237+
function allocate_exchange_impl(
238+
snd::DebugArray,graph::ExchangeGraph{<:DebugArray})
239+
graph2 = ExchangeGraph(graph.snd.items,graph.rcv.items)
240+
rcv = allocate_exchange_impl(snd.items,graph2)
241+
DebugArray(rcv)
242+
end
243+
244+
function setup_exchange_impl(
245+
rcv::DebugArray,snd::DebugArray,graph::ExchangeGraph{<:DebugArray})
246+
graph2 = ExchangeGraph(graph.snd.items,graph.rcv.items)
247+
setup_exchange_impl(rcv.items,snd.items,graph2)
180248
end
181249

182250
function exchange_impl!(
183-
rcv::DebugArray,
184-
snd::DebugArray,
185-
graph::ExchangeGraph{<:DebugArray},
186-
::Type{T}) where T <: AbstractVector
187-
g = ExchangeGraph(graph.snd.items,graph.rcv.items)
188-
@async begin
189-
yield() # This is to make more likely to have errors if we don't wait
190-
exchange_impl!(rcv.items,snd.items,g,T) |> wait
191-
rcv
192-
end
251+
rcv::DebugArray,snd::DebugArray,graph::ExchangeGraph{<:DebugArray},setup)
252+
graph2 = ExchangeGraph(graph.snd.items,graph.rcv.items)
253+
exchange_impl!(rcv.items,snd.items,graph2,setup)
254+
@fake_async rcv
193255
end
194256

257+
#function exchange_impl!(
258+
# rcv::DebugArray,
259+
# snd::DebugArray,
260+
# graph::ExchangeGraph{<:DebugArray},
261+
# setup,
262+
# ::Type{T}) where T
263+
# g = ExchangeGraph(graph.snd.items,graph.rcv.items)
264+
# @fake_async begin
265+
# yield() # This is to make more likely to have errors if we don't wait
266+
# exchange_impl!(rcv.items,snd.items,g,setup,T) |> wait
267+
# rcv
268+
# end
269+
#end
270+
#
271+
#function exchange_impl!(
272+
# rcv::DebugArray,
273+
# snd::DebugArray,
274+
# graph::ExchangeGraph{<:DebugArray},
275+
# setup,
276+
# ::Type{T}) where T <: AbstractVector
277+
# g = ExchangeGraph(graph.snd.items,graph.rcv.items)
278+
# @fake_async begin
279+
# yield() # This is to make more likely to have errors if we don't wait
280+
# exchange_impl!(rcv.items,snd.items,g,setup,T) |> wait
281+
# rcv
282+
# end
283+
#end
284+

0 commit comments

Comments
 (0)