Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/auxiliary/vector_of_arrays.jl
2055 views
1
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
2
# Since these FMAs can increase the performance of many numerical algorithms,
3
# we need to opt-in explicitly.
4
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
5
@muladd begin
6
#! format: noindent
7
8
# Wraps a Vector of Arrays, forwards `getindex` to the underlying Vector.
9
# Implements `Adapt.adapt_structure` to allow offloading to the GPU which is
10
# not possible for a plain Vector of Arrays.
11
struct VecOfArrays{T <: AbstractArray}
12
arrays::Vector{T}
13
end
14
Base.getindex(v::VecOfArrays, i::Int) = Base.getindex(v.arrays, i)
15
Base.IndexStyle(v::VecOfArrays) = Base.IndexStyle(v.arrays)
16
Base.size(v::VecOfArrays) = Base.size(v.arrays)
17
Base.length(v::VecOfArrays) = Base.length(v.arrays)
18
Base.eltype(v::VecOfArrays{T}) where {T} = T
19
function Adapt.adapt_structure(to, v::VecOfArrays)
20
return VecOfArrays([Adapt.adapt(to, arr) for arr in v.arrays])
21
end
22
function Adapt.parent_type(::Type{<:VecOfArrays{T}}) where {T}
23
return T
24
end
25
function Adapt.unwrap_type(A::Type{<:VecOfArrays})
26
Adapt.unwrap_type(Adapt.parent_type(A))
27
end
28
function Base.convert(::Type{<:VecOfArrays}, v::Vector{<:AbstractArray})
29
VecOfArrays(v)
30
end
31
end # @muladd
32
33