# GPU memory layout for custom type with different array lengths: StructArrays?

**URL:** <https://discourse.julialang.org/t/gpu-memory-layout-for-custom-type-with-different-array-lengths-structarrays/24479>\
**Category:** GPU\
**Tags:** question\
**Created:** [May 22, 2019, 3:04pm UTC](https://discourse.julialang.org/t/gpu-memory-layout-for-custom-type-with-different-array-lengths-structarrays/24479 "2019-05-22T15:04:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [May 22, 2019, 3:04pm UTC](https://discourse.julialang.org/t/gpu-memory-layout-for-custom-type-with-different-array-lengths-structarrays/24479/1 "2019-05-22T15:04:34Z")

</div>

I have the following example of a structure for a data type (real type has more fields):

```julia
mutable struct Worker
    id :: Int # name
    T :: Int # number of periods observed
    t :: Int # current period
    w :: Vector{Float64} # vector of wages in each period
end

```

where the data is such that `T` is potentially different for each `Worker`. The computational task involves evaluation of a likelihood function, and it is an operation that is conceptually similar to summing over `w` for each worker in an array `W` of `Worker`, and then summing the result for each worker:

```julia
julia> typeof(W)  
Array{Worker}

result = sum( sum( worker.w ) for worker in W )

```

Given that `w` is of different length for each worker, I cannot store the `w` data in a rectangular `N,T = size(W)` matrix, which would make it easier to parallelize the workload. In short, I have a list `W` and differently-long lasting computational tasks for each. Assume the list is long, like several million elements (`Worker`s).

I would like to offload the computational task (`sum(w)`) to a GPU. I have been looking around and found the [StructArrays](https://github.com/piever/StructArrays.jl) package. From the last section of the readme I seem to gather that this could handle a non-standard datastructure like this one, but I’m not sure it’s the best solution. Any advice on this greatly appreciated!
