How to access field values in ParallelStencil.jl custom struct

I am trying to use a custom struct with ParallelStencil.jl. I define the custom struct as

@CellType Field2D fieldnames=(xx, yy, zz)

Then I initialize it for 2 variables as

F1 =  @zeros( nx, ny, celltype=Field2D)
F2 = @zeros( nx, ny, celltype=Field2D)

Finally I would like to use its fields in a computation kernel as

@parallel_indices (ix, iy) function Evolve!(F1, F2)
    F1.xx [ix, iy] = F2.yy[ix, iy] - F2.zz[ix, iy] 

However, the last step fails. I am assuming i do not know the right way to access the field value of F1 and F2 variables. If so, can someone please point the correct way to access field values?

Or am I completely mistaken about the use case of @CellType macro and define a variable for each component separately?

There is currently an issue with this which I’m working on. It already works on CPU if you use the main branch of CellArrays (] add CellArrays#main) - for GPU some work in CUDA.jl is required it seems:

julia> using ParallelStencil

julia> @init_parallel_stencil(package=Threads, numbertype=Float64)

julia> @CellType Field2D fieldnames=(xx, yy, zz)

julia> nx = ny = 2
2

julia> F1 = @zeros(nx, ny, celltype=Field2D)
2×2 CellArrays.CPUCellArray{Field2D, 2, 1, Float64}:
 [0.0, 0.0, 0.0]  [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]  [0.0, 0.0, 0.0]

julia> F2 = @rand(nx, ny, celltype=Field2D)
2×2 CellArrays.CPUCellArray{Field2D, 2, 1, Float64}:
 [0.326463, 0.451149, 0.802571]   [0.280195, 0.0683425, 0.166727]
 [0.239031, 0.230775, 0.0981809]  [0.636965, 0.886454, 0.62971]

julia> @parallel_indices (ix, iy) function evolve!(F1, F2)
           F1.xx[ix, iy] = F2.yy[ix, iy] - F2.zz[ix, iy]
           return
       end
evolve! (generic function with 1 method)

julia> @parallel evolve!(F1, F2)

julia> F1
2×2 CellArrays.CPUCellArray{Field2D, 2, 1, Float64}:
 [-0.351422, 0.0, 0.0]  [-0.0983844, 0.0, 0.0]
 [0.132594, 0.0, 0.0]   [0.256745, 0.0, 0.0]

I will try to fix it as soon as possible for GPU.

3 Likes

Thanks! looking forward to the new functionality.

Kudos for writing the awesome package!

1 Like