Input data for main simulation with ParallelStencil.jl

chloisu
Wed, 25 Oct 2023 16:06:18 +0000
GPU

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,

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))

4 posts - 2 participants