# Parallelizing interpolation? (BoundsError)

**URL:** <https://discourse.julialang.org/t/parallelizing-interpolation-boundserror/56221>\
**Category:** Performance\
**Tags:** parallel, interpolations\
**Created:** [March 1, 2021, 1:27am UTC](https://discourse.julialang.org/t/parallelizing-interpolation-boundserror/56221 "2021-03-01T01:27:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![taeukseo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/taeukseo/32/21819_2.png) [@taeukseo](https://discourse.julialang.org/u/taeukseo)\
**Post date:** [March 1, 2021, 1:27am UTC](https://discourse.julialang.org/t/parallelizing-interpolation-boundserror/56221/1 "2021-03-01T01:27:19Z")

</div>

Hi, I am new to Julia and I have been trying to use `Interpolations.jl` to obtain interpolated values for grids. At some point, the number of points became quite large and I felt I should try to parallelize the code but have been unsuccessful ☹

I was wondering if it is possible send interpolated objects to multiple processes, and obtain interpolated values? I have attached a small attempt here, which resulted in `BoundsError`.

```julia
@everywhere using Interpolations

using Distributed

using SharedArrays

# two variables, not necessarily evenly spaced

x = [1,2,3,4,5]

y = [2,4,6,8,10]

nodes = (x,y)

# some known values for (x,y)

V = randn(5,5)

itp = interpolate(nodes, V, Gridded(Linear()));

# inputs, interior of (x,y)

x2 = collect(range(1.1,4.9,length = 1000));

y2 = collect(range(2.1,9.9,length = 1000));

z = SharedArray{Float64}(1000)

@distributed for i = 1:1000

    z[i] = itp(x2[i], y2[i]);

end

#= Error Message

Task (failed) @0x00000000157370f0

BoundsError: attempt to access 5×5 interpolate((::Array{Int64,1},::Array{Int64,1}), ::Array{Float64,2}, Gridded(Linear())) with element type Float64 at index [5, 1]

throw_boundserror(::Interpolations.GriddedInterpolation{Float64,2,Float64,Gridded{Linear},Tuple{Array{Int64,1},Array{Int64,1}}}, ::Tuple{Int64,Int64}) at .\abstractarray.jl:541

=#

```

I would really appreciate any advice!! Thank you in advance. 🙂

---

<div class="post-metadata">

**Author:** ![taeukseo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/taeukseo/32/21819_2.png) [@taeukseo](https://discourse.julialang.org/u/taeukseo)\
**Post date:** [March 1, 2021, 5:09am UTC](https://discourse.julialang.org/t/parallelizing-interpolation-boundserror/56221/2 "2021-03-01T05:09:25Z")

</div>

After some research, I realized that `GridInterpolations.jl` can offer good performance in the context of the above example.

```julia
using Distributed
using SharedArrays
@everywhere using GridInterpolations

# two variables, not necessarily evenly spaced
x = [1,2,3,4,5]
y = [2,4,6,8,10]

V = randn(5,5)
V = V[:]

grid = RectangleGrid(x,y)

NN = 10000000
# inputs, interior of (x,y)
x2 = collect(range(1.1,4.9,length = NN));
y2 = collect(range(2.1,9.9,length = NN));

XX = hcat(x2,y2);

zz = SharedArray{Float64}(NN)

@sync @distributed for i = 1:NN
    zz[i] = interpolate(grid,V,XX[i,:])
end

```

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [March 1, 2021, 5:18am UTC](https://discourse.julialang.org/t/parallelizing-interpolation-boundserror/56221/3 "2021-03-01T05:18:31Z")

</div>

nice sleuthing
