types, allocatable members, and OpenACC in Fortran

I’m trying to encapsulate my data in a structure, like so:

type MeshContainer
   real, dimension(:,:,:,:), allocatable :: data1, data2, data3
end type

Without this type of encapsulation, the number of explicitly mentioned arrays and/or indices in my code is becoming unwieldy.

I try to make that available on the device, but it seems the “%” notation is almost entirely incompatible with OpenACC at this time? Do I have that right?

Can anyone recommend an alternate method both encapsulating multiple dynamically allocatable arrays, and making them available on an accelerator?

Hi Andrew,

I try to make that available on the device, but it seems the “%” notation is almost entirely incompatible with OpenACC at this time? Do I have that right?

Currently only fixed size user defined data types (as well as structs) are allowed (i.e. no dynamically allocated members).

The OpenACC standards committee is in the process of defining how such structures can be described. It’s a very difficult issue since these structures would require a deep copy and the standards committee wants to ensure all OpenACC implementations and targets act the same way. Making things more difficult is that not all accelerators can dynamically allocate memory on the device (another requirement).

Can anyone recommend an alternate method both encapsulating multiple dynamically allocatable arrays, and making them available on an accelerator?

When used on the device, is each variable a single MeshContainer or is there an array of MeshContainers? For a single MeshContainier, you can use F90 pointers to point to each of the member arrays and then reference the pointers in the accelerator regions.

For an array of MeshContainer, then you’d need to modify the data structure, make the data arrays fixed size, or move to using CUDA Fortran where you write your own deep copy routine.

  • Mat

Thanks, Mat,

I’ve managed to get something working with pointers in the way you suggest. Deciding on how best to organize the code is going to take a bit, but at least I see some ways to use objects without excessive host/device copies.

And a general thank you for responding to my questions and others on the forums. It helps a lot having you lurking in here.

– Andrew

You’re welcome Andrew. I’m assuming you mean stackoverflow? I try to lurk around there but don’t do it often enough. I need to make it part of my daily regiment since it looks like more and more OpenACC questions are getting posted.

  • Mat