@@ -438,6 +438,10 @@ function do_longrange!(
438438 # Copy point data to the cache (possibly on a GPU).
439439 @assert pointdata_cpu != = pointdata # they are different objects
440440 GC. @preserve pointdata begin # see docs for KA.copyto! (it shouldn't really be needed here)
441+ # Resize output arrays
442+ noutputs = length(pointdata_cpu. nodes)
443+ foreach(v -> resize_no_copy!(v, noutputs), outputs)
444+
441445 @timeit to " Copy point charges (host -> device)" begin
442446 # Only copy fields needed for long-range computations
443447 copy_host_to_device!(pointdata. nodes, pointdata_cpu. nodes)
@@ -491,6 +495,10 @@ function do_shortrange!(cache::ShortRangeCache, outputs::NamedTuple, pointdata_c
491495
492496 @timeit to " Short-range component (async)" begin
493497 GC. @preserve pointdata begin # see docs for KA.copyto! (it shouldn't really be needed here)
498+ # Resize output arrays
499+ noutputs = length(pointdata_cpu. nodes)
500+ foreach(v -> resize_no_copy!(v, noutputs), outputs) # resize output arrays
501+
494502 if LIA === Val(true ) || LIA === Val(:only)
495503 @timeit to " Copy point charges (host -> device)" begin
496504 # For now, only copy what we need for local term
@@ -543,15 +551,13 @@ function _compute_on_nodes!(
543551 # TODO : skip unneeded quantities if LIA === Val(:only) or LIA === Val(false)
544552 @timeit to " Add point charges" add_point_charges!(pointdata, fs, params) # done on the CPU
545553
546- noutputs = sum(length, fs) # total number of interpolation points
547554 channel = Channel{Symbol}(2 ) # 2 is the length of the channel (for :shortrange + :longrange)
548555 tasks = Task[]
549556
550557 if with_longrange
551558 let cache = cache. longrange
552559 # Select elements of outputs with the same names as in `fields` (in this case :velocity and/or :streamfunction).
553560 local outputs = NamedTuple{keys(fields)}(cache. outputs)
554- foreach(v -> resize_no_copy!(v, noutputs), outputs) # resize output arrays
555561 # Compute long-range part asynchronously (e.g. on a GPU).
556562 local task = Threads. @spawn :interactive try
557563 do_longrange!(cache, outputs, pointdata; callback_vorticity)
@@ -567,7 +573,6 @@ function _compute_on_nodes!(
567573 let cache = cache. shortrange
568574 # Select elements of outputs with the same names as in `fields` (in this case :velocity and/or :streamfunction).
569575 local outputs = NamedTuple{keys(fields)}(cache. outputs)
570- foreach(v -> resize_no_copy!(v, noutputs), outputs) # resize output arrays
571576 # Compute short-range part asynchronously (e.g. on a GPU).
572577 local task = Threads. @spawn :interactive try
573578 do_shortrange!(cache, outputs, pointdata; LIA)
0 commit comments