Skip to content

One too many allocations in generated julia code #60

@jarlebring

Description

@jarlebring

At some point start_j disappeared in this code gen_code/gen_julia_code.jl and was replaced by a hard-coded 1.

    push_code!(code, "memslots=Vector{Matrix{T}}(undef,max_memslots)")
    push_code!(code, "n=size(A,1)")
    push_code!(code, "for j=1:max_memslots")
    push_code!(code, "memslots[j]=Matrix{T}(undef,n,n)", ind_lvl = 2)
    push_code!(code, "end")

This generates code with an additional allocation since the code becomes

    max_memslots=8
    memslots=Vector{Matrix{T}}(undef,max_memslots)
    n=size(A,1)
    for j=1:max_memslots
        memslots[j]=Matrix{T}(undef,n,n)
    end
    # The first slots are precomputed nodes [:A]
    memslots[1]=A # overwrite A

The first memslot should just be A which can be overwritten.

When I wanted to fix the memslots (in the previous issue) I copied that problem so the generated code looks a bit different now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions