Skip to content

copyto!(::Field, ::Field) performance is 2x slower than parent array #1403

Closed
@charleskawczynski

Description

@charleskawczynski

MWE:

using Revise
import ClimaCore;
import ClimaCore.Fields as Fields
@isdefined(TU) || include(joinpath(pkgdir(ClimaCore), "test", "TestUtilities", "TestUtilities.jl"));
import .TestUtilities as TU;
FT = Float64;
space = TU.CenterExtrudedFiniteDifferenceSpace(FT;zelem=100, helem=25); # requires adding helem to kwarg.
Base.@kwdef struct BigStruct{T}
    x1::T = 0
    x2::T = 0
end;
function copy_arr!(x, y)
    Base.copyto!(x, y)
    return nothing
end;
function copy_arr_parent!(x, y)
    Base.copyto!(parent(x), parent(y))
    return nothing
end;
using BenchmarkTools;
x = fill((;s=BigStruct{FT}()), space);
y = fill((;s=BigStruct{FT}()), space);
trial = BenchmarkTools.@benchmark copy_arr!($x, $y);
show(stdout, MIME("text/plain"), trial);
trial = BenchmarkTools.@benchmark copy_arr_parent!($x, $y);
show(stdout, MIME("text/plain"), trial);
nothing

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions