CUDA Fortran - Dynamic Allocation Structure

Hi everyone,
I have a doubt about how to allocate arrays in a structure.

Type node_type
real, dimension(3) :: coord

End type

Type RBC_type

type(node_type), allocatable, dimension(:) :: node
End type

And then in the main I have

type(RBC_type), DEVICE, allocatable, dimension(:) :: RBC

Then, when I have to allocate the structure, I do the following:


and it seems to work.

But when I try to allocate the node:

do i = 1, N
end do

I can compile, but when running I get this error: Segmentation fault (core dumped).
I am allocating everything on the host side. Could you help me with this?

Thank you.

That’s the problem. RBC is a device allocatable so accessing RBC(i) will cause a seg fault on the host since it’s not a host address.

Better to move the device attribute to “node” and then only use “node” within device code. Or make “node” a fixed size array so it doesn’t need to be allocated.