Skip to content

Resizing multi-dimensional DiffCaches #140

Description

@ranocha

We use some multi-dimensional caches in Trixi.jl that we have to resize! for some operations. Since Julia only supports to resize! vectors, we construct the plain storage as vectors and unsafe_wrap them in multi-dimensional arrays, e.g.,

# create multi-dimensional cache
_cache = zeros(10)
cache = unsafe_wrap(Array, pointer(_cache), (2, 5))

# resize it
resize!(_cache, 12)
cache = unsafe_wrap(Array, pointer(_cache), (2, 6))

To use the same pattern with DiffCaches, we have to use knowledge about the interval structure of them at the moment, e.g.,

# create multi-dimensional cache
_cache = DiffCache(zeros(10))
s = (2, 5)
cache = DiffCache(unsafe_wrap(Array, pointer(_cache.du), s),
                  unsafe_wrap(Array, pointer(_cache.dual_du), s),
                  Any[])

# resize it
resize!(_cache, 12)
s = (2, 6)
cache = DiffCache(unsafe_wrap(Array, pointer(_cache.du), s),
                  unsafe_wrap(Array, pointer(_cache.dual_du), s),
                  Any[])
  • Can we assume that this is safe to do?
  • If not, can we add something to the public API of PreallocationTools.jl that allows us to obtain multi-dimensional DiffCaches that can be resize!d like this without allocating a lot of memory every time?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions