# Input data for main simulation with ParallelStencil.jl

**URL:** <https://discourse.julialang.org/t/input-data-for-main-simulation-with-parallelstencil-jl/105385>\
**Category:** GPU\
**Tags:** input-output\
**Created:** [October 25, 2023, 4:06pm UTC](https://discourse.julialang.org/t/input-data-for-main-simulation-with-parallelstencil-jl/105385 "2023-10-25T16:06:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chloisu](https://avatars.discourse-cdn.com/v4/letter/c/3ab097/32.png) [@chloisu](https://discourse.julialang.org/u/chloisu)\
**Post date:** [October 25, 2023, 4:06pm UTC](https://discourse.julialang.org/t/input-data-for-main-simulation-with-parallelstencil-jl/105385/1 "2023-10-25T16:06:18Z")

</div>

Hello,

I have a question regarding the use of ParallelStencil.jl. I would like to initialize a simulation or load a previous solution and assign these input fields like temperature or so to the ParallelStencil Arrays before solving further in time.

Once the fields are correctly, loaded, I would like to move to the time loop where I don’t intend to have any input only an output for saving the solution.

Below is a small script that shows what I’m trying to do. This works fine with USE\_GPU = false (i.e. cpu) but doesn’t work with USE\_GPU = true.

How can I load fields into the main simulation loop from outside?

Thank you very much in advance and best regards,

```julia
const USE_GPU = true
using ParallelStencil
using ParallelStencil.FiniteDifferences2D
@static if USE_GPU
    @init_parallel_stencil(CUDA, Float64, 2)
else
    @init_parallel_stencil(Threads, Float64, 2)
end

using Plots, Printf, Statistics, LinearAlgebra

function simulation(input_data, nx, ny)
    # initialize simulation with input data
    T = @zeros(nx, ny)
    T .= input_data
    # time loop 
    print("I reached the time loop")
end

function load_old_data(filename)
    # load data

    # for simplicity, just created an array to return
    input_data = zeros(10, 10)
    return input_data
end

filename = "..."
input_data = load_old_data(filename)
simulation(input_data, size(input_data, 1), size(input_data, 2))

```

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [October 25, 2023, 5:06pm UTC](https://discourse.julialang.org/t/input-data-for-main-simulation-with-parallelstencil-jl/105385/2 "2023-10-25T17:06:25Z")

</div>

Can you try something like

```julia
# initialize simulation with input data
T .= Data.Array(input_data)

```

---

<div class="post-metadata">

**Author:** ![chloisu](https://avatars.discourse-cdn.com/v4/letter/c/3ab097/32.png) [@chloisu](https://discourse.julialang.org/u/chloisu)\
**Post date:** [October 25, 2023, 6:02pm UTC](https://discourse.julialang.org/t/input-data-for-main-simulation-with-parallelstencil-jl/105385/3 "2023-10-25T18:02:48Z")

</div>

Thank you very much for the fast reply! That answered my question 🙂

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [October 25, 2023, 7:38pm UTC](https://discourse.julialang.org/t/input-data-for-main-simulation-with-parallelstencil-jl/105385/4 "2023-10-25T19:38:16Z")

</div>

My pleasure !

I hope that we can publish soon a simple 3D wave simulation package based on ParallelStencil.jl and ImplicitGlobalGrid.jl.  
I think that it adds some pedagogical value to the docs of the PS.jl and IGG.jl showing how to use them in a more practical context (like your original question).
