Is it possible to write to output randomly?

I have defined a struct

typedef struct ElementRec {
float a,b,c,d,e,f,g,h;
} Element;

My first problem is whether CUDA support types like Element.

Second problem is that, if it does, can i write to output randomly, that is, the destination of output is decided in the runtime ?

output[idx mod 8 ].a = input[idx].a
output[idx mod 8 + 1].b = input[idx].b
output[idx mod 8 + 2].c = input[idx].c
output[idx mod 8 + 3].d = input[idx].e

output[idx mod 8 + 7].h = input[idx].h




yes, this kind of operation is called ‘scatter’ and is one of the common reasons to use CUDA in the first place

However, you might wish to reconsider the layout of your data structures to get good bandwidth. If memory accesses are not coalesced, it is common to get 10x lower bandwidth. I observed up to 100x deterioration in memory accesses with large stride.